]>
git.ipfire.org Git - thirdparty/systemd.git/blob - util.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
11 usec_t
now(clockid_t clock
) {
14 assert_se(clock_gettime(clock
, &ts
) == 0);
16 return timespec_load(&ts
);
19 usec_t
timespec_load(const struct timespec
*ts
) {
23 (usec_t
) ts
->tv_sec
* USEC_PER_SEC
+
24 (usec_t
) ts
->tv_nsec
/ NSEC_PER_USEC
;
27 struct timespec
*timespec_store(struct timespec
*ts
, usec_t u
) {
30 ts
->tv_sec
= (time_t) (u
/ USEC_PER_SEC
);
31 ts
->tv_nsec
= (long int) ((u
% USEC_PER_SEC
) * NSEC_PER_USEC
);
36 usec_t
timeval_load(const struct timeval
*tv
) {
40 (usec_t
) tv
->tv_sec
* USEC_PER_SEC
+
44 struct timeval
*timeval_store(struct timeval
*tv
, usec_t u
) {
47 tv
->tv_sec
= (time_t) (u
/ USEC_PER_SEC
);
48 tv
->tv_usec
= (suseconds_t
) (u
% USEC_PER_SEC
);
53 bool endswith(const char *s
, const char *postfix
) {
65 return memcmp(s
+ sl
- pl
, postfix
, pl
) == 0;
68 bool startswith(const char *s
, const char *prefix
) {
80 return memcmp(s
, prefix
, pl
) == 0;
83 int nointr_close(int fd
) {
89 if ((r
= close(fd
)) >= 0)