From 3da753a3f7023389c492e8ad1ce61ced613db3a3 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 26 Oct 2020 22:12:36 -0300 Subject: [PATCH] Fixing windows build. --- configure.ac | 1 + src/core/rpq.c | 52 ++++++++++++++++++++++++++++------------------------ src/core/telnet.c | 7 ++++++- src/include/config.h.in | 1 + 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index 25ac2bf..1334499 100644 --- a/configure.ac +++ b/configure.ac @@ -539,6 +539,7 @@ AC_CHECK_HEADER(syslog.h, AC_DEFINE(HAVE_SYSLOG,,[do we have syslog.h?])) AC_CHECK_FUNCS(getaddrinfo, AC_DEFINE(HAVE_GETADDRINFO) ) AC_CHECK_FUNC(vasprintf, AC_DEFINE(HAVE_VASPRINTF) ) AC_CHECK_FUNC(strtok_r, AC_DEFINE(HAVE_STRTOK_R) ) +AC_CHECK_FUNC(localtime_r, AC_DEFINE(HAVE_LOCALTIME_R) ) AC_ARG_WITH([inet-ntop], [AS_HELP_STRING([--with-inet-ntop], [Assume that inet_nto() is available])], [ app_cv_inet_ntop="$withval" ],[ app_cv_inet_ntop="auto" ]) diff --git a/src/core/rpq.c b/src/core/rpq.c index cf43b00..e40c847 100644 --- a/src/core/rpq.c +++ b/src/core/rpq.c @@ -273,9 +273,7 @@ void do_qr_rpqnames(H3270 *hSession) rpq_dump_warnings(hSession); } -/** - * @brief Utility function used by the RPQNAMES query reply. - */ +/// @brief Utility function used by the RPQNAMES query reply. static Boolean select_rpq_terms(H3270 *hSession) { int i,j,k,len; @@ -438,6 +436,8 @@ static int get_rpq_timezone(H3270 *hSession) } +#ifdef HAVE_LOCALTIME_R + localtime_r(&here,&here_tm); if(gmtime_r(&here,&utc_tm) == NULL) @@ -446,23 +446,27 @@ static int get_rpq_timezone(H3270 *hSession) return 2; } - /* +#else + memcpy(&here_tm, localtime(&here), sizeof(struct tm)); + struct tm * _tm = gmtime(&here); - if ((utc_tm = gmtime(&here)) == NULL) + if(_tm == NULL) { rpq_warning(hSession, _("RPQ: Unable to determine workstation UTC time")); return 2; } - */ - /* - * Do not take Daylight Saving Time into account. - * We just want the "raw" time difference. - */ + memcpy(&utc_tm,_tm,sizeof(struct tm)); + +#endif // HAVE_LOCALTIME_R + + // Do not take Daylight Saving Time into account. + // We just want the "raw" time difference. here_tm.tm_isdst = 0; utc_tm.tm_isdst = 0; delta = difftime(mktime(&here_tm), mktime(&utc_tm)) / 60L; + } // sanity check: difference cannot exceed +/- 12 hours @@ -480,20 +484,20 @@ static int get_rpq_timezone(H3270 *hSession) */ static int get_rpq_user(H3270 *hSession, unsigned char buf[], const int buflen) { - /* - * Text may be specified in one of two ways, but not both. - * An environment variable provides the user interface: - * - X3270RPQ: Keyword USER= - * - * NOTE: If the string begins with 0x then no ASCII/EBCDIC - * translation is done. The hex characters will be sent as true hex - * data. E.g., X3270RPQ="user=0x ab 12 EF" will result in 3 bytes - * sent as 0xAB12EF. White space is optional in hex data format. - * When hex format is required, the 0x prefix must be the first two - * characters of the string. E.g., X3270RPQ="user= 0X AB" will - * result in 6 bytes sent as 0x40F0E740C1C2 because the text is - * accepted "as is" then translated from ASCII to EBCDIC. - */ + // + // Text may be specified in one of two ways, but not both. + // An environment variable provides the user interface: + // - X3270RPQ: Keyword USER= + // + // NOTE: If the string begins with 0x then no ASCII/EBCDIC + // translation is done. The hex characters will be sent as true hex + // data. E.g., X3270RPQ="user=0x ab 12 EF" will result in 3 bytes + // sent as 0xAB12EF. White space is optional in hex data format. + // When hex format is required, the 0x prefix must be the first two + // characters of the string. E.g., X3270RPQ="user= 0X AB" will + // result in 6 bytes sent as 0x40F0E740C1C2 because the text is + // accepted "as is" then translated from ASCII to EBCDIC. + // const char *rpqtext = CN; int x; struct rpq_keyword *kw; diff --git a/src/core/telnet.c b/src/core/telnet.c index 5641aec..5ef36dc 100644 --- a/src/core/telnet.c +++ b/src/core/telnet.c @@ -2154,9 +2154,14 @@ void trace_netdata(H3270 *hSession, char direction, unsigned const char *buf, in { time_t ltime; - struct tm tm; time(<ime); + +#ifdef HAVE_LOCALTIME_R + struct tm tm; strftime(l1, 81, "%x %X", localtime_r(<ime,&tm)); +#else + strftime(l1, 81, "%x %X", localtime(<ime)); +#endif // HAVE_LOCALTIME_R } lib3270_write_nettrace(hSession,"%c %s %s data len=%d\n\n",direction,l1,direction == '>' ? "SEND" : "RECV", len); diff --git a/src/include/config.h.in b/src/include/config.h.in index 81ab152..5d83003 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -94,6 +94,7 @@ #undef HAVE_PRINTER #undef HAVE_MALLOC_H #undef HAVE_STRTOK_R + #undef HAVE_LOCALTIME_R #endif /* LIB3270_CONFIG_INCLUDED */ -- libgit2 0.21.2