20
20
#include < config.h>
21
21
22
22
#ifdef __linux__
23
+ #ifndef _XOPEN_SOURCE
23
24
#define _XOPEN_SOURCE
24
25
#endif
26
+ #endif
25
27
26
28
#include < sys/stat.h>
27
29
#include < sys/types.h>
@@ -195,29 +197,29 @@ static gchar *exif_build_formatted_Camera(ExifData *exif)
195
197
(software2 && (make || model2)) ? " )" : " " );
196
198
}
197
199
198
- static gchar *exif_build_formatted_DateTime (ExifData *exif)
200
+ static gchar *exif_build_formatted_DateTime (ExifData *exif, const gchar *text_key, const gchar *subsec_key )
199
201
{
200
202
g_autofree gchar *subsec = nullptr ;
201
- gchar buf[128 ];
202
- gint buflen;
203
- struct tm tm ;
204
203
205
- gchar *text = exif_get_data_as_text (exif, " Exif.Photo.DateTimeOriginal " );
204
+ gchar *text = exif_get_data_as_text (exif, text_key );
206
205
if (text)
207
206
{
208
- subsec = exif_get_data_as_text (exif, " Exif.Photo.SubSecTimeOriginal " );
207
+ subsec = exif_get_data_as_text (exif, subsec_key );
209
208
}
210
209
else
211
210
{
212
211
text = exif_get_data_as_text (exif, " Exif.Image.DateTime" );
213
- if (text) subsec = exif_get_data_as_text (exif, " Exif.Photo.SubSecTime" );
212
+ if (!text) return nullptr ;
213
+
214
+ subsec = exif_get_data_as_text (exif, " Exif.Photo.SubSecTime" );
214
215
}
215
216
216
217
/* Convert the stuff into a tm struct */
217
- memset (& tm , 0 , sizeof ( tm )) ; /* Uh, strptime could let garbage in tm! */
218
- if (text && strptime (text, " %Y:%m:%d %H:%M:%S" , &tm ))
218
+ std:: tm tm {} ; /* Uh, strptime could let garbage in tm! */
219
+ if (strptime (text, " %Y:%m:%d %H:%M:%S" , &tm ))
219
220
{
220
- buflen = strftime (buf, sizeof (buf), " %x %X" , &tm );
221
+ gchar buf[128 ];
222
+ const gint buflen = strftime (buf, sizeof (buf), " %x %X" , &tm );
221
223
if (buflen > 0 )
222
224
{
223
225
g_autoptr (GError) error = nullptr ;
@@ -242,51 +244,14 @@ static gchar *exif_build_formatted_DateTime(ExifData *exif)
242
244
return text;
243
245
}
244
246
245
- static gchar *exif_build_formatted_DateTimeDigitized (ExifData *exif)
247
+ static gchar *exif_build_formatted_DateTime (ExifData *exif)
246
248
{
247
- g_autofree gchar *subsec = nullptr ;
248
- gchar buf[128 ];
249
- gint buflen;
250
- struct tm tm ;
251
-
252
- gchar *text = exif_get_data_as_text (exif, " Exif.Photo.DateTimeDigitized" );
253
- if (text)
254
- {
255
- subsec = exif_get_data_as_text (exif, " Exif.Photo.SubSecTimeDigitized" );
256
- }
257
- else
258
- {
259
- text = exif_get_data_as_text (exif, " Exif.Image.DateTime" );
260
- if (text) subsec = exif_get_data_as_text (exif, " Exif.Photo.SubSecTime" );
261
- }
262
-
263
- /* Convert the stuff into a tm struct */
264
- memset (&tm , 0 , sizeof (tm )); /* Uh, strptime could let garbage in tm! */
265
- if (text && strptime (text, " %Y:%m:%d %H:%M:%S" , &tm ))
266
- {
267
- buflen = strftime (buf, sizeof (buf), " %x %X" , &tm );
268
- if (buflen > 0 )
269
- {
270
- g_autoptr (GError) error = nullptr ;
271
- g_autofree gchar *tmp = g_locale_to_utf8 (buf, buflen, nullptr , nullptr , &error);
272
- if (error)
273
- {
274
- log_printf (" Error converting locale strftime to UTF-8: %s\n " , error->message );
275
- }
276
- else
277
- {
278
- std::swap (text, tmp);
279
- }
280
- }
281
- }
282
-
283
- if (subsec)
284
- {
285
- g_autofree gchar *tmp = text;
286
- text = g_strconcat (tmp, " ." , subsec, NULL );
287
- }
249
+ return exif_build_formatted_DateTime (exif, " Exif.Photo.DateTimeOriginal" , " Exif.Photo.SubSecTimeOriginal" );
250
+ }
288
251
289
- return text;
252
+ static gchar *exif_build_formatted_DateTimeDigitized (ExifData *exif)
253
+ {
254
+ return exif_build_formatted_DateTime (exif, " Exif.Photo.DateTimeDigitized" , " Exif.Photo.SubSecTimeDigitized" );
290
255
}
291
256
292
257
static gchar *exif_build_formatted_ShutterSpeed (ExifData *exif)
0 commit comments