diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-06-27 20:39:15 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-06-28 03:39:54 +0000 |
commit | 8304f69fd7f02cb5fe79010170c7550d441ad6e7 (patch) | |
tree | 5b95441afcd9ff732999054dffb13939e03cdce9 /wsutil/nstime.h | |
parent | c8518753c8d3f7bb809d2615adc9f6f2e5e89530 (diff) |
Add macros to initialize nstime_t values and use them.
This allows code to initialize them without having to know the details
of the structure; the initializes should, and will, be changed if the
members of the structure are changed.
Change-Id: I93e6ebfcde9ceca17df696fcba4e8410c5afb175
Reviewed-on: https://code.wireshark.org/review/28501
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil/nstime.h')
-rw-r--r-- | wsutil/nstime.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/wsutil/nstime.h b/wsutil/nstime.h index 0d976200b8..273569a82b 100644 --- a/wsutil/nstime.h +++ b/wsutil/nstime.h @@ -29,6 +29,26 @@ typedef struct { int nsecs; } nstime_t; +/* Macros that expand to nstime_t initializers */ + +/* Initialize to zero */ +#define NSTIME_INIT_ZERO {0, 0} + +/* Initialize to a specified number of seconds and nanoseconds */ +#define NSTIME_INIT_SECS_NSECS(secs, nsecs) {secs, nsecs} + +/* Initialize to a specified number of seconds and microseconds */ +#define NSTIME_INIT_SECS_USECS(secs, usecs) {secs, usecs*1000} + +/* Initialize to a specified number of seconds and milliseconds */ +#define NSTIME_INIT_SECS_MSECS(secs, msecs) {secs, msecs*1000000} + +/* Initialize to a specified number of seconds */ +#define NSTIME_INIT_SECS(secs) {secs, 0} + +/* Initialize to the maxximum possible value */ +#define NSTIME_INIT_MAX {sizeof(time_t) > sizeof(int) ? LONG_MAX : INT_MAX, INT_MAX} + /* functions */ /** set the given nstime_t to zero */ |