From 27bbe80f4d9e00b1c27ceb997c554b7e63c03fb6 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 23 Feb 2016 20:52:30 +1030 Subject: [PATCH 1/2] Emulate some non portable glibc functions when not available --- CMakeLists.txt | 2 ++ cpp/tests/poppler-dump.cpp | 5 +---- glib/demo/utils.c | 6 ------ goo/Makefile.am | 6 ++++-- goo/glibc.cc | 32 ++++++++++++++++++++++++++++++++ goo/glibc.h | 31 +++++++++++++++++++++++++++++++ poppler/DateInfo.cc | 7 ++----- 7 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 goo/glibc.cc create mode 100644 goo/glibc.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d30fa4b..b4ea46a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -314,6 +314,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 @@ -573,6 +574,7 @@ if(ENABLE_XPDF_HEADERS) goo/GooLikely.h goo/gstrtod.h goo/grandom.h + goo/glibc.h DESTINATION include/poppler/goo) if(PNG_FOUND) install(FILES 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 #include #include #include @@ -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..bb11389 100644 --- a/goo/Makefile.am +++ b/goo/Makefile.am @@ -20,7 +20,8 @@ poppler_goo_include_HEADERS = \ ImgWriter.h \ GooLikely.h \ gstrtod.h \ - grandom.h + grandom.h \ + glibc.h endif @@ -40,7 +41,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..b1589db --- /dev/null +++ b/goo/glibc.cc @@ -0,0 +1,32 @@ +//======================================================================== +// +// glibc.h +// +// Emulate various non-portable glibc functions. +// +// Copyright (C) 2016 Adrian Johnson +// +//======================================================================== + +#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..527c8b3 --- /dev/null +++ b/goo/glibc.h @@ -0,0 +1,31 @@ +//======================================================================== +// +// glibc.h +// +// Emulate various non-portable glibc functions. +// +// Copyright (C) 2016 Adrian Johnson +// +//======================================================================== + +#ifndef GLIBC_H +#define GLIBC_H + +#include "config.h" + +#include + +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 563204a..f411303 100644 --- a/poppler/DateInfo.cc +++ b/poppler/DateInfo.cc @@ -20,6 +20,7 @@ #include +#include "glibc.h" #include "DateInfo.h" #include @@ -79,13 +80,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:"); -- 2.1.4