getosreldate.c revision 211416
1185573Srwatson/* 2189279Srwatson * Copyright (c) 1989, 1993 3155131Srwatson * The Regents of the University of California. All rights reserved. 4155131Srwatson * 5155131Srwatson * Redistribution and use in source and binary forms, with or without 6155131Srwatson * modification, are permitted provided that the following conditions 7155131Srwatson * are met: 8155131Srwatson * 1. Redistributions of source code must retain the above copyright 9155131Srwatson * notice, this list of conditions and the following disclaimer. 10155131Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11155131Srwatson * notice, this list of conditions and the following disclaimer in the 12155131Srwatson * documentation and/or other materials provided with the distribution. 13185573Srwatson * 4. Neither the name of the University nor the names of its contributors 14155131Srwatson * may be used to endorse or promote products derived from this software 15155131Srwatson * without specific prior written permission. 16155131Srwatson * 17155131Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18155131Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19155131Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20155131Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21155131Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22155131Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23155131Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24155131Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25155131Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26155131Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27155131Srwatson * SUCH DAMAGE. 28155131Srwatson */ 29244390Srwatson 30155131Srwatson#if defined(LIBC_SCCS) && !defined(lint) 31155131Srwatsonstatic char sccsid[] = "@(#)gethostid.c 8.1 (Berkeley) 6/2/93"; 32155131Srwatson#endif /* LIBC_SCCS and not lint */ 33155131Srwatson#include <sys/cdefs.h> 34155131Srwatson__FBSDID("$FreeBSD: head/lib/libc/gen/getosreldate.c 211416 2010-08-17 09:13:26Z kib $"); 35155131Srwatson 36155131Srwatson#include <sys/param.h> 37155131Srwatson#include <sys/sysctl.h> 38155131Srwatson#include <errno.h> 39155131Srwatson#include <stdlib.h> 40155131Srwatson 41155131Srwatson#include <osreldate.h> 42155131Srwatson 43159985Srwatsonint 44156283Srwatsongetosreldate(void) 45155518Srwatson{ 46155131Srwatson int mib[2]; 47155131Srwatson size_t size; 48155131Srwatson int value; 49155131Srwatson char *temp; 50155131Srwatson 51155131Srwatson if ((temp = getenv("OSVERSION"))) { 52155131Srwatson value = atoi(temp); 53155131Srwatson return (value); 54155131Srwatson } 55162503Srwatson 56162503Srwatson mib[0] = CTL_KERN; 57162503Srwatson mib[1] = KERN_OSRELDATE; 58162503Srwatson size = sizeof value; 59162503Srwatson if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) 60162503Srwatson return (-1); 61162503Srwatson return (value); 62162503Srwatson} 63162503Srwatson