zic.c (30829) | zic.c (42997) |
---|---|
1#ifndef lint 2#ifndef NOID | 1#ifndef lint 2#ifndef NOID |
3static char elsieid[] = "@(#)zic.c 7.77"; | 3static char elsieid[] = "@(#)zic.c 7.96"; |
4#endif /* !defined NOID */ 5#endif /* !defined lint */ 6 7#ifndef lint 8static const char rcsid[] = | 4#endif /* !defined NOID */ 5#endif /* !defined lint */ 6 7#ifndef lint 8static const char rcsid[] = |
9 "$Id$"; | 9 "$Id: zic.c,v 1.8 1999/01/21 17:12:49 wollman Exp $"; |
10#endif /* not lint */ 11 12#include "private.h" 13#include "tzfile.h" 14#include <err.h> 15#include <locale.h> 16#include <sys/stat.h> /* for umask manifest constants */ 17#include <sys/types.h> --- 60 unchanged lines hidden (view full) --- 78 79 struct rule * z_rules; 80 int z_nrules; 81 82 struct rule z_untilrule; 83 time_t z_untiltime; 84}; 85 | 10#endif /* not lint */ 11 12#include "private.h" 13#include "tzfile.h" 14#include <err.h> 15#include <locale.h> 16#include <sys/stat.h> /* for umask manifest constants */ 17#include <sys/types.h> --- 60 unchanged lines hidden (view full) --- 78 79 struct rule * z_rules; 80 int z_nrules; 81 82 struct rule z_untilrule; 83 time_t z_untiltime; 84}; 85 |
86extern int getopt P((int argc, char * const argv[], 87 const char * options)); 88extern char * icatalloc P((char * old, const char * new)); 89extern char * icpyalloc P((const char * string)); 90extern void ifree P((char * p)); 91extern char * imalloc P((int n)); 92extern void * irealloc P((void * old, int n)); 93extern int link P((const char * fromname, const char * toname)); 94extern char * optarg; 95extern int optind; 96extern char * scheck P((const char * string, const char * format)); 97 | |
98static void addtt P((time_t starttime, int type)); 99static int addtype P((long gmtoff, const char * abbr, int isdst, 100 int ttisstd, int ttisgmt)); 101static void leapadd P((time_t t, int positive, int rolling, int count)); 102static void adjleap P((void)); 103static void associate P((void)); 104static int ciequal P((const char * ap, const char * bp)); 105static void convert P((long val, char * buf)); --- 26 unchanged lines hidden (view full) --- 132static void puttzcode P((long code, FILE * fp)); 133static int rcomp P((const void * leftp, const void * rightp)); 134static time_t rpytime P((const struct rule * rp, int wantedy)); 135static void rulesub P((struct rule * rp, 136 const char * loyearp, const char * hiyearp, 137 const char * typep, const char * monthp, 138 const char * dayp, const char * timep)); 139static void setboundaries P((void)); | 86static void addtt P((time_t starttime, int type)); 87static int addtype P((long gmtoff, const char * abbr, int isdst, 88 int ttisstd, int ttisgmt)); 89static void leapadd P((time_t t, int positive, int rolling, int count)); 90static void adjleap P((void)); 91static void associate P((void)); 92static int ciequal P((const char * ap, const char * bp)); 93static void convert P((long val, char * buf)); --- 26 unchanged lines hidden (view full) --- 120static void puttzcode P((long code, FILE * fp)); 121static int rcomp P((const void * leftp, const void * rightp)); 122static time_t rpytime P((const struct rule * rp, int wantedy)); 123static void rulesub P((struct rule * rp, 124 const char * loyearp, const char * hiyearp, 125 const char * typep, const char * monthp, 126 const char * dayp, const char * timep)); 127static void setboundaries P((void)); |
128static void setgroup P((gid_t *flag, const char *name)); 129static void setuser P((uid_t *flag, const char *name)); |
|
140static time_t tadd P((time_t t1, long t2)); 141static void usage P((void)); 142static void writezone P((const char * name)); 143static int yearistype P((int year, const char * type)); 144 | 130static time_t tadd P((time_t t1, long t2)); 131static void usage P((void)); 132static void writezone P((const char * name)); 133static int yearistype P((int year, const char * type)); 134 |
145#if !HAVE_STRERROR | 135#if !(HAVE_STRERROR - 0) |
146static char * strerror P((int)); | 136static char * strerror P((int)); |
147#endif /* !HAVE_STRERROR */ | 137#endif /* !(HAVE_STRERROR - 0) */ |
148 149static int charcnt; 150static int errors; 151static const char * filename; 152static int leapcnt; 153static int linenum; 154static time_t max_time; 155static int max_year; | 138 139static int charcnt; 140static int errors; 141static const char * filename; 142static int leapcnt; 143static int linenum; 144static time_t max_time; 145static int max_year; |
146static int max_year_representable; |
|
156static time_t min_time; 157static int min_year; | 147static time_t min_time; 148static int min_year; |
149static int min_year_representable; |
|
158static int noise; 159static const char * rfilename; 160static int rlinenum; 161static int timecnt; 162static int typecnt; 163 164/* 165** Line codes. --- 205 unchanged lines hidden (view full) --- 371#define erealloc(ptr, size) memcheck(irealloc((ptr), (size))) 372#define ecpyalloc(ptr) memcheck(icpyalloc(ptr)) 373#define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp))) 374 375/* 376** Error handling. 377*/ 378 | 150static int noise; 151static const char * rfilename; 152static int rlinenum; 153static int timecnt; 154static int typecnt; 155 156/* 157** Line codes. --- 205 unchanged lines hidden (view full) --- 363#define erealloc(ptr, size) memcheck(irealloc((ptr), (size))) 364#define ecpyalloc(ptr) memcheck(icpyalloc(ptr)) 365#define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp))) 366 367/* 368** Error handling. 369*/ 370 |
379#if ! HAVE_STRERROR | 371#if !(HAVE_STRERROR - 0) |
380static char * 381strerror(errnum) 382int errnum; 383{ | 372static char * 373strerror(errnum) 374int errnum; 375{ |
384 extern char *sys_errlist[]; 385 extern int sys_nerr; | 376 extern char * sys_errlist[]; 377 extern int sys_nerr; |
386 | 378 |
387 if (errnum > 0 && errnum <= sys_nerr) 388 return sys_errlist[errnum]; 389 return "Unknown system error"; | 379 return (errnum > 0 && errnum <= sys_nerr) ? 380 sys_errlist[errnum] : _("Unknown system error"); |
390} | 381} |
391#endif /* ! HAVE_STRERROR */ | 382#endif /* !(HAVE_STRERROR - 0) */ |
392 393static void 394eats(name, num, rname, rnum) 395const char * const name; 396const int num; 397const char * const rname; 398const int rnum; 399{ --- 30 unchanged lines hidden (view full) --- 430} 431 432static void 433warning(string) 434const char * const string; 435{ 436 char * cp; 437 | 383 384static void 385eats(name, num, rname, rnum) 386const char * const name; 387const int num; 388const char * const rname; 389const int rnum; 390{ --- 30 unchanged lines hidden (view full) --- 421} 422 423static void 424warning(string) 425const char * const string; 426{ 427 char * cp; 428 |
438 cp = ecpyalloc("warning: "); | 429 cp = ecpyalloc(_("warning: ")); |
439 cp = ecatalloc(cp, string); | 430 cp = ecatalloc(cp, string); |
440 error(string); | 431 error(cp); |
441 ifree(cp); 442 --errors; 443} 444 445static void 446usage P((void)) 447{ 448 (void) fprintf(stderr, "%s\n%s\n", 449_("usage: zic [-s] [-v] [-l localtime] [-p posixrules] [-d directory]"), 450_(" [-L leapseconds] [-y yearistype] [filename ... ]")); 451 (void) exit(EXIT_FAILURE); 452} 453 454static const char * psxrules; 455static const char * lcltime; 456static const char * directory; 457static const char * leapsec; 458static const char * yitcommand; 459static int sflag = FALSE; | 432 ifree(cp); 433 --errors; 434} 435 436static void 437usage P((void)) 438{ 439 (void) fprintf(stderr, "%s\n%s\n", 440_("usage: zic [-s] [-v] [-l localtime] [-p posixrules] [-d directory]"), 441_(" [-L leapseconds] [-y yearistype] [filename ... ]")); 442 (void) exit(EXIT_FAILURE); 443} 444 445static const char * psxrules; 446static const char * lcltime; 447static const char * directory; 448static const char * leapsec; 449static const char * yitcommand; 450static int sflag = FALSE; |
451static int Dflag; 452static uid_t oflag = (uid_t)-1; 453static gid_t gflag = (gid_t)-1; 454static mode_t mflag = (S_IRUSR | S_IRGRP | S_IROTH 455 | S_IWUSR); |
|
460 461int 462main(argc, argv) 463int argc; 464char * argv[]; 465{ 466 register int i; 467 register int j; --- 4 unchanged lines hidden (view full) --- 472#endif /* defined unix */ 473#if HAVE_GETTEXT - 0 474 (void) setlocale(LC_MESSAGES, ""); 475#ifdef TZ_DOMAINDIR 476 (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); 477#endif /* defined TEXTDOMAINDIR */ 478 (void) textdomain(TZ_DOMAIN); 479#endif /* HAVE_GETTEXT - 0 */ | 456 457int 458main(argc, argv) 459int argc; 460char * argv[]; 461{ 462 register int i; 463 register int j; --- 4 unchanged lines hidden (view full) --- 468#endif /* defined unix */ 469#if HAVE_GETTEXT - 0 470 (void) setlocale(LC_MESSAGES, ""); 471#ifdef TZ_DOMAINDIR 472 (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); 473#endif /* defined TEXTDOMAINDIR */ 474 (void) textdomain(TZ_DOMAIN); 475#endif /* HAVE_GETTEXT - 0 */ |
480 while ((c = getopt(argc, argv, "d:l:p:L:vsy:")) != -1) | 476 while ((c = getopt(argc, argv, "Dd:g:l:m:p:L:u:vsy:")) != -1) |
481 switch (c) { 482 default: 483 usage(); | 477 switch (c) { 478 default: 479 usage(); |
480 case 'D': 481 Dflag = 1; 482 break; |
|
484 case 'd': 485 if (directory == NULL) 486 directory = optarg; 487 else 488 errx(EXIT_FAILURE, 489_("more than one -d option specified")); 490 break; | 483 case 'd': 484 if (directory == NULL) 485 directory = optarg; 486 else 487 errx(EXIT_FAILURE, 488_("more than one -d option specified")); 489 break; |
490 case 'g': 491 setgroup(&gflag, optarg); 492 break; |
|
491 case 'l': 492 if (lcltime == NULL) 493 lcltime = optarg; 494 else 495 errx(EXIT_FAILURE, 496_("more than one -l option specified")); 497 break; | 493 case 'l': 494 if (lcltime == NULL) 495 lcltime = optarg; 496 else 497 errx(EXIT_FAILURE, 498_("more than one -l option specified")); 499 break; |
500 case 'm': 501 { 502 void *set = setmode(optarg); 503 getmode(set, mflag); 504 break; 505 } |
|
498 case 'p': 499 if (psxrules == NULL) 500 psxrules = optarg; 501 else 502 errx(EXIT_FAILURE, 503_("more than one -p option specified")); 504 break; | 506 case 'p': 507 if (psxrules == NULL) 508 psxrules = optarg; 509 else 510 errx(EXIT_FAILURE, 511_("more than one -p option specified")); 512 break; |
513 case 'u': 514 setuser(&uflag, optarg); 515 break; |
|
505 case 'y': 506 if (yitcommand == NULL) 507 yitcommand = optarg; 508 else 509 errx(EXIT_FAILURE, 510_("more than one -y option specified")); 511 break; 512 case 'L': --- 73 unchanged lines hidden (view full) --- 586 } 587 /* 588 ** We get to be careful here since 589 ** there's a fair chance of root running us. 590 */ 591 if (!itsdir(toname)) 592 (void) remove(toname); 593 if (link(fromname, toname) != 0) { | 516 case 'y': 517 if (yitcommand == NULL) 518 yitcommand = optarg; 519 else 520 errx(EXIT_FAILURE, 521_("more than one -y option specified")); 522 break; 523 case 'L': --- 73 unchanged lines hidden (view full) --- 597 } 598 /* 599 ** We get to be careful here since 600 ** there's a fair chance of root running us. 601 */ 602 if (!itsdir(toname)) 603 (void) remove(toname); 604 if (link(fromname, toname) != 0) { |
605 int result; 606 |
|
594 if (mkdirs(toname) != 0) 595 (void) exit(EXIT_FAILURE); | 607 if (mkdirs(toname) != 0) 608 (void) exit(EXIT_FAILURE); |
596 if (link(fromname, toname) != 0) 597 err(EXIT_FAILURE, _("can't link from %s to %s"), 598 fromname, toname); | 609 result = link(fromname, toname); 610#if (HAVE_SYMLINK - 0) 611 if (result != 0) { 612 result = symlink(fromname, toname); 613 if (result == 0) 614warning(_("hard link failed, symbolic link used")); 615 } 616#endif 617 if (result != 0) { 618 err(EXIT_FAILURE, 619 _("%s: Can't link from %s to %s"), 620 fromname, toname); 621 } |
599 } 600 ifree(fromname); 601 ifree(toname); 602} 603 604#ifndef INT_MAX 605#define INT_MAX ((int) (((unsigned)~0)>>1)) 606#endif /* !defined INT_MAX */ --- 24 unchanged lines hidden (view full) --- 631 } else { 632 min_time = 0; 633 max_time = 2 - sflag; 634 max_time <<= TIME_T_BITS_IN_FILE - 1; 635 --max_time; 636 } 637 min_year = TM_YEAR_BASE + gmtime(&min_time)->tm_year; 638 max_year = TM_YEAR_BASE + gmtime(&max_time)->tm_year; | 622 } 623 ifree(fromname); 624 ifree(toname); 625} 626 627#ifndef INT_MAX 628#define INT_MAX ((int) (((unsigned)~0)>>1)) 629#endif /* !defined INT_MAX */ --- 24 unchanged lines hidden (view full) --- 654 } else { 655 min_time = 0; 656 max_time = 2 - sflag; 657 max_time <<= TIME_T_BITS_IN_FILE - 1; 658 --max_time; 659 } 660 min_year = TM_YEAR_BASE + gmtime(&min_time)->tm_year; 661 max_year = TM_YEAR_BASE + gmtime(&max_time)->tm_year; |
662 min_year_representable = min_year; 663 max_year_representable = max_year; |
|
639} 640 641static int 642itsdir(name) 643const char * const name; 644{ 645 register char * myname; 646 register int accres; --- 206 unchanged lines hidden (view full) --- 853 mm = ss = 0; 854 else if (sscanf(string, scheck(string, "%d:%d"), &hh, &mm) == 2) 855 ss = 0; 856 else if (sscanf(string, scheck(string, "%d:%d:%d"), 857 &hh, &mm, &ss) != 3) { 858 error(errstring); 859 return 0; 860 } | 664} 665 666static int 667itsdir(name) 668const char * const name; 669{ 670 register char * myname; 671 register int accres; --- 206 unchanged lines hidden (view full) --- 878 mm = ss = 0; 879 else if (sscanf(string, scheck(string, "%d:%d"), &hh, &mm) == 2) 880 ss = 0; 881 else if (sscanf(string, scheck(string, "%d:%d:%d"), 882 &hh, &mm, &ss) != 3) { 883 error(errstring); 884 return 0; 885 } |
861 if (hh < 0 || hh >= HOURSPERDAY || | 886 if ((hh < 0 || hh >= HOURSPERDAY || |
862 mm < 0 || mm >= MINSPERHOUR || | 887 mm < 0 || mm >= MINSPERHOUR || |
863 ss < 0 || ss > SECSPERMIN) { | 888 ss < 0 || ss > SECSPERMIN) && 889 !(hh == HOURSPERDAY && mm == 0 && ss == 0)) { |
864 error(errstring); 865 return 0; 866 } 867 return eitol(sign) * 868 (eitol(hh * MINSPERHOUR + mm) * 869 eitol(SECSPERMIN) + eitol(ss)); 870} 871 --- 110 unchanged lines hidden (view full) --- 982 i_untilyear = ZF_TILYEAR; 983 i_untilmonth = ZF_TILMONTH; 984 i_untilday = ZF_TILDAY; 985 i_untiltime = ZF_TILTIME; 986 z.z_name = ecpyalloc(fields[ZF_NAME]); 987 } 988 z.z_filename = filename; 989 z.z_linenum = linenum; | 890 error(errstring); 891 return 0; 892 } 893 return eitol(sign) * 894 (eitol(hh * MINSPERHOUR + mm) * 895 eitol(SECSPERMIN) + eitol(ss)); 896} 897 --- 110 unchanged lines hidden (view full) --- 1008 i_untilyear = ZF_TILYEAR; 1009 i_untilmonth = ZF_TILMONTH; 1010 i_untilday = ZF_TILDAY; 1011 i_untiltime = ZF_TILTIME; 1012 z.z_name = ecpyalloc(fields[ZF_NAME]); 1013 } 1014 z.z_filename = filename; 1015 z.z_linenum = linenum; |
990 z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid GMT offset"), TRUE); | 1016 z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UTC offset"), TRUE); |
991 if ((cp = strchr(fields[i_format], '%')) != 0) { 992 if (*++cp != 's' || strchr(cp, '%') != 0) { 993 error(_("invalid abbreviation format")); 994 return FALSE; 995 } 996 } 997 z.z_rule = ecpyalloc(fields[i_rule]); 998 z.z_format = ecpyalloc(fields[i_format]); --- 185 unchanged lines hidden (view full) --- 1184 rp->r_todisstd = TRUE; 1185 rp->r_todisgmt = FALSE; 1186 *ep = '\0'; 1187 break; 1188 case 'w': /* Wall */ 1189 rp->r_todisstd = FALSE; 1190 rp->r_todisgmt = FALSE; 1191 *ep = '\0'; | 1017 if ((cp = strchr(fields[i_format], '%')) != 0) { 1018 if (*++cp != 's' || strchr(cp, '%') != 0) { 1019 error(_("invalid abbreviation format")); 1020 return FALSE; 1021 } 1022 } 1023 z.z_rule = ecpyalloc(fields[i_rule]); 1024 z.z_format = ecpyalloc(fields[i_format]); --- 185 unchanged lines hidden (view full) --- 1210 rp->r_todisstd = TRUE; 1211 rp->r_todisgmt = FALSE; 1212 *ep = '\0'; 1213 break; 1214 case 'w': /* Wall */ 1215 rp->r_todisstd = FALSE; 1216 rp->r_todisgmt = FALSE; 1217 *ep = '\0'; |
1218 break; |
|
1192 case 'g': /* Greenwich */ 1193 case 'u': /* Universal */ 1194 case 'z': /* Zulu */ 1195 rp->r_todisstd = TRUE; 1196 rp->r_todisgmt = TRUE; 1197 *ep = '\0'; 1198 break; 1199 } --- 13 unchanged lines hidden (view full) --- 1213 rp->r_loyear = INT_MAX; 1214 break; 1215 default: /* "cannot happen" */ 1216 errx(EXIT_FAILURE, 1217 _("panic: invalid l_value %d"), lp->l_value); 1218 } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_loyear) != 1) { 1219 error(_("invalid starting year")); 1220 return; | 1219 case 'g': /* Greenwich */ 1220 case 'u': /* Universal */ 1221 case 'z': /* Zulu */ 1222 rp->r_todisstd = TRUE; 1223 rp->r_todisgmt = TRUE; 1224 *ep = '\0'; 1225 break; 1226 } --- 13 unchanged lines hidden (view full) --- 1240 rp->r_loyear = INT_MAX; 1241 break; 1242 default: /* "cannot happen" */ 1243 errx(EXIT_FAILURE, 1244 _("panic: invalid l_value %d"), lp->l_value); 1245 } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_loyear) != 1) { 1246 error(_("invalid starting year")); 1247 return; |
1248 } else if (noise) { 1249 if (rp->r_loyear < min_year_representable) 1250 warning(_("starting year too low to be represented")); 1251 else if (rp->r_loyear > max_year_representable) 1252 warning(_("starting year too high to be represented")); |
|
1221 } 1222 cp = hiyearp; 1223 if ((lp = byword(cp, end_years)) != NULL) switch ((int) lp->l_value) { 1224 case YR_MINIMUM: 1225 rp->r_hiyear = INT_MIN; 1226 break; 1227 case YR_MAXIMUM: 1228 rp->r_hiyear = INT_MAX; 1229 break; 1230 case YR_ONLY: 1231 rp->r_hiyear = rp->r_loyear; 1232 break; 1233 default: /* "cannot happen" */ 1234 errx(EXIT_FAILURE, 1235 _("panic: invalid l_value %d"), lp->l_value); 1236 } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_hiyear) != 1) { 1237 error(_("invalid ending year")); 1238 return; | 1253 } 1254 cp = hiyearp; 1255 if ((lp = byword(cp, end_years)) != NULL) switch ((int) lp->l_value) { 1256 case YR_MINIMUM: 1257 rp->r_hiyear = INT_MIN; 1258 break; 1259 case YR_MAXIMUM: 1260 rp->r_hiyear = INT_MAX; 1261 break; 1262 case YR_ONLY: 1263 rp->r_hiyear = rp->r_loyear; 1264 break; 1265 default: /* "cannot happen" */ 1266 errx(EXIT_FAILURE, 1267 _("panic: invalid l_value %d"), lp->l_value); 1268 } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_hiyear) != 1) { 1269 error(_("invalid ending year")); 1270 return; |
1271 } else if (noise) { 1272 if (rp->r_loyear < min_year_representable) 1273 warning(_("starting year too low to be represented")); 1274 else if (rp->r_loyear > max_year_representable) 1275 warning(_("starting year too high to be represented")); |
|
1239 } 1240 if (rp->r_loyear > rp->r_hiyear) { 1241 error(_("starting year greater than ending year")); 1242 return; 1243 } 1244 if (*typep == '\0') 1245 rp->r_yrtype = NULL; 1246 else { 1247 if (rp->r_loyear == rp->r_hiyear) { 1248 error(_("typed single year")); 1249 return; 1250 } 1251 rp->r_yrtype = ecpyalloc(typep); 1252 } | 1276 } 1277 if (rp->r_loyear > rp->r_hiyear) { 1278 error(_("starting year greater than ending year")); 1279 return; 1280 } 1281 if (*typep == '\0') 1282 rp->r_yrtype = NULL; 1283 else { 1284 if (rp->r_loyear == rp->r_hiyear) { 1285 error(_("typed single year")); 1286 return; 1287 } 1288 rp->r_yrtype = ecpyalloc(typep); 1289 } |
1290 if (rp->r_loyear < min_year && rp->r_loyear > 0) 1291 min_year = rp->r_loyear; |
|
1253 /* 1254 ** Day work. 1255 ** Accept things such as: 1256 ** 1 1257 ** last-Sunday 1258 ** Sun<=20 1259 ** Sun>=7 1260 */ --- 92 unchanged lines hidden (view full) --- 1353 ** Optimize. 1354 */ 1355 { 1356 int fromi; 1357 int toi; 1358 1359 toi = 0; 1360 fromi = 0; | 1292 /* 1293 ** Day work. 1294 ** Accept things such as: 1295 ** 1 1296 ** last-Sunday 1297 ** Sun<=20 1298 ** Sun>=7 1299 */ --- 92 unchanged lines hidden (view full) --- 1392 ** Optimize. 1393 */ 1394 { 1395 int fromi; 1396 int toi; 1397 1398 toi = 0; 1399 fromi = 0; |
1400 while (fromi < timecnt && attypes[fromi].at < min_time) 1401 ++fromi; |
|
1361 if (isdsts[0] == 0) | 1402 if (isdsts[0] == 0) |
1362 while (attypes[fromi].type == 0) | 1403 while (fromi < timecnt && attypes[fromi].type == 0) |
1363 ++fromi; /* handled by default rule */ 1364 for ( ; fromi < timecnt; ++fromi) { 1365 if (toi != 0 1366 && ((attypes[fromi].at 1367 + gmtoffs[attypes[toi - 1].type]) 1368 <= (attypes[toi - 1].at 1369 + gmtoffs[toi == 1 ? 0 1370 : attypes[toi - 2].type]))) { --- 30 unchanged lines hidden (view full) --- 1401 err(EXIT_FAILURE, _("can't create %s"), fullname); 1402 } 1403 convert(eitol(typecnt), tzh.tzh_ttisgmtcnt); 1404 convert(eitol(typecnt), tzh.tzh_ttisstdcnt); 1405 convert(eitol(leapcnt), tzh.tzh_leapcnt); 1406 convert(eitol(timecnt), tzh.tzh_timecnt); 1407 convert(eitol(typecnt), tzh.tzh_typecnt); 1408 convert(eitol(charcnt), tzh.tzh_charcnt); | 1404 ++fromi; /* handled by default rule */ 1405 for ( ; fromi < timecnt; ++fromi) { 1406 if (toi != 0 1407 && ((attypes[fromi].at 1408 + gmtoffs[attypes[toi - 1].type]) 1409 <= (attypes[toi - 1].at 1410 + gmtoffs[toi == 1 ? 0 1411 : attypes[toi - 2].type]))) { --- 30 unchanged lines hidden (view full) --- 1442 err(EXIT_FAILURE, _("can't create %s"), fullname); 1443 } 1444 convert(eitol(typecnt), tzh.tzh_ttisgmtcnt); 1445 convert(eitol(typecnt), tzh.tzh_ttisstdcnt); 1446 convert(eitol(leapcnt), tzh.tzh_leapcnt); 1447 convert(eitol(timecnt), tzh.tzh_timecnt); 1448 convert(eitol(typecnt), tzh.tzh_typecnt); 1449 convert(eitol(charcnt), tzh.tzh_charcnt); |
1450 (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); |
|
1409#define DO(field) (void) fwrite((void *) tzh.field, (size_t) sizeof tzh.field, (size_t) 1, fp) | 1451#define DO(field) (void) fwrite((void *) tzh.field, (size_t) sizeof tzh.field, (size_t) 1, fp) |
1452 DO(tzh_magic); |
|
1410 DO(tzh_reserved); 1411 DO(tzh_ttisgmtcnt); 1412 DO(tzh_ttisstdcnt); 1413 DO(tzh_leapcnt); 1414 DO(tzh_timecnt); 1415 DO(tzh_typecnt); 1416 DO(tzh_charcnt); 1417#undef DO --- 37 unchanged lines hidden (view full) --- 1455 puttzcode((long) corr[i], fp); 1456 } 1457 for (i = 0; i < typecnt; ++i) 1458 (void) putc(ttisstds[i], fp); 1459 for (i = 0; i < typecnt; ++i) 1460 (void) putc(ttisgmts[i], fp); 1461 if (ferror(fp) || fclose(fp)) 1462 errx(EXIT_FAILURE, _("error writing %s"), fullname); | 1453 DO(tzh_reserved); 1454 DO(tzh_ttisgmtcnt); 1455 DO(tzh_ttisstdcnt); 1456 DO(tzh_leapcnt); 1457 DO(tzh_timecnt); 1458 DO(tzh_typecnt); 1459 DO(tzh_charcnt); 1460#undef DO --- 37 unchanged lines hidden (view full) --- 1498 puttzcode((long) corr[i], fp); 1499 } 1500 for (i = 0; i < typecnt; ++i) 1501 (void) putc(ttisstds[i], fp); 1502 for (i = 0; i < typecnt; ++i) 1503 (void) putc(ttisgmts[i], fp); 1504 if (ferror(fp) || fclose(fp)) 1505 errx(EXIT_FAILURE, _("error writing %s"), fullname); |
1506 if (chmod(fullname, mflag) < 0) 1507 err(EXIT_FAILURE, _("cannot change mode of %s to %03o"), 1508 fullname, (unsigned)mflag); 1509 if ((uflag != (uid_t)-1 || gflag != (gid_t)-1) 1510 && chown(fullname, uflag, gflag) < 0) 1511 err(EXIT_FAILURE, _("cannot change ownership of %s"), 1512 fullname); |
|
1463} 1464 1465static void 1466doabbr(abbr, format, letters, isdst) 1467char * const abbr; 1468const char * const format; 1469const char * const letters; 1470const int isdst; --- 91 unchanged lines hidden (view full) --- 1562 register int k; 1563 register time_t jtime, ktime; 1564 register long offset; 1565 char buf[BUFSIZ]; 1566 1567 INITIALIZE(ktime); 1568 if (useuntil) { 1569 /* | 1513} 1514 1515static void 1516doabbr(abbr, format, letters, isdst) 1517char * const abbr; 1518const char * const format; 1519const char * const letters; 1520const int isdst; --- 91 unchanged lines hidden (view full) --- 1612 register int k; 1613 register time_t jtime, ktime; 1614 register long offset; 1615 char buf[BUFSIZ]; 1616 1617 INITIALIZE(ktime); 1618 if (useuntil) { 1619 /* |
1570 ** Turn untiltime into GMT | 1620 ** Turn untiltime into UTC |
1571 ** assuming the current gmtoff and 1572 ** stdoff values. 1573 */ 1574 untiltime = zp->z_untiltime; 1575 if (!zp->z_untilrule.r_todisgmt) 1576 untiltime = tadd(untiltime, 1577 -gmtoff); 1578 if (!zp->z_untilrule.r_todisstd) --- 63 unchanged lines hidden (view full) --- 1642 if (usestart) { 1643 if (*startbuf == '\0' && 1644 zp->z_format != NULL && 1645 strchr(zp->z_format, '%') == NULL && 1646 strchr(zp->z_format, '/') == NULL) 1647 (void) strcpy(startbuf, zp->z_format); 1648 eat(zp->z_filename, zp->z_linenum); 1649 if (*startbuf == '\0') | 1621 ** assuming the current gmtoff and 1622 ** stdoff values. 1623 */ 1624 untiltime = zp->z_untiltime; 1625 if (!zp->z_untilrule.r_todisgmt) 1626 untiltime = tadd(untiltime, 1627 -gmtoff); 1628 if (!zp->z_untilrule.r_todisstd) --- 63 unchanged lines hidden (view full) --- 1692 if (usestart) { 1693 if (*startbuf == '\0' && 1694 zp->z_format != NULL && 1695 strchr(zp->z_format, '%') == NULL && 1696 strchr(zp->z_format, '/') == NULL) 1697 (void) strcpy(startbuf, zp->z_format); 1698 eat(zp->z_filename, zp->z_linenum); 1699 if (*startbuf == '\0') |
1650error(_("can't determine time zone abbrevation to use just after until time")); | 1700error(_("can't determine time zone abbreviation to use just after until time")); |
1651 else addtt(starttime, 1652 addtype(startoff, startbuf, 1653 startoff != zp->z_gmtoff, 1654 startttisstd, 1655 startttisgmt)); 1656 } 1657 /* 1658 ** Now we may get to set starttime for the next zone line. --- 9 unchanged lines hidden (view full) --- 1668 } 1669 } 1670 writezone(zpfirst->z_name); 1671} 1672 1673static void 1674addtt(starttime, type) 1675const time_t starttime; | 1701 else addtt(starttime, 1702 addtype(startoff, startbuf, 1703 startoff != zp->z_gmtoff, 1704 startttisstd, 1705 startttisgmt)); 1706 } 1707 /* 1708 ** Now we may get to set starttime for the next zone line. --- 9 unchanged lines hidden (view full) --- 1718 } 1719 } 1720 writezone(zpfirst->z_name); 1721} 1722 1723static void 1724addtt(starttime, type) 1725const time_t starttime; |
1676const int type; | 1726int type; |
1677{ | 1727{ |
1728 if (starttime <= min_time || 1729 (timecnt == 1 && attypes[0].at < min_time)) { 1730 gmtoffs[0] = gmtoffs[type]; 1731 isdsts[0] = isdsts[type]; 1732 ttisstds[0] = ttisstds[type]; 1733 ttisgmts[0] = ttisgmts[type]; 1734 if (abbrinds[type] != 0) 1735 (void) strcpy(chars, &chars[abbrinds[type]]); 1736 abbrinds[0] = 0; 1737 charcnt = strlen(chars) + 1; 1738 typecnt = 1; 1739 timecnt = 0; 1740 type = 0; 1741 } |
|
1678 if (timecnt >= TZ_MAX_TIMES) { 1679 error(_("too many transitions?!")); 1680 (void) exit(EXIT_FAILURE); 1681 } 1682 attypes[timecnt].at = starttime; 1683 attypes[timecnt].type = type; 1684 ++timecnt; 1685} --- 177 unchanged lines hidden (view full) --- 1863 for (lp = table; lp->l_word != NULL; ++lp) 1864 if (ciequal(word, lp->l_word)) 1865 return lp; 1866 /* 1867 ** Look for inexact match. 1868 */ 1869 foundlp = NULL; 1870 for (lp = table; lp->l_word != NULL; ++lp) | 1742 if (timecnt >= TZ_MAX_TIMES) { 1743 error(_("too many transitions?!")); 1744 (void) exit(EXIT_FAILURE); 1745 } 1746 attypes[timecnt].at = starttime; 1747 attypes[timecnt].type = type; 1748 ++timecnt; 1749} --- 177 unchanged lines hidden (view full) --- 1927 for (lp = table; lp->l_word != NULL; ++lp) 1928 if (ciequal(word, lp->l_word)) 1929 return lp; 1930 /* 1931 ** Look for inexact match. 1932 */ 1933 foundlp = NULL; 1934 for (lp = table; lp->l_word != NULL; ++lp) |
1871 if (itsabbr(word, lp->l_word)) | 1935 if (itsabbr(word, lp->l_word)) { |
1872 if (foundlp == NULL) 1873 foundlp = lp; 1874 else return NULL; /* multiple inexact matches */ | 1936 if (foundlp == NULL) 1937 foundlp = lp; 1938 else return NULL; /* multiple inexact matches */ |
1939 } |
|
1875 return foundlp; 1876} 1877 1878static char ** 1879getfields(cp) 1880register char * cp; 1881{ 1882 register char * dp; --- 169 unchanged lines hidden (view full) --- 2052 2053static int 2054mkdirs(argname) 2055char * const argname; 2056{ 2057 register char * name; 2058 register char * cp; 2059 | 1940 return foundlp; 1941} 1942 1943static char ** 1944getfields(cp) 1945register char * cp; 1946{ 1947 register char * dp; --- 169 unchanged lines hidden (view full) --- 2117 2118static int 2119mkdirs(argname) 2120char * const argname; 2121{ 2122 register char * name; 2123 register char * cp; 2124 |
2060 if (argname == NULL || *argname == '\0') | 2125 if (argname == NULL || *argname == '\0' || Dflag) |
2061 return 0; 2062 cp = name = ecpyalloc(argname); 2063 while ((cp = strchr(cp + 1, '/')) != 0) { 2064 *cp = '\0'; 2065#ifndef unix 2066 /* 2067 ** DOS drive specifier? 2068 */ 2069 if (isalpha((unsigned char) name[0]) && 2070 name[1] == ':' && name[2] == '\0') { 2071 *cp = '/'; 2072 continue; 2073 } 2074#endif /* !defined unix */ 2075 if (!itsdir(name)) { 2076 /* 2077 ** It doesn't seem to exist, so we try to create it. | 2126 return 0; 2127 cp = name = ecpyalloc(argname); 2128 while ((cp = strchr(cp + 1, '/')) != 0) { 2129 *cp = '\0'; 2130#ifndef unix 2131 /* 2132 ** DOS drive specifier? 2133 */ 2134 if (isalpha((unsigned char) name[0]) && 2135 name[1] == ':' && name[2] == '\0') { 2136 *cp = '/'; 2137 continue; 2138 } 2139#endif /* !defined unix */ 2140 if (!itsdir(name)) { 2141 /* 2142 ** It doesn't seem to exist, so we try to create it. |
2143 ** Creation may fail because of the directory being 2144 ** created by some other multiprocessor, so we get 2145 ** to do extra checking. |
|
2078 */ | 2146 */ |
2079 if (mkdir(name, 0755) != 0) { | 2147 if (mkdir(name, (S_IRUSR | S_IWUSR | S_IXUSR 2148 | S_IRGRP | S_IXGRP | S_IROTH 2149 | S_IXOTH)) != 0 2150 && (errno != EEXIST || !itsdir(name))) { |
2080 warn(_("can't create directory %s"), name); 2081 ifree(name); 2082 return -1; 2083 } 2084 } 2085 *cp = '/'; 2086 } 2087 ifree(name); --- 7 unchanged lines hidden (view full) --- 2095 long l; 2096 2097 l = i; 2098 if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) 2099 errx(EXIT_FAILURE, _("%d did not sign extend correctly"), i); 2100 return l; 2101} 2102 | 2151 warn(_("can't create directory %s"), name); 2152 ifree(name); 2153 return -1; 2154 } 2155 } 2156 *cp = '/'; 2157 } 2158 ifree(name); --- 7 unchanged lines hidden (view full) --- 2166 long l; 2167 2168 l = i; 2169 if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) 2170 errx(EXIT_FAILURE, _("%d did not sign extend correctly"), i); 2171 return l; 2172} 2173 |
2174#include <grp.h> 2175#include <pwd.h> 2176 2177static void 2178setgroup(flag, name) 2179 gid_t *flag; 2180 const char *name; 2181{ 2182 struct group *gr; 2183 2184 if (*flag != (gid_t)-1) 2185 errx(EXIT_FAILURE, _("multiple -g flags specified")); 2186 2187 gr = getgrnam(name); 2188 if (gr == 0) { 2189 char *ep; 2190 unsigned long ul; 2191 2192 ul = strtoul(name, &ep, 10); 2193 if (ul == (unsigned long)(gid_t)ul && *ep == '\0') { 2194 *flag = ul; 2195 return; 2196 } 2197 errx(EXIT_FAILURE, _("group `%s' not found"), name); 2198 } 2199 *flag = gr->gr_gid; 2200} 2201 2202static void 2203setuser(flag, name) 2204 uid_t *flag; 2205 const char *name; 2206{ 2207 struct passwd *pw; 2208 2209 if (*flag != (gid_t)-1) 2210 errx(EXIT_FAILURE, _("multiple -u flags specified")); 2211 2212 pw = getpwnam(name); 2213 if (pw == 0) { 2214 char *ep; 2215 unsigned long ul; 2216 2217 ul = strtoul(name, &ep, 10); 2218 if (ul == (unsigned long)(gid_t)ul && *ep == '\0') { 2219 *flag = ul; 2220 return; 2221 } 2222 errx(EXIT_FAILURE, _("user `%s' not found"), name); 2223 } 2224 *flag = pw->pw_uid; 2225} 2226 |
|
2103/* 2104** UNIX was a registered trademark of UNIX System Laboratories in 1993. 2105*/ | 2227/* 2228** UNIX was a registered trademark of UNIX System Laboratories in 1993. 2229*/ |