]> git.ozlabs.org Git - ccan/blob - ccan/time/_info
5cf20f79611a85e3322b4b08b0ae57dadd547efb
[ccan] / ccan / time / _info
1 #include <string.h>
2 #include "config.h"
3
4 /**
5  * time - routines for dealing with time
6  *
7  * This code provides convenient functions for working with time, in the
8  * form of 'struct timerel' for durations and 'struct timeabs' for timestamps
9  * which are light wrappers around struct timespec.
10  *
11  * Author: Rusty Russell <rusty@rustcorp.com.au>
12  * License: BSD-MIT
13  *
14  * Example:
15  *      #include <ccan/time/time.h>
16  *      #include <stdlib.h>
17  *      #include <stdio.h>
18  *      #include <err.h>
19  *
20  *      int main(int argc, char *argv[])
21  *      {
22  *              struct timeabs t;
23  *
24  *              if (argc != 2)
25  *                      errx(1, "Usage: %s <diff in millisec>", argv[0]);
26  *
27  *              t = time_now();
28  *              if (argv[1][0] == '-')
29  *                      t = timeabs_sub(t, time_from_msec(atol(argv[1]+1)));
30  *              else
31  *                      t = timeabs_add(t, time_from_msec(atol(argv[1])));
32  *
33  *              printf("%lu.%09u\n",
34  *                     (unsigned long)t.ts.tv_sec, (unsigned)t.ts.tv_nsec);
35  *              return 0;
36  *      }
37  */
38 int main(int argc, char *argv[])
39 {
40         /* Expect exactly one argument */
41         if (argc != 2)
42                 return 1;
43
44         if (strcmp(argv[1], "depends") == 0) {
45                 return 0;
46         }
47
48 #if HAVE_CLOCK_GETTIME_IN_LIBRT
49         if (strcmp(argv[1], "libs") == 0) {
50                 printf("rt\n");
51                 return 0;
52         }
53 #endif
54
55         return 1;
56 }