diff options
-rw-r--r-- | ConfigureChecks.cmake | 2 | ||||
-rw-r--r-- | debian/libwsutil0.symbols | 1 | ||||
-rw-r--r-- | editcap.c | 14 | ||||
-rw-r--r-- | epan/ftypes/ftype-time.c | 30 | ||||
-rw-r--r-- | ui/text_import.c | 38 | ||||
-rw-r--r-- | wsutil/nstime.c | 6 | ||||
-rw-r--r-- | wsutil/strptime.c | 5 | ||||
-rw-r--r-- | wsutil/strptime.h | 6 | ||||
-rw-r--r-- | wsutil/time_util.c | 22 | ||||
-rw-r--r-- | wsutil/time_util.h | 9 |
10 files changed, 43 insertions, 90 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index b379666e15..b52b7c3fac 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -87,7 +87,6 @@ check_function_exists("getifaddrs" HAVE_GETIFADDRS) check_function_exists("issetugid" HAVE_ISSETUGID) check_function_exists("setresgid" HAVE_SETRESGID) check_function_exists("setresuid" HAVE_SETRESUID) -check_function_exists("strptime" HAVE_STRPTIME) if (APPLE) cmake_push_check_state() set(CMAKE_REQUIRED_LIBRARIES ${APPLE_CORE_FOUNDATION_LIBRARY}) @@ -99,6 +98,7 @@ if(UNIX) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) check_symbol_exists("memmem" "string.h" HAVE_MEMMEM) check_symbol_exists("strcasestr" "string.h" HAVE_STRCASESTR) + check_symbol_exists("strptime" "time.h" HAVE_STRPTIME) check_symbol_exists("vasprintf" "stdio.h" HAVE_VASPRINTF) cmake_pop_check_state() endif() diff --git a/debian/libwsutil0.symbols b/debian/libwsutil0.symbols index 7da55031ff..226096c8e2 100644 --- a/debian/libwsutil0.symbols +++ b/debian/libwsutil0.symbols @@ -428,6 +428,7 @@ libwsutil.so.0 libwsutil0 #MINVER# ws_regex_pattern@Base 3.7.0 ws_socket_ptoa@Base 3.1.1 ws_strcasestr@Base 3.7.0 + ws_strptime@Base 3.7.0 ws_strtoi16@Base 2.3.0 ws_strtoi32@Base 2.3.0 ws_strtoi64@Base 2.3.0 @@ -23,16 +23,6 @@ #include <stdarg.h> #include <math.h> -/* - * Just make sure we include the prototype for strptime as well - * (needed for glibc 2.2) but make sure we do this only if not - * yet defined. - */ - -#ifndef __USE_XOPEN -# define __USE_XOPEN -#endif - #include <time.h> #include <glib.h> @@ -53,10 +43,6 @@ #include <winsock2.h> #endif -#ifndef HAVE_STRPTIME -# include "wsutil/strptime.h" -#endif - #include <ui/clopts_common.h> #include <ui/cmdarg_err.h> #include <ui/exit_codes.h> diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c index da76463751..ca9a02abd0 100644 --- a/epan/ftypes/ftype-time.c +++ b/epan/ftypes/ftype-time.c @@ -7,28 +7,14 @@ */ #include "config.h" +#include "ftypes-int.h" #include <stdio.h> #include <stdlib.h> #include <string.h> -/* - * Just make sure we include the prototype for strptime as well - * (needed for glibc 2.2) but make sure we do this only if not - * yet defined. - */ -#ifndef __USE_XOPEN -# define __USE_XOPEN -#endif - -#include <time.h> - -#include <ftypes-int.h> #include <epan/to_str.h> - -#ifndef HAVE_STRPTIME -#include "wsutil/strptime.h" -#endif +#include <wsutil/time_util.h> static int @@ -204,20 +190,20 @@ absolute_val_from_string(fvalue_t *fv, const char *s, gchar **err_msg) /* Do not use '%b' to parse the month name, it is locale-specific. */ if (s[3] == ' ' && parse_month_name(s, &tm.tm_mon)) - curptr = strptime(s + 4, "%d, %Y %H:%M:%S", &tm); + curptr = ws_strptime(s + 4, "%d, %Y %H:%M:%S", &tm); if (curptr == NULL) - curptr = strptime(s,"%Y-%m-%dT%H:%M:%S", &tm); + curptr = ws_strptime(s,"%Y-%m-%dT%H:%M:%S", &tm); if (curptr == NULL) - curptr = strptime(s,"%Y-%m-%d %H:%M:%S", &tm); + curptr = ws_strptime(s,"%Y-%m-%d %H:%M:%S", &tm); if (curptr == NULL) { has_seconds = FALSE; - curptr = strptime(s,"%Y-%m-%d %H:%M", &tm); + curptr = ws_strptime(s,"%Y-%m-%d %H:%M", &tm); } if (curptr == NULL) - curptr = strptime(s,"%Y-%m-%d %H", &tm); + curptr = ws_strptime(s,"%Y-%m-%d %H", &tm); if (curptr == NULL) - curptr = strptime(s,"%Y-%m-%d", &tm); + curptr = ws_strptime(s,"%Y-%m-%d", &tm); if (curptr == NULL) goto fail; tm.tm_isdst = -1; /* let the computer figure out if it's DST */ diff --git a/ui/text_import.c b/ui/text_import.c index a2814b1b37..8657a792e7 100644 --- a/ui/text_import.c +++ b/ui/text_import.c @@ -75,38 +75,8 @@ */ #include "config.h" - -/* - * Just make sure we include the prototype for strptime as well - * (needed for glibc 2.2) but make sure we do this only if not - * yet defined. - */ -#ifndef __USE_XOPEN -# define __USE_XOPEN -#endif -#ifndef _XOPEN_SOURCE -# ifndef __sun -# define _XOPEN_SOURCE 600 -# endif -#endif #include "text_import.h" -/* - * Defining _XOPEN_SOURCE is needed on some platforms, e.g. platforms - * using glibc, to expand the set of things system header files define. - * - * Unfortunately, on other platforms, such as some versions of Solaris - * (including Solaris 10), it *reduces* that set as well, causing - * strptime() not to be declared, presumably because the version of the - * X/Open spec that _XOPEN_SOURCE implies doesn't include strptime() and - * blah blah blah namespace pollution blah blah blah. - * - * So we define __EXTENSIONS__ so that "strptime()" is declared. - */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ -#endif - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -127,9 +97,7 @@ #include <wsutil/exported_pdu_tlvs.h> #include <wsutil/nstime.h> -#ifndef HAVE_STRPTIME -# include "wsutil/strptime.h" -#endif +#include <wsutil/time_util.h> #include "text_import_scanner.h" #include "text_import_scanner_lex.h" @@ -1082,7 +1050,7 @@ _parse_time(const guchar* start_field, const guchar* end_field, const gchar* _fo *subsecs_fmt = 0; } - cursor = strptime(cursor, format, &timecode); + cursor = ws_strptime(cursor, format, &timecode); if (cursor == NULL) { return FALSE; @@ -1099,7 +1067,7 @@ _parse_time(const guchar* start_field, const guchar* end_field, const gchar* _fo subseclen = (int) (p - cursor); cursor = p; - cursor = strptime(cursor, subsecs_fmt + 2, &timecode); + cursor = ws_strptime(cursor, subsecs_fmt + 2, &timecode); if (cursor == NULL) { return FALSE; } diff --git a/wsutil/nstime.c b/wsutil/nstime.c index 2636e47be9..eeacf2b97d 100644 --- a/wsutil/nstime.c +++ b/wsutil/nstime.c @@ -17,10 +17,6 @@ #include "epochs.h" #include "time_util.h" -#ifndef HAVE_STRPTIME -# include "wsutil/strptime.h" -#endif - /* this is #defined so that we can clearly see that we have the right number of zeros, rather than as a guard against the number of nanoseconds in a second changing ;) */ @@ -539,7 +535,7 @@ unix_epoch_to_nstime(nstime_t *nstime, const char *ptr) tm.tm_isdst = -1; nstime_set_unset(nstime); - if (!(ptr_new=strptime(ptr, "%s", &tm))) { + if (!(ptr_new = ws_strptime(ptr, "%s", &tm))) { return 0; } diff --git a/wsutil/strptime.c b/wsutil/strptime.c index e525ca38e6..7aa34442d8 100644 --- a/wsutil/strptime.c +++ b/wsutil/strptime.c @@ -12,6 +12,7 @@ this is enough information for determining the date. */ #include "config.h" +#include "strptime.h" #include <ctype.h> #include <string.h> @@ -21,8 +22,6 @@ # include "../locale/localeinfo.h" #endif -#include "strptime.h" - #ifndef __P # if defined (__GNUC__) || (defined (__STDC__) && __STDC__) # define __P(args) args @@ -974,7 +973,7 @@ strptime_internal (rp, fmt, tm, decided, era_cnt) char * -strptime (buf, format, tm) +strptime_gnulib (buf, format, tm) const char *buf; const char *format; struct tm *tm; diff --git a/wsutil/strptime.h b/wsutil/strptime.h index 43671a4af3..b574bdbf47 100644 --- a/wsutil/strptime.h +++ b/wsutil/strptime.h @@ -10,11 +10,13 @@ #ifndef __STRPTIME_H__ #define __STRPTIME_H__ -#include "ws_symbol_export.h" +#include <ws_symbol_export.h> +#include <time.h> /* * Version of "strptime()", for the benefit of OSes that don't have it. */ -WS_DLL_PUBLIC char *strptime(const char *, const char *, struct tm *); +WS_DLL_LOCAL +char *strptime_gnulib(const char *s, const char *format, struct tm *tm); #endif diff --git a/wsutil/time_util.c b/wsutil/time_util.c index 14c04a4882..d6ea6342be 100644 --- a/wsutil/time_util.c +++ b/wsutil/time_util.c @@ -7,16 +7,12 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ - +#define _GNU_SOURCE /* For strptime(). */ #include "config.h" #define WS_LOG_DOMAIN LOG_DOMAIN_WSUTIL - -#include <glib.h> +#include "time_util.h" #include <wsutil/epochs.h> -#include <wsutil/wslog.h> - -#include "time_util.h" #ifndef _WIN32 #include <sys/time.h> @@ -25,6 +21,10 @@ #include <windows.h> #endif +#ifndef HAVE_STRPTIME +#include "strptime.h" +#endif + /* Test if the given year is a leap year */ #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) @@ -240,6 +240,16 @@ ws_clock_get_realtime(struct timespec *ts) #endif } +char *ws_strptime(const char *restrict s, const char *restrict format, + struct tm *restrict tm) +{ +#ifdef HAVE_STRPTIME + return strptime(s, format, tm); +#else + return strptime_gnulib(s, format, tm); +#endif +} + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/wsutil/time_util.h b/wsutil/time_util.h index 5f93b7dde0..6002b1587d 100644 --- a/wsutil/time_util.h +++ b/wsutil/time_util.h @@ -10,8 +10,7 @@ #ifndef __TIME_UTIL_H__ #define __TIME_UTIL_H__ -#include "ws_symbol_export.h" - +#include <wireshark.h> #include <time.h> #ifdef __cplusplus @@ -66,6 +65,12 @@ guint64 create_timestamp(void); WS_DLL_PUBLIC struct timespec *ws_clock_get_realtime(struct timespec *ts); +/* + * Portability wrapper around strptime(). + */ +WS_DLL_PUBLIC +char *ws_strptime(const char *s, const char *format, struct tm *tm); + #ifdef __cplusplus } #endif /* __cplusplus */ |