sysctlnametomib.c revision 1.3
11.3Slukem/*	$NetBSD: sysctlnametomib.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */
21.1Satatat
31.1Satatat/*-
41.1Satatat * Copyright (c) 2003,2004 The NetBSD Foundation, Inc.
51.1Satatat *	All rights reserved.
61.1Satatat *
71.1Satatat * This code is derived from software contributed to The NetBSD Foundation
81.1Satatat * by Andrew Brown.
91.1Satatat *
101.1Satatat * Redistribution and use in source and binary forms, with or without
111.1Satatat * modification, are permitted provided that the following conditions
121.1Satatat * are met:
131.1Satatat * 1. Redistributions of source code must retain the above copyright
141.1Satatat *    notice, this list of conditions and the following disclaimer.
151.1Satatat * 2. Redistributions in binary form must reproduce the above copyright
161.1Satatat *    notice, this list of conditions and the following disclaimer in the
171.1Satatat *    documentation and/or other materials provided with the distribution.
181.1Satatat * 3. Neither the name of The NetBSD Foundation nor the names of its
191.1Satatat *    contributors may be used to endorse or promote products derived
201.1Satatat *    from this software without specific prior written permission.
211.1Satatat *
221.1Satatat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
231.1Satatat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
241.1Satatat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
251.1Satatat * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
261.1Satatat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
271.1Satatat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
281.1Satatat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
291.1Satatat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
301.1Satatat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
311.1Satatat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
321.1Satatat * POSSIBILITY OF SUCH DAMAGE.
331.1Satatat */
341.1Satatat
351.3Slukem#include <sys/cdefs.h>
361.3Slukem#if defined(LIBC_SCCS) && !defined(lint)
371.3Slukem__RCSID("$NetBSD: sysctlnametomib.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");
381.3Slukem#endif /* LIBC_SCCS and not lint */
391.3Slukem
401.2Satatat#include "namespace.h"
411.1Satatat#include <sys/param.h>
421.1Satatat#include <sys/sysctl.h>
431.1Satatat
441.2Satatat#ifdef __weak_alias
451.2Satatat__weak_alias(sysctlnametomib,_sysctlnametomib)
461.2Satatat#endif
471.2Satatat
481.1Satatat/*
491.1Satatat * freebsd compatible sysctlnametomib() function, implemented as an
501.1Satatat * extremely thin wrapper around sysctlgetmibinfo().  i think the use
511.1Satatat * of size_t as the third argument is erroneous, but what can we do
521.1Satatat * about that?
531.1Satatat */
541.1Satatatint
551.1Satatatsysctlnametomib(const char *gname, int *iname, size_t *namelenp)
561.1Satatat{
571.1Satatat	u_int unamelen;
581.1Satatat	int rc;
591.1Satatat
601.1Satatat	unamelen = *namelenp;
611.1Satatat	rc = sysctlgetmibinfo(gname, iname, &unamelen, NULL, NULL, NULL,
621.1Satatat			      SYSCTL_VERSION);
631.1Satatat	*namelenp = unamelen;
641.1Satatat
651.1Satatat	return (rc);
661.1Satatat}
67