diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | timezone/README | 7 | ||||
-rw-r--r-- | timezone/checktab.awk | 2 | ||||
-rw-r--r-- | timezone/ialloc.c | 62 | ||||
-rw-r--r-- | timezone/private.h | 21 | ||||
-rw-r--r-- | timezone/scheck.c | 16 | ||||
-rw-r--r-- | timezone/tzfile.h | 10 | ||||
-rw-r--r-- | timezone/tzselect.ksh | 33 | ||||
-rw-r--r-- | timezone/version.h | 1 | ||||
-rw-r--r-- | timezone/zdump.c | 131 | ||||
-rw-r--r-- | timezone/zic.c | 404 |
11 files changed, 236 insertions, 463 deletions
@@ -1,5 +1,17 @@ 2012-11-09 Joseph Myers <joseph@codesourcery.com> + * timezone/checktab.awk: Update from tzcode 2012i. + * timezone/ialloc.c: Likewise. + * timezone/private.h: Likewise. + * timezone/scheck.c: Likewise. + * timezone/tzfile.h: Likewise. + * timezone/tzselect.ksh: Merge in changes from tzcode 2012i. + (TZVERSION): Hardcode tzcode version number. + * timezone/zdump.c: Update from tzcode 2012i. + * timezone/zic.c: Likewise. + * timezone/version.h: New file. + * timezone/README: Describe version.h. Update upstream location. + [BZ #14824] * stdlib/stdlib.h [__USE_XOPEN_EXTENDED && __USE_XOPEN2K] (mktemp): Enable declaration. diff --git a/timezone/README b/timezone/README index 05bfe91..cb3d2cd 100644 --- a/timezone/README +++ b/timezone/README @@ -1,7 +1,10 @@ The files zic.c zdump.c ialloc.c scheck.c tzfile.h private.h tzselect.ksh checktab.awk -come from the tzcode package by Arthur David Olson et.al. +come from the tzcode package by Arthur David Olson et.al.; the file + version.h +has the contents that would be generated by that package's Makefile, +and tzselect.ksh has been modified for use in glibc. The files africa antarctica asia australasia europe @@ -13,5 +16,5 @@ come from the tzdata package by Arthur David Olson et.al. Please check the ChangeLog files in the top level directory for the version of the tzcode and tzdata packages. -These packages may be found at ftp://munnari.oz.au/pub/. Commentary +These packages may be found at ftp://ftp.iana.org/tz/releases/. Commentary should be addressed to tz@iana.org. diff --git a/timezone/checktab.awk b/timezone/checktab.awk index 80ad7d5..c88b12f 100644 --- a/timezone/checktab.awk +++ b/timezone/checktab.awk @@ -1,7 +1,5 @@ # Check tz tables for consistency. -# @(#)checktab.awk 8.1 - # Contributed by Paul Eggert. BEGIN { diff --git a/timezone/ialloc.c b/timezone/ialloc.c index 1fc2035..b6f0188 100644 --- a/timezone/ialloc.c +++ b/timezone/ialloc.c @@ -3,49 +3,12 @@ ** 2006-07-17 by Arthur David Olson. */ -#ifndef lint -#ifndef NOID -static char elsieid[] = "@(#)ialloc.c 8.30"; -#endif /* !defined NOID */ -#endif /* !defined lint */ - /*LINTLIBRARY*/ #include "private.h" -#define nonzero(n) (((n) == 0) ? 1 : (n)) - -char * -imalloc(n) -const int n; -{ - return malloc((size_t) nonzero(n)); -} - char * -icalloc(nelem, elsize) -int nelem; -int elsize; -{ - if (nelem == 0 || elsize == 0) - nelem = elsize = 1; - return calloc((size_t) nelem, (size_t) elsize); -} - -void * -irealloc(pointer, size) -void * const pointer; -const int size; -{ - if (pointer == NULL) - return imalloc(size); - return realloc((void *) pointer, (size_t) nonzero(size)); -} - -char * -icatalloc(old, new) -char * const old; -const char * const new; +icatalloc(char *const old, const char *const new) { register char * result; register int oldsize, newsize; @@ -56,31 +19,14 @@ const char * const new; else if (newsize == 0) return old; else oldsize = strlen(old); - if ((result = irealloc(old, oldsize + newsize + 1)) != NULL) + if ((result = realloc(old, oldsize + newsize + 1)) != NULL) if (new != NULL) (void) strcpy(result + oldsize, new); return result; } char * -icpyalloc(string) -const char * const string; -{ - return icatalloc((char *) NULL, string); -} - -void -ifree(p) -char * const p; -{ - if (p != NULL) - (void) free(p); -} - -void -icfree(p) -char * const p; +icpyalloc(const char *const string) { - if (p != NULL) - (void) free(p); + return icatalloc(NULL, string); } diff --git a/timezone/private.h b/timezone/private.h index 008d468..1d1d391 100644 --- a/timezone/private.h +++ b/timezone/private.h @@ -15,16 +15,6 @@ ** Thank you! */ -/* -** ID -*/ - -#ifndef lint -#ifndef NOID -static char privatehid[] = "@(#)private.h 8.6"; -#endif /* !defined NOID */ -#endif /* !defined lint */ - #define GRANDPARENTED "Local time zone must be set--see zic manual page" /* @@ -154,6 +144,12 @@ typedef long int_fast64_t; #define INT32_MIN (-1 - INT32_MAX) #endif /* !defined INT32_MIN */ +#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__) +# define ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +# define ATTRIBUTE_PURE /* empty */ +#endif + /* ** Workarounds for compilers/systems. */ @@ -172,13 +168,8 @@ extern char * asctime_r(struct tm const *, char *); ** Private function declarations. */ -char * icalloc(int nelem, int elsize); char * icatalloc(char * old, const char * new); char * icpyalloc(const char * string); -char * imalloc(int n); -void * irealloc(void * pointer, int size); -void icfree(char * pointer); -void ifree(char * pointer); const char * scheck(const char * string, const char * format); /* diff --git a/timezone/scheck.c b/timezone/scheck.c index 74d9b07..ed60980 100644 --- a/timezone/scheck.c +++ b/timezone/scheck.c @@ -3,20 +3,12 @@ ** 2006-07-17 by Arthur David Olson. */ -#ifndef lint -#ifndef NOID -static char elsieid[] = "@(#)scheck.c 8.19"; -#endif /* !defined lint */ -#endif /* !defined NOID */ - /*LINTLIBRARY*/ #include "private.h" const char * -scheck(string, format) -const char * const string; -const char * const format; +scheck(const char *const string, const char *const format) { register char * fbuf; register const char * fp; @@ -28,7 +20,7 @@ const char * const format; result = ""; if (string == NULL || format == NULL) return result; - fbuf = imalloc((int) (2 * strlen(format) + 4)); + fbuf = malloc(2 * strlen(format) + 4); if (fbuf == NULL) return result; fp = format; @@ -57,7 +49,7 @@ const char * const format; *tp++ = 'c'; *tp = '\0'; if (sscanf(string, fbuf, &dummy) != 1) - result = (char *) format; - ifree(fbuf); + result = format; + free(fbuf); return result; } diff --git a/timezone/tzfile.h b/timezone/tzfile.h index 3a9eee3..0f6c687 100644 --- a/timezone/tzfile.h +++ b/timezone/tzfile.h @@ -16,16 +16,6 @@ */ /* -** ID -*/ - -#ifndef lint -#ifndef NOID -static char tzfilehid[] = "@(#)tzfile.h 8.1"; -#endif /* !defined NOID */ -#endif /* !defined lint */ - -/* ** Information about time zone files. */ diff --git a/timezone/tzselect.ksh b/timezone/tzselect.ksh index 57bf707..0e93d79 100644 --- a/timezone/tzselect.ksh +++ b/timezone/tzselect.ksh @@ -1,6 +1,6 @@ #! @KSH@ -VERSION='@(#)tzselect.ksh 8.2' +TZVERSION=tz2012i # Ask the user about the time zone, and output the resulting TZ value to stdout. # Interact with the user via stderr and stdin. @@ -9,29 +9,22 @@ VERSION='@(#)tzselect.ksh 8.2' # Porting notes: # -# This script requires several features of the Korn shell. -# If your host lacks the Korn shell, -# you can use either of the following free programs instead: -# -# <a href=ftp://ftp.gnu.org/pub/gnu/> -# Bourne-Again shell (bash) -# </a> +# This script requires a Posix-like shell with the extension of a +# 'select' statement. The 'select' statement was introduced in the +# Korn shell and is available in Bash and other shell implementations. +# If your host lacks both Bash and the Korn shell, you can get their +# source from one of these locations: # -# <a href=ftp://ftp.cs.mun.ca/pub/pdksh/pdksh.tar.gz> -# Public domain ksh -# </a> +# Bash <http://www.gnu.org/software/bash/bash.html> +# Korn Shell <http://www.kornshell.com/> +# Public Domain Korn Shell <http://www.cs.mun.ca/~michael/pdksh/> # # This script also uses several features of modern awk programs. -# If your host lacks awk, or has an old awk that does not conform to Posix.2, +# If your host lacks awk, or has an old awk that does not conform to Posix, # you can use either of the following free programs instead: # -# <a href=ftp://ftp.gnu.org/pub/gnu/> -# GNU awk (gawk) -# </a> -# -# <a href=ftp://ftp.whidbey.net/pub/brennan/> -# mawk -# </a> +# Gawk (GNU awk) <http://www.gnu.org/software/gawk/> +# mawk <http://invisible-island.net/mawk/> # Specify default values for environment variables if they are unset. @@ -55,7 +48,7 @@ EOF exit 0 elif [ "$1" = "--version" ]; then cat <<EOF -tzselect $VERSION +tzselect $TZVERSION EOF exit 0 fi diff --git a/timezone/version.h b/timezone/version.h new file mode 100644 index 0000000..0873ea1 --- /dev/null +++ b/timezone/version.h @@ -0,0 +1 @@ +static char const TZVERSION[]="tz2012i"; diff --git a/timezone/zdump.c b/timezone/zdump.c index 67bed06..805267d 100644 --- a/timezone/zdump.c +++ b/timezone/zdump.c @@ -3,7 +3,7 @@ ** 2009-05-17 by Arthur David Olson. */ -static char elsieid[] = "@(#)zdump.c 8.10"; +#include "version.h" /* ** This code has been made independent of the rest of the time @@ -17,6 +17,7 @@ static char elsieid[] = "@(#)zdump.c 8.10"; #include "time.h" /* for struct tm */ #include "stdlib.h" /* for exit, malloc, atoi */ #include "float.h" /* for FLT_MAX and DBL_MAX */ +#include "limits.h" /* for CHAR_BIT, LLONG_MAX */ #include "ctype.h" /* for isalpha et al. */ #ifndef isascii #define isascii(x) 1 @@ -119,6 +120,12 @@ static char elsieid[] = "@(#)zdump.c 8.10"; #endif /* !defined GNUC_or_lint */ #endif /* !defined INITIALIZE */ +#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__) +# define ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +# define ATTRIBUTE_PURE /* empty */ +#endif + /* ** For the benefit of GNU folk... ** `_(MSGID)' uses the current locale's message library string for MSGID. @@ -144,28 +151,54 @@ extern char * optarg; extern int optind; extern char * tzname[2]; -static time_t absolute_min_time; -static time_t absolute_max_time; +/* The minimum and maximum finite time values. Shift 'long long' or + 'long' instead of 'time_t'; this avoids compile-time errors when + time_t is floating-point. In practice, 'long long' is wide enough. */ +static time_t const absolute_min_time = + ((time_t) 0.5 == 0.5 + ? (sizeof (time_t) == sizeof (float) ? (time_t) -FLT_MAX + : sizeof (time_t) == sizeof (double) ? (time_t) -DBL_MAX + : sizeof (time_t) == sizeof (long double) ? (time_t) -LDBL_MAX + : 0) + : (time_t) -1 < 0 +#ifdef LLONG_MAX + ? (time_t) ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1)) +#else + ? (time_t) ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1)) +#endif + : 0); +static time_t const absolute_max_time = + ((time_t) 0.5 == 0.5 + ? (sizeof (time_t) == sizeof (float) ? (time_t) FLT_MAX + : sizeof (time_t) == sizeof (double) ? (time_t) DBL_MAX + : sizeof (time_t) == sizeof (long double) ? (time_t) LDBL_MAX + : -1) + : (time_t) -1 < 0 +#ifdef LLONG_MAX + ? (time_t) (- (~ 0 < 0) - ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1))) +#else + ? (time_t) (- (~ 0 < 0) - ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1))) +#endif + : (time_t) -1); static size_t longest; static char * progname; static int warned; static char * abbr(struct tm * tmp); static void abbrok(const char * abbrp, const char * zone); -static long delta(struct tm * newp, struct tm * oldp); +static long delta(struct tm * newp, struct tm * oldp) ATTRIBUTE_PURE; static void dumptime(const struct tm * tmp); static time_t hunt(char * name, time_t lot, time_t hit); -static void setabsolutes(void); +static void checkabsolutes(void); static void show(char * zone, time_t t, int v); static const char * tformat(void); -static time_t yeartot(long y); +static time_t yeartot(long y) ATTRIBUTE_PURE; #ifndef TYPECHECK #define my_localtime localtime #else /* !defined TYPECHECK */ static struct tm * -my_localtime(tp) -time_t * tp; +my_localtime(time_t *tp) { register struct tm * tmp; @@ -198,12 +231,10 @@ time_t * tp; #endif /* !defined TYPECHECK */ static void -abbrok(abbrp, zone) -const char * const abbrp; -const char * const zone; +abbrok(const char *const abbrp, const char *const zone) { register const char * cp; - register char * wp; + register const char * wp; if (warned) return; @@ -236,9 +267,7 @@ const char * const zone; } static void -usage(stream, status) -FILE * const stream; -const int status; +usage(FILE * const stream, const int status) { (void) fprintf(stream, _("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n\ @@ -249,9 +278,7 @@ Report bugs to tz@elsie.nci.nih.gov.\n"), } int -main(argc, argv) -int argc; -char * argv[]; +main(int argc, char *argv[]) { register int i; register int c; @@ -282,7 +309,7 @@ char * argv[]; progname = argv[0]; for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { - (void) printf("%s\n", elsieid); + (void) printf("%s\n", TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); @@ -315,7 +342,7 @@ char * argv[]; exit(EXIT_FAILURE); } } - setabsolutes(); + checkabsolutes(); cutlotime = yeartot(cutloyear); cuthitime = yeartot(cuthiyear); } @@ -330,10 +357,9 @@ char * argv[]; for (i = 0; environ[i] != NULL; ++i) continue; - fakeenv = (char **) malloc((size_t) ((i + 2) * - sizeof *fakeenv)); - if (fakeenv == NULL || - (fakeenv[0] = (char *) malloc(longest + 4)) == NULL) { + fakeenv = malloc((i + 2) * sizeof *fakeenv); + if (fakeenv == NULL + || (fakeenv[0] = malloc(longest + 4)) == NULL) { (void) perror(progname); exit(EXIT_FAILURE); } @@ -406,53 +432,18 @@ char * argv[]; } static void -setabsolutes(void) +checkabsolutes(void) { - if (0.5 == (time_t) 0.5) { - /* - ** time_t is floating. - */ - if (sizeof (time_t) == sizeof (float)) { - absolute_min_time = (time_t) -FLT_MAX; - absolute_max_time = (time_t) FLT_MAX; - } else if (sizeof (time_t) == sizeof (double)) { - absolute_min_time = (time_t) -DBL_MAX; - absolute_max_time = (time_t) DBL_MAX; - } else { - (void) fprintf(stderr, + if (absolute_max_time < absolute_min_time) { + (void) fprintf(stderr, _("%s: use of -v on system with floating time_t other than float or double\n"), - progname); - exit(EXIT_FAILURE); - } - } else if (0 > (time_t) -1) { - /* - ** time_t is signed. Assume overflow wraps around. - */ - time_t t = 0; - time_t t1 = 1; - - while (t < t1) { - t = t1; - t1 = 2 * t1 + 1; - } - - absolute_max_time = t; - t = -t; - absolute_min_time = t - 1; - if (t < absolute_min_time) - absolute_min_time = t; - } else { - /* - ** time_t is unsigned. - */ - absolute_min_time = 0; - absolute_max_time = absolute_min_time - 1; + progname); + exit(EXIT_FAILURE); } } static time_t -yeartot(y) -const long y; +yeartot(const long y) { register long myy; register long seconds; @@ -530,9 +521,7 @@ hunt(char *name, time_t lot, time_t hit) */ static long -delta(newp, oldp) -struct tm * newp; -struct tm * oldp; +delta(struct tm * newp, struct tm *oldp) { register long result; register int tmy; @@ -586,8 +575,7 @@ show(char *zone, time_t t, int v) } static char * -abbr(tmp) -struct tm * tmp; +abbr(struct tm *tmp) { register char * result; static char nada; @@ -626,8 +614,7 @@ tformat(void) } static void -dumptime(timeptr) -register const struct tm * timeptr; +dumptime(register const struct tm *timeptr) { static const char wday_name[][3] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" diff --git a/timezone/zic.c b/timezone/zic.c index 1ea7b18..64af1b2 100644 --- a/timezone/zic.c +++ b/timezone/zic.c @@ -3,8 +3,7 @@ ** 2006-07-17 by Arthur David Olson. */ -static char elsieid[] = "@(#)zic.c 8.25"; - +#include "version.h" #include "private.h" #include "locale.h" #include "tzfile.h" @@ -111,17 +110,8 @@ static int addtype(long gmtoff, const char * abbr, int isdst, static void leapadd(zic_t t, int positive, int rolling, int count); static void adjleap(void); static void associate(void); -static int ciequal(const char * ap, const char * bp); -static void convert(long val, char * buf); -static void convert64(zic_t val, char * buf); static void dolink(const char * fromfield, const char * tofield); -static void doabbr(char * abbr, const char * format, - const char * letters, int isdst, int doquotes); -static void eat(const char * name, int num); -static void eats(const char * name, int num, - const char * rname, int rnum); static long eitol(int i); -static void error(const char * message); static char ** getfields(char * buf); static long gethms(const char * string, const char * errstrng, int signable); @@ -132,32 +122,18 @@ static void inrule(char ** fields, int nfields); static int inzcont(char ** fields, int nfields); static int inzone(char ** fields, int nfields); static int inzsub(char ** fields, int nfields, int iscont); -static int is32(zic_t x); -static int itsabbr(const char * abbr, const char * word); static int itsdir(const char * name); static int lowerit(int c); -static char * memcheck(char * tocheck); static int mkdirs(char * filename); static void newabbr(const char * abbr); static long oadd(long t1, long t2); static void outzone(const struct zone * zp, int ntzones); -static void puttzcode(long code, FILE * fp); -static void puttzcode64(zic_t code, FILE * fp); -static int rcomp(const void * leftp, const void * rightp); static zic_t rpytime(const struct rule * rp, int wantedy); static void rulesub(struct rule * rp, const char * loyearp, const char * hiyearp, const char * typep, const char * monthp, const char * dayp, const char * timep); -static int stringoffset(char * result, long offset); -static int stringrule(char * result, const struct rule * rp, - long dstoff, long gmtoff); -static void stringzone(char * result, - const struct zone * zp, int ntzones); -static void setboundaries(void); static zic_t tadd(zic_t t1, long t2); -static void usage(FILE *stream, int status); -static void writezone(const char * name, const char * string); static int yearistype(int year, const char * type); static int charcnt; @@ -170,9 +146,7 @@ static int leapmaxyear; static int linenum; static int max_abbrvar_len; static int max_format_len; -static zic_t max_time; static int max_year; -static zic_t min_time; static int min_year; static int noise; static const char * rfilename; @@ -378,9 +352,8 @@ static char roll[TZ_MAX_LEAPS]; ** Memory allocation. */ -static char * -memcheck(ptr) -char * const ptr; +static ATTRIBUTE_PURE void * +memcheck(void *const ptr) { if (ptr == NULL) { const char *e = strerror(errno); @@ -392,8 +365,8 @@ char * const ptr; return ptr; } -#define emalloc(size) memcheck(imalloc(size)) -#define erealloc(ptr, size) memcheck(irealloc((ptr), (size))) +#define emalloc(size) memcheck(malloc(size)) +#define erealloc(ptr, size) memcheck(realloc(ptr, size)) #define ecpyalloc(ptr) memcheck(icpyalloc(ptr)) #define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp))) @@ -402,11 +375,8 @@ char * const ptr; */ static void -eats(name, num, rname, rnum) -const char * const name; -const int num; -const char * const rname; -const int rnum; +eats(const char *const name, const int num, const char *const rname, + const int rnum) { filename = name; linenum = num; @@ -415,16 +385,13 @@ const int rnum; } static void -eat(name, num) -const char * const name; -const int num; +eat(const char *const name, const int num) { - eats(name, num, (char *) NULL, -1); + eats(name, num, NULL, -1); } static void -error(string) -const char * const string; +error(const char *const string) { /* ** Match the format of "cc" to allow sh users to @@ -441,15 +408,14 @@ const char * const string; } static void -warning(string) -const char * const string; +warning(const char *const string) { char * cp; cp = ecpyalloc(_("warning: ")); cp = ecatalloc(cp, string); error(cp); - ifree(cp); + free(cp); --errors; } @@ -472,9 +438,7 @@ static const char * leapsec; static const char * yitcommand; int -main(argc, argv) -int argc; -char * argv[]; +main(int argc, char **argv) { register int i; register int j; @@ -498,7 +462,7 @@ char * argv[]; } for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { - (void) printf("%s\n", elsieid); + (void) printf("%s\n", TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); @@ -571,8 +535,6 @@ _("%s: More than one -L option specified\n"), if (yitcommand == NULL) yitcommand = "yearistype"; - setboundaries(); - if (optind < argc && leapsec != NULL) { infile(leapsec); adjleap(); @@ -615,9 +577,7 @@ _("%s: More than one -L option specified\n"), } static void -dolink(fromfield, tofield) -const char * const fromfield; -const char * const tofield; +dolink(const char *const fromfield, const char *const tofield) { register char * fromname; register char * toname; @@ -667,7 +627,7 @@ const char * const tofield; toname); if (result == 0) warning(_("hard link failed, symbolic link used")); - ifree(symlinkcontents); + free(symlinkcontents); } #endif /* HAVE_SYMLINK */ if (result != 0) { @@ -679,26 +639,17 @@ warning(_("hard link failed, symbolic link used")); exit(EXIT_FAILURE); } } - ifree(fromname); - ifree(toname); + free(fromname); + free(toname); } #define TIME_T_BITS_IN_FILE 64 -static void -setboundaries(void) -{ - register int i; - - min_time = -1; - for (i = 0; i < TIME_T_BITS_IN_FILE - 1; ++i) - min_time *= 2; - max_time = -(min_time + 1); -} +static const zic_t min_time = (zic_t) -1 << (TIME_T_BITS_IN_FILE - 1); +static const zic_t max_time = -1 - ((zic_t) -1 << (TIME_T_BITS_IN_FILE - 1)); static int -itsdir(name) -const char * const name; +itsdir(const char *const name) { register char * myname; register int accres; @@ -706,7 +657,7 @@ const char * const name; myname = ecpyalloc(name); myname = ecatalloc(myname, "/."); accres = access(myname, F_OK); - ifree(myname); + free(myname); return accres == 0; } @@ -719,9 +670,7 @@ const char * const name; */ static int -rcomp(cp1, cp2) -const void * cp1; -const void * cp2; +rcomp(const void *cp1, const void *cp2) { return strcmp(((const struct rule *) cp1)->r_name, ((const struct rule *) cp2)->r_name); @@ -736,8 +685,7 @@ associate(void) register int i, j; if (nrules != 0) { - (void) qsort((void *) rules, (size_t) nrules, - (size_t) sizeof *rules, rcomp); + (void) qsort(rules, nrules, sizeof *rules, rcomp); for (i = 0; i < nrules - 1; ++i) { if (strcmp(rules[i].r_name, rules[i + 1].r_name) != 0) @@ -804,8 +752,7 @@ associate(void) } static void -infile(name) -const char * name; +infile(const char *name) { register FILE * fp; register char ** fields; @@ -829,7 +776,7 @@ const char * name; wantcont = FALSE; for (num = 1; ; ++num) { eat(name, num); - if (fgets(buf, (int) sizeof buf, fp) != buf) + if (fgets(buf, sizeof buf, fp) != buf) break; cp = strchr(buf, '\n'); if (cp == NULL) { @@ -881,7 +828,7 @@ _("%s: panic: Invalid l_value %d\n"), exit(EXIT_FAILURE); } } - ifree((char *) fields); + free(fields); } if (ferror(fp)) { (void) fprintf(stderr, _("%s: Error reading %s\n"), @@ -908,10 +855,7 @@ _("%s: panic: Invalid l_value %d\n"), */ static long -gethms(string, errstring, signable) -const char * string; -const char * const errstring; -const int signable; +gethms(const char *string, const char *const errstring, const int signable) { long hh; int mm, ss, sign; @@ -953,9 +897,7 @@ warning(_("values over 24 hours not handled by pre-2007 versions of zic")); } static void -inrule(fields, nfields) -register char ** const fields; -const int nfields; +inrule(register char **const fields, const int nfields) { static struct rule r; @@ -976,15 +918,12 @@ const int nfields; r.r_abbrvar = ecpyalloc(fields[RF_ABBRVAR]); if (max_abbrvar_len < strlen(r.r_abbrvar)) max_abbrvar_len = strlen(r.r_abbrvar); - rules = (struct rule *) (void *) erealloc((char *) rules, - (int) ((nrules + 1) * sizeof *rules)); + rules = erealloc(rules, (nrules + 1) * sizeof *rules); rules[nrules++] = r; } static int -inzone(fields, nfields) -register char ** const fields; -const int nfields; +inzone(register char **const fields, const int nfields) { register int i; static char * buf; @@ -994,7 +933,7 @@ const int nfields; return FALSE; } if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL) { - buf = erealloc(buf, (int) (132 + strlen(TZDEFAULT))); + buf = erealloc(buf, 132 + strlen(TZDEFAULT)); (void) sprintf(buf, _("\"Zone %s\" line and -l option are mutually exclusive"), TZDEFAULT); @@ -1002,7 +941,7 @@ _("\"Zone %s\" line and -l option are mutually exclusive"), return FALSE; } if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL) { - buf = erealloc(buf, (int) (132 + strlen(TZDEFRULES))); + buf = erealloc(buf, 132 + strlen(TZDEFRULES)); (void) sprintf(buf, _("\"Zone %s\" line and -p option are mutually exclusive"), TZDEFRULES); @@ -1012,9 +951,9 @@ _("\"Zone %s\" line and -p option are mutually exclusive"), for (i = 0; i < nzones; ++i) if (zones[i].z_name != NULL && strcmp(zones[i].z_name, fields[ZF_NAME]) == 0) { - buf = erealloc(buf, (int) (132 + - strlen(fields[ZF_NAME]) + - strlen(zones[i].z_filename))); + buf = erealloc(buf, + (132 + strlen(fields[ZF_NAME]) + + strlen(zones[i].z_filename))); (void) sprintf(buf, _("duplicate zone name %s (file \"%s\", line %d)"), fields[ZF_NAME], @@ -1027,9 +966,7 @@ _("duplicate zone name %s (file \"%s\", line %d)"), } static int -inzcont(fields, nfields) -register char ** const fields; -const int nfields; +inzcont(register char **const fields, const int nfields) { if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS) { error(_("wrong number of fields on Zone continuation line")); @@ -1039,10 +976,7 @@ const int nfields; } static int -inzsub(fields, nfields, iscont) -register char ** const fields; -const int nfields; -const int iscont; +inzsub(register char **const fields, const int nfields, const int iscont) { register char * cp; static struct zone z; @@ -1109,8 +1043,7 @@ const int iscont; return FALSE; } } - zones = (struct zone *) (void *) erealloc((char *) zones, - (int) ((nzones + 1) * sizeof *zones)); + zones = erealloc(zones, (nzones + 1) * sizeof *zones); zones[nzones++] = z; /* ** If there was an UNTIL field on this line, @@ -1120,9 +1053,7 @@ const int iscont; } static void -inleap(fields, nfields) -register char ** const fields; -const int nfields; +inleap(register char ** const fields, const int nfields) { register const char * cp; register const struct lookup * lp; @@ -1224,9 +1155,7 @@ const int nfields; } static void -inlink(fields, nfields) -register char ** const fields; -const int nfields; +inlink(register char **const fields, const int nfields) { struct link l; @@ -1246,20 +1175,18 @@ const int nfields; l.l_linenum = linenum; l.l_from = ecpyalloc(fields[LF_FROM]); l.l_to = ecpyalloc(fields[LF_TO]); - links = (struct link *) (void *) erealloc((char *) links, - (int) ((nlinks + 1) * sizeof *links)); + links = erealloc(links, (nlinks + 1) * sizeof *links); links[nlinks++] = l; } static void -rulesub(rp, loyearp, hiyearp, typep, monthp, dayp, timep) -register struct rule * const rp; -const char * const loyearp; -const char * const hiyearp; -const char * const typep; -const char * const monthp; -const char * const dayp; -const char * const timep; +rulesub(register struct rule *const rp, + const char *const loyearp, + const char *const hiyearp, + const char *const typep, + const char *const monthp, + const char *const dayp, + const char *const timep) { register const struct lookup * lp; register const char * cp; @@ -1297,7 +1224,7 @@ const char * const timep; } } rp->r_tod = gethms(dp, _("invalid time of day"), FALSE); - ifree(dp); + free(dp); /* ** Year work. */ @@ -1381,12 +1308,12 @@ const char * const timep; *ep++ = 0; if (*ep++ != '=') { error(_("invalid day of month")); - ifree(dp); + free(dp); return; } if ((lp = byword(dp, wday_names)) == NULL) { error(_("invalid weekday name")); - ifree(dp); + free(dp); return; } rp->r_wday = lp->l_value; @@ -1395,63 +1322,55 @@ const char * const timep; rp->r_dayofmonth <= 0 || (rp->r_dayofmonth > len_months[1][rp->r_month])) { error(_("invalid day of month")); - ifree(dp); + free(dp); return; } } - ifree(dp); + free(dp); } static void -convert(val, buf) -const long val; -char * const buf; +convert(const long val, char *const buf) { register int i; register int shift; + unsigned char *const b = (unsigned char *) buf; for (i = 0, shift = 24; i < 4; ++i, shift -= 8) - buf[i] = val >> shift; + b[i] = val >> shift; } static void -convert64(val, buf) -const zic_t val; -char * const buf; +convert64(const zic_t val, char *const buf) { register int i; register int shift; + unsigned char *const b = (unsigned char *) buf; for (i = 0, shift = 56; i < 8; ++i, shift -= 8) - buf[i] = val >> shift; + b[i] = val >> shift; } static void -puttzcode(val, fp) -const long val; -FILE * const fp; +puttzcode(const long val, FILE *const fp) { char buf[4]; convert(val, buf); - (void) fwrite((void *) buf, (size_t) sizeof buf, (size_t) 1, fp); + (void) fwrite(buf, sizeof buf, 1, fp); } static void -puttzcode64(val, fp) -const zic_t val; -FILE * const fp; +puttzcode64(const zic_t val, FILE *const fp) { char buf[8]; convert64(val, buf); - (void) fwrite((void *) buf, (size_t) sizeof buf, (size_t) 1, fp); + (void) fwrite(buf, sizeof buf, 1, fp); } static int -atcomp(avp, bvp) -const void * avp; -const void * bvp; +atcomp(const void *avp, const void *bvp) { const zic_t a = ((const struct attype *) avp)->at; const zic_t b = ((const struct attype *) bvp)->at; @@ -1460,16 +1379,13 @@ const void * bvp; } static int -is32(x) -const zic_t x; +is32(const zic_t x) { return INT32_MIN <= x && x <= INT32_MAX; } static void -writezone(name, string) -const char * const name; -const char * const string; +writezone(const char *const name, const char *const string) { register FILE * fp; register int i, j; @@ -1486,8 +1402,7 @@ const char * const string; ** Sort. */ if (timecnt > 1) - (void) qsort((void *) attypes, (size_t) timecnt, - (size_t) sizeof *attypes, atcomp); + (void) qsort(attypes, timecnt, sizeof *attypes, atcomp); /* ** Optimize. */ @@ -1555,7 +1470,7 @@ const char * const string; ++leapi32; } fullname = erealloc(fullname, - (int) (strlen(directory) + 1 + strlen(name) + 1)); + strlen(directory) + 1 + strlen(name) + 1); (void) sprintf(fullname, "%s/%s", directory, name); /* ** Remove old file, if any, to snap links. @@ -1692,8 +1607,7 @@ const char * const string; } indmap[abbrinds[i]] = j; } -#define DO(field) (void) fwrite((void *) tzh.field, \ - (size_t) sizeof tzh.field, (size_t) 1, fp) +#define DO(field) ((void) fwrite(tzh.field, sizeof tzh.field, 1, fp)) tzh = tzh0; (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); tzh.tzh_version[0] = ZIC_VERSION; @@ -1721,10 +1635,7 @@ const char * const string; unsigned char uc; uc = typemap[types[i]]; - (void) fwrite((void *) &uc, - (size_t) sizeof uc, - (size_t) 1, - fp); + (void) fwrite(&uc, sizeof uc, 1, fp); } for (i = 0; i < typecnt; ++i) if (writetype[i]) { @@ -1733,9 +1644,8 @@ const char * const string; (void) putc((unsigned char) indmap[abbrinds[i]], fp); } if (thischarcnt != 0) - (void) fwrite((void *) thischars, - (size_t) sizeof thischars[0], - (size_t) thischarcnt, fp); + (void) fwrite(thischars, sizeof thischars[0], + thischarcnt, fp); for (i = thisleapi; i < thisleaplim; ++i) { register zic_t todo; @@ -1757,7 +1667,7 @@ const char * const string; todo = tadd(trans[i], -gmtoffs[j]); } else todo = trans[i]; if (pass == 1) - puttzcode((long) todo, fp); + puttzcode(todo, fp); else puttzcode64(todo, fp); puttzcode(corr[i], fp); } @@ -1777,12 +1687,8 @@ const char * const string; } static void -doabbr(abbr, format, letters, isdst, doquotes) -char * const abbr; -const char * const format; -const char * const letters; -const int isdst; -const int doquotes; +doabbr(char *const abbr, const char *const format, const char *const letters, + const int isdst, const int doquotes) { register char * cp; register char * slashp; @@ -1797,8 +1703,7 @@ const int doquotes; (void) strcpy(abbr, slashp + 1); } else { if (slashp > format) - (void) strncpy(abbr, format, - (unsigned) (slashp - format)); + (void) strncpy(abbr, format, slashp - format); abbr[slashp - format] = '\0'; } if (!doquotes) @@ -1818,8 +1723,7 @@ const int doquotes; } static void -updateminmax(x) -const int x; +updateminmax(const int x) { if (min_year > x) min_year = x; @@ -1828,9 +1732,7 @@ const int x; } static int -stringoffset(result, offset) -char * result; -long offset; +stringoffset(char *result, long offset) { register int hours; register int minutes; @@ -1860,11 +1762,8 @@ long offset; } static int -stringrule(result, rp, dstoff, gmtoff) -char * result; -const struct rule * const rp; -const long dstoff; -const long gmtoff; +stringrule(char *result, const struct rule *const rp, const long dstoff, + const long gmtoff) { register long tod; @@ -1915,10 +1814,7 @@ const long gmtoff; } static void -stringzone(result, zpfirst, zonecount) -char * result; -const struct zone * const zpfirst; -const int zonecount; +stringzone(char *result, const struct zone *const zpfirst, const int zonecount) { register const struct zone * zp; register struct rule * rp; @@ -1998,9 +1894,7 @@ const int zonecount; } static void -outzone(zpfirst, zonecount) -const struct zone * const zpfirst; -const int zonecount; +outzone(const struct zone * const zpfirst, const int zonecount) { register const struct zone * zp; register struct rule * rp; @@ -2071,7 +1965,7 @@ wp = ecpyalloc(_("no POSIX environment variable for zone")); wp = ecatalloc(wp, " "); wp = ecatalloc(wp, zpfirst->z_name); warning(wp); - ifree(wp); + free(wp); } if (envvar[0] == '\0') { if (min_year >= INT_MIN + YEARSPERREPEAT) @@ -2116,7 +2010,7 @@ wp = ecpyalloc(_("no POSIX environment variable for zone")); if (zp->z_nrules == 0) { stdoff = zp->z_stdoff; doabbr(startbuf, zp->z_format, - (char *) NULL, stdoff != 0, FALSE); + NULL, stdoff != 0, FALSE); type = addtype(oadd(zp->z_gmtoff, stdoff), startbuf, stdoff != 0, startttisstd, startttisgmt); @@ -2255,15 +2149,13 @@ error(_("can't determine time zone abbreviation to use just after until time")); } } writezone(zpfirst->z_name, envvar); - ifree(startbuf); - ifree(ab); - ifree(envvar); + free(startbuf); + free(ab); + free(envvar); } static void -addtt(starttime, type) -const zic_t starttime; -int type; +addtt(const zic_t starttime, int type) { if (starttime <= min_time || (timecnt == 1 && attypes[0].at < min_time)) { @@ -2289,12 +2181,8 @@ int type; } static int -addtype(gmtoff, abbr, isdst, ttisstd, ttisgmt) -const long gmtoff; -const char * const abbr; -const int isdst; -const int ttisstd; -const int ttisgmt; +addtype(const long gmtoff, const char *const abbr, const int isdst, + const int ttisstd, const int ttisgmt) { register int i, j; @@ -2349,11 +2237,7 @@ const int ttisgmt; } static void -leapadd(t, positive, rolling, count) -const zic_t t; -const int positive; -const int rolling; -int count; +leapadd(const zic_t t, const int positive, const int rolling, int count) { register int i, j; @@ -2398,16 +2282,14 @@ adjleap(void) } static int -yearistype(year, type) -const int year; -const char * const type; +yearistype(const int year, const char *const type) { static char * buf; int result; if (type == NULL || *type == '\0') return TRUE; - buf = erealloc(buf, (int) (132 + strlen(yitcommand) + strlen(type))); + buf = erealloc(buf, 132 + strlen(yitcommand) + strlen(type)); (void) sprintf(buf, "%s %d %s", yitcommand, year, type); result = system(buf); if (WIFEXITED(result)) switch (WEXITSTATUS(result)) { @@ -2424,17 +2306,15 @@ const char * const type; } static int -lowerit(a) -int a; +lowerit(int a) { a = (unsigned char) a; return (isascii(a) && isupper(a)) ? tolower(a) : a; } -static int -ciequal(ap, bp) /* case-insensitive equality */ -register const char * ap; -register const char * bp; +/* case-insensitive equality */ +static ATTRIBUTE_PURE int +ciequal(register const char *ap, register const char *bp) { while (lowerit(*ap) == lowerit(*bp++)) if (*ap++ == '\0') @@ -2442,10 +2322,8 @@ register const char * bp; return FALSE; } -static int -itsabbr(abbr, word) -register const char * abbr; -register const char * word; +static ATTRIBUTE_PURE int +itsabbr(register const char *abbr, register const char *word) { if (lowerit(*abbr) != lowerit(*word)) return FALSE; @@ -2458,10 +2336,9 @@ register const char * word; return TRUE; } -static const struct lookup * -byword(word, table) -register const char * const word; -register const struct lookup * const table; +static ATTRIBUTE_PURE const struct lookup * +byword(register const char *const word, + register const struct lookup *const table) { register const struct lookup * foundlp; register const struct lookup * lp; @@ -2488,8 +2365,7 @@ register const struct lookup * const table; } static char ** -getfields(cp) -register char * cp; +getfields(register char *cp) { register char * dp; register char ** array; @@ -2497,8 +2373,7 @@ register char * cp; if (cp == NULL) return NULL; - array = (char **) (void *) - emalloc((int) ((strlen(cp) + 1) * sizeof *array)); + array = emalloc((strlen(cp) + 1) * sizeof *array); nsubs = 0; for ( ; ; ) { while (isascii((unsigned char) *cp) && @@ -2529,38 +2404,28 @@ register char * cp; return array; } -static long -oadd(t1, t2) -const long t1; -const long t2; +static ATTRIBUTE_PURE long +oadd(const long t1, const long t2) { - register long t; - - t = t1 + t2; - if ((t2 > 0 && t <= t1) || (t2 < 0 && t >= t1)) { + if (t1 < 0 ? t2 < LONG_MIN - t1 : LONG_MAX - t1 < t2) { error(_("time overflow")); exit(EXIT_FAILURE); } - return t; + return t1 + t2; } -static zic_t -tadd(t1, t2) -const zic_t t1; -const long t2; +static ATTRIBUTE_PURE zic_t +tadd(const zic_t t1, const long t2) { - register zic_t t; - if (t1 == max_time && t2 > 0) return max_time; if (t1 == min_time && t2 < 0) return min_time; - t = t1 + t2; - if ((t2 > 0 && t <= t1) || (t2 < 0 && t >= t1)) { + if (t1 < 0 ? t2 < min_time - t1 : max_time - t1 < t2) { error(_("time overflow")); exit(EXIT_FAILURE); } - return t; + return t1 + t2; } /* @@ -2569,9 +2434,7 @@ const long t2; */ static zic_t -rpytime(rp, wantedy) -register const struct rule * const rp; -register const int wantedy; +rpytime(register const struct rule *const rp, register const int wantedy) { register int y, m, i; register long dayoff; /* with a nod to Margaret O. */ @@ -2627,12 +2490,12 @@ register const int wantedy; } while (wday != eitol(rp->r_wday)) if (rp->r_dycode == DC_DOWGEQ) { - dayoff = oadd(dayoff, (long) 1); + dayoff = oadd(dayoff, 1); if (++wday >= LDAYSPERWEEK) wday = 0; ++i; } else { - dayoff = oadd(dayoff, (long) -1); + dayoff = oadd(dayoff, -1); if (--wday < 0) wday = LDAYSPERWEEK - 1; --i; @@ -2652,31 +2515,30 @@ will not work with pre-2004 versions of zic")); } static void -newabbr(string) -const char * const string; +newabbr(const char *const string) { register int i; if (strcmp(string, GRANDPARENTED) != 0) { register const char * cp; - register char * wp; + const char * mp; /* ** Want one to ZIC_MAX_ABBR_LEN_WO_WARN alphabetics ** optionally followed by a + or - and a number from 1 to 14. */ cp = string; - wp = NULL; + mp = NULL; while (isascii((unsigned char) *cp) && isalpha((unsigned char) *cp)) ++cp; if (cp - string == 0) -wp = _("time zone abbreviation lacks alphabetic at start"); +mp = _("time zone abbreviation lacks alphabetic at start"); if (noise && cp - string > 3) -wp = _("time zone abbreviation has more than 3 alphabetics"); +mp = _("time zone abbreviation has more than 3 alphabetics"); if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN) -wp = _("time zone abbreviation has too many alphabetics"); - if (wp == NULL && (*cp == '+' || *cp == '-')) { +mp = _("time zone abbreviation has too many alphabetics"); + if (mp == NULL && (*cp == '+' || *cp == '-')) { ++cp; if (isascii((unsigned char) *cp) && isdigit((unsigned char) *cp)) @@ -2685,14 +2547,14 @@ wp = _("time zone abbreviation has too many alphabetics"); ++cp; } if (*cp != '\0') -wp = _("time zone abbreviation differs from POSIX standard"); - if (wp != NULL) { - wp = ecpyalloc(wp); +mp = _("time zone abbreviation differs from POSIX standard"); + if (mp != NULL) { + char *wp = ecpyalloc(mp); wp = ecatalloc(wp, " ("); wp = ecatalloc(wp, string); wp = ecatalloc(wp, ")"); warning(wp); - ifree(wp); + free(wp); } } i = strlen(string) + 1; @@ -2705,8 +2567,7 @@ wp = _("time zone abbreviation differs from POSIX standard"); } static int -mkdirs(argname) -char * argname; +mkdirs(char *argname) { register char * name; register char * cp; @@ -2740,20 +2601,19 @@ char * argname; (void) fprintf(stderr, _("%s: Can't create directory %s: %s\n"), progname, name, e); - ifree(name); + free(name); return -1; } } } *cp = '/'; } - ifree(name); + free(name); return 0; } -static long -eitol(i) -const int i; +static ATTRIBUTE_PURE long +eitol(const int i) { long l; |