[PROPOSED PATCH] port 'environ' decl to Solaris 10
POSIX says apps must declare 'environ' themselves. Although this is not necessary on GNU/Linux with _GNU_SOURCE defined, it is needed with stricter environments like Solaris 10. * date.c, zdump.c (environ): Declare even if HAVE_POSIX_DECLS. --- date.c | 3 ++- zdump.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/date.c b/date.c index 4c11f61..512d1ef 100644 --- a/date.c +++ b/date.c @@ -42,8 +42,9 @@ #define SECSPERMIN 60 #endif /* !defined SECSPERMIN */ -#if !HAVE_POSIX_DECLS extern char ** environ; + +#if !HAVE_POSIX_DECLS extern char * optarg; extern int optind; extern char * tzname[]; diff --git a/zdump.c b/zdump.c index 694b04f..f68ba3d 100644 --- a/zdump.c +++ b/zdump.c @@ -258,8 +258,9 @@ enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 }; # define timezone_t char ** #endif -#if !HAVE_POSIX_DECLS extern char ** environ; + +#if !HAVE_POSIX_DECLS extern int getopt(int argc, char * const argv[], const char * options); extern char * optarg; -- 2.7.4
On Sun, Sep 4, 2016, at 20:27, Paul Eggert wrote:
POSIX says apps must declare 'environ' themselves. Although this is not necessary on GNU/Linux with _GNU_SOURCE defined, it is needed with stricter environments like Solaris 10. * date.c, zdump.c (environ): Declare even if HAVE_POSIX_DECLS.
1. Why exactly does this code do this instead of using setenv/putenv? 2. Why mess with the environment at all instead of conditionally calling gmtime rather than localtime?
Random832 wrote:
1. Why exactly does this code do this instead of using setenv/putenv?
The code predates the standardization of setenv/putenv by POSIX. It manipulates 'environ' directly for portability to pre-POSIX platforms. If we can assume setenv the code could be simplified.
2. Why mess with the environment at all instead of conditionally calling gmtime rather than localtime?
For zdump.c, calling gmtime doesn't suffice because zdump needs arbitrary time zones, not just localtime and gmtime. For date.c, the shell command 'date -u +%Z' should output "GMT". Merely using gmtime+strftime does not suffice for that, because strftime is given a struct tm, which on some platforms does not contain a time zone abbreviation.
participants (2)
-
Paul Eggert -
Random832