1*9e66e6d7Sabs /* $NetBSD: catclose.c,v 1.14 2012/06/25 22:32:45 abs Exp $ */
27ce7ea94Scgd
3adfd5ba7Sjtc /*-
4adfd5ba7Sjtc * Copyright (c) 1996 The NetBSD Foundation, Inc.
5adfd5ba7Sjtc * All rights reserved.
6adfd5ba7Sjtc *
7adfd5ba7Sjtc * This code is derived from software contributed to The NetBSD Foundation
8adfd5ba7Sjtc * by J.T. Conklin.
9adfd5ba7Sjtc *
10adfd5ba7Sjtc * Redistribution and use in source and binary forms, with or without
11adfd5ba7Sjtc * modification, are permitted provided that the following conditions
12adfd5ba7Sjtc * are met:
13adfd5ba7Sjtc * 1. Redistributions of source code must retain the above copyright
14adfd5ba7Sjtc * notice, this list of conditions and the following disclaimer.
15adfd5ba7Sjtc * 2. Redistributions in binary form must reproduce the above copyright
16adfd5ba7Sjtc * notice, this list of conditions and the following disclaimer in the
17adfd5ba7Sjtc * documentation and/or other materials provided with the distribution.
18adfd5ba7Sjtc *
19adfd5ba7Sjtc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20adfd5ba7Sjtc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21adfd5ba7Sjtc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2287f4ccd4Sjtc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2387f4ccd4Sjtc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24adfd5ba7Sjtc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25adfd5ba7Sjtc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26adfd5ba7Sjtc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27adfd5ba7Sjtc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28adfd5ba7Sjtc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29adfd5ba7Sjtc * POSSIBILITY OF SUCH DAMAGE.
3056fa6d53Sjtc */
3156fa6d53Sjtc
3288c3eadbSlukem #include <sys/cdefs.h>
3388c3eadbSlukem #if defined(LIBC_SCCS) && !defined(lint)
34*9e66e6d7Sabs __RCSID("$NetBSD: catclose.c,v 1.14 2012/06/25 22:32:45 abs Exp $");
3588c3eadbSlukem #endif /* LIBC_SCCS and not lint */
3688c3eadbSlukem
37adfd5ba7Sjtc #define _NLS_PRIVATE
3856fa6d53Sjtc
394515f6e8Schristos #include "namespace.h"
40adfd5ba7Sjtc #include <sys/types.h>
41adfd5ba7Sjtc #include <sys/mman.h>
42adfd5ba7Sjtc #include <errno.h>
434515f6e8Schristos #include <stdlib.h>
4456fa6d53Sjtc #include <nl_types.h>
4556fa6d53Sjtc
469f5f4ac6Smycroft #ifdef __weak_alias
__weak_alias(catclose,_catclose)479f5f4ac6Smycroft __weak_alias(catclose, _catclose)
489f5f4ac6Smycroft #endif
499f5f4ac6Smycroft
503f10e2daSjtc int
51*9e66e6d7Sabs _catclose(nl_catd catd)
5256fa6d53Sjtc {
53adfd5ba7Sjtc if (catd == (nl_catd) -1) {
54adfd5ba7Sjtc errno = EBADF;
55adfd5ba7Sjtc return -1;
5656fa6d53Sjtc }
5756fa6d53Sjtc
58adfd5ba7Sjtc if (catd) {
5938676913Schristos munmap(catd->__data, (size_t)catd->__size);
60adfd5ba7Sjtc free (catd);
61adfd5ba7Sjtc }
62adfd5ba7Sjtc
63adfd5ba7Sjtc return 0;
64adfd5ba7Sjtc }
65