getosreldate.c revision 331722
14Srgrimes/* 24Srgrimes * Copyright (c) 1989, 1993 34Srgrimes * The Regents of the University of California. All rights reserved. 44Srgrimes * 54Srgrimes * Redistribution and use in source and binary forms, with or without 64Srgrimes * modification, are permitted provided that the following conditions 74Srgrimes * are met: 84Srgrimes * 1. Redistributions of source code must retain the above copyright 94Srgrimes * notice, this list of conditions and the following disclaimer. 104Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 114Srgrimes * notice, this list of conditions and the following disclaimer in the 124Srgrimes * documentation and/or other materials provided with the distribution. 134Srgrimes * 4. Neither the name of the University nor the names of its contributors 144Srgrimes * may be used to endorse or promote products derived from this software 154Srgrimes * without specific prior written permission. 164Srgrimes * 174Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 184Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 194Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 204Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 214Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 224Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 234Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 244Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 254Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 264Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 274Srgrimes * SUCH DAMAGE. 284Srgrimes */ 294Srgrimes 304Srgrimes#if defined(LIBC_SCCS) && !defined(lint) 314Srgrimesstatic char sccsid[] = "@(#)gethostid.c 8.1 (Berkeley) 6/2/93"; 324Srgrimes#endif /* LIBC_SCCS and not lint */ 334Srgrimes#include <sys/cdefs.h> 344Srgrimes__FBSDID("$FreeBSD: stable/11/lib/libc/gen/getosreldate.c 331722 2018-03-29 02:50:57Z eadler $"); 354Srgrimes 364Srgrimes#include <sys/types.h> 374Srgrimes#include <sys/sysctl.h> 38620Srgrimes 3912701Sphk#include <stdlib.h> 404Srgrimes#include <unistd.h> 414Srgrimes 422056Swollmanint 4312675Sjuliangetosreldate(void) 4412675Sjulian{ 4512675Sjulian int mib[2]; 461549Srgrimes size_t size; 475764Sbde int value; 4812675Sjulian char *temp; 4912701Sphk 502056Swollman if ((temp = getenv("OSVERSION"))) { 512056Swollman value = atoi(temp); 524Srgrimes return (value); 5312701Sphk } 542056Swollman 555764Sbde mib[0] = CTL_KERN; 564Srgrimes mib[1] = KERN_OSRELDATE; 578023Sbde size = sizeof value; 588047Sbde if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) 598047Sbde return (-1); 608047Sbde return (value); 615764Sbde} 6210666Sbde