sysctlnametomib.c revision 1.2
11.2Satatat/* $NetBSD: sysctlnametomib.c,v 1.2 2004/04/08 05:45:26 atatat 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.2Satatat#include "namespace.h" 361.1Satatat#include <sys/param.h> 371.1Satatat#include <sys/sysctl.h> 381.1Satatat 391.2Satatat#ifdef __weak_alias 401.2Satatat__weak_alias(sysctlnametomib,_sysctlnametomib) 411.2Satatat#endif 421.2Satatat 431.1Satatat/* 441.1Satatat * freebsd compatible sysctlnametomib() function, implemented as an 451.1Satatat * extremely thin wrapper around sysctlgetmibinfo(). i think the use 461.1Satatat * of size_t as the third argument is erroneous, but what can we do 471.1Satatat * about that? 481.1Satatat */ 491.1Satatatint 501.1Satatatsysctlnametomib(const char *gname, int *iname, size_t *namelenp) 511.1Satatat{ 521.1Satatat u_int unamelen; 531.1Satatat int rc; 541.1Satatat 551.1Satatat unamelen = *namelenp; 561.1Satatat rc = sysctlgetmibinfo(gname, iname, &unamelen, NULL, NULL, NULL, 571.1Satatat SYSCTL_VERSION); 581.1Satatat *namelenp = unamelen; 591.1Satatat 601.1Satatat return (rc); 611.1Satatat} 62