The function timespec_get() is C17 so assume we have it

This commit is contained in:
João Valverde 2021-12-12 22:19:40 +00:00 committed by Wireshark GitLab Utility
parent 0781007df4
commit 8b15d0e641
2 changed files with 1 additions and 20 deletions

View File

@ -618,22 +618,8 @@ void ImportTextDialog::on_timestampFormatLineEdit_textChanged(const QString &tim
char time_str[100];
QString timefmt = QString(time_format);
#if defined(HAVE_CLOCK_GETTIME)
// Newer POSIX API. Some UN*Xes whose C libraries lack
// timespec_get() (C11) have this.
clock_gettime(CLOCK_REALTIME, &timenow);
#elif defined(_WIN32)
// At least some Windows C libraries have this.
// Some UN*X C libraries do, as well, but they might not
// show it unless you're requesting C11 - or C++17.
timespec_get(&timenow, TIME_UTC);
#else
// Fall back on gettimeofday().
struct timeval usectimenow;
gettimeofday(&usectimenow, NULL);
timenow.tv_sec = usectimenow.tv_sec;
timenow.tv_nsec = usectimenow.tv_usec*1000;
#endif
/* On windows strftime/wcsftime does not support %s yet, this works on all OSs */
timefmt.replace(QString("%s"), QString::number(timenow.tv_sec));
/* subsecond example as usec */

View File

@ -906,13 +906,8 @@ static void log_write_do_work(FILE *fp, gboolean use_color,
static inline ws_log_time_t *get_timestamp(ws_log_time_t *ts)
{
assert(ts);
#if defined(HAVE_CLOCK_GETTIME)
if (clock_gettime(CLOCK_REALTIME, (struct timespec *)ts) == 0)
return ts;
#elif defined(_WIN32)
if (timespec_get((struct timespec *)ts, TIME_UTC) == TIME_UTC)
return ts;
#endif
ts->tv_sec = time(NULL);
ts->tv_nsec = -1;
return ts;