tzsetup.c (290031) | tzsetup.c (298033) |
---|---|
1/* 2 * Copyright 1996 Massachusetts Institute of Technology 3 * 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 --- 19 unchanged lines hidden (view full) --- 28 */ 29 30/* 31 * Second attempt at a `tzmenu' program, using the separate description 32 * files provided in newer tzdata releases. 33 */ 34 35#include <sys/cdefs.h> | 1/* 2 * Copyright 1996 Massachusetts Institute of Technology 3 * 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 --- 19 unchanged lines hidden (view full) --- 28 */ 29 30/* 31 * Second attempt at a `tzmenu' program, using the separate description 32 * files provided in newer tzdata releases. 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/usr.sbin/tzsetup/tzsetup.c 290031 2015-10-27 01:26:50Z delphij $"); | 36__FBSDID("$FreeBSD: head/usr.sbin/tzsetup/tzsetup.c 298033 2016-04-15 04:10:47Z araujo $"); |
37 38#include <err.h> 39#include <errno.h> 40#include <stdio.h> 41#include <stdlib.h> 42#include <string.h> 43#include <time.h> 44#include <unistd.h> --- 294 unchanged lines hidden (view full) --- 339 char *s, *t, *name; 340 int lineno; 341 342 fp = fopen(path_iso3166, "r"); 343 if (!fp) 344 err(1, "%s", path_iso3166); 345 lineno = 0; 346 | 37 38#include <err.h> 39#include <errno.h> 40#include <stdio.h> 41#include <stdlib.h> 42#include <string.h> 43#include <time.h> 44#include <unistd.h> --- 294 unchanged lines hidden (view full) --- 339 char *s, *t, *name; 340 int lineno; 341 342 fp = fopen(path_iso3166, "r"); 343 if (!fp) 344 err(1, "%s", path_iso3166); 345 lineno = 0; 346 |
347 while ((s = fgetln(fp, &len)) != 0) { | 347 while ((s = fgetln(fp, &len)) != NULL) { |
348 lineno++; 349 if (s[len - 1] != '\n') 350 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 351 s[len - 1] = '\0'; 352 if (s[0] == '#' || strspn(s, " \t") == len - 1) 353 continue; 354 355 /* Isolate the two-letter code. */ 356 t = strsep(&s, "\t"); | 348 lineno++; 349 if (s[len - 1] != '\n') 350 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 351 s[len - 1] = '\0'; 352 if (s[0] == '#' || strspn(s, " \t") == len - 1) 353 continue; 354 355 /* Isolate the two-letter code. */ 356 t = strsep(&s, "\t"); |
357 if (t == 0 || strlen(t) != 2) | 357 if (t == NULL || strlen(t) != 2) |
358 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 359 if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z') 360 errx(1, "%s:%d: invalid code `%s'", path_iso3166, 361 lineno, t); 362 363 /* Now skip past the three-letter and numeric codes. */ 364 name = strsep(&s, "\t"); /* 3-let */ | 358 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 359 if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z') 360 errx(1, "%s:%d: invalid code `%s'", path_iso3166, 361 lineno, t); 362 363 /* Now skip past the three-letter and numeric codes. */ 364 name = strsep(&s, "\t"); /* 3-let */ |
365 if (name == 0 || strlen(name) != 3) | 365 if (name == NULL || strlen(name) != 3) |
366 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 367 name = strsep(&s, "\t"); /* numeric */ | 366 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 367 name = strsep(&s, "\t"); /* numeric */ |
368 if (name == 0 || strlen(name) != 3) | 368 if (name == NULL || strlen(name) != 3) |
369 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 370 371 name = s; 372 373 cp = &countries[CODE2INT(t)]; 374 if (cp->name) 375 errx(1, "%s:%d: country code `%s' multiply defined: %s", 376 path_iso3166, lineno, t, cp->name); --- 25 unchanged lines hidden (view full) --- 402 lineno, tlc); 403 404 if (descr) { 405 if (cp->nzones < 0) 406 errx(1, "%s:%d: conflicting zone definition", 407 path_zonetab, lineno); 408 409 zp = malloc(sizeof(*zp)); | 369 errx(1, "%s:%d: invalid format", path_iso3166, lineno); 370 371 name = s; 372 373 cp = &countries[CODE2INT(t)]; 374 if (cp->name) 375 errx(1, "%s:%d: country code `%s' multiply defined: %s", 376 path_iso3166, lineno, t, cp->name); --- 25 unchanged lines hidden (view full) --- 402 lineno, tlc); 403 404 if (descr) { 405 if (cp->nzones < 0) 406 errx(1, "%s:%d: conflicting zone definition", 407 path_zonetab, lineno); 408 409 zp = malloc(sizeof(*zp)); |
410 if (zp == 0) | 410 if (zp == NULL) |
411 errx(1, "malloc(%zu)", sizeof(*zp)); 412 413 if (cp->nzones == 0) 414 TAILQ_INIT(&cp->zones); 415 416 zp->descr = strdup(descr); 417 if (zp->descr == NULL) 418 errx(1, "malloc failed"); --- 59 unchanged lines hidden (view full) --- 478 char *line, *tlc, *file, *descr, *p; 479 int lineno; 480 481 fp = fopen(path_zonetab, "r"); 482 if (!fp) 483 err(1, "%s", path_zonetab); 484 lineno = 0; 485 | 411 errx(1, "malloc(%zu)", sizeof(*zp)); 412 413 if (cp->nzones == 0) 414 TAILQ_INIT(&cp->zones); 415 416 zp->descr = strdup(descr); 417 if (zp->descr == NULL) 418 errx(1, "malloc failed"); --- 59 unchanged lines hidden (view full) --- 478 char *line, *tlc, *file, *descr, *p; 479 int lineno; 480 481 fp = fopen(path_zonetab, "r"); 482 if (!fp) 483 err(1, "%s", path_zonetab); 484 lineno = 0; 485 |
486 while ((line = fgetln(fp, &len)) != 0) { | 486 while ((line = fgetln(fp, &len)) != NULL) { |
487 lineno++; 488 if (line[len - 1] != '\n') 489 errx(1, "%s:%d: invalid format", path_zonetab, lineno); 490 line[len - 1] = '\0'; 491 if (line[0] == '#') 492 continue; 493 494 tlc = strsep(&line, "\t"); 495 if (strlen(tlc) != 2) 496 errx(1, "%s:%d: invalid country code `%s'", 497 path_zonetab, lineno, tlc); 498 /* coord = */ strsep(&line, "\t"); /* Unused */ 499 file = strsep(&line, "\t"); 500 p = strchr(file, '/'); | 487 lineno++; 488 if (line[len - 1] != '\n') 489 errx(1, "%s:%d: invalid format", path_zonetab, lineno); 490 line[len - 1] = '\0'; 491 if (line[0] == '#') 492 continue; 493 494 tlc = strsep(&line, "\t"); 495 if (strlen(tlc) != 2) 496 errx(1, "%s:%d: invalid country code `%s'", 497 path_zonetab, lineno, tlc); 498 /* coord = */ strsep(&line, "\t"); /* Unused */ 499 file = strsep(&line, "\t"); 500 p = strchr(file, '/'); |
501 if (p == 0) | 501 if (p == NULL) |
502 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab, 503 lineno, file); 504 contbuf[0] = '\0'; 505 strncat(contbuf, file, p - file); 506 cont = find_continent(contbuf); 507 if (!cont) 508 errx(1, "%s:%d: invalid region `%s'", path_zonetab, 509 lineno, contbuf); --- 43 unchanged lines hidden (view full) --- 553 * continent menus. We set nitems back to zero so that we can 554 * use it for counting again when we actually build the menus. 555 */ 556 memset(continents, 0, sizeof(continents)); 557 for (i = 0; i < NCONTINENTS; i++) { 558 continent_names[i].continent->menu = 559 malloc(sizeof(dialogMenuItem) * 560 continent_names[i].continent->nitems); | 502 errx(1, "%s:%d: invalid zone name `%s'", path_zonetab, 503 lineno, file); 504 contbuf[0] = '\0'; 505 strncat(contbuf, file, p - file); 506 cont = find_continent(contbuf); 507 if (!cont) 508 errx(1, "%s:%d: invalid region `%s'", path_zonetab, 509 lineno, contbuf); --- 43 unchanged lines hidden (view full) --- 553 * continent menus. We set nitems back to zero so that we can 554 * use it for counting again when we actually build the menus. 555 */ 556 memset(continents, 0, sizeof(continents)); 557 for (i = 0; i < NCONTINENTS; i++) { 558 continent_names[i].continent->menu = 559 malloc(sizeof(dialogMenuItem) * 560 continent_names[i].continent->nitems); |
561 if (continent_names[i].continent->menu == 0) | 561 if (continent_names[i].continent->menu == NULL) |
562 errx(1, "malloc for continent menu"); 563 continent_names[i].continent->nitems = 0; 564 continents[i].prompt = continent_items[i].prompt; 565 continents[i].title = continent_items[i].title; 566 continents[i].fire = continent_country_menu; 567 continents[i].data = continent_names[i].continent; 568 } 569 --- 496 unchanged lines hidden --- | 562 errx(1, "malloc for continent menu"); 563 continent_names[i].continent->nitems = 0; 564 continents[i].prompt = continent_items[i].prompt; 565 continents[i].title = continent_items[i].title; 566 continents[i].fire = continent_country_menu; 567 continents[i].data = continent_names[i].continent; 568 } 569 --- 496 unchanged lines hidden --- |