libexif/exif-entry.c & configure.ac: use localtime_r when available
authorDan Fandrich <dan@coneharvesters.com>
Tue, 18 Nov 2008 10:15:50 +0000 (02:15 -0800)
committerDan Fandrich <dan@coneharvesters.com>
Tue, 18 Nov 2008 10:15:50 +0000 (02:15 -0800)
to be more thread safe

ChangeLog
configure.ac
libexif/exif-entry.c

index e93b154..e15eb15 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-18  Dan Fandrich <dan@coneharvesters.com>
+
+       * libexif/exif-entry.c & configure.ac: use localtime_r when available
+         to be more thread safe
+
 2008-11-06  Dan Fandrich <dan@coneharvesters.com>
 
        * Released 0.6.17
index 265996c..3e71176 100644 (file)
@@ -164,6 +164,11 @@ GP_GETTEXT_FLAGS()
 
 
 dnl ---------------------------------------------------------------------------
+dnl Thread-safe functions
+dnl ---------------------------------------------------------------------------
+AC_CHECK_FUNCS(localtime_r)
+
+dnl ---------------------------------------------------------------------------
 dnl Compiler/Linker Options and Warnings
 dnl ---------------------------------------------------------------------------
 AM_CPPFLAGS="$AM_CPPFLAGS -I\$(top_srcdir)"
index c81137d..4a1fd1a 100644 (file)
@@ -1130,8 +1130,6 @@ exif_entry_get_value (ExifEntry *e, char *val, unsigned int maxlen)
 void
 exif_entry_initialize (ExifEntry *e, ExifTag tag)
 {
-       time_t t;
-       struct tm *tm;
        ExifRational r;
        ExifByteOrder o;
 
@@ -1334,8 +1332,17 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
        case EXIF_TAG_DATE_TIME:
        case EXIF_TAG_DATE_TIME_ORIGINAL:
        case EXIF_TAG_DATE_TIME_DIGITIZED:
+       {
+               time_t t;
+               struct tm tms;
+               struct tm *tm;
+
                t = time (NULL);
+#ifdef HAVE_LOCALTIME_R
+               tm = localtime_r (&t, &tms);
+#else
                tm = localtime (&t);
+#endif
                e->components = 20;
                e->format = EXIF_FORMAT_ASCII;
                e->size = exif_format_get_size (e->format) * e->components;
@@ -1346,6 +1353,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                          tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
                          tm->tm_hour, tm->tm_min, tm->tm_sec);
                break;
+       }
 
        /* ASCII, no default */
        case EXIF_TAG_SUB_SEC_TIME: