[poppler] 5 commits - CMakeLists.txt config.h.cmake configure.ac ConfigureChecks.cmake cpp/poppler-document.cpp cpp/poppler-embedded-file.cpp cpp/poppler-global.cpp cpp/poppler-private.cpp cpp/poppler-private.h cpp/tests glib/demo glib/poppler-date.cc goo/glibc.cc goo/glibc.h goo/Makefile.am poppler/DateInfo.cc poppler/DateInfo.h poppler/Form.cc utils/pdfinfo.1 utils/pdfinfo.cc
Adrian Johnson
ajohnson at kemper.freedesktop.org
Mon Jun 6 10:38:19 UTC 2016
CMakeLists.txt | 1
ConfigureChecks.cmake | 1
config.h.cmake | 3 ++
configure.ac | 1
cpp/poppler-document.cpp | 4 ++
cpp/poppler-embedded-file.cpp | 6 ++--
cpp/poppler-global.cpp | 6 +++-
cpp/poppler-private.cpp | 25 -----------------
cpp/poppler-private.h | 3 --
cpp/tests/poppler-dump.cpp | 5 ---
glib/demo/utils.c | 6 ----
glib/poppler-date.cc | 33 ++++-------------------
goo/Makefile.am | 3 +-
goo/glibc.cc | 58 +++++++++++++++++++++++++++++++++++++++++
goo/glibc.h | 37 ++++++++++++++++++++++++++
poppler/DateInfo.cc | 59 ++++++++++++++++++++++--------------------
poppler/DateInfo.h | 6 +++-
poppler/Form.cc | 2 -
utils/pdfinfo.1 | 3 ++
utils/pdfinfo.cc | 47 +++++++++++++++++++++++++++++++--
20 files changed, 210 insertions(+), 99 deletions(-)
New commits:
commit df0779031d6ae0180024f92602bc2a680cf73dd5
Author: Jakub Kucharski <jakubkucharski97 at gmail.com>
Date: Thu May 19 16:11:04 2016 +0200
cpp: switched from detail::convert_date() to core's dateStringToTime()
diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 1c24b47..3b2c066 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009-2011, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2016 Jakub Kucharski <jakubkucharski97 at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,6 +28,7 @@
#include "poppler-toc-private.h"
#include "Catalog.h"
+#include "DateInfo.h"
#include "ErrorCodes.h"
#include "GlobalParams.h"
#include "Outline.h"
@@ -379,7 +381,7 @@ time_type document::info_date(const std::string &key) const
Object obj;
time_type result = time_type(-1);
if (info_dict->lookup(PSTR(key.c_str()), &obj)->isString()) {
- result = detail::convert_date(obj.getString()->getCString());
+ result = dateStringToTime(obj.getString());
}
obj.free();
info.free();
diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index 2c5d077..f87649c 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009-2011, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2016 Jakub Kucharski <jakubkucharski97 at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,6 +26,7 @@
#include "Stream.h"
#include "Catalog.h"
#include "FileSpec.h"
+#include "DateInfo.h"
using namespace poppler;
@@ -107,7 +109,7 @@ int embedded_file::size() const
time_type embedded_file::modification_date() const
{
GooString *goo = d->file_spec->getEmbeddedFile()->modDate();
- return goo ? detail::convert_date(goo->getCString()) : time_type(-1);
+ return goo ? dateStringToTime(goo) : time_type(-1);
}
/**
@@ -117,7 +119,7 @@ time_type embedded_file::modification_date() const
time_type embedded_file::creation_date() const
{
GooString *goo = d->file_spec->getEmbeddedFile()->createDate();
- return goo ? detail::convert_date(goo->getCString()) : time_type(-1);
+ return goo ? dateStringToTime(goo) : time_type(-1);
}
/**
diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index b99259f..db2953e 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -3,6 +3,7 @@
* Copyright (C) 2010, Hib Eris <hib at hiberis.nl>
* Copyright (C) 2014, 2015 Hans-Peter Deifel <hpdeifel at gmx.de>
* Copyright (C) 2015, Tamas Szekeres <szekerest at gmail.com>
+ * Copyright (C) 2016 Jakub Kucharski <jakubkucharski97 at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,6 +24,8 @@
#include "poppler-private.h"
+#include "DateInfo.h"
+
#include <algorithm>
#include <cerrno>
@@ -315,7 +318,8 @@ ustring ustring::from_latin1(const std::string &str)
*/
time_type poppler::convert_date(const std::string &date)
{
- return detail::convert_date(date.c_str());
+ GooString gooDateStr(date.c_str());
+ return dateStringToTime(&gooDateStr);
}
std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array)
diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp
index 3c3fe95..4362319 100644
--- a/cpp/poppler-private.cpp
+++ b/cpp/poppler-private.cpp
@@ -2,6 +2,7 @@
* Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
* Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
* Copyright (C) 2014, Hans-Peter Deifel <hpdeifel at gmx.de>
+ * Copyright (C) 2016 Jakub Kucharski <jakubkucharski97 at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,7 +21,6 @@
#include "poppler-private.h"
-#include "DateInfo.h"
#include "GooString.h"
#include "Page.h"
@@ -115,26 +115,3 @@ GooString* detail::ustring_to_unicode_GooString(const ustring &str)
GooString *goo = new GooString(&ba[0]);
return goo;
}
-
-time_type detail::convert_date(const char *date)
-{
- int year, mon, day, hour, min, sec, tzHours, tzMins;
- char tz;
-
- if (!parseDateString(date, &year, &mon, &day, &hour, &min, &sec,
- &tz, &tzHours, &tzMins)) {
- return time_type(-1);
- }
-
- struct tm time;
- time.tm_sec = sec;
- time.tm_min = min;
- time.tm_hour = hour;
- time.tm_mday = day;
- time.tm_mon = mon - 1;
- time.tm_year = year - 1900;
- time.tm_wday = -1;
- time.tm_yday = -1;
- time.tm_isdst = -1;
- return mktime(&time);
-}
diff --git a/cpp/poppler-private.h b/cpp/poppler-private.h
index 8d315c8..7d554d0 100644
--- a/cpp/poppler-private.h
+++ b/cpp/poppler-private.h
@@ -2,6 +2,7 @@
* Copyright (C) 2009, Pino Toscano <pino at kde.org>
* Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
* Copyright (C) 2014, Hans-Peter Deifel <hpdeifel at gmx.de>
+ * Copyright (C) 2016 Jakub Kucharski <jakubkucharski97 at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -50,8 +51,6 @@ ustring unicode_GooString_to_ustring(GooString *str);
ustring unicode_to_ustring(const Unicode *u, int length);
GooString* ustring_to_unicode_GooString(const ustring &str);
-time_type convert_date(const char *date);
-
}
template <typename ConstIterator>
commit ff24d677c6078c3dfb54c35541369d908314bcdb
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Wed Feb 24 20:57:37 2016 +1030
pdfinfo: add -isodates for printing dates in ISO-8601 format
diff --git a/utils/pdfinfo.1 b/utils/pdfinfo.1
index 35bf6d5..f3a60d7 100644
--- a/utils/pdfinfo.1
+++ b/utils/pdfinfo.1
@@ -105,6 +105,9 @@ file. Note that extracting text this way might be slow for big PDF files.
(Implies
.BR \-struct .)
.TP
+.B \-isodates
+Prints dates in ISO-8601 format (including the time zone).
+.TP
.B \-rawdates
Prints the raw (undecoded) date strings, directly from the PDF file.
.TP
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 413de2f..3756ad3 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -63,6 +63,7 @@
static void printInfoString(Dict *infoDict, const char *key, const char *text,
UnicodeMap *uMap);
static void printInfoDate(Dict *infoDict, const char *key, const char *text);
+static void printISODate(Dict *infoDict, const char *key, const char *text);
static void printBox(const char *text, PDFRectangle *box);
static void printStruct(const StructElement *element, unsigned indent = 0);
static void printIndent(unsigned level);
@@ -72,6 +73,7 @@ static int lastPage = 0;
static GBool printBoxes = gFalse;
static GBool printMetadata = gFalse;
static GBool printJS = gFalse;
+static GBool isoDates = gFalse;
static GBool rawDates = gFalse;
static char textEncName[128] = "";
static char ownerPassword[33] = "\001";
@@ -97,6 +99,8 @@ static const ArgDesc argDesc[] = {
"print the logical document structure (for tagged files)"},
{"-struct-text", argFlag, &printStructureText, 0,
"print text contents along with document structure (for tagged files)"},
+ {"-isodates", argFlag, &isoDates, 0,
+ "print the dates in ISO-8601 format"},
{"-rawdates", argFlag, &rawDates, 0,
"print the undecoded date strings directly from the PDF file"},
{"-enc", argString, textEncName, sizeof(textEncName),
@@ -238,7 +242,10 @@ int main(int argc, char *argv[]) {
printInfoString(info.getDict(), "Author", "Author: ", uMap);
printInfoString(info.getDict(), "Creator", "Creator: ", uMap);
printInfoString(info.getDict(), "Producer", "Producer: ", uMap);
- if (rawDates) {
+ if (isoDates) {
+ printISODate(info.getDict(), "CreationDate", "CreationDate: ");
+ printISODate(info.getDict(), "ModDate", "ModDate: ");
+ } else if (rawDates) {
printInfoString(info.getDict(), "CreationDate", "CreationDate: ",
uMap);
printInfoString(info.getDict(), "ModDate", "ModDate: ",
@@ -508,6 +515,33 @@ static void printInfoDate(Dict *infoDict, const char *key, const char *text) {
obj.free();
}
+void printISODate(Dict *infoDict, const char *key, const char *text)
+{
+ Object obj;
+ char *s;
+ int year, mon, day, hour, min, sec, tz_hour, tz_minute;
+ char tz;
+
+ if (infoDict->lookup(key, &obj)->isString()) {
+ fputs(text, stdout);
+ s = obj.getString()->getCString();
+ if ( parseDateString( s, &year, &mon, &day, &hour, &min, &sec, &tz, &tz_hour, &tz_minute ) ) {
+ fprintf(stdout, "%04d-%02d-%02dT%02d:%02d:%02d", year, mon, day, hour, min, sec);
+ if (tz_hour == 0 && tz_minute == 0) {
+ fprintf(stdout, "Z");
+ } else {
+ fprintf(stdout, "%c%02d", tz, tz_hour);
+ if (tz_minute)
+ fprintf(stdout, ":%02d", tz_minute);
+ }
+ } else {
+ fputs(s, stdout);
+ }
+ fputc('\n', stdout);
+ }
+ obj.free();
+}
+
static void printBox(const char *text, PDFRectangle *box) {
printf("%s%8.2f %8.2f %8.2f %8.2f\n",
text, box->x1, box->y1, box->x2, box->y2);
commit dd08f24f5e52c56546dfda70be483dc29e03c2e6
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Wed Feb 24 21:10:08 2016 +1030
pdfinfo: convert dates to local time zone
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 911d40b..413de2f 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -470,6 +470,7 @@ static void printInfoDate(Dict *infoDict, const char *key, const char *text) {
int year, mon, day, hour, min, sec, tz_hour, tz_minute;
char tz;
struct tm tmStruct;
+ time_t time;
char buf[256];
if (infoDict->lookup(key, &obj)->isString()) {
@@ -487,8 +488,14 @@ static void printInfoDate(Dict *infoDict, const char *key, const char *text) {
tmStruct.tm_yday = -1;
tmStruct.tm_isdst = -1;
// compute the tm_wday and tm_yday fields
- if (mktime(&tmStruct) != (time_t)-1 &&
- strftime(buf, sizeof(buf), "%c", &tmStruct)) {
+ time = timegm(&tmStruct);
+ if (time != (time_t)-1) {
+ int offset = (tz_hour*60 + tz_minute)*60;
+ if (tz == '-')
+ offset *= -1;
+ time -= offset;
+ localtime_r(&time, &tmStruct);
+ strftime(buf, sizeof(buf), "%c %Z", &tmStruct);
fputs(buf, stdout);
} else {
fputs(s, stdout);
commit e4690ee1be027dd7028e86ea6732a3f4f2680ef7
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Tue Feb 23 21:01:49 2016 +1030
glib: return date in UTC instead of local time
Bug 94173
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index d3f5732..345f29c 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -30,6 +30,7 @@ check_function_exists(ftell64 HAVE_FTELL64)
check_function_exists(pread64 HAVE_PREAD64)
check_function_exists(lseek64 HAVE_LSEEK64)
check_function_exists(gmtime_r HAVE_GMTIME_R)
+check_function_exists(timegm HAVE_TIMEGM)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
check_function_exists(localtime_r HAVE_LOCALTIME_R)
check_function_exists(popen HAVE_POPEN)
diff --git a/config.h.cmake b/config.h.cmake
index 85c6d32..7988b74 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -64,6 +64,9 @@
/* Defines if gmtime_r is available on your system */
#cmakedefine HAVE_GMTIME_R 1
+/* Defines if timegm is available on your system */
+#cmakedefine HAVE_TIMEGM 1
+
/* Define if you have the iconv() function and it works. */
#cmakedefine HAVE_ICONV 1
diff --git a/configure.ac b/configure.ac
index 8ff8ea5..e9b0687 100644
--- a/configure.ac
+++ b/configure.ac
@@ -178,6 +178,7 @@ AC_LANG_CPLUSPLUS
AC_CHECK_DECL(gettimeofday, [AC_CHECK_FUNC(gettimeofday, AC_DEFINE(HAVE_GETTIMEOFDAY, 1, [Defines if gettimeofday is available on your system]))],[],[#include <sys/time.h>])
AC_CHECK_FUNC(localtime_r, AC_DEFINE(HAVE_LOCALTIME_R, 1, [Defines if localtime_r is available on your system]))
AC_CHECK_FUNC(gmtime_r, AC_DEFINE(HAVE_GMTIME_R, 1, [Defines if gmtime_r is available on your system]))
+AC_CHECK_FUNC(timegm, AC_DEFINE(HAVE_TIMEGM, 1, [Defines if timegm is available on your system]))
AC_CHECK_FUNC(rand_r, AC_DEFINE(HAVE_RAND_R, 1, [Defines if rand_r is available on your system]))
dnl ##### Check for extra libraries needed by X. (LynxOS needs this.)
diff --git a/glib/poppler-date.cc b/glib/poppler-date.cc
index e3141c1..ad86b30 100644
--- a/glib/poppler-date.cc
+++ b/glib/poppler-date.cc
@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <goo/glibc.h>
#include <DateInfo.h>
#include "poppler-date.h"
@@ -37,32 +38,12 @@ gboolean
poppler_date_parse (const gchar *date,
time_t *timet)
{
- gint year, mon, day, hour, min, sec, tz_hour, tz_minute;
- gchar tz;
- struct tm time;
- time_t retval;
-
- /* See PDF Reference 1.3, Section 3.8.2 for PDF Date representation */
- // TODO do something with the timezone information
- if (!parseDateString (date, &year, &mon, &day, &hour, &min, &sec, &tz, &tz_hour, &tz_minute))
+ time_t t;
+ GooString dateString(date);
+ t = dateStringToTime(&dateString);
+ if (t == (time_t)-1)
return FALSE;
-
- time.tm_year = year - 1900;
- time.tm_mon = mon - 1;
- time.tm_mday = day;
- time.tm_hour = hour;
- time.tm_min = min;
- time.tm_sec = sec;
- time.tm_wday = -1;
- time.tm_yday = -1;
- time.tm_isdst = -1; /* 0 = DST off, 1 = DST on, -1 = don't know */
-
- /* compute tm_wday and tm_yday and check date */
- retval = mktime (&time);
- if (retval == (time_t) - 1)
- return FALSE;
-
- *timet = retval;
- return TRUE;
+ *timet = t;
+ return TRUE;
}
diff --git a/goo/glibc.cc b/goo/glibc.cc
index fa1c858..4968047 100644
--- a/goo/glibc.cc
+++ b/goo/glibc.cc
@@ -32,3 +32,27 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
return lt;
}
#endif
+
+#ifndef HAVE_TIMEGM
+// Get offset of local time from UTC in seconds. DST is ignored.
+static time_t getLocalTimeZoneOffset()
+{
+ time_t utc, local;
+ struct tm tm_utc;
+ time (&utc);
+ gmtime_r(&utc, &tm_utc);
+ local = mktime(&tm_utc);
+ return difftime(utc, local);
+}
+
+time_t timegm(struct tm *tm)
+{
+ tm->tm_isdst = 0;
+ time_t t = mktime(tm);
+ if (t == -1)
+ return t;
+
+ t += getLocalTimeZoneOffset();
+ return t;
+}
+#endif
diff --git a/goo/glibc.h b/goo/glibc.h
index cc156e7..49479e9 100644
--- a/goo/glibc.h
+++ b/goo/glibc.h
@@ -27,6 +27,10 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime_r(const time_t *timep, struct tm *result);
#endif
+#ifndef HAVE_TIMEGM
+time_t timegm(struct tm *tm);
+#endif
+
};
#endif // GLIBC_H
diff --git a/poppler/DateInfo.cc b/poppler/DateInfo.cc
index 99da404..791f19e 100644
--- a/poppler/DateInfo.cc
+++ b/poppler/DateInfo.cc
@@ -75,7 +75,7 @@ GBool parseDateString(const char *dateString, int *year, int *month, int *day, i
return gFalse;
}
-
+// Convert time to PDF date string
GooString *timeToDateString(time_t *timet) {
GooString *dateString;
char s[5];
@@ -115,27 +115,35 @@ GooString *timeToDateString(time_t *timet) {
return dateString;
}
-time_t pdfTimeToInteger(GooString *time_str)
-{
+// Convert PDF date string to time. Returns -1 if conversion fails.
+time_t dateStringToTime(GooString *dateString) {
int year, mon, day, hour, min, sec, tz_hour, tz_minute;
char tz;
- struct tm time_struct;
-
- if (!parseDateString (time_str->getCString(), &year,
- &mon, &day, &hour, &min, &sec, &tz, &tz_hour, &tz_minute))
- return 0;
-
- time_struct.tm_year = year - 1900;
- time_struct.tm_mon = mon - 1;
- time_struct.tm_mday = day;
- time_struct.tm_hour = hour;
- time_struct.tm_min = min;
- time_struct.tm_sec = sec;
- time_struct.tm_wday = -1;
- time_struct.tm_yday = -1;
- time_struct.tm_isdst = -1;
-
- time_t unix_time = mktime(&time_struct);
-
- return unix_time;
+ struct tm tm;
+ time_t time;
+
+ if (!parseDateString (dateString->getCString(), &year, &mon, &day, &hour, &min, &sec, &tz, &tz_hour, &tz_minute))
+ return -1;
+
+ tm.tm_year = year - 1900;
+ tm.tm_mon = mon - 1;
+ tm.tm_mday = day;
+ tm.tm_hour = hour;
+ tm.tm_min = min;
+ tm.tm_sec = sec;
+ tm.tm_wday = -1;
+ tm.tm_yday = -1;
+ tm.tm_isdst = -1; /* 0 = DST off, 1 = DST on, -1 = don't know */
+
+ /* compute tm_wday and tm_yday and check date */
+ time = timegm (&tm);
+ if (time == (time_t)-1)
+ return time;
+
+ time_t offset = (tz_hour*60 + tz_minute)*60;
+ if (tz == '-')
+ offset *= -1;
+ time -= offset;
+
+ return time;
}
diff --git a/poppler/DateInfo.h b/poppler/DateInfo.h
index 840ee5a..e411268 100644
--- a/poppler/DateInfo.h
+++ b/poppler/DateInfo.h
@@ -33,6 +33,10 @@ GBool parseDateString(const char *string, int *year, int *month, int *day, int *
* If timet is NULL, current time is used.
*/
GooString *timeToDateString(time_t *timet);
-time_t pdfTimeToInteger(GooString *time_str);
+
+/* Convert PDF date string to time.
+ * Returns -1 if conversion fails.
+ */
+time_t dateStringToTime(GooString *dateString);
#endif
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 4dd56b7..b63ea36 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -1421,7 +1421,7 @@ void FormFieldSignature::parseInfo()
sig_dict.dictLookup("M", &time_of_signing);
if (time_of_signing.isString()) {
GooString *time_str = time_of_signing.getString();
- signature_info->setSigningTime(pdfTimeToInteger(time_str)); // Put this information directly in SignatureInfo object
+ signature_info->setSigningTime(dateStringToTime(time_str)); // Put this information directly in SignatureInfo object
time_of_signing.free();
}
commit 7936af2eeb8f84993acabd1b306da50d49256b31
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Tue Feb 23 20:52:30 2016 +1030
Emulate some non portable glibc functions when not available
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dd81d27..a2986f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -325,6 +325,7 @@ set(poppler_SRCS
goo/ImgWriter.cc
goo/gstrtod.cc
goo/grandom.cc
+ goo/glibc.cc
fofi/FoFiBase.cc
fofi/FoFiEncodings.cc
fofi/FoFiTrueType.cc
diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index d335ff0..c7ff349 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <goo/glibc.h>
#include <poppler-document.h>
#include <poppler-embedded-file.h>
#include <poppler-font.h>
@@ -94,13 +95,9 @@ std::ostream& operator<<(std::ostream& stream, const poppler::ustring &str)
static std::string out_date(std::time_t date)
{
if (date != std::time_t(-1)) {
-#ifdef HAVE_GMTIME_R
struct tm time;
gmtime_r(&date, &time);
struct tm *t = &time;
-#else
- struct tm *t = gmtime(&date);
-#endif
char buf[32];
strftime(buf, sizeof(buf) - 1, "%d/%m/%Y %H:%M:%S", t);
return std::string(buf);
diff --git a/glib/demo/utils.c b/glib/demo/utils.c
index 440793b..10d6d4b 100644
--- a/glib/demo/utils.c
+++ b/glib/demo/utils.c
@@ -484,15 +484,9 @@ pgd_format_date (time_t utime)
char s[256];
const char *fmt_hack = "%c";
size_t len;
-#ifdef HAVE_LOCALTIME_R
struct tm t;
if (time == 0 || !localtime_r (&time, &t)) return NULL;
len = strftime (s, sizeof (s), fmt_hack, &t);
-#else
- struct tm *t;
- if (time == 0 || !(t = localtime (&time)) ) return NULL;
- len = strftime (s, sizeof (s), fmt_hack, t);
-#endif
if (len == 0 || s[0] == '\0') return NULL;
diff --git a/goo/Makefile.am b/goo/Makefile.am
index 370e850..8b4595e 100644
--- a/goo/Makefile.am
+++ b/goo/Makefile.am
@@ -40,7 +40,8 @@ libgoo_la_SOURCES = \
ImgWriter.cc \
gtypes_p.h \
gstrtod.cc \
- grandom.cc
+ grandom.cc \
+ glibc.cc
if BUILD_LIBJPEG
libjpeg_includes = $(LIBJPEG_CFLAGS)
diff --git a/goo/glibc.cc b/goo/glibc.cc
new file mode 100644
index 0000000..fa1c858
--- /dev/null
+++ b/goo/glibc.cc
@@ -0,0 +1,34 @@
+//========================================================================
+//
+// glibc.h
+//
+// Emulate various non-portable glibc functions.
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright (C) 2016 Adrian Johnson <ajohnson at redneon.com>
+//
+//========================================================================
+
+#include "glibc.h"
+
+#ifndef HAVE_GMTIME_R
+struct tm *gmtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *gt;
+ gt = gmtime(timep);
+ if (gt)
+ *result = *gt;
+ return gt;
+}
+#endif
+
+#ifndef HAVE_LOCALTIME_R
+struct tm *localtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *lt;
+ lt = localtime(timep);
+ *result = *lt;
+ return lt;
+}
+#endif
diff --git a/goo/glibc.h b/goo/glibc.h
new file mode 100644
index 0000000..cc156e7
--- /dev/null
+++ b/goo/glibc.h
@@ -0,0 +1,33 @@
+//========================================================================
+//
+// glibc.h
+//
+// Emulate various non-portable glibc functions.
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright (C) 2016 Adrian Johnson <ajohnson at redneon.com>
+//
+//========================================================================
+
+#ifndef GLIBC_H
+#define GLIBC_H
+
+#include "config.h"
+
+#include <time.h>
+
+extern "C" {
+
+#ifndef HAVE_GMTIME_R
+struct tm *gmtime_r(const time_t *timep, struct tm *result);
+#endif
+
+#ifndef HAVE_LOCALTIME_R
+struct tm *localtime_r(const time_t *timep, struct tm *result);
+#endif
+
+};
+
+#endif // GLIBC_H
+
diff --git a/poppler/DateInfo.cc b/poppler/DateInfo.cc
index 8cd4883..99da404 100644
--- a/poppler/DateInfo.cc
+++ b/poppler/DateInfo.cc
@@ -22,6 +22,7 @@
#include <config.h>
+#include "glibc.h"
#include "DateInfo.h"
#include <stdio.h>
@@ -81,13 +82,9 @@ GooString *timeToDateString(time_t *timet) {
struct tm *gt;
size_t len;
time_t timep = timet ? *timet : time(NULL);
-
-#ifdef HAVE_GMTIME_R
struct tm t;
+
gt = gmtime_r (&timep, &t);
-#else
- gt = gmtime (&timep);
-#endif
dateString = new GooString ("D:");
More information about the poppler
mailing list