1 /* $NetBSD: posixver.c,v 1.1.1.1 2016/01/13 03:15:30 christos Exp $ */
2
3 /* Which POSIX version to conform to, for utilities.
4
5 Copyright (C) 2002 Free Software Foundation, Inc.
6
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Library General Public License as published
9 by the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 USA. */
21
22 /* Written by Paul Eggert. */
23
24 #if HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <limits.h>
29
30 #include <stdlib.h>
31 #if !HAVE_DECL_GETENV && !defined getenv
32 char *getenv ();
33 #endif
34
35 #if HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38 #ifndef _POSIX2_VERSION
39 # define _POSIX2_VERSION 0
40 #endif
41
42 /* The POSIX version that utilities should conform to. The default is
43 specified by the system. */
44
45 int
posix2_version(void)46 posix2_version (void)
47 {
48 long int v = _POSIX2_VERSION;
49 char const *s = getenv ("_POSIX2_VERSION");
50
51 if (s && *s)
52 {
53 char *e;
54 long int i = strtol (s, &e, 10);
55 if (! *e)
56 v = i;
57 }
58
59 return v < INT_MIN ? INT_MIN : v < INT_MAX ? v : INT_MAX;
60 }
61