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