MCPcopy Create free account
hub / github.com/eggert/tz / main

Function main

date.c:42–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40ATTRIBUTE_NORETURN static void usage(void);
41
42int
43main(const int argc, char *argv[])
44{
45 register const char * format = "+%+";
46 register int ch;
47 register bool rflag = false;
48 time_t t;
49 intmax_t secs;
50 char * endarg;
51
52#ifdef LC_ALL
53 setlocale(LC_ALL, "");
54#endif /* defined(LC_ALL) */
55#if HAVE_GETTEXT
56# ifdef TZ_DOMAINDIR
57 bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
58# endif /* defined(TEXTDOMAINDIR) */
59 textdomain(TZ_DOMAIN);
60#endif /* HAVE_GETTEXT */
61 t = time(NULL);
62 while ((ch = getopt(argc, argv, "ucr:")) != -1) {
63 switch (ch) {
64 default:
65 usage();
66 case 'u': /* do it in UT */
67 case 'c':
68 dogmt();
69 break;
70 case 'r': /* seconds since 1970 */
71 if (rflag) {
72 fprintf(stderr,
73 _("date: error: multiple -r's used"));
74 usage();
75 }
76 rflag = true;
77 errno = 0;
78 secs = strtoimax(optarg, &endarg, 0);
79 if (*endarg || optarg == endarg)
80 errno = EINVAL;
81 else if (! (TIME_T_MIN <= secs && secs <= TIME_T_MAX))
82 errno = ERANGE;
83 if (errno) {
84 char const *e = strerror(errno);
85 fprintf(stderr, _("date: %s: %s\n"),
86 optarg, e);
87 errensure();
88 exit(retval);
89 }
90 t = secs;
91 break;
92 }
93 }
94 if (optind < argc) {
95 if (argc - optind != 1) {
96 fprintf(stderr,
97 _("date: error: multiple operands in command line\n"));
98 usage();
99 }

Callers

nothing calls this directly

Calls 5

timeFunction · 0.85
dogmtFunction · 0.85
errensureFunction · 0.85
displayFunction · 0.85
usageFunction · 0.70

Tested by

no test coverage detected