Skip to content

Commit 54b2f89

Browse files
committed
format_timespan: get rid of usec_t/nsec_t types, use uint64_t instead
Signed-off-by: Arnaud Rebillout <[email protected]>
1 parent 2374ae0 commit 54b2f89

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/time-util.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#include "util.h"
44
#include "time-util.h"
55

6-
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
6+
char *format_timespan(char *buf, size_t l, uint64_t t, uint64_t accuracy) {
77
static const struct {
88
const char *suffix;
9-
usec_t usec;
9+
uint64_t usec;
1010
} table[] = {
1111
{ "y", USEC_PER_YEAR },
1212
{ "month", USEC_PER_MONTH },
@@ -44,7 +44,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
4444
int k = 0;
4545
size_t n;
4646
bool done = false;
47-
usec_t a, b;
47+
uint64_t a, b;
4848

4949
if (t <= 0)
5050
break;
@@ -63,7 +63,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
6363

6464
/* Let's see if we should shows this in dot notation */
6565
if (t < USEC_PER_MINUTE && b > 0) {
66-
usec_t cc;
66+
uint64_t cc;
6767
signed char j;
6868

6969
j = 0;

src/time-util.h

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,34 @@
33
#ifndef footimeutilfoo
44
#define footimeutilfoo
55

6-
typedef uint64_t usec_t;
7-
typedef uint64_t nsec_t;
8-
96
#define PRI_NSEC PRIu64
107
#define PRI_USEC PRIu64
118
#define NSEC_FMT "%" PRI_NSEC
129
#define USEC_FMT "%" PRI_USEC
1310

14-
#define USEC_INFINITY ((usec_t) -1)
15-
#define NSEC_INFINITY ((nsec_t) -1)
11+
#define USEC_INFINITY ((uint64_t) -1)
12+
#define NSEC_INFINITY ((uint64_t) -1)
1613

1714
#define MSEC_PER_SEC 1000ULL
18-
#define USEC_PER_SEC ((usec_t) 1000000ULL)
19-
#define USEC_PER_MSEC ((usec_t) 1000ULL)
20-
//#define NSEC_PER_SEC ((nsec_t) 1000000000ULL) already defined in util.h
21-
#define NSEC_PER_MSEC ((nsec_t) 1000000ULL)
22-
#define NSEC_PER_USEC ((nsec_t) 1000ULL)
23-
24-
#define USEC_PER_MINUTE ((usec_t) (60ULL*USEC_PER_SEC))
25-
#define NSEC_PER_MINUTE ((nsec_t) (60ULL*NSEC_PER_SEC))
26-
#define USEC_PER_HOUR ((usec_t) (60ULL*USEC_PER_MINUTE))
27-
#define NSEC_PER_HOUR ((nsec_t) (60ULL*NSEC_PER_MINUTE))
28-
#define USEC_PER_DAY ((usec_t) (24ULL*USEC_PER_HOUR))
29-
#define NSEC_PER_DAY ((nsec_t) (24ULL*NSEC_PER_HOUR))
30-
#define USEC_PER_WEEK ((usec_t) (7ULL*USEC_PER_DAY))
31-
#define NSEC_PER_WEEK ((nsec_t) (7ULL*NSEC_PER_DAY))
32-
#define USEC_PER_MONTH ((usec_t) (2629800ULL*USEC_PER_SEC))
33-
#define NSEC_PER_MONTH ((nsec_t) (2629800ULL*NSEC_PER_SEC))
34-
#define USEC_PER_YEAR ((usec_t) (31557600ULL*USEC_PER_SEC))
35-
#define NSEC_PER_YEAR ((nsec_t) (31557600ULL*NSEC_PER_SEC))
36-
37-
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
15+
#define USEC_PER_SEC ((uint64_t) 1000000ULL)
16+
#define USEC_PER_MSEC ((uint64_t) 1000ULL)
17+
//#define NSEC_PER_SEC ((uint64_t) 1000000000ULL) already defined in util.h
18+
#define NSEC_PER_MSEC ((uint64_t) 1000000ULL)
19+
#define NSEC_PER_USEC ((uint64_t) 1000ULL)
20+
21+
#define USEC_PER_MINUTE ((uint64_t) (60ULL*USEC_PER_SEC))
22+
#define NSEC_PER_MINUTE ((uint64_t) (60ULL*NSEC_PER_SEC))
23+
#define USEC_PER_HOUR ((uint64_t) (60ULL*USEC_PER_MINUTE))
24+
#define NSEC_PER_HOUR ((uint64_t) (60ULL*NSEC_PER_MINUTE))
25+
#define USEC_PER_DAY ((uint64_t) (24ULL*USEC_PER_HOUR))
26+
#define NSEC_PER_DAY ((uint64_t) (24ULL*NSEC_PER_HOUR))
27+
#define USEC_PER_WEEK ((uint64_t) (7ULL*USEC_PER_DAY))
28+
#define NSEC_PER_WEEK ((uint64_t) (7ULL*NSEC_PER_DAY))
29+
#define USEC_PER_MONTH ((uint64_t) (2629800ULL*USEC_PER_SEC))
30+
#define NSEC_PER_MONTH ((uint64_t) (2629800ULL*NSEC_PER_SEC))
31+
#define USEC_PER_YEAR ((uint64_t) (31557600ULL*USEC_PER_SEC))
32+
#define NSEC_PER_YEAR ((uint64_t) (31557600ULL*NSEC_PER_SEC))
33+
34+
char *format_timespan(char *buf, size_t l, uint64_t t, uint64_t accuracy);
3835

3936
#endif

0 commit comments

Comments
 (0)