3 static char elsieid
[] = "@(#)zic.c 7.50";
4 #endif /* !defined NOID */
5 #endif /* !defined lint */
10 #include "sys/stat.h" /* for umask manifest constants */
11 #endif /* defined unix */
14 const char * r_filename
;
18 int r_loyear
; /* for example, 1986 */
19 int r_hiyear
; /* for example, 1986 */
20 const char * r_yrtype
;
22 int r_month
; /* 0..11 */
24 int r_dycode
; /* see below */
28 long r_tod
; /* time from midnight */
29 int r_todisstd
; /* above is standard time if TRUE */
30 /* or wall clock time if FALSE */
31 int r_todisgmt
; /* above is GMT if TRUE */
32 /* or local time if FALSE */
33 long r_stdoff
; /* offset from standard time */
34 const char * r_abbrvar
; /* variable part of abbreviation */
36 int r_todo
; /* a rule to do (used in outzone) */
37 time_t r_temp
; /* used in outzone */
41 ** r_dycode r_dayofmonth r_wday
44 #define DC_DOM 0 /* 1..31 */ /* unused */
45 #define DC_DOWGEQ 1 /* 1..31 */ /* 0..6 (Sun..Sat) */
46 #define DC_DOWLEQ 2 /* 1..31 */ /* 0..6 (Sun..Sat) */
49 const char * z_filename
;
55 const char * z_format
;
59 struct rule
* z_rules
;
62 struct rule z_untilrule
;
66 extern int getopt
P((int argc
, char * const argv
[],
67 const char * options
));
68 extern char * icatalloc
P((char * old
, const char * new));
69 extern char * icpyalloc
P((const char * string
));
70 extern void ifree
P((char * p
));
71 extern char * imalloc
P((int n
));
72 extern void * irealloc
P((void * old
, int n
));
73 extern int link
P((const char * fromname
, const char * toname
));
76 extern char * scheck
P((const char * string
, const char * format
));
78 static void addtt
P((time_t starttime
, int type
));
79 static int addtype
P((long gmtoff
, const char * abbr
, int isdst
,
80 int ttisstd
, int ttisgmt
));
81 static void leapadd
P((time_t t
, int positive
, int rolling
, int count
));
82 static void adjleap
P((void));
83 static void associate
P((void));
84 static int ciequal
P((const char * ap
, const char * bp
));
85 static void convert
P((long val
, char * buf
));
86 static void dolink
P((const char * fromfile
, const char * tofile
));
87 static void doabbr
P((char * abbr
, const char * format
,
88 const char * letters
, int isdst
));
89 static void eat
P((const char * name
, int num
));
90 static void eats
P((const char * name
, int num
,
91 const char * rname
, int rnum
));
92 static long eitol
P((int i
));
93 static void error
P((const char * message
));
94 static char ** getfields
P((char * buf
));
95 static long gethms
P((const char * string
, const char * errstrng
,
97 static void infile
P((const char * filename
));
98 static void inleap
P((char ** fields
, int nfields
));
99 static void inlink
P((char ** fields
, int nfields
));
100 static void inrule
P((char ** fields
, int nfields
));
101 static int inzcont
P((char ** fields
, int nfields
));
102 static int inzone
P((char ** fields
, int nfields
));
103 static int inzsub
P((char ** fields
, int nfields
, int iscont
));
104 static int itsabbr
P((const char * abbr
, const char * word
));
105 static int itsdir
P((const char * name
));
106 static int lowerit
P((int c
));
107 static char * memcheck
P((char * tocheck
));
108 static int mkdirs
P((char * filename
));
109 static void newabbr
P((const char * abbr
));
110 static long oadd
P((long t1
, long t2
));
111 static void outzone
P((const struct zone
* zp
, int ntzones
));
112 static void puttzcode
P((long code
, FILE * fp
));
113 static int rcomp
P((const void * leftp
, const void * rightp
));
114 static time_t rpytime
P((const struct rule
* rp
, int wantedy
));
115 static void rulesub
P((struct rule
* rp
,
116 const char * loyearp
, const char * hiyearp
,
117 const char * typep
, const char * monthp
,
118 const char * dayp
, const char * timep
));
119 static void setboundaries
P((void));
120 static time_t tadd
P((time_t t1
, long t2
));
121 static void usage
P((void));
122 static void writezone
P((const char * name
));
123 static int yearistype
P((int year
, const char * type
));
127 static const char * filename
;
131 static time_t max_time
;
134 static time_t min_time
;
137 static const char * rfilename
;
139 static const char * progname
;
142 static int tt_signed
;
154 ** Which fields are which on a Zone line.
162 #define ZF_TILMONTH 6
165 #define ZONE_MINFIELDS 5
166 #define ZONE_MAXFIELDS 9
169 ** Which fields are which on a Zone continuation line.
175 #define ZFC_TILYEAR 3
176 #define ZFC_TILMONTH 4
178 #define ZFC_TILTIME 6
179 #define ZONEC_MINFIELDS 3
180 #define ZONEC_MAXFIELDS 7
183 ** Which files are which on a Rule line.
195 #define RULE_FIELDS 10
198 ** Which fields are which on a Link line.
203 #define LINK_FIELDS 3
206 ** Which fields are which on a Leap line.
215 #define LEAP_FIELDS 7
225 static struct rule
* rules
;
226 static int nrules
; /* number of rules */
228 static struct zone
* zones
;
229 static int nzones
; /* number of zones */
232 const char * l_filename
;
238 static struct link
* links
;
246 static struct lookup
const * byword
P((const char * string
,
247 const struct lookup
* lp
));
249 static struct lookup
const line_codes
[] = {
257 static struct lookup
const mon_names
[] = {
258 { "January", TM_JANUARY
},
259 { "February", TM_FEBRUARY
},
260 { "March", TM_MARCH
},
261 { "April", TM_APRIL
},
265 { "August", TM_AUGUST
},
266 { "September", TM_SEPTEMBER
},
267 { "October", TM_OCTOBER
},
268 { "November", TM_NOVEMBER
},
269 { "December", TM_DECEMBER
},
273 static struct lookup
const wday_names
[] = {
274 { "Sunday", TM_SUNDAY
},
275 { "Monday", TM_MONDAY
},
276 { "Tuesday", TM_TUESDAY
},
277 { "Wednesday", TM_WEDNESDAY
},
278 { "Thursday", TM_THURSDAY
},
279 { "Friday", TM_FRIDAY
},
280 { "Saturday", TM_SATURDAY
},
284 static struct lookup
const lasts
[] = {
285 { "last-Sunday", TM_SUNDAY
},
286 { "last-Monday", TM_MONDAY
},
287 { "last-Tuesday", TM_TUESDAY
},
288 { "last-Wednesday", TM_WEDNESDAY
},
289 { "last-Thursday", TM_THURSDAY
},
290 { "last-Friday", TM_FRIDAY
},
291 { "last-Saturday", TM_SATURDAY
},
295 static struct lookup
const begin_years
[] = {
296 { "minimum", YR_MINIMUM
},
297 { "maximum", YR_MAXIMUM
},
301 static struct lookup
const end_years
[] = {
302 { "minimum", YR_MINIMUM
},
303 { "maximum", YR_MAXIMUM
},
308 static struct lookup
const leap_types
[] = {
310 { "Stationary", FALSE
},
314 static const int len_months
[2][MONSPERYEAR
] = {
315 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
316 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
319 static const int len_years
[2] = {
320 DAYSPERNYEAR
, DAYSPERLYEAR
323 static time_t ats
[TZ_MAX_TIMES
];
324 static unsigned char types
[TZ_MAX_TIMES
];
325 static long gmtoffs
[TZ_MAX_TYPES
];
326 static char isdsts
[TZ_MAX_TYPES
];
327 static unsigned char abbrinds
[TZ_MAX_TYPES
];
328 static char ttisstds
[TZ_MAX_TYPES
];
329 static char ttisgmts
[TZ_MAX_TYPES
];
330 static char chars
[TZ_MAX_CHARS
];
331 static time_t trans
[TZ_MAX_LEAPS
];
332 static long corr
[TZ_MAX_LEAPS
];
333 static char roll
[TZ_MAX_LEAPS
];
336 ** Memory allocation.
344 (void) perror(progname
);
345 (void) exit(EXIT_FAILURE
);
350 #define emalloc(size) memcheck(imalloc(size))
351 #define erealloc(ptr, size) memcheck(irealloc((ptr), (size)))
352 #define ecpyalloc(ptr) memcheck(icpyalloc(ptr))
353 #define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp)))
360 eats(name
, num
, rname
, rnum
)
361 const char * const name
;
363 const char * const rname
;
374 const char * const name
;
377 eats(name
, num
, (char *) NULL
, -1);
382 const char * const string
;
385 ** Match the format of "cc" to allow sh users to
386 ** zic ... 2>&1 | error -t "*" -v
389 (void) fprintf(stderr
, "\"%s\", line %d: %s",
390 filename
, linenum
, string
);
391 if (rfilename
!= NULL
)
392 (void) fprintf(stderr
, " (rule from \"%s\", line %d)",
393 rfilename
, rlinenum
);
394 (void) fprintf(stderr
, "\n");
401 (void) fprintf(stderr
, "%s: usage is %s \
402 [ -s ] [ -v ] [ -l localtime ] [ -p posixrules ] [ -d directory ]\n\
403 \t[ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n",
405 (void) exit(EXIT_FAILURE
);
408 static const char * psxrules
;
409 static const char * lcltime
;
410 static const char * directory
;
411 static const char * leapsec
;
412 static const char * yitcommand
;
413 static int sflag
= FALSE
;
425 (void) umask(umask(S_IWGRP
| S_IWOTH
) | (S_IWGRP
| S_IWOTH
));
426 #endif /* defined unix */
428 while ((c
= getopt(argc
, argv
, "d:l:p:L:vsy:")) != EOF
)
433 if (directory
== NULL
)
436 (void) fprintf(stderr
,
437 "%s: More than one -d option specified\n",
439 (void) exit(EXIT_FAILURE
);
446 (void) fprintf(stderr
,
447 "%s: More than one -l option specified\n",
449 (void) exit(EXIT_FAILURE
);
453 if (psxrules
== NULL
)
456 (void) fprintf(stderr
,
457 "%s: More than one -p option specified\n",
459 (void) exit(EXIT_FAILURE
);
463 if (yitcommand
== NULL
)
466 (void) fprintf(stderr
,
467 "%s: More than one -y option specified\n",
469 (void) exit(EXIT_FAILURE
);
476 (void) fprintf(stderr
,
477 "%s: More than one -L option specified\n",
479 (void) exit(EXIT_FAILURE
);
489 if (optind
== argc
- 1 && strcmp(argv
[optind
], "=") == 0)
490 usage(); /* usage message by request */
491 if (directory
== NULL
)
493 if (yitcommand
== NULL
)
494 yitcommand
= "yearistype";
498 if (optind
< argc
&& leapsec
!= NULL
) {
503 for (i
= optind
; i
< argc
; ++i
)
506 (void) exit(EXIT_FAILURE
);
508 for (i
= 0; i
< nzones
; i
= j
) {
510 ** Find the next non-continuation zone entry.
512 for (j
= i
+ 1; j
< nzones
&& zones
[j
].z_name
== NULL
; ++j
)
514 outzone(&zones
[i
], j
- i
);
519 for (i
= 0; i
< nlinks
; ++i
)
520 dolink(links
[i
].l_from
, links
[i
].l_to
);
522 dolink(lcltime
, TZDEFAULT
);
523 if (psxrules
!= NULL
)
524 dolink(psxrules
, TZDEFRULES
);
525 return (errors
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
529 dolink(fromfile
, tofile
)
530 const char * const fromfile
;
531 const char * const tofile
;
533 register char * fromname
;
534 register char * toname
;
536 if (fromfile
[0] == '/')
537 fromname
= ecpyalloc(fromfile
);
539 fromname
= ecpyalloc(directory
);
540 fromname
= ecatalloc(fromname
, "/");
541 fromname
= ecatalloc(fromname
, fromfile
);
543 if (tofile
[0] == '/')
544 toname
= ecpyalloc(tofile
);
546 toname
= ecpyalloc(directory
);
547 toname
= ecatalloc(toname
, "/");
548 toname
= ecatalloc(toname
, tofile
);
551 ** We get to be careful here since
552 ** there's a fair chance of root running us.
555 (void) remove(toname
);
556 if (link(fromname
, toname
) != 0) {
557 if (mkdirs(toname
) != 0)
558 (void) exit(EXIT_FAILURE
);
559 if (link(fromname
, toname
) != 0) {
560 (void) fprintf(stderr
, "%s: Can't link from %s to ",
562 (void) perror(toname
);
563 (void) exit(EXIT_FAILURE
);
571 setboundaries
P((void))
576 for (bit
= 1; bit
> 0; bit
<<= 1)
578 if (bit
== 0) { /* time_t is an unsigned type */
581 max_time
= ~(time_t) 0;
589 max_time
= -max_time
;
593 min_year
= TM_YEAR_BASE
+ gmtime(&min_time
)->tm_year
;
594 max_year
= TM_YEAR_BASE
+ gmtime(&max_time
)->tm_year
;
596 for (bii
= 1; bii
> 0; bii
<<= 1)
604 const char * const name
;
606 register char * myname
;
609 myname
= ecpyalloc(name
);
610 myname
= ecatalloc(myname
, "/.");
611 accres
= access(myname
, F_OK
);
617 ** Associate sets of rules with zones.
621 ** Sort by rule name.
629 return strcmp(((const struct rule
*) cp1
)->r_name
,
630 ((const struct rule
*) cp2
)->r_name
);
636 register struct zone
* zp
;
637 register struct rule
* rp
;
638 register int base
, out
;
642 (void) qsort((void *) rules
, (size_t) nrules
,
643 (size_t) sizeof *rules
, rcomp
);
644 for (i
= 0; i
< nzones
; ++i
) {
649 for (base
= 0; base
< nrules
; base
= out
) {
651 for (out
= base
+ 1; out
< nrules
; ++out
)
652 if (strcmp(rp
->r_name
, rules
[out
].r_name
) != 0)
654 for (i
= 0; i
< nzones
; ++i
) {
656 if (strcmp(zp
->z_rule
, rp
->r_name
) != 0)
659 zp
->z_nrules
= out
- base
;
662 for (i
= 0; i
< nzones
; ++i
) {
664 if (zp
->z_nrules
== 0) {
666 ** Maybe we have a local standard time offset.
668 eat(zp
->z_filename
, zp
->z_linenum
);
669 zp
->z_stdoff
= gethms(zp
->z_rule
, "unruly zone", TRUE
);
671 ** Note, though, that if there's no rule,
672 ** a '%s' in the format is a bad thing.
674 if (strchr(zp
->z_format
, '%') != 0)
675 error("%s in ruleless zone");
679 (void) exit(EXIT_FAILURE
);
687 register char ** fields
;
689 register const struct lookup
* lp
;
690 register int nfields
;
691 register int wantcont
;
695 if (strcmp(name
, "-") == 0) {
696 name
= "standard input";
698 } else if ((fp
= fopen(name
, "r")) == NULL
) {
699 (void) fprintf(stderr
, "%s: Can't open ", progname
);
701 (void) exit(EXIT_FAILURE
);
704 for (num
= 1; ; ++num
) {
706 if (fgets(buf
, (int) sizeof buf
, fp
) != buf
)
708 cp
= strchr(buf
, '\n');
710 error("line too long");
711 (void) exit(EXIT_FAILURE
);
714 fields
= getfields(buf
);
716 while (fields
[nfields
] != NULL
) {
719 if (ciequal(fields
[nfields
], "-"))
720 fields
[nfields
] = &nada
;
725 } else if (wantcont
) {
726 wantcont
= inzcont(fields
, nfields
);
728 lp
= byword(fields
[0], line_codes
);
730 error("input line of unknown type");
731 else switch ((int) (lp
->l_value
)) {
733 inrule(fields
, nfields
);
737 wantcont
= inzone(fields
, nfields
);
740 inlink(fields
, nfields
);
745 (void) fprintf(stderr
,
746 "%s: Leap line in non leap seconds file %s\n",
748 else inleap(fields
, nfields
);
751 default: /* "cannot happen" */
752 (void) fprintf(stderr
,
753 "%s: panic: Invalid l_value %d\n",
754 progname
, lp
->l_value
);
755 (void) exit(EXIT_FAILURE
);
758 ifree((char *) fields
);
761 (void) fprintf(stderr
, "%s: Error reading ", progname
);
762 (void) perror(filename
);
763 (void) exit(EXIT_FAILURE
);
765 if (fp
!= stdin
&& fclose(fp
)) {
766 (void) fprintf(stderr
, "%s: Error closing ", progname
);
767 (void) perror(filename
);
768 (void) exit(EXIT_FAILURE
);
771 error("expected continuation line not found");
775 ** Convert a string of one of the forms
776 ** h -h hh:mm -hh:mm hh:mm:ss -hh:mm:ss
777 ** into a number of seconds.
778 ** A null string maps to zero.
779 ** Call error with errstring and return zero on errors.
783 gethms(string
, errstring
, signable
)
785 const char * const errstring
;
788 int hh
, mm
, ss
, sign
;
790 if (string
== NULL
|| *string
== '\0')
794 else if (*string
== '-') {
798 if (sscanf(string
, scheck(string
, "%d"), &hh
) == 1)
800 else if (sscanf(string
, scheck(string
, "%d:%d"), &hh
, &mm
) == 2)
802 else if (sscanf(string
, scheck(string
, "%d:%d:%d"),
803 &hh
, &mm
, &ss
) != 3) {
807 if (hh
< 0 || hh
>= HOURSPERDAY
||
808 mm
< 0 || mm
>= MINSPERHOUR
||
809 ss
< 0 || ss
> SECSPERMIN
) {
814 (eitol(hh
* MINSPERHOUR
+ mm
) *
815 eitol(SECSPERMIN
) + eitol(ss
));
819 inrule(fields
, nfields
)
820 register char ** const fields
;
823 static struct rule r
;
825 if (nfields
!= RULE_FIELDS
) {
826 error("wrong number of fields on Rule line");
829 if (*fields
[RF_NAME
] == '\0') {
830 error("nameless rule");
833 r
.r_filename
= filename
;
834 r
.r_linenum
= linenum
;
835 r
.r_stdoff
= gethms(fields
[RF_STDOFF
], "invalid saved time", TRUE
);
836 rulesub(&r
, fields
[RF_LOYEAR
], fields
[RF_HIYEAR
], fields
[RF_COMMAND
],
837 fields
[RF_MONTH
], fields
[RF_DAY
], fields
[RF_TOD
]);
838 r
.r_name
= ecpyalloc(fields
[RF_NAME
]);
839 r
.r_abbrvar
= ecpyalloc(fields
[RF_ABBRVAR
]);
840 rules
= (struct rule
*) (void *) erealloc((char *) rules
,
841 (int) ((nrules
+ 1) * sizeof *rules
));
846 inzone(fields
, nfields
)
847 register char ** const fields
;
853 if (nfields
< ZONE_MINFIELDS
|| nfields
> ZONE_MAXFIELDS
) {
854 error("wrong number of fields on Zone line");
857 if (strcmp(fields
[ZF_NAME
], TZDEFAULT
) == 0 && lcltime
!= NULL
) {
858 buf
= erealloc(buf
, (int) (132 + strlen(TZDEFAULT
)));
860 "\"Zone %s\" line and -l option are mutually exclusive",
865 if (strcmp(fields
[ZF_NAME
], TZDEFRULES
) == 0 && psxrules
!= NULL
) {
866 buf
= erealloc(buf
, (int) (132 + strlen(TZDEFRULES
)));
868 "\"Zone %s\" line and -p option are mutually exclusive",
873 for (i
= 0; i
< nzones
; ++i
)
874 if (zones
[i
].z_name
!= NULL
&&
875 strcmp(zones
[i
].z_name
, fields
[ZF_NAME
]) == 0) {
876 buf
= erealloc(buf
, (int) (132 +
877 strlen(fields
[ZF_NAME
]) +
878 strlen(zones
[i
].z_filename
)));
880 "duplicate zone name %s (file \"%s\", line %d)",
887 return inzsub(fields
, nfields
, FALSE
);
891 inzcont(fields
, nfields
)
892 register char ** const fields
;
895 if (nfields
< ZONEC_MINFIELDS
|| nfields
> ZONEC_MAXFIELDS
) {
896 error("wrong number of fields on Zone continuation line");
899 return inzsub(fields
, nfields
, TRUE
);
903 inzsub(fields
, nfields
, iscont
)
904 register char ** const fields
;
909 static struct zone z
;
910 register int i_gmtoff
, i_rule
, i_format
;
911 register int i_untilyear
, i_untilmonth
;
912 register int i_untilday
, i_untiltime
;
913 register int hasuntil
;
916 i_gmtoff
= ZFC_GMTOFF
;
918 i_format
= ZFC_FORMAT
;
919 i_untilyear
= ZFC_TILYEAR
;
920 i_untilmonth
= ZFC_TILMONTH
;
921 i_untilday
= ZFC_TILDAY
;
922 i_untiltime
= ZFC_TILTIME
;
925 i_gmtoff
= ZF_GMTOFF
;
927 i_format
= ZF_FORMAT
;
928 i_untilyear
= ZF_TILYEAR
;
929 i_untilmonth
= ZF_TILMONTH
;
930 i_untilday
= ZF_TILDAY
;
931 i_untiltime
= ZF_TILTIME
;
932 z
.z_name
= ecpyalloc(fields
[ZF_NAME
]);
934 z
.z_filename
= filename
;
935 z
.z_linenum
= linenum
;
936 z
.z_gmtoff
= gethms(fields
[i_gmtoff
], "invalid GMT offset", TRUE
);
937 if ((cp
= strchr(fields
[i_format
], '%')) != 0) {
938 if (*++cp
!= 's' || strchr(cp
, '%') != 0) {
939 error("invalid abbreviation format");
943 z
.z_rule
= ecpyalloc(fields
[i_rule
]);
944 z
.z_format
= ecpyalloc(fields
[i_format
]);
945 hasuntil
= nfields
> i_untilyear
;
947 z
.z_untilrule
.r_filename
= filename
;
948 z
.z_untilrule
.r_linenum
= linenum
;
949 rulesub(&z
.z_untilrule
,
953 (nfields
> i_untilmonth
) ?
954 fields
[i_untilmonth
] : "Jan",
955 (nfields
> i_untilday
) ? fields
[i_untilday
] : "1",
956 (nfields
> i_untiltime
) ? fields
[i_untiltime
] : "0");
957 z
.z_untiltime
= rpytime(&z
.z_untilrule
,
958 z
.z_untilrule
.r_loyear
);
959 if (iscont
&& nzones
> 0 &&
960 z
.z_untiltime
> min_time
&&
961 z
.z_untiltime
< max_time
&&
962 zones
[nzones
- 1].z_untiltime
> min_time
&&
963 zones
[nzones
- 1].z_untiltime
< max_time
&&
964 zones
[nzones
- 1].z_untiltime
>= z
.z_untiltime
) {
965 error("Zone continuation line end time is not \
966 after end time of previous line");
970 zones
= (struct zone
*) (void *) erealloc((char *) zones
,
971 (int) ((nzones
+ 1) * sizeof *zones
));
974 ** If there was an UNTIL field on this line,
975 ** there's more information about the zone on the next line.
981 inleap(fields
, nfields
)
982 register char ** const fields
;
985 register const char * cp
;
986 register const struct lookup
* lp
;
988 int year
, month
, day
;
992 if (nfields
!= LEAP_FIELDS
) {
993 error("wrong number of fields on Leap line");
997 cp
= fields
[LP_YEAR
];
998 if (sscanf(cp
, scheck(cp
, "%d"), &year
) != 1) {
1002 error("invalid leaping year");
1008 i
= len_years
[isleap(j
)];
1012 i
= -len_years
[isleap(j
)];
1014 dayoff
= oadd(dayoff
, eitol(i
));
1016 if ((lp
= byword(fields
[LP_MONTH
], mon_names
)) == NULL
) {
1017 error("invalid month name");
1020 month
= lp
->l_value
;
1022 while (j
!= month
) {
1023 i
= len_months
[isleap(year
)][j
];
1024 dayoff
= oadd(dayoff
, eitol(i
));
1027 cp
= fields
[LP_DAY
];
1028 if (sscanf(cp
, scheck(cp
, "%d"), &day
) != 1 ||
1029 day
<= 0 || day
> len_months
[isleap(year
)][month
]) {
1030 error("invalid day of month");
1033 dayoff
= oadd(dayoff
, eitol(day
- 1));
1034 if (dayoff
< 0 && !tt_signed
) {
1035 error("time before zero");
1038 t
= (time_t) dayoff
* SECSPERDAY
;
1040 ** Cheap overflow check.
1042 if (t
/ SECSPERDAY
!= dayoff
) {
1043 error("time overflow");
1046 tod
= gethms(fields
[LP_TIME
], "invalid time of day", FALSE
);
1047 cp
= fields
[LP_CORR
];
1049 register int positive
;
1052 if (strcmp(cp
, "") == 0) { /* infile() turns "-" into "" */
1055 } else if (strcmp(cp
, "--") == 0) {
1058 } else if (strcmp(cp
, "+") == 0) {
1061 } else if (strcmp(cp
, "++") == 0) {
1065 error("illegal CORRECTION field on Leap line");
1068 if ((lp
= byword(fields
[LP_ROLL
], leap_types
)) == NULL
) {
1069 error("illegal Rolling/Stationary field on Leap line");
1072 leapadd(tadd(t
, tod
), positive
, lp
->l_value
, count
);
1077 inlink(fields
, nfields
)
1078 register char ** const fields
;
1083 if (nfields
!= LINK_FIELDS
) {
1084 error("wrong number of fields on Link line");
1087 if (*fields
[LF_FROM
] == '\0') {
1088 error("blank FROM field on Link line");
1091 if (*fields
[LF_TO
] == '\0') {
1092 error("blank TO field on Link line");
1095 l
.l_filename
= filename
;
1096 l
.l_linenum
= linenum
;
1097 l
.l_from
= ecpyalloc(fields
[LF_FROM
]);
1098 l
.l_to
= ecpyalloc(fields
[LF_TO
]);
1099 links
= (struct link
*) (void *) erealloc((char *) links
,
1100 (int) ((nlinks
+ 1) * sizeof *links
));
1101 links
[nlinks
++] = l
;
1105 rulesub(rp
, loyearp
, hiyearp
, typep
, monthp
, dayp
, timep
)
1106 register struct rule
* const rp
;
1107 const char * const loyearp
;
1108 const char * const hiyearp
;
1109 const char * const typep
;
1110 const char * const monthp
;
1111 const char * const dayp
;
1112 const char * const timep
;
1114 register const struct lookup
* lp
;
1115 register const char * cp
;
1119 if ((lp
= byword(monthp
, mon_names
)) == NULL
) {
1120 error("invalid month name");
1123 rp
->r_month
= lp
->l_value
;
1124 rp
->r_todisstd
= FALSE
;
1125 rp
->r_todisgmt
= FALSE
;
1126 dp
= ecpyalloc(timep
);
1128 ep
= dp
+ strlen(dp
) - 1;
1129 switch (lowerit(*ep
)) {
1130 case 's': /* Standard */
1131 rp
->r_todisstd
= TRUE
;
1132 rp
->r_todisgmt
= FALSE
;
1135 case 'w': /* Wall */
1136 rp
->r_todisstd
= FALSE
;
1137 rp
->r_todisgmt
= FALSE
;
1139 case 'g': /* Greenwich */
1140 case 'u': /* Universal */
1141 case 'z': /* Zulu */
1142 rp
->r_todisstd
= TRUE
;
1143 rp
->r_todisgmt
= TRUE
;
1148 rp
->r_tod
= gethms(dp
, "invalid time of day", FALSE
);
1154 lp
= byword(cp
, begin_years
);
1155 if (lp
!= NULL
) switch ((int) lp
->l_value
) {
1157 rp
->r_loyear
= min_int
;
1160 rp
->r_loyear
= max_int
;
1162 default: /* "cannot happen" */
1163 (void) fprintf(stderr
,
1164 "%s: panic: Invalid l_value %d\n",
1165 progname
, lp
->l_value
);
1166 (void) exit(EXIT_FAILURE
);
1167 } else if (sscanf(cp
, scheck(cp
, "%d"), &rp
->r_loyear
) != 1) {
1168 error("invalid starting year");
1172 if ((lp
= byword(cp
, end_years
)) != NULL
) switch ((int) lp
->l_value
) {
1174 rp
->r_hiyear
= min_int
;
1177 rp
->r_hiyear
= max_int
;
1180 rp
->r_hiyear
= rp
->r_loyear
;
1182 default: /* "cannot happen" */
1183 (void) fprintf(stderr
,
1184 "%s: panic: Invalid l_value %d\n",
1185 progname
, lp
->l_value
);
1186 (void) exit(EXIT_FAILURE
);
1187 } else if (sscanf(cp
, scheck(cp
, "%d"), &rp
->r_hiyear
) != 1) {
1188 error("invalid ending year");
1191 if (rp
->r_loyear
> rp
->r_hiyear
) {
1192 error("starting year greater than ending year");
1196 rp
->r_yrtype
= NULL
;
1198 if (rp
->r_loyear
== rp
->r_hiyear
) {
1199 error("typed single year");
1202 rp
->r_yrtype
= ecpyalloc(typep
);
1206 ** Accept things such as:
1212 dp
= ecpyalloc(dayp
);
1213 if ((lp
= byword(dp
, lasts
)) != NULL
) {
1214 rp
->r_dycode
= DC_DOWLEQ
;
1215 rp
->r_wday
= lp
->l_value
;
1216 rp
->r_dayofmonth
= len_months
[1][rp
->r_month
];
1218 if ((ep
= strchr(dp
, '<')) != 0)
1219 rp
->r_dycode
= DC_DOWLEQ
;
1220 else if ((ep
= strchr(dp
, '>')) != 0)
1221 rp
->r_dycode
= DC_DOWGEQ
;
1224 rp
->r_dycode
= DC_DOM
;
1226 if (rp
->r_dycode
!= DC_DOM
) {
1229 error("invalid day of month");
1233 if ((lp
= byword(dp
, wday_names
)) == NULL
) {
1234 error("invalid weekday name");
1238 rp
->r_wday
= lp
->l_value
;
1240 if (sscanf(ep
, scheck(ep
, "%d"), &rp
->r_dayofmonth
) != 1 ||
1241 rp
->r_dayofmonth
<= 0 ||
1242 (rp
->r_dayofmonth
> len_months
[1][rp
->r_month
])) {
1243 error("invalid day of month");
1257 register long shift
;
1259 for (i
= 0, shift
= 24; i
< 4; ++i
, shift
-= 8)
1260 buf
[i
] = val
>> shift
;
1271 (void) fwrite((void *) buf
, (size_t) sizeof buf
, (size_t) 1, fp
);
1276 const char * const name
;
1280 static char * fullname
;
1281 static struct tzhead tzh
;
1283 fullname
= erealloc(fullname
,
1284 (int) (strlen(directory
) + 1 + strlen(name
) + 1));
1285 (void) sprintf(fullname
, "%s/%s", directory
, name
);
1286 if ((fp
= fopen(fullname
, "wb")) == NULL
) {
1287 if (mkdirs(fullname
) != 0)
1288 (void) exit(EXIT_FAILURE
);
1289 if ((fp
= fopen(fullname
, "wb")) == NULL
) {
1290 (void) fprintf(stderr
, "%s: Can't create ", progname
);
1291 (void) perror(fullname
);
1292 (void) exit(EXIT_FAILURE
);
1295 convert(eitol(typecnt
), tzh
.tzh_ttisgmtcnt
);
1296 convert(eitol(typecnt
), tzh
.tzh_ttisstdcnt
);
1297 convert(eitol(leapcnt
), tzh
.tzh_leapcnt
);
1298 convert(eitol(timecnt
), tzh
.tzh_timecnt
);
1299 convert(eitol(typecnt
), tzh
.tzh_typecnt
);
1300 convert(eitol(charcnt
), tzh
.tzh_charcnt
);
1301 #define DO(field) (void) fwrite((void *) tzh.field, \
1302 (size_t) sizeof tzh.field, (size_t) 1, fp)
1311 for (i
= 0; i
< timecnt
; ++i
) {
1314 if (ats
[i
] >= trans
[j
]) {
1315 ats
[i
] = tadd(ats
[i
], corr
[j
]);
1318 puttzcode((long) ats
[i
], fp
);
1321 (void) fwrite((void *) types
, (size_t) sizeof types
[0],
1322 (size_t) timecnt
, fp
);
1323 for (i
= 0; i
< typecnt
; ++i
) {
1324 puttzcode((long) gmtoffs
[i
], fp
);
1325 (void) putc(isdsts
[i
], fp
);
1326 (void) putc(abbrinds
[i
], fp
);
1329 (void) fwrite((void *) chars
, (size_t) sizeof chars
[0],
1330 (size_t) charcnt
, fp
);
1331 for (i
= 0; i
< leapcnt
; ++i
) {
1333 if (timecnt
== 0 || trans
[i
] < ats
[0]) {
1336 if (++j
>= typecnt
) {
1342 while (j
< timecnt
&& trans
[i
] >= ats
[j
])
1346 puttzcode((long) tadd(trans
[i
], -gmtoffs
[j
]), fp
);
1347 } else puttzcode((long) trans
[i
], fp
);
1348 puttzcode((long) corr
[i
], fp
);
1350 for (i
= 0; i
< typecnt
; ++i
)
1351 (void) putc(ttisstds
[i
], fp
);
1352 for (i
= 0; i
< typecnt
; ++i
)
1353 (void) putc(ttisgmts
[i
], fp
);
1354 if (ferror(fp
) || fclose(fp
)) {
1355 (void) fprintf(stderr
, "%s: Write error on ", progname
);
1356 (void) perror(fullname
);
1357 (void) exit(EXIT_FAILURE
);
1362 doabbr(abbr
, format
, letters
, isdst
)
1364 const char * const format
;
1365 const char * const letters
;
1368 if (strchr(format
, '/') == NULL
) {
1369 if (letters
== NULL
)
1370 (void) strcpy(abbr
, format
);
1371 else (void) sprintf(abbr
, format
, letters
);
1373 (void) strcpy(abbr
, strchr(format
, '/') + 1);
1375 (void) strcpy(abbr
, format
);
1376 *strchr(abbr
, '/') = '\0';
1381 outzone(zpfirst
, zonecount
)
1382 const struct zone
* const zpfirst
;
1383 const int zonecount
;
1385 register const struct zone
* zp
;
1386 register struct rule
* rp
;
1388 register int usestart
, useuntil
;
1389 register time_t starttime
, untiltime
;
1390 register long gmtoff
;
1391 register long stdoff
;
1393 register long startoff
;
1394 register int startisdst
;
1395 register int startttisstd
;
1396 register int startttisgmt
;
1398 char startbuf
[BUFSIZ
];
1400 INITIALIZE(untiltime
);
1401 INITIALIZE(starttime
);
1402 INITIALIZE(startoff
);
1404 ** Now. . .finally. . .generate some useful data!
1410 ** A guess that may well be corrected later.
1414 ** Thanks to Earl Chew (earl@dnd.icp.nec.com.au)
1415 ** for noting the need to unconditionally initialize startttisstd.
1417 startttisstd
= FALSE
;
1418 startttisgmt
= FALSE
;
1419 for (i
= 0; i
< zonecount
; ++i
) {
1421 usestart
= i
> 0 && (zp
- 1)->z_untiltime
> min_time
;
1422 useuntil
= i
< (zonecount
- 1);
1423 if (useuntil
&& zp
->z_untiltime
<= min_time
)
1425 gmtoff
= zp
->z_gmtoff
;
1426 eat(zp
->z_filename
, zp
->z_linenum
);
1428 if (zp
->z_nrules
== 0) {
1429 stdoff
= zp
->z_stdoff
;
1430 doabbr(startbuf
, zp
->z_format
,
1431 (char *) NULL
, stdoff
!= 0);
1432 type
= addtype(oadd(zp
->z_gmtoff
, stdoff
),
1433 startbuf
, stdoff
!= 0, startttisstd
,
1436 addtt(starttime
, type
);
1437 else if (stdoff
!= 0)
1438 addtt(min_time
, type
);
1439 } else for (year
= min_year
; year
<= max_year
; ++year
) {
1440 if (useuntil
&& year
> zp
->z_untilrule
.r_hiyear
)
1443 ** Mark which rules to do in the current year.
1444 ** For those to do, calculate rpytime(rp, year);
1446 for (j
= 0; j
< zp
->z_nrules
; ++j
) {
1447 rp
= &zp
->z_rules
[j
];
1448 eats(zp
->z_filename
, zp
->z_linenum
,
1449 rp
->r_filename
, rp
->r_linenum
);
1450 rp
->r_todo
= year
>= rp
->r_loyear
&&
1451 year
<= rp
->r_hiyear
&&
1452 yearistype(year
, rp
->r_yrtype
);
1454 rp
->r_temp
= rpytime(rp
, year
);
1458 register time_t jtime
, ktime
;
1459 register long offset
;
1465 ** Turn untiltime into GMT
1466 ** assuming the current gmtoff and
1469 untiltime
= zp
->z_untiltime
;
1470 if (!zp
->z_untilrule
.r_todisgmt
)
1471 untiltime
= tadd(untiltime
,
1473 if (!zp
->z_untilrule
.r_todisstd
)
1474 untiltime
= tadd(untiltime
,
1478 ** Find the rule (of those to do, if any)
1479 ** that takes effect earliest in the year.
1482 for (j
= 0; j
< zp
->z_nrules
; ++j
) {
1483 rp
= &zp
->z_rules
[j
];
1486 eats(zp
->z_filename
, zp
->z_linenum
,
1487 rp
->r_filename
, rp
->r_linenum
);
1488 offset
= rp
->r_todisgmt
? 0 : gmtoff
;
1489 if (!rp
->r_todisstd
)
1490 offset
= oadd(offset
, stdoff
);
1492 if (jtime
== min_time
||
1495 jtime
= tadd(jtime
, -offset
);
1496 if (k
< 0 || jtime
< ktime
) {
1502 break; /* go on to next year */
1503 rp
= &zp
->z_rules
[k
];
1505 if (useuntil
&& ktime
>= untiltime
)
1508 if (ktime
< starttime
) {
1509 stdoff
= rp
->r_stdoff
;
1510 startoff
= oadd(zp
->z_gmtoff
,
1512 doabbr(startbuf
, zp
->z_format
,
1515 startisdst
= rp
->r_stdoff
!= 0;
1519 if (ktime
!= starttime
) {
1520 if (startisdst
< 0 &&
1522 (zp
- 1)->z_gmtoff
) {
1523 type
= (timecnt
== 0) ? 0 :
1525 startoff
= oadd(gmtoffs
[type
],
1526 -(zp
- 1)->z_gmtoff
);
1527 startisdst
= startoff
!= 0;
1528 startoff
= oadd(startoff
,
1530 (void) strcpy(startbuf
,
1531 &chars
[abbrinds
[type
]]);
1533 if (startisdst
>= 0)
1534 addtt(starttime
, addtype(startoff
, startbuf
, startisdst
, startttisstd
,
1538 eats(zp
->z_filename
, zp
->z_linenum
,
1539 rp
->r_filename
, rp
->r_linenum
);
1540 doabbr(buf
, zp
->z_format
, rp
->r_abbrvar
,
1542 offset
= oadd(zp
->z_gmtoff
, rp
->r_stdoff
);
1543 type
= addtype(offset
, buf
, rp
->r_stdoff
!= 0,
1544 rp
->r_todisstd
, rp
->r_todisgmt
);
1546 stdoff
= rp
->r_stdoff
;
1550 ** Now we may get to set starttime for the next zone line.
1553 starttime
= tadd(zp
->z_untiltime
, -gmtoff
);
1554 startttisstd
= zp
->z_untilrule
.r_todisstd
;
1555 startttisgmt
= zp
->z_untilrule
.r_todisgmt
;
1557 starttime
= tadd(starttime
, -stdoff
);
1560 writezone(zpfirst
->z_name
);
1564 addtt(starttime
, type
)
1565 const time_t starttime
;
1568 if (timecnt
!= 0 && type
== types
[timecnt
- 1])
1569 return; /* easy enough! */
1570 if (timecnt
== 0 && type
== 0 && isdsts
[0] == 0)
1571 return; /* handled by default rule */
1572 if (timecnt
>= TZ_MAX_TIMES
) {
1573 error("too many transitions?!");
1574 (void) exit(EXIT_FAILURE
);
1576 ats
[timecnt
] = starttime
;
1577 types
[timecnt
] = type
;
1582 addtype(gmtoff
, abbr
, isdst
, ttisstd
, ttisgmt
)
1584 const char * const abbr
;
1592 ** See if there's already an entry for this zone type.
1593 ** If so, just return its index.
1595 for (i
= 0; i
< typecnt
; ++i
) {
1596 if (gmtoff
== gmtoffs
[i
] && isdst
== isdsts
[i
] &&
1597 strcmp(abbr
, &chars
[abbrinds
[i
]]) == 0 &&
1598 ttisstd
== ttisstds
[i
] &&
1599 ttisgmt
== ttisgmts
[i
])
1603 ** There isn't one; add a new one, unless there are already too
1606 if (typecnt
>= TZ_MAX_TYPES
) {
1607 error("too many local time types");
1608 (void) exit(EXIT_FAILURE
);
1610 gmtoffs
[i
] = gmtoff
;
1612 ttisstds
[i
] = ttisstd
;
1613 ttisgmts
[i
] = ttisgmt
;
1615 for (j
= 0; j
< charcnt
; ++j
)
1616 if (strcmp(&chars
[j
], abbr
) == 0)
1626 leapadd(t
, positive
, rolling
, count
)
1634 if (leapcnt
+ (positive
? count
: 1) > TZ_MAX_LEAPS
) {
1635 error("too many leap seconds");
1636 (void) exit(EXIT_FAILURE
);
1638 for (i
= 0; i
< leapcnt
; ++i
)
1639 if (t
<= trans
[i
]) {
1640 if (t
== trans
[i
]) {
1641 error("repeated leap second moment");
1642 (void) exit(EXIT_FAILURE
);
1647 for (j
= leapcnt
; j
> i
; --j
) {
1648 trans
[j
] = trans
[j
- 1];
1649 corr
[j
] = corr
[j
- 1];
1650 roll
[j
] = roll
[j
- 1];
1653 corr
[i
] = positive
? 1L : eitol(-count
);
1656 } while (positive
&& --count
!= 0);
1663 register long last
= 0;
1666 ** propagate leap seconds forward
1668 for (i
= 0; i
< leapcnt
; ++i
) {
1669 trans
[i
] = tadd(trans
[i
], last
);
1670 last
= corr
[i
] += last
;
1675 yearistype(year
, type
)
1677 const char * const type
;
1682 if (type
== NULL
|| *type
== '\0')
1684 buf
= erealloc(buf
, (int) (132 + strlen(yitcommand
) + strlen(type
)));
1685 (void) sprintf(buf
, "%s %d %s", yitcommand
, year
, type
);
1686 result
= system(buf
);
1689 if (result
== (1 << 8))
1691 error("Wild result from command execution");
1692 (void) fprintf(stderr
, "%s: command was '%s', result was %d\n",
1693 progname
, buf
, result
);
1695 (void) exit(EXIT_FAILURE
);
1702 return (isascii(a
) && isupper(a
)) ? tolower(a
) : a
;
1706 ciequal(ap
, bp
) /* case-insensitive equality */
1707 register const char * ap
;
1708 register const char * bp
;
1710 while (lowerit(*ap
) == lowerit(*bp
++))
1718 register const char * abbr
;
1719 register const char * word
;
1721 if (lowerit(*abbr
) != lowerit(*word
))
1724 while (*++abbr
!= '\0')
1725 do if (*word
== '\0')
1727 while (lowerit(*word
++) != lowerit(*abbr
));
1731 static const struct lookup
*
1733 register const char * const word
;
1734 register const struct lookup
* const table
;
1736 register const struct lookup
* foundlp
;
1737 register const struct lookup
* lp
;
1739 if (word
== NULL
|| table
== NULL
)
1742 ** Look for exact match.
1744 for (lp
= table
; lp
->l_word
!= NULL
; ++lp
)
1745 if (ciequal(word
, lp
->l_word
))
1748 ** Look for inexact match.
1751 for (lp
= table
; lp
->l_word
!= NULL
; ++lp
)
1752 if (itsabbr(word
, lp
->l_word
))
1753 if (foundlp
== NULL
)
1755 else return NULL
; /* multiple inexact matches */
1764 register char ** array
;
1769 array
= (char **) (void *)
1770 emalloc((int) ((strlen(cp
) + 1) * sizeof *array
));
1773 while (isascii(*cp
) && isspace(*cp
))
1775 if (*cp
== '\0' || *cp
== '#')
1777 array
[nsubs
++] = dp
= cp
;
1779 if ((*dp
= *cp
++) != '"')
1781 else while ((*dp
= *cp
++) != '"')
1784 else error("Odd number of quotation marks");
1785 } while (*cp
!= '\0' && *cp
!= '#' &&
1786 (!isascii(*cp
) || !isspace(*cp
)));
1787 if (isascii(*cp
) && isspace(*cp
))
1791 array
[nsubs
] = NULL
;
1803 if ((t2
> 0 && t
<= t1
) || (t2
< 0 && t
>= t1
)) {
1804 error("time overflow");
1805 (void) exit(EXIT_FAILURE
);
1817 if (t1
== max_time
&& t2
> 0)
1819 if (t1
== min_time
&& t2
< 0)
1822 if ((t2
> 0 && t
<= t1
) || (t2
< 0 && t
>= t1
)) {
1823 error("time overflow");
1824 (void) exit(EXIT_FAILURE
);
1830 ** Given a rule, and a year, compute the date - in seconds since January 1,
1831 ** 1970, 00:00 LOCAL time - in that year that the rule refers to.
1835 rpytime(rp
, wantedy
)
1836 register const struct rule
* const rp
;
1837 register const int wantedy
;
1839 register int y
, m
, i
;
1840 register long dayoff
; /* with a nod to Margaret O. */
1843 if (wantedy
== min_int
)
1845 if (wantedy
== max_int
)
1850 while (wantedy
!= y
) {
1852 i
= len_years
[isleap(y
)];
1856 i
= -len_years
[isleap(y
)];
1858 dayoff
= oadd(dayoff
, eitol(i
));
1860 while (m
!= rp
->r_month
) {
1861 i
= len_months
[isleap(y
)][m
];
1862 dayoff
= oadd(dayoff
, eitol(i
));
1865 i
= rp
->r_dayofmonth
;
1866 if (m
== TM_FEBRUARY
&& i
== 29 && !isleap(y
)) {
1867 if (rp
->r_dycode
== DC_DOWLEQ
)
1870 error("use of 2/29 in non leap-year");
1871 (void) exit(EXIT_FAILURE
);
1875 dayoff
= oadd(dayoff
, eitol(i
));
1876 if (rp
->r_dycode
== DC_DOWGEQ
|| rp
->r_dycode
== DC_DOWLEQ
) {
1879 #define LDAYSPERWEEK ((long) DAYSPERWEEK)
1880 wday
= eitol(EPOCH_WDAY
);
1882 ** Don't trust mod of negative numbers.
1885 wday
= (wday
+ dayoff
) % LDAYSPERWEEK
;
1887 wday
-= ((-dayoff
) % LDAYSPERWEEK
);
1889 wday
+= LDAYSPERWEEK
;
1891 while (wday
!= eitol(rp
->r_wday
))
1892 if (rp
->r_dycode
== DC_DOWGEQ
) {
1893 dayoff
= oadd(dayoff
, (long) 1);
1894 if (++wday
>= LDAYSPERWEEK
)
1898 dayoff
= oadd(dayoff
, (long) -1);
1900 wday
= LDAYSPERWEEK
- 1;
1903 if (i
< 0 || i
>= len_months
[isleap(y
)][m
]) {
1904 error("no day in month matches rule");
1905 (void) exit(EXIT_FAILURE
);
1908 if (dayoff
< 0 && !tt_signed
)
1910 t
= (time_t) dayoff
* SECSPERDAY
;
1912 ** Cheap overflow check.
1914 if (t
/ SECSPERDAY
!= dayoff
)
1915 return (dayoff
> 0) ? max_time
: min_time
;
1916 return tadd(t
, rp
->r_tod
);
1921 const char * const string
;
1925 i
= strlen(string
) + 1;
1926 if (charcnt
+ i
> TZ_MAX_CHARS
) {
1927 error("too many, or too long, time zone abbreviations");
1928 (void) exit(EXIT_FAILURE
);
1930 (void) strcpy(&chars
[charcnt
], string
);
1931 charcnt
+= eitol(i
);
1936 char * const argname
;
1938 register char * name
;
1941 if (argname
== NULL
|| *argname
== '\0')
1943 cp
= name
= ecpyalloc(argname
);
1944 while ((cp
= strchr(cp
+ 1, '/')) != 0) {
1948 ** DOS drive specifier?
1950 if (strlen(name
) == 2 && isascii(name
[0]) &&
1951 isalpha(name
[0]) && name
[1] == ':') {
1955 #endif /* !defined unix */
1956 if (!itsdir(name
)) {
1958 ** It doesn't seem to exist, so we try to create it.
1960 if (mkdir(name
, 0755) != 0) {
1961 (void) fprintf(stderr
,
1962 "%s: Can't create directory ",
1964 (void) perror(name
);
1982 if ((i
< 0 && l
>= 0) || (i
== 0 && l
!= 0) || (i
> 0 && l
<= 0)) {
1983 (void) fprintf(stderr
,
1984 "%s: %d did not sign extend correctly\n",
1986 (void) exit(EXIT_FAILURE
);
1992 ** UNIX was a registered trademark of UNIX System Laboratories in 1993.