• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***
2   This file is part of eudev, forked from systemd.
3 
4   Copyright 2010 Lennart Poettering
5 
6   systemd is free software; you can redistribute it and/or modify it
7   under the terms of the GNU Lesser General Public License as published by
8   the Free Software Foundation; either version 2.1 of the License, or
9   (at your option) any later version.
10 
11   systemd is distributed in the hope that it will be useful, but
12   WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   Lesser General Public License for more details.
15 
16   You should have received a copy of the GNU Lesser General Public License
17   along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19 
20 #pragma once
21 
22 #include <inttypes.h>
23 
24 typedef uint64_t usec_t;
25 typedef uint64_t nsec_t;
26 
27 #define USEC_FMT "%" PRIu64
28 
29 #include "macro.h"
30 
31 typedef struct dual_timestamp {
32         usec_t realtime;
33         usec_t monotonic;
34 } dual_timestamp;
35 
36 #define USEC_INFINITY ((usec_t) -1)
37 #define NSEC_INFINITY ((nsec_t) -1)
38 
39 #define MSEC_PER_SEC  1000ULL
40 #define USEC_PER_SEC  ((usec_t) 1000000ULL)
41 #define USEC_PER_MSEC ((usec_t) 1000ULL)
42 #define NSEC_PER_SEC  ((nsec_t) 1000000000ULL)
43 #define NSEC_PER_MSEC ((nsec_t) 1000000ULL)
44 #define NSEC_PER_USEC ((nsec_t) 1000ULL)
45 
46 #define USEC_PER_MINUTE ((usec_t) (60ULL*USEC_PER_SEC))
47 #define NSEC_PER_MINUTE ((nsec_t) (60ULL*NSEC_PER_SEC))
48 #define USEC_PER_HOUR ((usec_t) (60ULL*USEC_PER_MINUTE))
49 #define NSEC_PER_HOUR ((nsec_t) (60ULL*NSEC_PER_MINUTE))
50 #define USEC_PER_DAY ((usec_t) (24ULL*USEC_PER_HOUR))
51 #define NSEC_PER_DAY ((nsec_t) (24ULL*NSEC_PER_HOUR))
52 #define USEC_PER_WEEK ((usec_t) (7ULL*USEC_PER_DAY))
53 #define NSEC_PER_WEEK ((nsec_t) (7ULL*NSEC_PER_DAY))
54 #define USEC_PER_MONTH ((usec_t) (2629800ULL*USEC_PER_SEC))
55 #define NSEC_PER_MONTH ((nsec_t) (2629800ULL*NSEC_PER_SEC))
56 #define USEC_PER_YEAR ((usec_t) (31557600ULL*USEC_PER_SEC))
57 #define NSEC_PER_YEAR ((nsec_t) (31557600ULL*NSEC_PER_SEC))
58 
59 #define FORMAT_TIMESPAN_MAX 64
60 
61 usec_t now(clockid_t clock);
62 
63 usec_t timespec_load(const struct timespec *ts) _pure_;
64 struct timespec *timespec_store(struct timespec *ts, usec_t u);
65 
66 struct timeval *timeval_store(struct timeval *tv, usec_t u);
67 char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
68