2 * Copyright 1996 Massachusetts Institute of Technology
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose and without fee is hereby
6 * granted, provided that both the above copyright notice and this
7 * permission notice appear in all copies, that both the above
8 * copyright notice and this permission notice appear in all
9 * supporting documentation, and that the name of M.I.T. not be used
10 * in advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission. M.I.T. makes
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied
16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Second attempt at a `tzmenu' program, using the separate description
32 * files provided in newer tzdata releases.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
47 #include <sys/fcntl.h>
48 #include <sys/param.h>
49 #include <sys/queue.h>
52 #define _PATH_ZONETAB "/usr/share/zoneinfo/zone.tab"
53 #define _PATH_ISO3166 "/usr/share/misc/iso3166"
54 #define _PATH_ZONEINFO "/usr/share/zoneinfo"
55 #define _PATH_LOCALTIME "/etc/localtime"
56 #define _PATH_DB "/var/db/zoneinfo"
57 #define _PATH_WALL_CMOS_CLOCK "/etc/wall_cmos_clock"
60 #define SILLY_BUFFER_SIZE 2*PATH_MAX
62 #warning "Somebody needs to fix this to dynamically size this buffer."
63 #define SILLY_BUFFER_SIZE 2048
66 static char path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
67 path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN],
68 path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
70 static int reallydoit = 1;
71 static int reinstall = 0;
72 static int usedialog = 1;
73 static char *chrootenv = NULL;
75 static void usage(void);
76 static int confirm_zone(const char *filename);
77 static int continent_country_menu(dialogMenuItem *);
78 static int install_zoneinfo_file(const char *zoneinfo_file);
79 static int set_zone_multi(dialogMenuItem *);
80 static int set_zone_whole_country(dialogMenuItem *);
81 static int set_zone_menu(dialogMenuItem *);
82 static int set_zone_utc(void);
91 static struct continent africa, america, antarctica, arctic, asia, atlantic;
92 static struct continent australia, europe, indian, pacific, utc;
94 static struct continent_names {
96 struct continent *continent;
97 } continent_names[] = {
98 { "Africa", &africa },
99 { "America", &america },
100 { "Antarctica", &antarctica },
101 { "Arctic", &arctic },
103 { "Atlantic", &atlantic },
104 { "Australia", &australia },
105 { "Europe", &europe },
106 { "Indian", &indian },
107 { "Pacific", &pacific },
111 static struct continent_items {
114 } continent_items[] = {
116 { "2", "America -- North and South" },
117 { "3", "Antarctica" },
118 { "4", "Arctic Ocean" },
120 { "6", "Atlantic Ocean" },
121 { "7", "Australia" },
123 { "9", "Indian Ocean" },
124 { "0", "Pacific Ocean" },
128 #define NCONTINENTS \
129 (int)((sizeof(continent_items)) / (sizeof(continent_items[0])))
130 static dialogMenuItem continents[NCONTINENTS];
132 #define OCEANP(x) ((x) == 3 || (x) == 5 || (x) == 8 || (x) == 9)
135 continent_country_menu(dialogMenuItem *continent)
137 char title[64], prompt[64];
138 struct continent *contp = continent->data;
139 int isocean = OCEANP(continent - continents);
143 if (strcmp(continent->title, "UTC") == 0)
144 return set_zone_utc();
146 /* Short cut -- if there's only one country, don't post a menu. */
147 if (contp->nitems == 1)
148 return (contp->menu[0].fire(&contp->menu[0]));
150 /* It's amazing how much good grammar really matters... */
152 snprintf(title, sizeof(title), "Countries in %s",
154 snprintf(prompt, sizeof(prompt), "Select a country or region");
156 snprintf(title, sizeof(title), "Islands and groups in the %s",
158 snprintf(prompt, sizeof(prompt), "Select an island or group");
161 menulen = contp->nitems < 16 ? contp->nitems : 16;
162 rv = dialog_menu(title, prompt, -1, -1, menulen, -contp->nitems,
163 contp->menu, 0, &contp->ch, &contp->sc);
165 return (DITEM_LEAVE_MENU);
166 return (DITEM_RECREATE);
169 static struct continent *
170 find_continent(const char *name)
174 for (i = 0; i < NCONTINENTS; i++)
175 if (strcmp(name, continent_names[i].name) == 0)
176 return (continent_names[i].continent);
184 char *filename; /* use iff nzones < 0 */
185 struct continent *continent; /* use iff nzones < 0 */
186 TAILQ_HEAD(, zone) zones; /* use iff nzones > 0 */
187 dialogMenuItem *submenu; /* use iff nzones > 0 */
191 TAILQ_ENTRY(zone) link;
194 struct continent *continent;
198 * This is the easiest organization... we use ISO 3166 country codes,
199 * of the two-letter variety, so we just size this array to suit.
200 * Beats worrying about dynamic allocation.
202 #define NCOUNTRIES (26 * 26)
203 static struct country countries[NCOUNTRIES];
205 #define CODE2INT(s) ((s[0] - 'A') * 26 + (s[1] - 'A'))
208 * Read the ISO 3166 country code database in _PATH_ISO3166
209 * (/usr/share/misc/iso3166). On error, exit via err(3).
212 read_iso3166_table(void)
220 fp = fopen(path_iso3166, "r");
222 err(1, "%s", path_iso3166);
225 while ((s = fgetln(fp, &len)) != 0) {
227 if (s[len - 1] != '\n')
228 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
230 if (s[0] == '#' || strspn(s, " \t") == len - 1)
233 /* Isolate the two-letter code. */
234 t = strsep(&s, "\t");
235 if (t == 0 || strlen(t) != 2)
236 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
237 if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z')
238 errx(1, "%s:%d: invalid code `%s'", path_iso3166,
241 /* Now skip past the three-letter and numeric codes. */
242 name = strsep(&s, "\t"); /* 3-let */
243 if (name == 0 || strlen(name) != 3)
244 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
245 name = strsep(&s, "\t"); /* numeric */
246 if (name == 0 || strlen(name) != 3)
247 errx(1, "%s:%d: invalid format", path_iso3166, lineno);
251 cp = &countries[CODE2INT(t)];
253 errx(1, "%s:%d: country code `%s' multiply defined: %s",
254 path_iso3166, lineno, t, cp->name);
255 cp->name = strdup(name);
256 if (cp->name == NULL)
257 errx(1, "malloc failed");
260 errx(1, "malloc failed");
267 add_zone_to_country(int lineno, const char *tlc, const char *descr,
268 const char *file, struct continent *cont)
273 if (tlc[0] < 'A' || tlc[0] > 'Z' || tlc[1] < 'A' || tlc[1] > 'Z')
274 errx(1, "%s:%d: country code `%s' invalid", path_zonetab,
277 cp = &countries[CODE2INT(tlc)];
279 errx(1, "%s:%d: country code `%s' unknown", path_zonetab,
284 errx(1, "%s:%d: conflicting zone definition",
285 path_zonetab, lineno);
287 zp = malloc(sizeof(*zp));
289 errx(1, "malloc(%zu)", sizeof(*zp));
292 TAILQ_INIT(&cp->zones);
294 zp->descr = strdup(descr);
295 if (zp->descr == NULL)
296 errx(1, "malloc failed");
297 zp->filename = strdup(file);
298 if (zp->filename == NULL)
299 errx(1, "malloc failed");
300 zp->continent = cont;
301 TAILQ_INSERT_TAIL(&cp->zones, zp, link);
305 errx(1, "%s:%d: zone must have description",
306 path_zonetab, lineno);
308 errx(1, "%s:%d: zone multiply defined",
309 path_zonetab, lineno);
311 cp->filename = strdup(file);
312 if (cp->filename == NULL)
313 errx(1, "malloc failed");
314 cp->continent = cont;
319 * This comparison function intentionally sorts all of the null-named
320 * ``countries''---i.e., the codes that don't correspond to a real
321 * country---to the end. Everything else is lexical by country name.
324 compare_countries(const void *xa, const void *xb)
326 const struct country *a = xa, *b = xb;
328 if (a->name == 0 && b->name == 0)
330 if (a->name == 0 && b->name != 0)
335 return (strcmp(a->name, b->name));
339 * This must be done AFTER all zone descriptions are read, since it breaks
346 qsort(countries, NCOUNTRIES, sizeof(countries[0]), compare_countries);
354 struct continent *cont;
356 char *line, *tlc, *coord, *file, *descr, *p;
359 fp = fopen(path_zonetab, "r");
361 err(1, "%s", path_zonetab);
364 while ((line = fgetln(fp, &len)) != 0) {
366 if (line[len - 1] != '\n')
367 errx(1, "%s:%d: invalid format", path_zonetab, lineno);
368 line[len - 1] = '\0';
372 tlc = strsep(&line, "\t");
373 if (strlen(tlc) != 2)
374 errx(1, "%s:%d: invalid country code `%s'",
375 path_zonetab, lineno, tlc);
376 coord = strsep(&line, "\t"); /* Unused */
377 file = strsep(&line, "\t");
378 p = strchr(file, '/');
380 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
383 strncat(contbuf, file, p - file);
384 cont = find_continent(contbuf);
386 errx(1, "%s:%d: invalid region `%s'", path_zonetab,
389 descr = (line != NULL && *line != '\0') ? line : NULL;
391 add_zone_to_country(lineno, tlc, descr, file, cont);
400 struct zone *zp, *zp2;
401 struct continent *cont;
406 * First, count up all the countries in each continent/ocean.
407 * Be careful to count those countries which have multiple zones
408 * only once for each. NB: some countries are in multiple
411 for (cp = countries; cp->name; cp++) {
414 if (cp->nzones < 0) {
415 cp->continent->nitems++;
417 TAILQ_FOREACH(zp, &cp->zones, link) {
418 cont = zp->continent;
419 for (zp2 = TAILQ_FIRST(&cp->zones);
420 zp2->continent != cont;
421 zp2 = TAILQ_NEXT(zp2, link))
424 zp->continent->nitems++;
430 * Now allocate memory for the country menus and initialize
431 * continent menus. We set nitems back to zero so that we can
432 * use it for counting again when we actually build the menus.
434 memset(continents, 0, sizeof(continents));
435 for (i = 0; i < NCONTINENTS; i++) {
436 continent_names[i].continent->menu =
437 malloc(sizeof(dialogMenuItem) *
438 continent_names[i].continent->nitems);
439 if (continent_names[i].continent->menu == 0)
440 errx(1, "malloc for continent menu");
441 continent_names[i].continent->nitems = 0;
442 continents[i].prompt = continent_items[i].prompt;
443 continents[i].title = continent_items[i].title;
444 continents[i].fire = continent_country_menu;
445 continents[i].data = continent_names[i].continent;
449 * Now that memory is allocated, create the menu items for
450 * each continent. For multiple-zone countries, also create
451 * the country's zone submenu.
453 for (cp = countries; cp->name; cp++) {
456 if (cp->nzones < 0) {
457 dmi = &cp->continent->menu[cp->continent->nitems];
458 memset(dmi, 0, sizeof(*dmi));
459 asprintf(&dmi->prompt, "%d", ++cp->continent->nitems);
460 dmi->title = cp->name;
462 dmi->fire = set_zone_whole_country;
466 cp->submenu = malloc(cp->nzones * sizeof(*dmi));
467 if (cp->submenu == 0)
468 errx(1, "malloc for submenu");
470 TAILQ_FOREACH(zp, &cp->zones, link) {
471 cont = zp->continent;
472 dmi = &cp->submenu[cp->nzones];
473 memset(dmi, 0, sizeof(*dmi));
474 asprintf(&dmi->prompt, "%d", ++cp->nzones);
475 dmi->title = zp->descr;
477 dmi->fire = set_zone_multi;
481 for (zp2 = TAILQ_FIRST(&cp->zones);
482 zp2->continent != cont;
483 zp2 = TAILQ_NEXT(zp2, link))
488 dmi = &cont->menu[cont->nitems];
489 memset(dmi, 0, sizeof(*dmi));
490 asprintf(&dmi->prompt, "%d", ++cont->nitems);
491 dmi->title = cp->name;
493 dmi->fire = set_zone_menu;
502 set_zone_menu(dialogMenuItem *dmi)
504 char title[64], prompt[64];
505 struct country *cp = dmi->data;
509 snprintf(title, sizeof(title), "%s Time Zones", cp->name);
510 snprintf(prompt, sizeof(prompt),
511 "Select a zone which observes the same time as your locality.");
512 menulen = cp->nzones < 16 ? cp->nzones : 16;
513 rv = dialog_menu(title, prompt, -1, -1, menulen, -cp->nzones,
514 cp->submenu, 0, 0, 0);
516 return (DITEM_RECREATE);
517 return (DITEM_LEAVE_MENU);
523 if (!confirm_zone(NULL))
524 return (DITEM_FAILURE | DITEM_RECREATE);
526 return (install_zoneinfo_file(NULL));
530 install_zoneinfo_file(const char *zoneinfo_file)
533 char title[64], prompt[SILLY_BUFFER_SIZE];
536 int fd1, fd2, copymode;
538 if (lstat(path_localtime, &sb) < 0) {
539 /* Nothing there yet... */
541 } else if (S_ISLNK(sb.st_mode))
547 snprintf(title, sizeof(title), "Info");
548 if (zoneinfo_file == NULL)
549 snprintf(prompt, sizeof(prompt),
550 "Removing %s", path_localtime);
552 snprintf(prompt, sizeof(prompt),
553 "Copying %s to %s", zoneinfo_file, path_localtime);
555 snprintf(prompt, sizeof(prompt),
556 "Creating symbolic link %s to %s",
557 path_localtime, zoneinfo_file);
559 dialog_mesgbox(title, prompt, 8, 72);
561 fprintf(stderr, "%s\n", prompt);
565 if (zoneinfo_file == NULL) {
566 if (unlink(path_localtime) < 0 && errno != ENOENT) {
567 snprintf(title, sizeof(title), "Error");
568 snprintf(prompt, sizeof(prompt),
569 "Could not delete %s: %s", path_localtime,
572 dialog_mesgbox(title, prompt, 8, 72);
574 fprintf(stderr, "%s\n", prompt);
576 return (DITEM_FAILURE | DITEM_RECREATE);
578 if (unlink(path_db) < 0 && errno != ENOENT) {
579 snprintf(title, sizeof(title), "Error");
580 snprintf(prompt, sizeof(prompt),
581 "Could not delete %s: %s", path_db,
584 dialog_mesgbox(title, prompt, 8, 72);
586 fprintf(stderr, "%s\n", prompt);
588 return (DITEM_FAILURE | DITEM_RECREATE);
591 snprintf(prompt, sizeof(prompt),
592 "Removed %s", path_localtime);
594 return (DITEM_LEAVE_MENU);
598 fd1 = open(zoneinfo_file, O_RDONLY, 0);
600 snprintf(title, sizeof(title), "Error");
601 snprintf(prompt, sizeof(prompt),
602 "Could not open %s: %s", zoneinfo_file,
605 dialog_mesgbox(title, prompt, 8, 72);
607 fprintf(stderr, "%s\n", prompt);
608 return (DITEM_FAILURE | DITEM_RECREATE);
611 if (unlink(path_localtime) < 0 && errno != ENOENT) {
612 snprintf(prompt, sizeof(prompt),
613 "Could not unlink %s: %s",
614 path_localtime, strerror(errno));
616 snprintf(title, sizeof(title), "Error");
617 dialog_msgbox(title, prompt, 8, 72, 1);
619 fprintf(stderr, "%s\n", prompt);
620 return (DITEM_FAILURE | DITEM_RECREATE);
623 fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
624 S_IRUSR | S_IRGRP | S_IROTH);
626 snprintf(title, sizeof(title), "Error");
627 snprintf(prompt, sizeof(prompt),
628 "Could not open %s: %s",
629 path_localtime, strerror(errno));
631 dialog_mesgbox(title, prompt, 8, 72);
633 fprintf(stderr, "%s\n", prompt);
634 return (DITEM_FAILURE | DITEM_RECREATE);
637 while ((len = read(fd1, buf, sizeof(buf))) > 0)
638 if ((len = write(fd2, buf, len)) < 0)
642 snprintf(title, sizeof(title), "Error");
643 snprintf(prompt, sizeof(prompt),
644 "Error copying %s to %s %s", zoneinfo_file,
645 path_localtime, strerror(errno));
647 dialog_mesgbox(title, prompt, 8, 72);
649 fprintf(stderr, "%s\n", prompt);
650 /* Better to leave none than a corrupt one. */
651 unlink(path_localtime);
652 return (DITEM_FAILURE | DITEM_RECREATE);
657 if (access(zoneinfo_file, R_OK) != 0) {
658 snprintf(title, sizeof(title), "Error");
659 snprintf(prompt, sizeof(prompt),
660 "Cannot access %s: %s", zoneinfo_file,
663 dialog_mesgbox(title, prompt, 8, 72);
665 fprintf(stderr, "%s\n", prompt);
666 return (DITEM_FAILURE | DITEM_RECREATE);
668 if (unlink(path_localtime) < 0 && errno != ENOENT) {
669 snprintf(prompt, sizeof(prompt),
670 "Could not unlink %s: %s",
671 path_localtime, strerror(errno));
673 snprintf(title, sizeof(title), "Error");
674 dialog_msgbox(title, prompt, 8, 72, 1);
676 fprintf(stderr, "%s\n", prompt);
677 return (DITEM_FAILURE | DITEM_RECREATE);
679 if (symlink(zoneinfo_file, path_localtime) < 0) {
680 snprintf(title, sizeof(title), "Error");
681 snprintf(prompt, sizeof(prompt),
682 "Cannot create symbolic link %s to %s: %s",
683 path_localtime, zoneinfo_file,
686 dialog_mesgbox(title, prompt, 8, 72);
688 fprintf(stderr, "%s\n", prompt);
689 return (DITEM_FAILURE | DITEM_RECREATE);
694 snprintf(title, sizeof(title), "Done");
696 snprintf(prompt, sizeof(prompt),
697 "Copied timezone file from %s to %s",
698 zoneinfo_file, path_localtime);
700 snprintf(prompt, sizeof(prompt),
701 "Created symbolic link from %s to %s",
702 zoneinfo_file, path_localtime);
704 dialog_mesgbox(title, prompt, 8, 72);
706 fprintf(stderr, "%s\n", prompt);
710 return (DITEM_LEAVE_MENU);
714 install_zoneinfo(const char *zoneinfo)
718 char path_zoneinfo_file[MAXPATHLEN];
720 sprintf(path_zoneinfo_file, "%s/%s", path_zoneinfo, zoneinfo);
721 rv = install_zoneinfo_file(path_zoneinfo_file);
723 /* Save knowledge for later */
724 if (reallydoit && (rv & DITEM_FAILURE) == 0) {
725 if ((f = fopen(path_db, "w")) != NULL) {
726 fprintf(f, "%s\n", zoneinfo);
735 confirm_zone(const char *filename)
737 char title[64], prompt[64];
742 setenv("TZ", filename == NULL ? "" : filename, 1);
746 snprintf(title, sizeof(title), "Confirmation");
747 snprintf(prompt, sizeof(prompt),
748 "Does the abbreviation `%s' look reasonable?", tm->tm_zone);
749 rv = !dialog_yesno(title, prompt, 5, 72);
754 set_zone_multi(dialogMenuItem *dmi)
756 struct zone *zp = dmi->data;
759 if (!confirm_zone(zp->filename))
760 return (DITEM_FAILURE | DITEM_RECREATE);
762 rv = install_zoneinfo(zp->filename);
767 set_zone_whole_country(dialogMenuItem *dmi)
769 struct country *cp = dmi->data;
772 if (!confirm_zone(cp->filename))
773 return (DITEM_FAILURE | DITEM_RECREATE);
775 rv = install_zoneinfo(cp->filename);
783 fprintf(stderr, "usage: tzsetup [-nrs] [-C chroot_directory]"
784 " [zoneinfo_file | zoneinfo_name]\n");
788 #if defined(__sparc64__)
789 #define DIALOG_UTC dialog_yesno
791 #define DIALOG_UTC dialog_noyes
795 main(int argc, char **argv)
797 char title[64], prompt[128];
798 int c, fd, rv, skiputc;
801 while ((c = getopt(argc, argv, "C:nrs")) != -1) {
821 if (argc - optind > 1)
824 if (chrootenv == NULL) {
825 strcpy(path_zonetab, _PATH_ZONETAB);
826 strcpy(path_iso3166, _PATH_ISO3166);
827 strcpy(path_zoneinfo, _PATH_ZONEINFO);
828 strcpy(path_localtime, _PATH_LOCALTIME);
829 strcpy(path_db, _PATH_DB);
830 strcpy(path_wall_cmos_clock, _PATH_WALL_CMOS_CLOCK);
832 sprintf(path_zonetab, "%s/%s", chrootenv, _PATH_ZONETAB);
833 sprintf(path_iso3166, "%s/%s", chrootenv, _PATH_ISO3166);
834 sprintf(path_zoneinfo, "%s/%s", chrootenv, _PATH_ZONEINFO);
835 sprintf(path_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
836 sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
837 sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,
838 _PATH_WALL_CMOS_CLOCK);
842 /* Override the user-supplied umask. */
843 (void)umask(S_IWGRP | S_IWOTH);
845 if (reinstall == 1) {
847 char zoneinfo[MAXPATHLEN];
849 if ((f = fopen(path_db, "r")) != NULL) {
850 if (fgets(zoneinfo, sizeof(zoneinfo), f) != NULL) {
851 zoneinfo[sizeof(zoneinfo) - 1] = 0;
852 if (strlen(zoneinfo) > 0) {
853 zoneinfo[strlen(zoneinfo) - 1] = 0;
854 rv = install_zoneinfo(zoneinfo);
855 exit(rv & ~DITEM_LEAVE_MENU);
857 errx(1, "Error reading %s.\n", path_db);
861 "Unable to determine earlier installed zoneinfo "
862 "name. Check %s", path_db);
864 errx(1, "Cannot open %s for reading. Does it exist?", path_db);
868 * If the arguments on the command-line do not specify a file,
869 * then interpret it as a zoneinfo name
871 if (optind == argc - 1) {
874 if (stat(argv[optind], &sb) != 0) {
876 rv = install_zoneinfo(argv[optind]);
877 exit(rv & ~DITEM_LEAVE_MENU);
882 read_iso3166_table();
889 snprintf(title, sizeof(title),
890 "Select local or UTC (Greenwich Mean Time) clock");
891 snprintf(prompt, sizeof(prompt),
892 "Is this machine's CMOS clock set to UTC? "
893 "If it is set to local time,\n"
894 "or you don't know, please choose NO here!");
895 if (!DIALOG_UTC(title, prompt, 7, 72)) {
897 unlink(path_wall_cmos_clock);
900 fd = open(path_wall_cmos_clock,
901 O_WRONLY | O_CREAT | O_TRUNC,
902 S_IRUSR | S_IRGRP | S_IROTH);
906 path_wall_cmos_clock);
911 dialog_clear_norefresh();
913 if (optind == argc - 1) {
914 snprintf(title, sizeof(title), "Default timezone provided");
915 snprintf(prompt, sizeof(prompt),
916 "\nUse the default `%s' zone?", argv[optind]);
917 if (!dialog_yesno(title, prompt, 7, 72)) {
918 rv = install_zoneinfo_file(argv[optind]);
921 exit(rv & ~DITEM_LEAVE_MENU);
923 dialog_clear_norefresh();
925 snprintf(title, sizeof(title), "Time Zone Selector");
926 snprintf(prompt, sizeof(prompt), "Select a region");
927 dialog_menu(title, prompt, -1, -1, NCONTINENTS, -NCONTINENTS,
928 continents, 0, NULL, NULL);