forked from osmocom/wireshark
Revert "The function timespec_get() is C17 so assume we have it"
This reverts commit 8b15d0e641
.
This commit is contained in:
parent
67a4e70382
commit
e877460a9e
|
@ -618,8 +618,22 @@ 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 */
|
||||
|
|
|
@ -907,8 +907,13 @@ 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;
|
||||
|
|
Loading…
Reference in New Issue