chiark / gitweb /
configure.ac: Link `-lgc' when searching for `GC_mumble' functions.
[disorder] / lib / xgetdate.c
index de1c4d3c56f1cd867e07fc1d0ef72322d73f1ace..81472f1246c87e473dc16e8f34689b69b3d291a3 100644 (file)
@@ -1,7 +1,11 @@
-/* Derived from getdate.c in glibc 2.3.6.  This is pretty much
+/** @file lib/xgetdate.c
+ * @brief Date parsing
+ *
+ * Derived from getdate.c in glibc 2.3.6.  This is pretty much
  * standard getdate() except that you supply the template in an
  * argument, rather than messing around with environment variables and
- * files.  */
+ * files.
+ */
 
 /* Convert a string representation of time to a time value.
    Copyright (C) 1997,1998,1999,2000,2001,2003 Free Software Foundation, Inc.
@@ -23,6 +27,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#define _GNU_SOURCE 1          /* to expose strptime */
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -30,6 +35,7 @@
 #include <time.h>
 
 #include "dateparse.h"
+#include "strptime.h"
 
 #define TM_YEAR_BASE 1900
 
@@ -52,7 +58,7 @@ static int check_mday (int year, int mon, int mday);
      8  invalid input specification Example: February 31 or a time is
         specified that can not be represented in a time_t (representing
        the time in seconds since 00:00:00 UTC, January 1, 1970) */
-int xgetdate_err;
+/*int xgetdate_err;*/
 
 
 /* Returns the first weekday WDAY of month MON in the year YEAR.  */
@@ -113,23 +119,23 @@ xgetdate_r (const char *string, struct tm *tp,
            const char *const *template)
 {
   const char *line;
-  size_t len;
   char *result = NULL;
   time_t timer;
   struct tm tm;
   int mday_ok = 0;
 
   line = NULL;
-  len = 0;
   while((line = *template++))
     {
       /* Do the conversion.  */
       tp->tm_year = tp->tm_mon = tp->tm_mday = tp->tm_wday = INT_MIN;
       tp->tm_hour = tp->tm_sec = tp->tm_min = INT_MIN;
       tp->tm_isdst = -1;
+#if !_WIN32
       tp->tm_gmtoff = 0;
       tp->tm_zone = NULL;
-      result = strptime (string, line, tp);
+#endif
+      result = my_strptime (string, line, tp);
       if (result && *result == '\0')
        break;
     }
@@ -139,7 +145,11 @@ xgetdate_r (const char *string, struct tm *tp,
 
   /* Get current time.  */
   time (&timer);
-  localtime_r (&timer, &tm);
+#if _WIN32
+  localtime_s(&tm, &timer);
+#else
+  localtime_r(&timer, &tm);
+#endif
 
   /* If only the weekday is given, today is assumed if the given day
      is equal to the current day and next week if it is less.  */
@@ -208,7 +218,7 @@ xgetdate_r (const char *string, struct tm *tp,
 }
 
 
-
+#if 0
 struct tm *
   xgetdate (const char *string, const char *const *template)
 {
@@ -218,9 +228,10 @@ struct tm *
 
   if (errval != 0)
     {
-      getdate_err = errval;
+      xgetdate_err = errval;
       return NULL;
     }
 
   return &tmbuf;
 }
+#endif