From df7a82674d769e2c00f2e44223fc9de29c0f6195 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 23 Feb 2016 20:52:30 +1030 Subject: [PATCH 1/4] Emulate some non portable glibc functions when not available --- CMakeLists.txt | 1 + cpp/tests/poppler-dump.cpp | 5 +---- glib/demo/utils.c | 6 ------ goo/Makefile.am | 3 ++- goo/glibc.cc | 34 ++++++++++++++++++++++++++++++++++ goo/glibc.h | 33 +++++++++++++++++++++++++++++++++ poppler/DateInfo.cc | 7 ++----- 7 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 goo/glibc.cc create mode 100644 goo/glibc.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 580ab03..70817c1 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 #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..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 +// +//======================================================================== + +#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 +// +//======================================================================== + +#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 8cd4883..99da404 100644 --- a/poppler/DateInfo.cc +++ b/poppler/DateInfo.cc @@ -22,6 +22,7 @@ #include +#include "glibc.h" #include "DateInfo.h" #include @@ -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:"); -- 2.1.4