Browse files

Assume C89.

* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better.  Mostly this consists of using function
prototypes.  In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition.  But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
  • Loading branch information...
1 parent 66f0c30 commit 400ecf36bb0b73f6390f9641e6cb8bbfb91a5cfd @eggert committed Oct 12, 2012
Showing with 283 additions and 574 deletions.
  1. +12 −4 Makefile
  2. +2 −5 asctime.c
  3. +26 −40 date.c
  4. +1 −3 difftime.c
  5. +4 −52 ialloc.c
  6. +67 −134 localtime.c
  7. +6 −5 private.h
  8. +4 −6 scheck.c
  9. +11 −29 strftime.c
  10. +20 −27 zdump.c
  11. +130 −269 zic.c
View
16 Makefile
@@ -118,10 +118,18 @@ LDLIBS=
# -DZIC_MAX_ABBR_LEN_WO_WARN=3
# (or some other number) to set the maximum time zone abbreviation length
# that zic will accept without a warning (the default is 6)
-GCC_DEBUG_FLAGS = -Dlint -g -O3 -fno-common \
- -Wall -Wcast-qual -Wconversion -Wmissing-prototypes \
- -Wnested-externs -Wpointer-arith -Wshadow \
- -Wtraditional # -Wstrict-prototypes -Wwrite-strings
+GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \
+ -Wall -Wextra \
+ -Wbad-function-cast -Wcast-align -Wcast-qual \
+ -Wformat=2 -Winit-self \
+ -Wmissing-declarations -Wmissing-noreturn -Wmissing-prototypes \
+ -Wnested-externs \
+ -Wno-format-nonliteral -Wno-sign-compare -Wno-sign-conversion \
+ -Wno-type-limits \
+ -Wno-unused-parameter -Woverlength-strings -Wpointer-arith \
+ -Wshadow -Wstrict-prototypes -Wsuggest-attribute=const \
+ -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines \
+ -Wwrite-strings
#
# If you want to use System V compatibility code, add
# -DUSG_COMPAT
View
7 asctime.c
@@ -69,9 +69,7 @@ static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
*/
char *
-asctime_r(timeptr, buf)
-register const struct tm * timeptr;
-char * buf;
+asctime_r(register const struct tm *timeptr, char *buf)
{
static const char wday_name[][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
@@ -128,8 +126,7 @@ char * buf;
*/
char *
-asctime(timeptr)
-register const struct tm * timeptr;
+asctime(register const struct tm *timeptr)
{
return asctime_r(timeptr, buf_asctime);
}
View
66 date.c
@@ -83,9 +83,7 @@ static void wildinput(const char *, const char *,
const char *);
int
-main(argc, argv)
-const int argc;
-char * argv[];
+main(const int argc, char *argv[])
{
register const char * format;
register const char * value;
@@ -246,11 +244,11 @@ _("date: error: multiple values in command line\n"));
tv.tv_sec = (int) adjust;
tv.tv_usec = (int) ((adjust - tv.tv_sec) * 1000000L);
- if (adjtime(&tv, (struct timeval *) NULL) != 0)
+ if (adjtime(&tv, NULL) != 0)
oops("adjtime");
#endif /* HAVE_ADJTIME */
#if !HAVE_ADJTIME
- reset((time_t) (now + adjust), nflag);
+ reset(now + adjust, nflag);
#endif /* !HAVE_ADJTIME */
/*
** Sun silently ignores everything else; we follow suit.
@@ -262,13 +260,13 @@ _("date: error: multiple values in command line\n"));
struct timezone tz;
if (!dflag || !tflag)
- if (gettimeofday((struct timeval *) NULL, &tz) != 0)
+ if (gettimeofday(NULL, &tz) != 0)
oops("gettimeofday");
if (dflag)
tz.tz_dsttime = dsttime;
if (tflag)
tz.tz_minuteswest = minuteswest;
- if (settimeofday((struct timeval *) NULL, &tz) != 0)
+ if (settimeofday(NULL, &tz) != 0)
oops("settimeofday");
#endif /* HAVE_SETTIMEOFDAY == 2 */
#if HAVE_SETTIMEOFDAY != 2
@@ -314,7 +312,7 @@ dogmt(void)
for (n = 0; environ[n] != NULL; ++n)
continue;
- fakeenv = (char **) malloc((size_t) (n + 2) * sizeof *fakeenv);
+ fakeenv = malloc((n + 2) * sizeof *fakeenv);
if (fakeenv == NULL) {
(void) perror(_("Memory exhausted"));
errensure();
@@ -445,9 +443,7 @@ extern int logwtmp();
/*ARGSUSED*/
#endif /* !defined TSP_SETDATE */
static void
-reset(newt, nflag)
-const time_t newt;
-const int nflag;
+reset(const time_t newt, const int nflag)
{
register const char * username;
static struct timeval tv; /* static so tv_usec is 0 */
@@ -467,7 +463,7 @@ const int nflag;
** "old" entry is always written, for compatibility.
*/
logwtmp("|", TIME_NAME, "");
- if (settimeofday(&tv, (struct timezone *) NULL) == 0) {
+ if (settimeofday(&tv, NULL) == 0) {
logwtmp("{", TIME_NAME, ""); /* } */
syslog(LOG_AUTH | LOG_NOTICE, _("date set by %s"),
username);
@@ -478,10 +474,8 @@ const int nflag;
#endif /* !defined OLD_TIME */
static void
-wildinput(item, value, reason)
-const char * const item;
-const char * const value;
-const char * const reason;
+wildinput(const char *const item, const char *const value,
+ const char *const reason)
{
(void) fprintf(stderr,
_("date: error: bad command line %s \"%s\", %s\n"),
@@ -497,8 +491,7 @@ errensure(void)
}
static const char *
-nondigit(cp)
-register const char * cp;
+nondigit(register const char *cp)
{
while (is_digit(*cp))
++cp;
@@ -515,21 +508,19 @@ usage(void)
}
static void
-oops(string)
-const char * const string;
+oops(const char *const string)
{
int e = errno;
(void) fprintf(stderr, _("date: error: "));
errno = e;
(void) perror(string);
errensure();
- display((char *) NULL);
+ display(NULL);
}
static void
-display(format)
-const char * const format;
+display(const char *const format)
{
struct tm tm;
time_t now;
@@ -553,10 +544,7 @@ extern size_t strftime();
#define INCR 1024
static void
-timeout(fp, format, tmp)
-FILE * const fp;
-const char * const format;
-const struct tm * const tmp;
+timeout(FILE *const fp, const char *const format, const struct tm *const tmp)
{
char * cp;
size_t result;
@@ -565,7 +553,7 @@ const struct tm * const tmp;
if (*format == '\0')
return;
size = INCR;
- cp = malloc((size_t) size);
+ cp = malloc(size);
for ( ; ; ) {
if (cp == NULL) {
(void) fprintf(stderr,
@@ -578,16 +566,15 @@ const struct tm * const tmp;
if (result != 0 || cp[0] == '\0')
break;
size += INCR;
- cp = realloc(cp, (size_t) size);
+ cp = realloc(cp, size);
}
(void) fwrite(cp, 1, result, fp);
free(cp);
}
static int
-sametm(atmp, btmp)
-register const struct tm * const atmp;
-register const struct tm * const btmp;
+sametm(register const struct tm *const atmp,
+ register const struct tm *const btmp)
{
return atmp->tm_year == btmp->tm_year &&
atmp->tm_mon == btmp->tm_mon &&
@@ -813,8 +800,7 @@ iffy(const time_t thist, const time_t thatt,
* notifies the master that a correction is needed.
* Returns 1 on success, 0 on failure.
*/
-netsettime(ntv)
- struct timeval ntv;
+netsettime(struct timeval ntv)
{
int s, length, port, timed_ack, found, err;
long waittime;
@@ -833,7 +819,7 @@ netsettime(ntv)
}
dest.sin_port = sp->s_port;
dest.sin_family = AF_INET;
- dest.sin_addr.s_addr = htonl((u_long)INADDR_ANY);
+ dest.sin_addr.s_addr = htonl(INADDR_ANY);
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
if (errno != EPROTONOSUPPORT)
@@ -843,7 +829,7 @@ netsettime(ntv)
bzero((char *)&sin, sizeof (sin));
sin.sin_family = AF_INET;
for (port = IPPORT_RESERVED - 1; port > IPPORT_RESERVED / 2; port--) {
- sin.sin_port = htons((u_short)port);
+ sin.sin_port = htons(port);
if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0)
break;
if (errno != EADDRINUSE) {
@@ -863,9 +849,9 @@ netsettime(ntv)
goto bad;
}
(void) strncpy(msg.tsp_name, hostname, sizeof (hostname));
- msg.tsp_seq = htons((u_short)0);
- msg.tsp_time.tv_sec = htonl((u_long)ntv.tv_sec);
- msg.tsp_time.tv_usec = htonl((u_long)ntv.tv_usec);
+ msg.tsp_seq = htons(0);
+ msg.tsp_time.tv_sec = htonl(ntv.tv_sec);
+ msg.tsp_time.tv_usec = htonl(ntv.tv_usec);
length = sizeof (struct sockaddr_in);
if (connect(s, &dest, length) < 0) {
perror("date: connect");
@@ -883,7 +869,7 @@ netsettime(ntv)
tout.tv_usec = 0;
FD_ZERO(&ready);
FD_SET(s, &ready);
- found = select(FD_SETSIZE, &ready, (fd_set *)0, (fd_set *)0, &tout);
+ found = select(FD_SETSIZE, &ready, 0, 0, &tout);
length = sizeof err;
if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char *)&err, &length) == 0
&& err) {
View
4 difftime.c
@@ -8,9 +8,7 @@
#include "private.h" /* for time_t, TYPE_INTEGRAL, and TYPE_SIGNED */
double
-difftime(time1, time0)
-const time_t time1;
-const time_t time0;
+difftime(const time_t time1, const time_t time0)
{
/*
** If (sizeof (double) > sizeof (time_t)) simply convert and subtract
View
56 ialloc.c
@@ -7,39 +7,8 @@
#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;
@@ -50,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);
}
View
201 localtime.c
@@ -133,8 +133,9 @@ struct rule {
static long detzcode(const char * codep);
static time_t detzcode64(const char * codep);
static int differ_by_repeat(time_t t1, time_t t0);
-static const char * getzname(const char * strp);
-static const char * getqzname(const char * strp, const int delim);
+static const char * getzname(const char * strp) ATTRIBUTE_PURE;
+static const char * getqzname(const char * strp, const int delim)
+ ATTRIBUTE_PURE;
static const char * getnum(const char * strp, int * nump, int min,
int max);
static const char * getsecs(const char * strp, long * secsp);
@@ -146,7 +147,7 @@ static struct tm * gmtsub(const time_t * timep, long offset,
static struct tm * localsub(const time_t * timep, long offset,
struct tm * tmp);
static int increment_overflow(int * number, int delta);
-static int leaps_thru_end_of(int y);
+static int leaps_thru_end_of(int y) ATTRIBUTE_PURE;
static int long_increment_overflow(long * number, int delta);
static int long_normalize_overflow(long * tensptr,
int * unitsptr, int base);
@@ -170,7 +171,8 @@ static struct tm * timesub(const time_t * timep, long offset,
static int tmcomp(const struct tm * atmp,
const struct tm * btmp);
static time_t transtime(time_t janfirst, int year,
- const struct rule * rulep, long offset);
+ const struct rule * rulep, long offset)
+ ATTRIBUTE_PURE;
static int typesequiv(const struct state * sp, int a, int b);
static int tzload(const char * name, struct state * sp,
int doextend);
@@ -222,8 +224,7 @@ time_t altzone = 0;
#endif /* defined ALTZONE */
static long
-detzcode(codep)
-const char * const codep;
+detzcode(const char *const codep)
{
register long result;
register int i;
@@ -235,8 +236,7 @@ const char * const codep;
}
static time_t
-detzcode64(codep)
-const char * const codep;
+detzcode64(const char *const codep)
{
register time_t result;
register int i;
@@ -310,9 +310,7 @@ settzname(void)
}
static int
-differ_by_repeat(t1, t0)
-const time_t t1;
-const time_t t0;
+differ_by_repeat(const time_t t1, const time_t t0)
{
if (TYPE_INTEGRAL(time_t) &&
TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
@@ -321,10 +319,8 @@ const time_t t0;
}
static int
-tzload(name, sp, doextend)
-register const char * name;
-register struct state * const sp;
-register const int doextend;
+tzload(register const char *name, register struct state *const sp,
+ register const int doextend)
{
register const char * p;
register int i;
@@ -571,21 +567,18 @@ register const int doextend;
}
}
#ifdef ALL_STATE
- (void) free((void *) up);
+ free(up);
#endif /* defined ALL_STATE */
return 0;
oops:
#ifdef ALL_STATE
- (void) free((void *) up);
+ free(up);
#endif /* defined ALL_STATE */
return -1;
}
static int
-typesequiv(sp, a, b)
-const struct state * const sp;
-const int a;
-const int b;
+typesequiv(const struct state *const sp, const int a, const int b)
{
register int result;
@@ -622,8 +615,7 @@ static const int year_lengths[2] = {
*/
static const char *
-getzname(strp)
-register const char * strp;
+getzname(register const char *strp)
{
register char c;
@@ -660,11 +652,7 @@ getqzname(register const char *strp, const int delim)
*/
static const char *
-getnum(strp, nump, min, max)
-register const char * strp;
-int * const nump;
-const int min;
-const int max;
+getnum(register const char *strp, int *const nump, const int min, const int max)
{
register char c;
register int num;
@@ -693,9 +681,7 @@ const int max;
*/
static const char *
-getsecs(strp, secsp)
-register const char * strp;
-long * const secsp;
+getsecs(register const char *strp, long *const secsp)
{
int num;
@@ -735,9 +721,7 @@ long * const secsp;
*/
static const char *
-getoffset(strp, offsetp)
-register const char * strp;
-long * const offsetp;
+getoffset(register const char *strp, long *const offsetp)
{
register int neg = 0;
@@ -762,9 +746,7 @@ long * const offsetp;
*/
static const char *
-getrule(strp, rulep)
-const char * strp;
-register struct rule * const rulep;
+getrule(const char *strp, register struct rule *const rulep)
{
if (*strp == 'J') {
/*
@@ -816,11 +798,8 @@ register struct rule * const rulep;
*/
static time_t
-transtime(janfirst, year, rulep, offset)
-const time_t janfirst;
-const int year;
-register const struct rule * const rulep;
-const long offset;
+transtime(const time_t janfirst, const int year,
+ register const struct rule *const rulep, const long offset)
{
register int leapyear;
register time_t value;
@@ -911,10 +890,8 @@ const long offset;
*/
static int
-tzparse(name, sp, lastditch)
-const char * name;
-register struct state * const sp;
-const int lastditch;
+tzparse(const char *name, register struct state *const sp,
+ const int lastditch)
{
const char * stdname;
const char * dstname;
@@ -1149,8 +1126,7 @@ const int lastditch;
}
static void
-gmtload(sp)
-struct state * const sp;
+gmtload(struct state *const sp)
{
if (tzload(gmt, sp, TRUE) != 0)
(void) tzparse(gmt, sp, TRUE);
@@ -1172,14 +1148,14 @@ tzsetwall(void)
#ifdef ALL_STATE
if (lclptr == NULL) {
- lclptr = (struct state *) calloc(1, sizeof *lclptr);
+ lclptr = calloc(1, sizeof *lclptr);
if (lclptr == NULL) {
settzname(); /* all we can do */
return;
}
}
#endif /* defined ALL_STATE */
- if (tzload((char *) NULL, lclptr, TRUE) != 0)
+ if (tzload(NULL, lclptr, TRUE) != 0)
gmtload(lclptr);
settzname();
}
@@ -1203,7 +1179,7 @@ tzset(void)
#ifdef ALL_STATE
if (lclptr == NULL) {
- lclptr = (struct state *) calloc(1, sizeof *lclptr);
+ lclptr = calloc(1, sizeof *lclptr);
if (lclptr == NULL) {
settzname(); /* all we can do */
return;
@@ -1238,10 +1214,7 @@ tzset(void)
/*ARGSUSED*/
static struct tm *
-localsub(timep, offset, tmp)
-const time_t * const timep;
-const long offset;
-struct tm * const tmp;
+localsub(const time_t *const timep, const long offset, struct tm *const tmp)
{
register struct state * sp;
register const struct ttinfo * ttisp;
@@ -1330,8 +1303,7 @@ struct tm * const tmp;
}
struct tm *
-localtime(timep)
-const time_t * const timep;
+localtime(const time_t *const timep)
{
tzset();
return localsub(timep, 0L, &tm);
@@ -1342,9 +1314,7 @@ const time_t * const timep;
*/
struct tm *
-localtime_r(timep, tmp)
-const time_t * const timep;
-struct tm * tmp;
+localtime_r(const time_t *const timep, struct tm *tmp)
{
return localsub(timep, 0L, tmp);
}
@@ -1354,17 +1324,14 @@ struct tm * tmp;
*/
static struct tm *
-gmtsub(timep, offset, tmp)
-const time_t * const timep;
-const long offset;
-struct tm * const tmp;
+gmtsub(const time_t *const timep, const long offset, struct tm *const tmp)
{
register struct tm * result;
if (!gmt_is_set) {
gmt_is_set = TRUE;
#ifdef ALL_STATE
- gmtptr = (struct state *) calloc(1, sizeof *gmtptr);
+ gmtptr = calloc(1, sizeof *gmtptr);
if (gmtptr != NULL)
#endif /* defined ALL_STATE */
gmtload(gmtptr);
@@ -1393,8 +1360,7 @@ struct tm * const tmp;
}
struct tm *
-gmtime(timep)
-const time_t * const timep;
+gmtime(const time_t *const timep)
{
return gmtsub(timep, 0L, &tm);
}
@@ -1404,19 +1370,15 @@ const time_t * const timep;
*/
struct tm *
-gmtime_r(timep, tmp)
-const time_t * const timep;
-struct tm * tmp;
+gmtime_r(const time_t *const timep, struct tm *tmp)
{
return gmtsub(timep, 0L, tmp);
}
#ifdef STD_INSPIRED
struct tm *
-offtime(timep, offset)
-const time_t * const timep;
-const long offset;
+offtime(const time_t *const timep, const long offset)
{
return gmtsub(timep, offset, &tm);
}
@@ -1429,19 +1391,16 @@ const long offset;
*/
static int
-leaps_thru_end_of(y)
-register const int y;
+leaps_thru_end_of(register const int y)
{
return (y >= 0) ? (y / 4 - y / 100 + y / 400) :
-(leaps_thru_end_of(-(y + 1)) + 1);
}
static struct tm *
-timesub(timep, offset, sp, tmp)
-const time_t * const timep;
-const long offset;
-register const struct state * const sp;
-register struct tm * const tmp;
+timesub(const time_t *const timep, const long offset,
+ register const struct state *const sp,
+ register struct tm *const tmp)
{
register const struct lsinfo * lp;
register time_t tdays;
@@ -1571,8 +1530,7 @@ register struct tm * const tmp;
}
char *
-ctime(timep)
-const time_t * const timep;
+ctime(const time_t *const timep)
{
/*
** Section 4.12.3.2 of X3.159-1989 requires that
@@ -1584,9 +1542,7 @@ const time_t * const timep;
}
char *
-ctime_r(timep, buf)
-const time_t * const timep;
-char * buf;
+ctime_r(const time_t *const timep, char *buf)
{
struct tm mytm;
@@ -1611,9 +1567,7 @@ char * buf;
*/
static int
-increment_overflow(ip, j)
-int * const ip;
-int j;
+increment_overflow(int *const ip, int j)
{
register int const i = *ip;
@@ -1630,9 +1584,7 @@ int j;
}
static int
-long_increment_overflow(lp, m)
-long * const lp;
-int const m;
+long_increment_overflow(long *const lp, int const m)
{
register long const l = *lp;
@@ -1643,10 +1595,7 @@ int const m;
}
static int
-normalize_overflow(tensptr, unitsptr, base)
-int * const tensptr;
-int * const unitsptr;
-const int base;
+normalize_overflow(int *const tensptr, int *const unitsptr, const int base)
{
register int tensdelta;
@@ -1658,10 +1607,7 @@ const int base;
}
static int
-long_normalize_overflow(tensptr, unitsptr, base)
-long * const tensptr;
-int * const unitsptr;
-const int base;
+long_normalize_overflow(long *const tensptr, int *const unitsptr, const int base)
{
register int tensdelta;
@@ -1673,9 +1619,8 @@ const int base;
}
static int
-tmcomp(atmp, btmp)
-register const struct tm * const atmp;
-register const struct tm * const btmp;
+tmcomp(register const struct tm *const atmp,
+ register const struct tm *const btmp)
{
register int result;
@@ -1689,12 +1634,11 @@ register const struct tm * const btmp;
}
static time_t
-time2sub(tmp, funcp, offset, okayp, do_norm_secs)
-struct tm * const tmp;
-struct tm * (* const funcp)(const time_t*, long, struct tm*);
-const long offset;
-int * const okayp;
-const int do_norm_secs;
+time2sub(struct tm *const tmp,
+ struct tm *(*const funcp)(const time_t *, long, struct tm *),
+ const long offset,
+ int *const okayp,
+ const int do_norm_secs)
{
register const struct state * sp;
register int dir;
@@ -1873,11 +1817,10 @@ const int do_norm_secs;
}
static time_t
-time2(tmp, funcp, offset, okayp)
-struct tm * const tmp;
-struct tm * (* const funcp)(const time_t*, long, struct tm*);
-const long offset;
-int * const okayp;
+time2(struct tm * const tmp,
+ struct tm * (*const funcp)(const time_t *, long, struct tm *),
+ const long offset,
+ int *const okayp)
{
time_t t;
@@ -1891,10 +1834,9 @@ int * const okayp;
}
static time_t
-time1(tmp, funcp, offset)
-struct tm * const tmp;
-struct tm * (* const funcp)(const time_t *, long, struct tm *);
-const long offset;
+time1(struct tm *const tmp,
+ struct tm *(*const funcp) (const time_t *, long, struct tm *),
+ const long offset)
{
register time_t t;
register const struct state * sp;
@@ -1968,8 +1910,7 @@ const long offset;
}
time_t
-mktime(tmp)
-struct tm * const tmp;
+mktime(struct tm *const tmp)
{
tzset();
return time1(tmp, localsub, 0L);
@@ -1978,27 +1919,23 @@ struct tm * const tmp;
#ifdef STD_INSPIRED
time_t
-timelocal(tmp)
-struct tm * const tmp;
+timelocal(struct tm *const tmp)
{
if (tmp != NULL)
tmp->tm_isdst = -1; /* in case it wasn't initialized */
return mktime(tmp);
}
time_t
-timegm(tmp)
-struct tm * const tmp;
+timegm(struct tm *const tmp)
{
if (tmp != NULL)
tmp->tm_isdst = 0;
return time1(tmp, gmtsub, 0L);
}
time_t
-timeoff(tmp, offset)
-struct tm * const tmp;
-const long offset;
+timeoff(struct tm *const tmp, const long offset)
{
if (tmp != NULL)
tmp->tm_isdst = 0;
@@ -2015,8 +1952,7 @@ const long offset;
*/
long
-gtime(tmp)
-struct tm * const tmp;
+gtime(struct tm *const tmp)
{
const time_t t = mktime(tmp);
@@ -2042,8 +1978,7 @@ struct tm * const tmp;
*/
static long
-leapcorr(timep)
-time_t * timep;
+leapcorr(time_t *timep)
{
register struct state * sp;
register struct lsinfo * lp;
@@ -2060,16 +1995,14 @@ time_t * timep;
}
time_t
-time2posix(t)
-time_t t;
+time2posix(time_t t)
{
tzset();
return t - leapcorr(&t);
}
time_t
-posix2time(t)
-time_t t;
+posix2time(time_t t)
{
time_t x;
time_t y;
View
11 private.h
@@ -144,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.
*/
@@ -162,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);
/*
View
10 scheck.c
@@ -8,9 +8,7 @@
#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;
@@ -22,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;
@@ -51,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;
}
View
40 strftime.c
@@ -114,11 +114,8 @@ extern char * tzname[];
#define IN_ALL 3
size_t
-strftime(s, maxsize, format, t)
-char * const s;
-const size_t maxsize;
-const char * const format;
-const struct tm * const t;
+strftime(char * const s, const size_t maxsize, const char *const format,
+ const struct tm *const t)
{
char * p;
int warn;
@@ -152,12 +149,8 @@ const struct tm * const t;
}
static char *
-_fmt(format, t, pt, ptlim, warnp)
-const char * format;
-const struct tm * const t;
-char * pt;
-const char * const ptlim;
-int * warnp;
+_fmt(const char *format, const struct tm *const t, char * pt,
+ const char *const ptlim, int *warnp)
{
for ( ; *format; ++format) {
if (*format == '%') {
@@ -565,11 +558,8 @@ int * warnp;
}
static char *
-_conv(n, format, pt, ptlim)
-const int n;
-const char * const format;
-char * const pt;
-const char * const ptlim;
+_conv(const int n, const char *const format, char *const pt,
+ const char *const ptlim)
{
char buf[INT_STRLEN_MAXIMUM(int) + 1];
@@ -578,10 +568,7 @@ const char * const ptlim;
}
static char *
-_add(str, pt, ptlim)
-const char * str;
-char * pt;
-const char * const ptlim;
+_add(const char *str, char *pt, const char *const ptlim)
{
while (pt < ptlim && (*pt = *str++) != '\0')
++pt;
@@ -597,13 +584,8 @@ const char * const ptlim;
*/
static char *
-_yconv(a, b, convert_top, convert_yy, pt, ptlim)
-const int a;
-const int b;
-const int convert_top;
-const int convert_yy;
-char * pt;
-const char * const ptlim;
+_yconv(const int a, const int b, const int convert_top, const int convert_yy,
+ char *pt, const char *const ptlim)
{
register int lead;
register int trail;
@@ -654,7 +636,7 @@ _loc(void)
*/
if (localebuf.mon[0])
return &localebuf;
- name = setlocale(LC_TIME, (char *) NULL);
+ name = setlocale(LC_TIME, NULL);
if (name == NULL || *name == '\0')
goto no_locale;
/*
@@ -702,7 +684,7 @@ _loc(void)
(void) strcpy(lbuf, name);
p = lbuf + namesize;
plim = p + st.st_size;
- if (read(fd, p, (size_t) st.st_size) != st.st_size)
+ if (read(fd, p, st.st_size) != st.st_size)
goto bad_lbuf;
if (close(fd) != 0)
goto bad_lbuf;
View
47 zdump.c
@@ -119,6 +119,12 @@
#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.
@@ -152,20 +158,19 @@ 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 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 +203,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 +239,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 +250,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;
@@ -330,10 +329,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);
}
@@ -451,8 +449,7 @@ _("%s: use of -v on system with floating time_t other than float or double\n"),
}
static time_t
-yeartot(y)
-const long y;
+yeartot(const long y)
{
register long myy;
register long seconds;
@@ -530,9 +527,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 +581,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 +620,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"
View
399 zic.c
@@ -110,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);
@@ -131,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;
@@ -169,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;
@@ -377,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);
@@ -391,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)))
@@ -401,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;
@@ -414,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
@@ -440,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;
}
@@ -471,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;
@@ -570,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();
@@ -614,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;
@@ -666,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) {
@@ -678,34 +639,25 @@ 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;
myname = ecpyalloc(name);
myname = ecatalloc(myname, "/.");
accres = access(myname, F_OK);
- ifree(myname);
+ free(myname);
return accres == 0;
}
@@ -718,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);
@@ -735,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)
@@ -803,8 +752,7 @@ associate(void)
}
static void
-infile(name)
-const char * name;
+infile(const char *name)
{
register FILE * fp;
register char ** fields;
@@ -828,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) {
@@ -880,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"),
@@ -907,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;
@@ -952,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;
@@ -975,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;
@@ -993,15 +933,15 @@ 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);
error(buf);
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);
@@ -1011,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],
@@ -1026,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"));
@@ -1038,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;
@@ -1108,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,
@@ -1119,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;
@@ -1223,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;
@@ -1245,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;
@@ -1296,7 +1224,7 @@ const char * const timep;
}
}
rp->r_tod = gethms(dp, _("invalid time of day"), FALSE);
- ifree(dp);
+ free(dp);
/*
** Year work.
*/
@@ -1380,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;
@@ -1394,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;
@@ -1459,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;
@@ -1485,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.
*/
@@ -1554,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.
@@ -1691,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;
@@ -1720,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]) {
@@ -1732,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;
@@ -1756,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);
}
@@ -1776,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;
@@ -1796,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)
@@ -1817,8 +1723,7 @@ const int doquotes;
}
static void
-updateminmax(x)
-const int x;
+updateminmax(const int x)
{
if (min_year > x)
min_year = x;
@@ -1827,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;
@@ -1859,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;
@@ -1914,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;
@@ -1997,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;
@@ -2070,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)
@@ -2115,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);
@@ -2254,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)) {
@@ -2288,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;
@@ -2348,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;
@@ -2397,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)) {
@@ -2423,28 +2306,24 @@ 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')
return TRUE;
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;
@@ -2457,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;
@@ -2487,17 +2365,15 @@ register const struct lookup * const table;
}
static char **
-getfields(cp)