catclose.c revision 1.12
11.12Slukem/*	$NetBSD: catclose.c,v 1.12 2005/06/12 05:21:27 lukem Exp $	*/
21.4Scgd
31.7Sjtc/*-
41.7Sjtc * Copyright (c) 1996 The NetBSD Foundation, Inc.
51.7Sjtc * All rights reserved.
61.7Sjtc *
71.7Sjtc * This code is derived from software contributed to The NetBSD Foundation
81.7Sjtc * by J.T. Conklin.
91.7Sjtc *
101.7Sjtc * Redistribution and use in source and binary forms, with or without
111.7Sjtc * modification, are permitted provided that the following conditions
121.7Sjtc * are met:
131.7Sjtc * 1. Redistributions of source code must retain the above copyright
141.7Sjtc *    notice, this list of conditions and the following disclaimer.
151.7Sjtc * 2. Redistributions in binary form must reproduce the above copyright
161.7Sjtc *    notice, this list of conditions and the following disclaimer in the
171.7Sjtc *    documentation and/or other materials provided with the distribution.
181.7Sjtc * 3. All advertising materials mentioning features or use of this software
191.7Sjtc *    must display the following acknowledgement:
201.7Sjtc *        This product includes software developed by the NetBSD
211.7Sjtc *        Foundation, Inc. and its contributors.
221.7Sjtc * 4. Neither the name of The NetBSD Foundation nor the names of its
231.7Sjtc *    contributors may be used to endorse or promote products derived
241.7Sjtc *    from this software without specific prior written permission.
251.7Sjtc *
261.7Sjtc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.7Sjtc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.7Sjtc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.9Sjtc * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.9Sjtc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.7Sjtc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.7Sjtc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.7Sjtc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.7Sjtc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.7Sjtc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.7Sjtc * POSSIBILITY OF SUCH DAMAGE.
371.1Sjtc */
381.1Sjtc
391.12Slukem#include <sys/cdefs.h>
401.12Slukem#if defined(LIBC_SCCS) && !defined(lint)
411.12Slukem__RCSID("$NetBSD: catclose.c,v 1.12 2005/06/12 05:21:27 lukem Exp $");
421.12Slukem#endif /* LIBC_SCCS and not lint */
431.12Slukem
441.7Sjtc#define _NLS_PRIVATE
451.1Sjtc
461.8Schristos#include "namespace.h"
471.7Sjtc#include <sys/types.h>
481.7Sjtc#include <sys/mman.h>
491.7Sjtc#include <errno.h>
501.8Schristos#include <stdlib.h>
511.1Sjtc#include <nl_types.h>
521.11Smycroft
531.11Smycroft#ifdef __weak_alias
541.11Smycroft__weak_alias(catclose, _catclose)
551.11Smycroft#endif
561.1Sjtc
571.5Sjtcint
581.7Sjtc_catclose(catd)
591.1Sjtc	nl_catd catd;
601.1Sjtc{
611.7Sjtc	if (catd == (nl_catd) -1) {
621.7Sjtc		errno = EBADF;
631.7Sjtc		return -1;
641.7Sjtc	}
651.7Sjtc
661.7Sjtc	if (catd) {
671.10Schristos		munmap(catd->__data, (size_t)catd->__size);
681.7Sjtc		free (catd);
691.7Sjtc	}
701.7Sjtc
711.7Sjtc	return 0;
721.1Sjtc}
73