1171219Speter/*- 2171219Speter * Copyright (c) 2007 Peter Wemm 3171219Speter * All rights reserved. 4171219Speter * 5171219Speter * Redistribution and use in source and binary forms, with or without 6171219Speter * modification, are permitted provided that the following conditions 7171219Speter * are met: 8171219Speter * 1. Redistributions of source code must retain the above copyright 9171219Speter * notice, this list of conditions and the following disclaimer. 10171219Speter * 2. Redistributions in binary form must reproduce the above copyright 11171219Speter * notice, this list of conditions and the following disclaimer in the 12171219Speter * documentation and/or other materials provided with the distribution. 13171219Speter * 14171219Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15171219Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16171219Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17171219Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18171219Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19171219Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20171219Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21171219Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22171219Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23171219Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24171219Speter * SUCH DAMAGE. 25171219Speter */ 26171219Speter 27171219Speter#include <sys/cdefs.h> 28171219Speter__FBSDID("$FreeBSD: releng/10.2/lib/libc/gen/__getosreldate.c 211416 2010-08-17 09:13:26Z kib $"); 29171219Speter 30171219Speter#include <sys/param.h> 31171219Speter#include <sys/sysctl.h> 32211416Skib#include <errno.h> 33211416Skib#include <link.h> 34211416Skib#include "libc_private.h" 35171219Speter 36205997Sdelphijint __getosreldate(void); 37205997Sdelphij 38171219Speter/* 39171219Speter * This is private to libc. It is intended for wrapping syscall stubs in order 40171219Speter * to avoid having to put SIGSYS signal handlers in place to test for presence 41171219Speter * of new syscalls. This caches the result in order to be as quick as possible. 42171219Speter * 43171219Speter * Use getosreldate(3) for public use as it respects the $OSVERSION environment 44171219Speter * variable. 45171219Speter */ 46171219Speter 47171219Speterint 48171219Speter__getosreldate(void) 49171219Speter{ 50171219Speter static int osreldate; 51171219Speter size_t len; 52171219Speter int oid[2]; 53171219Speter int error, osrel; 54171219Speter 55171219Speter if (osreldate != 0) 56171219Speter return (osreldate); 57211416Skib 58211416Skib error = _elf_aux_info(AT_OSRELDATE, &osreldate, sizeof(osreldate)); 59211416Skib if (error == 0 && osreldate != 0) 60211416Skib return (osreldate); 61211416Skib 62171219Speter oid[0] = CTL_KERN; 63171219Speter oid[1] = KERN_OSRELDATE; 64171219Speter osrel = 0; 65171219Speter len = sizeof(osrel); 66171219Speter error = sysctl(oid, 2, &osrel, &len, NULL, 0); 67171219Speter if (error == 0 && osrel > 0 && len == sizeof(osrel)) 68171219Speter osreldate = osrel; 69171219Speter return (osreldate); 70171219Speter} 71