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