[gcr/nielsdg/certificate-gdatetime: 4/6] Drop remaning uses of strptime()




commit 350453053c13bd528de53d0003c0af4444dcd0f5
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Wed Jul 6 21:50:37 2022 +0200

    Drop remaning uses of strptime()

 gck/meson.build  |  1 -
 gcr/gcr-record.c | 22 ++++++++++------------
 gcr/meson.build  |  1 -
 3 files changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/gck/meson.build b/gck/meson.build
index 8a0e87b9..a42f3651 100644
--- a/gck/meson.build
+++ b/gck/meson.build
@@ -75,7 +75,6 @@ gck_cflags = [
   '-DGCK_API_SUBJECT_TO_CHANGE',
   '-DP11_KIT_API_SUBJECT_TO_CHANGE',
   '-DPKCS11_REGISTRY_DIR="@0@"'.format(get_option('prefix') / get_option('libdir') / 'pkcs11'),
-  '-D_XOPEN_SOURCE',   # Needed for strptime()
 ]
 
 gck_symbolmap = meson.current_source_dir() / 'libgck.map'
diff --git a/gcr/gcr-record.c b/gcr/gcr-record.c
index 414396ef..e9282008 100644
--- a/gcr/gcr-record.c
+++ b/gcr/gcr-record.c
@@ -588,10 +588,11 @@ GDateTime *
 _gcr_record_get_date (GcrRecord *record,
                       guint column)
 {
-       const gchar *raw;
-       gulong result;
-       gchar *end = NULL;
-       struct tm tm;
+       const char *raw;
+       guint64 result;
+       char *end = NULL;
+       GTimeZone *tz;
+       GDateTime *ret;
 
        g_return_val_if_fail (record, NULL);
 
@@ -600,7 +601,7 @@ _gcr_record_get_date (GcrRecord *record,
                return NULL;
 
        /* Try to parse as a number */
-       result = strtoul (raw, &end, 10);
+       result = g_ascii_strtoull (raw, &end, 10);
        if (end != NULL && end[0] == '\0') {
                if (result == 0)
                        return NULL;
@@ -609,14 +610,11 @@ _gcr_record_get_date (GcrRecord *record,
        }
 
        /* Try to parse as a date */
-       memset (&tm, 0, sizeof (tm));
-       end = strptime (raw, "%Y-%m-%d", &tm);
-       if (!end || end[0]) {
-               g_debug ("invalid date value: %s", raw);
-               return NULL;
-       }
+       tz = g_time_zone_new_utc ();
+       ret = g_date_time_new_from_iso8601 (raw, tz);
+       g_time_zone_unref (tz);
 
-       return g_date_time_new_utc (tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 0, 0, 0);
+       return ret;
 }
 
 /**
diff --git a/gcr/meson.build b/gcr/meson.build
index d3f231d9..414e5c2b 100644
--- a/gcr/meson.build
+++ b/gcr/meson.build
@@ -131,7 +131,6 @@ gcr_cflags = [
   '-DGCR_API_SUBJECT_TO_CHANGE',
   '-DGCK_API_SUBJECT_TO_CHANGE',
   '-DP11_KIT_API_SUBJECT_TO_CHANGE',
-  '-D_XOPEN_SOURCE',   # Needed for strptime()
 ]
 
 gcr_symbolmap = meson.current_source_dir() / 'libgcr.map'


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]