about summary refs log tree commit diff
path: root/time/strftime.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-09-25 22:23:09 +0000
committerUlrich Drepper <drepper@redhat.com>1998-09-25 22:23:09 +0000
commite07a51b539aee5663361a60f6b3f7a5a75df52d5 (patch)
tree36fa7504f082197bfa79c8643b9ab2d9f01296d0 /time/strftime.c
parent390a4882ffd0e4092641ffdd6c0e017e41793d0c (diff)
downloadglibc-e07a51b539aee5663361a60f6b3f7a5a75df52d5.tar.gz
glibc-e07a51b539aee5663361a60f6b3f7a5a75df52d5.tar.xz
glibc-e07a51b539aee5663361a60f6b3f7a5a75df52d5.zip
Update.
	* time/strftime.c [emacs]: Define my_strftime to emacs_strftimeu.
	Define ut_argument, ut_argument_spec, and ut_argument_spec_iso to
	allow using `ut' parameter.
	[!emacs]: Define ut_argument, ut_argument_spec, and
	ut_argument_spec_iso as empty.  Define ut to 0.  Add ut_argument and
	argument_spec to prototypes and definitions.
	(my_strftime): Don't call tzset of ut != 0.
	Compute diff as 0 is ut != 0;
	[emacs]: Define new emacs_strftime function.
	Based on a patch by Paul Eggert.

1998-09-24  Paul Eggert  <eggert@twinsun.com>

	* time/strftime.c (my_strftime): When asking for the length of the
	subformatted buffer, do not limit the length to look for;
	otherwise, we have no reliable way to distinguish between the
	empty buffer and an error.

1998-09-25  Ulrich Drepper  <drepper@cygnus.com>

	* debug/catchsegv.sh: Also produce output if clone process died.
Diffstat (limited to 'time/strftime.c')
-rw-r--r--time/strftime.c113
1 files changed, 76 insertions, 37 deletions
diff --git a/time/strftime.c b/time/strftime.c
index 04d0e565df..438384caf3 100644
--- a/time/strftime.c
+++ b/time/strftime.c
@@ -374,26 +374,35 @@ static char const month_name[][10] =
 
 
 #ifdef emacs
-# define my_strftime emacs_strftime
+# define my_strftime emacs_strftimeu
+# define ut_argument , ut
+# define ut_argument_spec int ut;
+# define ut_argument_spec_iso , int ut
 #else
 # define my_strftime strftime
+# define ut_argument
+# define ut_argument_spec
+# define ut_argument_spec_iso
+/* We don't have this information in general.  */
+# define ut 0
 #endif
 
 #if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
   /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
      Work around this bug by copying *tp before it might be munged.  */
   size_t _strftime_copytm __P ((char *, size_t, const char *,
-			        const struct tm *));
+			        const struct tm * ut_argument_spec_iso));
   size_t
-  my_strftime (s, maxsize, format, tp)
+  my_strftime (s, maxsize, format, tp ut_argument)
       char *s;
       size_t maxsize;
       const char *format;
       const struct tm *tp;
+      ut_argument_spec
   {
     struct tm tmcopy;
     tmcopy = *tp;
-    return _strftime_copytm (s, maxsize, format, &tmcopy);
+    return _strftime_copytm (s, maxsize, format, &tmcopy ut_argument);
   }
 # undef my_strftime
 # define my_strftime(S, Maxsize, Format, Tp) \
@@ -408,11 +417,12 @@ static char const month_name[][10] =
    anywhere, so to determine how many characters would be
    written, use NULL for S and (size_t) UINT_MAX for MAXSIZE.  */
 size_t
-my_strftime (s, maxsize, format, tp)
+my_strftime (s, maxsize, format, tp ut_argument)
       char *s;
       size_t maxsize;
       const char *format;
       const struct tm *tp;
+      ut_argument_spec
 {
   int hour12 = tp->tm_hour;
 #ifdef _NL_CURRENT
@@ -459,11 +469,21 @@ my_strftime (s, maxsize, format, tp)
      POSIX does not require it.  Do the right thing instead.  */
   zone = (const char *) tp->tm_zone;
 #endif
-#if HAVE_TZNAME && HAVE_TZSET
-  /* POSIX.1 8.1.1 requires that whenever strftime() is called, the
-     time zone names contained in the external variable `tzname' shall
-     be set as if the tzset() function had been called.  */
-  tzset ();
+#if HAVE_TZNAME
+  if (ut)
+    {
+      if (! (zone && *zone))
+	zone = "GMT";
+    }
+  else
+    {
+      /* POSIX.1 8.1.1 requires that whenever strftime() is called, the
+	 time zone names contained in the external variable `tzname' shall
+	 be set as if the tzset() function had been called.  */
+# if HAVE_TZSET
+      tzset ();
+# endif
+    }
 #endif
 
   if (hour12 > 12)
@@ -713,9 +733,7 @@ my_strftime (s, maxsize, format, tp)
 	subformat:
 	  {
 	    char *old_start = p;
-	    size_t len = my_strftime (NULL, maxsize - i, subfmt, tp);
-	    if (len == 0 && *subfmt)
-	      return 0;
+	    size_t len = my_strftime (NULL, (size_t) -1, subfmt, tp);
 	    add (len, my_strftime (p, maxsize - i, subfmt, tp));
 
 	    if (to_uppcase)
@@ -1161,34 +1179,39 @@ my_strftime (s, maxsize, format, tp)
 #if HAVE_TM_GMTOFF
 	    diff = tp->tm_gmtoff;
 #else
-	    struct tm gtm;
-	    struct tm ltm;
-	    time_t lt;
+	    if (ut)
+	      diff = 0;
+	    else
+	      {
+		struct tm gtm;
+		struct tm ltm;
+		time_t lt;
 
-	    ltm = *tp;
-	    lt = mktime (&ltm);
+		ltm = *tp;
+		lt = mktime (&ltm);
 
-	    if (lt == (time_t) -1)
-	      {
-		/* mktime returns -1 for errors, but -1 is also a
-		   valid time_t value.  Check whether an error really
-		   occurred.  */
-		struct tm tm;
-
-		if (! localtime_r (&lt, &tm)
-		    || ((ltm.tm_sec ^ tm.tm_sec)
-			| (ltm.tm_min ^ tm.tm_min)
-			| (ltm.tm_hour ^ tm.tm_hour)
-			| (ltm.tm_mday ^ tm.tm_mday)
-			| (ltm.tm_mon ^ tm.tm_mon)
-			| (ltm.tm_year ^ tm.tm_year)))
-		  break;
-	      }
+		if (lt == (time_t) -1)
+		  {
+		    /* mktime returns -1 for errors, but -1 is also a
+		       valid time_t value.  Check whether an error really
+		       occurred.  */
+		    struct tm tm;
+
+		    if (! localtime_r (&lt, &tm)
+			|| ((ltm.tm_sec ^ tm.tm_sec)
+			    | (ltm.tm_min ^ tm.tm_min)
+			    | (ltm.tm_hour ^ tm.tm_hour)
+			    | (ltm.tm_mday ^ tm.tm_mday)
+			    | (ltm.tm_mon ^ tm.tm_mon)
+			    | (ltm.tm_year ^ tm.tm_year)))
+		      break;
+		  }
 
-	    if (! gmtime_r (&lt, &gtm))
-	      break;
+		if (! gmtime_r (&lt, &gtm))
+		  break;
 
-	    diff = tm_diff (&ltm, &gtm);
+		diff = tm_diff (&ltm, &gtm);
+	      }
 #endif
 
 	    if (diff < 0)
@@ -1225,3 +1248,19 @@ my_strftime (s, maxsize, format, tp)
     *p = '\0';
   return i;
 }
+
+
+#ifdef emacs
+/* For Emacs we have a separate interface which corresponds to the normal
+   strftime function and does not have the extra information whether the
+   TP arguments comes from a `gmtime' call or not.  */
+size_t
+emacs_strftime (s, maxsize, format, tp)
+      char *s;
+      size_t maxsize;
+      const char *format;
+      const struct tm *tp;
+{
+  return my_strftime (s, maxsize, format, tp, 0);
+}
+#endif