Mercurial > emacs
comparison src/editfns.c @ 15841:80a852988718
(set_time_zone_rule): Don't put a string literal
"TZ=..." in environ.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 08 Aug 1996 20:04:18 +0000 |
parents | 5c12b862950f |
children | 8cd4f2fd5525 |
comparison
equal
deleted
inserted
replaced
15840:1d300843f03c | 15841:80a852988718 |
---|---|
934 environbuf = environ; | 934 environbuf = environ; |
935 | 935 |
936 return Qnil; | 936 return Qnil; |
937 } | 937 } |
938 | 938 |
939 /* These two values are known to load tz files in buggy implementations. | |
940 Their values shouldn't matter in non-buggy implementations. | |
941 We don't use string literals for these strings, | |
942 since if a string in the environment is in readonly | |
943 storage, it runs afoul of bugs in SVR4 and Solaris 2.3. | |
944 See Sun bugs 1113095 and 1114114, ``Timezone routines | |
945 improperly modify environment''. */ | |
946 | |
947 static char set_time_zone_rule_tz1[] = "TZ=GMT0"; | |
948 static char set_time_zone_rule_tz2[] = "TZ=GMT1"; | |
949 | |
939 /* Set the local time zone rule to TZSTRING. | 950 /* Set the local time zone rule to TZSTRING. |
940 This allocates memory into `environ', which it is the caller's | 951 This allocates memory into `environ', which it is the caller's |
941 responsibility to free. */ | 952 responsibility to free. */ |
942 void | 953 void |
943 set_time_zone_rule (tzstring) | 954 set_time_zone_rule (tzstring) |
984 its original value, the last change is (incorrectly) ignored. | 995 its original value, the last change is (incorrectly) ignored. |
985 Also, if TZ changes twice in succession to values that do | 996 Also, if TZ changes twice in succession to values that do |
986 not load a tz file, tzset can dump core (see Sun bug#1225179). | 997 not load a tz file, tzset can dump core (see Sun bug#1225179). |
987 The following code works around these bugs. */ | 998 The following code works around these bugs. */ |
988 | 999 |
989 /* These two values are known to load tz files in buggy implementations. | |
990 Their values shouldn't matter in non-buggy implementations. */ | |
991 char *tz1 = "TZ=GMT0"; | |
992 char *tz2 = "TZ=GMT1"; | |
993 | |
994 if (tzstring) | 1000 if (tzstring) |
995 { | 1001 { |
996 /* Temporarily set TZ to a value that loads a tz file | 1002 /* Temporarily set TZ to a value that loads a tz file |
997 and that differs from tzstring. */ | 1003 and that differs from tzstring. */ |
998 char *tz = *newenv; | 1004 char *tz = *newenv; |
999 *newenv = strcmp (tzstring, tz1 + 3) == 0 ? tz2 : tz1; | 1005 *newenv = (strcmp (tzstring, set_time_zone_rule_tz1 + 3) == 0 |
1006 ? set_time_zone_rule_tz2 : set_time_zone_rule_tz1); | |
1000 tzset (); | 1007 tzset (); |
1001 *newenv = tz; | 1008 *newenv = tz; |
1002 } | 1009 } |
1003 else | 1010 else |
1004 { | 1011 { |
1005 /* The implied tzstring is unknown, so temporarily set TZ to | 1012 /* The implied tzstring is unknown, so temporarily set TZ to |
1006 two different values that each load a tz file. */ | 1013 two different values that each load a tz file. */ |
1007 *to = tz1; | 1014 *to = set_time_zone_rule_tz1; |
1008 to[1] = 0; | 1015 to[1] = 0; |
1009 tzset (); | 1016 tzset (); |
1010 *to = tz2; | 1017 *to = set_time_zone_rule_tz2; |
1011 tzset (); | 1018 tzset (); |
1012 *to = 0; | 1019 *to = 0; |
1013 } | 1020 } |
1014 | 1021 |
1015 /* Now TZ has the desired value, and tzset can be invoked safely. */ | 1022 /* Now TZ has the desired value, and tzset can be invoked safely. */ |