[PROPOSED PATCH 1/3] Avoid (void) before calls.
Although the cast to void in usage like '(void) printf ("Hello")' may have been helpful decades ago when Lint Was Your Friend, nowadays such casts are not helpful. The tz code is currently not consistent about this: sometimes the casts are present, and sometimes absent. As they make the code harder to read, let's remove them. * asctime.c, date.c, ialloc.c, localtime.c, strftime.c, zdump.c, zic.c: Don't cast calls to 'void'. --- asctime.c | 4 +- date.c | 68 +++++++++++++++---------------- ialloc.c | 2 +- localtime.c | 6 +-- strftime.c | 30 +++++++------- zdump.c | 90 ++++++++++++++++++++--------------------- zic.c | 130 ++++++++++++++++++++++++++++++------------------------------ 7 files changed, 165 insertions(+), 165 deletions(-) diff --git a/asctime.c b/asctime.c index e057711..0ce1209 100644 --- a/asctime.c +++ b/asctime.c @@ -99,11 +99,11 @@ asctime_r(register const struct tm *timeptr, char *buf) ** Assume that strftime is unaffected by other out-of-range members ** (e.g., timeptr->tm_mday) when processing "%Y". */ - (void) strftime(year, sizeof year, "%Y", timeptr); + strftime(year, sizeof year, "%Y", timeptr); /* ** We avoid using snprintf since it's not available on all systems. */ - (void) sprintf(result, + sprintf(result, ((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B), wn, mn, timeptr->tm_mday, timeptr->tm_hour, diff --git a/date.c b/date.c index de56652..c2a39f2 100644 --- a/date.c +++ b/date.c @@ -91,13 +91,13 @@ main(const int argc, char *argv[]) INITIALIZE(dousg); #ifdef LC_ALL - (void) setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif /* defined(LC_ALL) */ #if HAVE_GETTEXT #ifdef TZ_DOMAINDIR - (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); + bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); #endif /* defined(TEXTDOMAINDIR) */ - (void) textdomain(TZ_DOMAIN); + textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ t = now = time(NULL); format = value = NULL; @@ -111,7 +111,7 @@ main(const int argc, char *argv[]) break; case 'r': /* seconds since 1970 */ if (rflag) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: multiple -r's used")); usage(); } @@ -134,7 +134,7 @@ main(const int argc, char *argv[]) break; case 'd': /* daylight saving time */ if (dflag) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: multiple -d's used")); usage(); } @@ -147,7 +147,7 @@ main(const int argc, char *argv[]) break; case 't': /* minutes west of UTC */ if (tflag) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: multiple -t's used")); usage(); } @@ -162,7 +162,7 @@ main(const int argc, char *argv[]) break; case 'a': /* adjustment */ if (aflag) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: multiple -a's used")); usage(); } @@ -189,14 +189,14 @@ main(const int argc, char *argv[]) if (format == NULL) format = cp + 1; else { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: multiple formats in command line\n")); usage(); } else if (value == NULL && !rflag) value = cp; else { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: multiple values in command line\n")); usage(); } @@ -277,7 +277,7 @@ _("date: error: multiple values in command line\n")); #if HAVE_SETTIMEOFDAY != 2 (void) dsttime; (void) minuteswest; - (void) fprintf(stderr, + fprintf(stderr, _("date: warning: kernel doesn't keep -d/-t information, option ignored\n")); #endif /* HAVE_SETTIMEOFDAY != 2 */ } @@ -307,7 +307,7 @@ dogmt(void) continue; fakeenv = malloc((n + 2) * sizeof *fakeenv); if (fakeenv == NULL) { - (void) perror(_("Memory exhausted")); + perror(_("Memory exhausted")); errensure(); exit(retval); } @@ -352,15 +352,15 @@ reset(const time_t newt, const int nflag) /* ** Wouldn't it be great if stime returned the old time? */ - (void) time(&oldt); + oldt = time(NULL); if (stime(&newt) != 0) oops("stime"); s.before.ut_type = OLD_TIME; s.before.ut_time = oldt; - (void) strcpy(s.before.ut_line, OTIME_MSG); + strcpy(s.before.ut_line, OTIME_MSG); s.after.ut_type = NEW_TIME; s.after.ut_time = newt; - (void) strcpy(s.after.ut_line, NTIME_MSG); + strcpy(s.after.ut_line, NTIME_MSG); fid = open(WTMP_FILE, O_WRONLY | O_APPEND); if (fid < 0) oops(_("log file open")); @@ -375,10 +375,10 @@ reset(const time_t newt, const int nflag) #if HAVE_UTMPX_H sx.before.ut_type = OLD_TIME; sx.before.ut_tv.tv_sec = oldt; - (void) strcpy(sx.before.ut_line, OTIME_MSG); + strcpy(sx.before.ut_line, OTIME_MSG); sx.after.ut_type = NEW_TIME; sx.after.ut_tv.tv_sec = newt; - (void) strcpy(sx.after.ut_line, NTIME_MSG); + strcpy(sx.after.ut_line, NTIME_MSG); #if defined WTMPX_FILE && !SUPPRESS_WTMPX_FILE_UPDATE /* In Solaris 2.5 (and presumably other systems), 'date' does not update /var/adm/wtmpx. @@ -471,7 +471,7 @@ static void wildinput(const char *const item, const char *const value, const char *const reason) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: bad command line %s \"%s\", %s\n"), item, value, reason); usage(); @@ -495,7 +495,7 @@ nondigit(register const char *cp) static void usage(void) { - (void) fprintf(stderr, + fprintf(stderr, _("date: usage: date [-u] [-c] [-r seconds] [-n]" " [-d dst] [-t min-west] [-a sss.fff]" " [[yyyy]mmddhhmm[yyyy][.ss]] [+format]\n")); @@ -508,9 +508,9 @@ oops(const char *const string) { int e = errno; - (void) fprintf(stderr, _("date: error: ")); + fprintf(stderr, _("date: error: ")); errno = e; - (void) perror(string); + perror(string); errensure(); display(NULL, time(NULL)); exit(retval); @@ -523,17 +523,17 @@ display(const char *const format, time_t const now) tmp = localtime(&now); if (!tmp) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: time out of range\n")); errensure(); return; } timeout(stdout, format ? format : "%+", tmp); - (void) putchar('\n'); - (void) fflush(stdout); - (void) fflush(stderr); + putchar('\n'); + fflush(stdout); + fflush(stderr); if (ferror(stdout) || ferror(stderr)) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: couldn't write results\n")); errensure(); } @@ -552,7 +552,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp) if (*format == '\0') return; if (!tmp) { - (void) fprintf(stderr, _("date: error: time out of range\n")); + fprintf(stderr, _("date: error: time out of range\n")); errensure(); return; } @@ -562,7 +562,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp) cp = malloc(size); for ( ; ; ) { if (cp == NULL) { - (void) fprintf(stderr, + fprintf(stderr, _("date: error: can't get memory\n")); errensure(); exit(retval); @@ -574,7 +574,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp) size += INCR; cp = realloc(cp, size); } - (void) fwrite(cp, 1, result, fp); + fwrite(cp, 1, result, fp); free(cp); } @@ -778,7 +778,7 @@ iffy(const time_t thist, const time_t thatt, struct tm *tmp; int dst; - (void) fprintf(stderr, _("date: warning: ambiguous time \"%s\", %s.\n"), + fprintf(stderr, _("date: warning: ambiguous time \"%s\", %s.\n"), value, reason); tmp = gmtime(&thist); /* @@ -790,7 +790,7 @@ iffy(const time_t thist, const time_t thatt, tmp = localtime(&thist); dst = tmp ? tmp->tm_isdst : 0; timeout(stderr, _("to get %c"), tmp); - (void) fprintf(stderr, _(" (%s). Use\n"), + fprintf(stderr, _(" (%s). Use\n"), dst ? _("summer time") : _("standard time")); tmp = gmtime(&thatt); timeout(stderr, _("\tdate -u %m%d%H\ @@ -799,7 +799,7 @@ iffy(const time_t thist, const time_t thatt, tmp = localtime(&thatt); dst = tmp ? tmp->tm_isdst : 0; timeout(stderr, _("to get %c"), tmp); - (void) fprintf(stderr, _(" (%s).\n"), + fprintf(stderr, _(" (%s).\n"), dst ? _("summer time") : _("standard time")); errensure(); exit(retval); @@ -865,7 +865,7 @@ netsettime(struct timeval ntv) perror("gethostname"); goto bad; } - (void) strncpy(msg.tsp_name, hostname, sizeof (hostname)); + strncpy(msg.tsp_name, hostname, sizeof (hostname)); msg.tsp_seq = htons(0); msg.tsp_time.tv_sec = htonl(ntv.tv_sec); msg.tsp_time.tv_usec = htonl(ntv.tv_usec); @@ -914,7 +914,7 @@ loop: goto loop; case TSP_DATEACK: - (void)close(s); + lose(s); return (1); default: @@ -929,7 +929,7 @@ loop: fputs(_("date: Can't reach time daemon, time set locally.\n"), stderr); bad: - (void)close(s); + lose(s); retval = 2; return (0); } diff --git a/ialloc.c b/ialloc.c index b6f0188..e228db5 100644 --- a/ialloc.c +++ b/ialloc.c @@ -21,7 +21,7 @@ icatalloc(char *const old, const char *const new) else oldsize = strlen(old); if ((result = realloc(old, oldsize + newsize + 1)) != NULL) if (new != NULL) - (void) strcpy(result + oldsize, new); + strcpy(result + oldsize, new); return result; } diff --git a/localtime.c b/localtime.c index fef273d..8a66650 100644 --- a/localtime.c +++ b/localtime.c @@ -1134,11 +1134,11 @@ tzparse(const char *name, register struct state *const sp, if ((size_t) sp->charcnt > sizeof sp->chars) return -1; cp = sp->chars; - (void) strncpy(cp, stdname, stdlen); + strncpy(cp, stdname, stdlen); cp += stdlen; *cp++ = '\0'; if (dstlen != 0) { - (void) strncpy(cp, dstname, dstlen); + strncpy(cp, dstname, dstlen); *(cp + dstlen) = '\0'; } return 0; @@ -1148,7 +1148,7 @@ static void gmtload(struct state *const sp) { if (tzload(gmt, sp, TRUE) != 0) - (void) tzparse(gmt, sp, TRUE); + tzparse(gmt, sp, TRUE); } static void diff --git a/strftime.c b/strftime.c index 9fbb1ec..259c90a 100644 --- a/strftime.c +++ b/strftime.c @@ -129,18 +129,18 @@ strftime(char * const s, const size_t maxsize, const char *const format, p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn); #ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) { - (void) fprintf(stderr, "\n"); + fprintf(stderr, "\n"); if (format == NULL) - (void) fprintf(stderr, "NULL strftime format "); - else (void) fprintf(stderr, "strftime format \"%s\" ", + fprintf(stderr, "NULL strftime format "); + else fprintf(stderr, "strftime format \"%s\" ", format); - (void) fprintf(stderr, "yields only two digits of years in "); + fprintf(stderr, "yields only two digits of years in "); if (warn == IN_SOME) - (void) fprintf(stderr, "some locales"); + fprintf(stderr, "some locales"); else if (warn == IN_THIS) - (void) fprintf(stderr, "the current locale"); - else (void) fprintf(stderr, "all locales"); - (void) fprintf(stderr, "\n"); + fprintf(stderr, "the current locale"); + else fprintf(stderr, "all locales"); + fprintf(stderr, "\n"); } #endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */ if (p == s + maxsize) @@ -311,9 +311,9 @@ label: tm = *t; mkt = mktime(&tm); if (TYPE_SIGNED(time_t)) - (void) sprintf(buf, "%"PRIdMAX, + sprintf(buf, "%"PRIdMAX, (intmax_t) mkt); - else (void) sprintf(buf, "%"PRIuMAX, + else sprintf(buf, "%"PRIuMAX, (uintmax_t) mkt); pt = _add(buf, pt, ptlim); } @@ -564,7 +564,7 @@ _conv(const int n, const char *const format, char *const pt, { char buf[INT_STRLEN_MAXIMUM(int) + 1]; - (void) sprintf(buf, format, n); + sprintf(buf, format, n); return _add(buf, pt, ptlim); } @@ -660,14 +660,14 @@ _loc(void) ((sizeof locale_home) + namesize + (sizeof lc_time))) goto no_locale; oldsun = 0; - (void) sprintf(filename, "%s/%s/%s", locale_home, name, lc_time); + sprintf(filename, "%s/%s/%s", locale_home, name, lc_time); fd = open(filename, O_RDONLY); if (fd < 0) { /* ** Old Sun systems have a different naming and data convention. */ oldsun = 1; - (void) sprintf(filename, "%s/%s/%s", locale_home, + sprintf(filename, "%s/%s/%s", locale_home, lc_time, name); fd = open(filename, O_RDONLY); if (fd < 0) @@ -682,7 +682,7 @@ _loc(void) lbuf = (lbuf == NULL) ? malloc(bufsize) : realloc(lbuf, bufsize); if (lbuf == NULL) goto bad_locale; - (void) strcpy(lbuf, name); + strcpy(lbuf, name); p = lbuf + namesize; plim = p + st.st_size; if (read(fd, p, st.st_size) != st.st_size) @@ -725,7 +725,7 @@ _loc(void) bad_lbuf: free(lbuf); bad_locale: - (void) close(fd); + close(fd); no_locale: localebuf = C_time_locale; locale_buf = NULL; diff --git a/zdump.c b/zdump.c index 515a80f..cdcde5a 100644 --- a/zdump.c +++ b/zdump.c @@ -250,20 +250,20 @@ my_localtime(time_t *tp) tm = *tmp; t = mktime(&tm); if (t != *tp) { - (void) fflush(stdout); - (void) fprintf(stderr, "\n%s: ", progname); - (void) fprintf(stderr, tformat(), *tp); - (void) fprintf(stderr, " ->"); - (void) fprintf(stderr, " year=%d", tmp->tm_year); - (void) fprintf(stderr, " mon=%d", tmp->tm_mon); - (void) fprintf(stderr, " mday=%d", tmp->tm_mday); - (void) fprintf(stderr, " hour=%d", tmp->tm_hour); - (void) fprintf(stderr, " min=%d", tmp->tm_min); - (void) fprintf(stderr, " sec=%d", tmp->tm_sec); - (void) fprintf(stderr, " isdst=%d", tmp->tm_isdst); - (void) fprintf(stderr, " -> "); - (void) fprintf(stderr, tformat(), t); - (void) fprintf(stderr, "\n"); + fflush(stdout); + fprintf(stderr, "\n%s: ", progname); + fprintf(stderr, tformat(), *tp); + fprintf(stderr, " ->"); + fprintf(stderr, " year=%d", tmp->tm_year); + fprintf(stderr, " mon=%d", tmp->tm_mon); + fprintf(stderr, " mday=%d", tmp->tm_mday); + fprintf(stderr, " hour=%d", tmp->tm_hour); + fprintf(stderr, " min=%d", tmp->tm_min); + fprintf(stderr, " sec=%d", tmp->tm_sec); + fprintf(stderr, " isdst=%d", tmp->tm_isdst); + fprintf(stderr, " -> "); + fprintf(stderr, tformat(), t); + fprintf(stderr, "\n"); } } return tmp; @@ -298,8 +298,8 @@ abbrok(const char *const abbrp, const char *const zone) } if (wp == NULL) return; - (void) fflush(stdout); - (void) fprintf(stderr, + fflush(stdout); + fprintf(stderr, _("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"), progname, zone, abbrp, wp); warned = TRUE; @@ -308,7 +308,7 @@ abbrok(const char *const abbrp, const char *const zone) static void usage(FILE * const stream, const int status) { - (void) fprintf(stream, + fprintf(stream, _("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n" "\n" "Report bugs to %s.\n"), @@ -338,16 +338,16 @@ main(int argc, char *argv[]) cutlotime = absolute_min_time; cuthitime = absolute_max_time; #if HAVE_GETTEXT - (void) setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #ifdef TZ_DOMAINDIR - (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); + bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); #endif /* defined TEXTDOMAINDIR */ - (void) textdomain(TZ_DOMAIN); + textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ progname = argv[0]; for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { - (void) printf("zdump %s%s\n", PKGVERSION, TZVERSION); + printf("zdump %s%s\n", PKGVERSION, TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); @@ -386,7 +386,7 @@ main(int argc, char *argv[]) cutloyear = lo; cuthiyear = hi; } else { -(void) fprintf(stderr, _("%s: wild -c argument %s\n"), + fprintf(stderr, _("%s: wild -c argument %s\n"), progname, cutarg); exit(EXIT_FAILURE); } @@ -418,14 +418,14 @@ main(int argc, char *argv[]) cuthitime = hi; } } else { - (void) fprintf(stderr, + fprintf(stderr, _("%s: wild -t argument %s\n"), progname, cuttimes); exit(EXIT_FAILURE); } } } - (void) time(&now); + now = time(NULL); longest = 0; for (i = optind; i < argc; ++i) if (strlen(argv[i]) > longest) @@ -439,11 +439,11 @@ main(int argc, char *argv[]) fakeenv = malloc((i + 2) * sizeof *fakeenv); if (fakeenv == NULL || (fakeenv[0] = malloc(longest + 4)) == NULL) { - (void) perror(progname); - exit(EXIT_FAILURE); + perror(progname); + exit(EXIT_FAILURE); } to = 0; - (void) strcpy(fakeenv[to++], "TZ="); + strcpy(fakeenv[to++], "TZ="); for (from = 0; environ[from] != NULL; ++from) if (strncmp(environ[from], "TZ=", 3) != 0) fakeenv[to++] = environ[from]; @@ -453,7 +453,7 @@ main(int argc, char *argv[]) for (i = optind; i < argc; ++i) { static char buf[MAX_STRING_LENGTH]; - (void) strcpy(&fakeenv[0][3], argv[i]); + strcpy(&fakeenv[0][3], argv[i]); if (! (vflag | Vflag)) { show(argv[i], now, FALSE); continue; @@ -470,7 +470,7 @@ main(int argc, char *argv[]) tmp = my_localtime(&t); if (tmp != NULL) { tm = *tmp; - (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); + strncpy(buf, abbr(&tm), (sizeof buf) - 1); } for ( ; ; ) { newt = (t < absolute_max_time - SECSPERDAY / 2 @@ -489,7 +489,7 @@ main(int argc, char *argv[]) newtmp = localtime(&newt); if (newtmp != NULL) { newtm = *newtmp; - (void) strncpy(buf, + strncpy(buf, abbr(&newtm), (sizeof buf) - 1); } @@ -507,8 +507,8 @@ main(int argc, char *argv[]) } } if (fflush(stdout) || ferror(stdout)) { - (void) fprintf(stderr, "%s: ", progname); - (void) perror(_("Error writing to standard output")); + fprintf(stderr, "%s: ", progname); + perror(_("Error writing to standard output")); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); @@ -572,7 +572,7 @@ hunt(char *name, time_t lot, time_t hit) lotmp = my_localtime(&lot); if (lotmp != NULL) { lotm = *lotmp; - (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); + strncpy(loab, abbr(&lotm), (sizeof loab) - 1); } for ( ; ; ) { time_t diff = hit - lot; @@ -631,30 +631,30 @@ show(char *zone, time_t t, int v) { register struct tm * tmp; - (void) printf("%-*s ", (int) longest, zone); + printf("%-*s ", (int) longest, zone); if (v) { tmp = gmtime(&t); if (tmp == NULL) { - (void) printf(tformat(), t); + printf(tformat(), t); } else { dumptime(tmp); - (void) printf(" UT"); + printf(" UT"); } - (void) printf(" = "); + printf(" = "); } tmp = my_localtime(&t); dumptime(tmp); if (tmp != NULL) { if (*abbr(tmp) != '\0') - (void) printf(" %s", abbr(tmp)); + printf(" %s", abbr(tmp)); if (v) { - (void) printf(" isdst=%d", tmp->tm_isdst); + printf(" isdst=%d", tmp->tm_isdst); #ifdef TM_GMTOFF - (void) printf(" gmtoff=%ld", tmp->TM_GMTOFF); + printf(" gmtoff=%ld", tmp->TM_GMTOFF); #endif /* defined TM_GMTOFF */ } } - (void) printf("\n"); + printf("\n"); if (tmp != NULL && *abbr(tmp) != '\0') abbrok(abbr(tmp), zone); } @@ -715,7 +715,7 @@ dumptime(register const struct tm *timeptr) register int trail; if (timeptr == NULL) { - (void) printf("NULL"); + printf("NULL"); return; } /* @@ -731,7 +731,7 @@ dumptime(register const struct tm *timeptr) (int) (sizeof mon_name / sizeof mon_name[0])) mn = "???"; else mn = mon_name[timeptr->tm_mon]; - (void) printf("%.3s %.3s%3d %.2d:%.2d:%.2d ", + printf("%.3s %.3s%3d %.2d:%.2d:%.2d ", wn, mn, timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); @@ -748,6 +748,6 @@ dumptime(register const struct tm *timeptr) ++lead; } if (lead == 0) - (void) printf("%d", trail); - else (void) printf("%d%d", lead, ((trail < 0) ? -trail : trail)); + printf("%d", trail); + else printf("%d%d", lead, ((trail < 0) ? -trail : trail)); } diff --git a/zic.c b/zic.c index a700291..ea63f76 100644 --- a/zic.c +++ b/zic.c @@ -426,9 +426,9 @@ verror(const char *const string, va_list args) fprintf(stderr, _("\"%s\", line %d: "), filename, linenum); vfprintf(stderr, string, args); if (rfilename != NULL) - (void) fprintf(stderr, _(" (rule from \"%s\", line %d)"), + fprintf(stderr, _(" (rule from \"%s\", line %d)"), rfilename, rlinenum); - (void) fprintf(stderr, "\n"); + fprintf(stderr, "\n"); ++errors; } @@ -455,7 +455,7 @@ warning(const char *const string, ...) static _Noreturn void usage(FILE *stream, int status) { - (void) fprintf(stream, _("%s: usage is %s \ + fprintf(stream, _("%s: usage is %s \ [ --version ] [ --help ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\ \t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\ \n\ @@ -478,24 +478,24 @@ main(int argc, char **argv) register int c; #ifdef S_IWGRP - (void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH)); + umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH)); #endif #if HAVE_GETTEXT - (void) setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #ifdef TZ_DOMAINDIR - (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); + bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); #endif /* defined TEXTDOMAINDIR */ - (void) textdomain(TZ_DOMAIN); + textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ progname = argv[0]; if (TYPE_BIT(zic_t) < 64) { - (void) fprintf(stderr, "%s: %s\n", progname, + fprintf(stderr, "%s: %s\n", progname, _("wild compilation-time specification of zic_t")); exit(EXIT_FAILURE); } for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { - (void) printf("zic %s%s\n", PKGVERSION, TZVERSION); + printf("zic %s%s\n", PKGVERSION, TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); @@ -508,7 +508,7 @@ main(int argc, char **argv) if (directory == NULL) directory = optarg; else { - (void) fprintf(stderr, + fprintf(stderr, _("%s: More than one -d option specified\n"), progname); exit(EXIT_FAILURE); @@ -518,7 +518,7 @@ _("%s: More than one -d option specified\n"), if (lcltime == NULL) lcltime = optarg; else { - (void) fprintf(stderr, + fprintf(stderr, _("%s: More than one -l option specified\n"), progname); exit(EXIT_FAILURE); @@ -528,7 +528,7 @@ _("%s: More than one -l option specified\n"), if (psxrules == NULL) psxrules = optarg; else { - (void) fprintf(stderr, + fprintf(stderr, _("%s: More than one -p option specified\n"), progname); exit(EXIT_FAILURE); @@ -538,7 +538,7 @@ _("%s: More than one -p option specified\n"), if (yitcommand == NULL) yitcommand = optarg; else { - (void) fprintf(stderr, + fprintf(stderr, _("%s: More than one -y option specified\n"), progname); exit(EXIT_FAILURE); @@ -548,7 +548,7 @@ _("%s: More than one -y option specified\n"), if (leapsec == NULL) leapsec = optarg; else { - (void) fprintf(stderr, + fprintf(stderr, _("%s: More than one -L option specified\n"), progname); exit(EXIT_FAILURE); @@ -558,7 +558,7 @@ _("%s: More than one -L option specified\n"), noise = TRUE; break; case 's': - (void) printf("%s: -s ignored\n", progname); + printf("%s: -s ignored\n", progname); break; } if (optind == argc - 1 && strcmp(argv[optind], "=") == 0) @@ -701,7 +701,7 @@ dolink(const char *const fromfield, const char *const tofield) exit(EXIT_FAILURE); } if (itsdir(toname) <= 0) - (void) remove(toname); + remove(toname); if (link(fromname, toname) != 0) { int result; @@ -738,7 +738,7 @@ warning(_("hard link failed, symbolic link used")); fp = fopen(fromname, "rb"); if (!fp) { const char *e = strerror(errno); - (void) fprintf(stderr, + fprintf(stderr, _("%s: Can't read %s: %s\n"), progname, fromname, e); exit(EXIT_FAILURE); @@ -746,7 +746,7 @@ warning(_("hard link failed, symbolic link used")); tp = fopen(toname, "wb"); if (!tp) { const char *e = strerror(errno); - (void) fprintf(stderr, + fprintf(stderr, _("%s: Can't create %s: %s\n"), progname, toname, e); exit(EXIT_FAILURE); @@ -754,13 +754,13 @@ warning(_("hard link failed, symbolic link used")); while ((c = getc(fp)) != EOF) putc(c, tp); if (ferror(fp) || fclose(fp)) { - (void) fprintf(stderr, + fprintf(stderr, _("%s: Error reading %s\n"), progname, fromname); exit(EXIT_FAILURE); } if (ferror(tp) || fclose(tp)) { - (void) fprintf(stderr, + fprintf(stderr, _("%s: Error writing %s\n"), progname, toname); exit(EXIT_FAILURE); @@ -851,7 +851,7 @@ associate(void) register int i, j; if (nrules != 0) { - (void) qsort(rules, nrules, sizeof *rules, rcomp); + 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) @@ -935,7 +935,7 @@ infile(const char *name) } else if ((fp = fopen(name, "r")) == NULL) { const char *e = strerror(errno); - (void) fprintf(stderr, _("%s: Can't open %s: %s\n"), + fprintf(stderr, _("%s: Can't open %s: %s\n"), progname, name, e); exit(EXIT_FAILURE); } @@ -981,14 +981,14 @@ infile(const char *name) break; case LC_LEAP: if (name != leapsec) - (void) fprintf(stderr, + fprintf(stderr, _("%s: Leap line in non leap seconds file %s\n"), progname, name); else inleap(fields, nfields); wantcont = FALSE; break; default: /* "cannot happen" */ - (void) fprintf(stderr, + fprintf(stderr, _("%s: panic: Invalid l_value %d\n"), progname, lp->l_value); exit(EXIT_FAILURE); @@ -997,14 +997,14 @@ _("%s: panic: Invalid l_value %d\n"), free(fields); } if (ferror(fp)) { - (void) fprintf(stderr, _("%s: Error reading %s\n"), + fprintf(stderr, _("%s: Error reading %s\n"), progname, filename); exit(EXIT_FAILURE); } if (fp != stdin && fclose(fp)) { const char *e = strerror(errno); - (void) fprintf(stderr, _("%s: Error closing %s: %s\n"), + fprintf(stderr, _("%s: Error closing %s: %s\n"), progname, filename, e); exit(EXIT_FAILURE); } @@ -1396,7 +1396,7 @@ rulesub(register struct rule *const rp, rp->r_loyear = ZIC_MAX; break; default: /* "cannot happen" */ - (void) fprintf(stderr, + fprintf(stderr, _("%s: panic: Invalid l_value %d\n"), progname, lp->l_value); exit(EXIT_FAILURE); @@ -1418,7 +1418,7 @@ rulesub(register struct rule *const rp, rp->r_hiyear = rp->r_loyear; break; default: /* "cannot happen" */ - (void) fprintf(stderr, + fprintf(stderr, _("%s: panic: Invalid l_value %d\n"), progname, lp->l_value); exit(EXIT_FAILURE); @@ -1514,7 +1514,7 @@ puttzcode(const int_fast32_t val, FILE *const fp) char buf[4]; convert(val, buf); - (void) fwrite(buf, sizeof buf, 1, fp); + fwrite(buf, sizeof buf, 1, fp); } static void @@ -1523,7 +1523,7 @@ puttzcode64(const zic_t val, FILE *const fp) char buf[8]; convert64(val, buf); - (void) fwrite(buf, sizeof buf, 1, fp); + fwrite(buf, sizeof buf, 1, fp); } static int @@ -1561,7 +1561,7 @@ writezone(const char *const name, const char *const string, char version) ** Sort. */ if (timecnt > 1) - (void) qsort(attypes, timecnt, sizeof *attypes, atcomp); + qsort(attypes, timecnt, sizeof *attypes, atcomp); /* ** Optimize. */ @@ -1637,14 +1637,14 @@ writezone(const char *const name, const char *const string, char version) } fullname = erealloc(fullname, strlen(directory) + 1 + strlen(name) + 1); - (void) sprintf(fullname, "%s/%s", directory, name); + sprintf(fullname, "%s/%s", directory, name); /* ** Remove old file, if any, to snap links. */ if (itsdir(fullname) <= 0 && remove(fullname) != 0 && errno != ENOENT) { const char *e = strerror(errno); - (void) fprintf(stderr, _("%s: Can't remove %s: %s\n"), + fprintf(stderr, _("%s: Can't remove %s: %s\n"), progname, fullname, e); exit(EXIT_FAILURE); } @@ -1654,7 +1654,7 @@ writezone(const char *const name, const char *const string, char version) if ((fp = fopen(fullname, "wb")) == NULL) { const char *e = strerror(errno); - (void) fprintf(stderr, _("%s: Can't create %s: %s\n"), + fprintf(stderr, _("%s: Can't create %s: %s\n"), progname, fullname, e); exit(EXIT_FAILURE); } @@ -1767,15 +1767,15 @@ writezone(const char *const name, const char *const string, char version) if (strcmp(&thischars[j], thisabbr) == 0) break; if (j == thischarcnt) { - (void) strcpy(&thischars[(int) thischarcnt], + strcpy(&thischars[(int) thischarcnt], thisabbr); thischarcnt += strlen(thisabbr) + 1; } indmap[abbrinds[i]] = j; } -#define DO(field) ((void) fwrite(tzh.field, sizeof tzh.field, 1, fp)) +#define DO(field) fwrite(tzh.field, sizeof tzh.field, 1, fp) tzh = tzh0; - (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); + strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic); tzh.tzh_version[0] = version; convert(thistypecnt, tzh.tzh_ttisgmtcnt); convert(thistypecnt, tzh.tzh_ttisstdcnt); @@ -1806,16 +1806,16 @@ writezone(const char *const name, const char *const string, char version) unsigned char uc; uc = typemap[types[i]]; - (void) fwrite(&uc, sizeof uc, 1, fp); + fwrite(&uc, sizeof uc, 1, fp); } for (i = 0; i < typecnt; ++i) if (writetype[i]) { puttzcode(gmtoffs[i], fp); - (void) putc(isdsts[i], fp); - (void) putc((unsigned char) indmap[abbrinds[i]], fp); + putc(isdsts[i], fp); + putc((unsigned char) indmap[abbrinds[i]], fp); } if (thischarcnt != 0) - (void) fwrite(thischars, sizeof thischars[0], + fwrite(thischars, sizeof thischars[0], thischarcnt, fp); for (i = thisleapi; i < thisleaplim; ++i) { register zic_t todo; @@ -1844,14 +1844,14 @@ writezone(const char *const name, const char *const string, char version) } for (i = 0; i < typecnt; ++i) if (writetype[i]) - (void) putc(ttisstds[i], fp); + putc(ttisstds[i], fp); for (i = 0; i < typecnt; ++i) if (writetype[i]) - (void) putc(ttisgmts[i], fp); + putc(ttisgmts[i], fp); } - (void) fprintf(fp, "\n%s\n", string); + fprintf(fp, "\n%s\n", string); if (ferror(fp) || fclose(fp)) { - (void) fprintf(stderr, _("%s: Error writing %s\n"), + fprintf(stderr, _("%s: Error writing %s\n"), progname, fullname); exit(EXIT_FAILURE); } @@ -1869,13 +1869,13 @@ doabbr(char *const abbr, const char *const format, const char *const letters, slashp = strchr(format, '/'); if (slashp == NULL) { if (letters == NULL) - (void) strcpy(abbr, format); - else (void) sprintf(abbr, format, letters); + strcpy(abbr, format); + else sprintf(abbr, format, letters); } else if (isdst) { - (void) strcpy(abbr, slashp + 1); + strcpy(abbr, slashp + 1); } else { if (slashp > format) - (void) strncpy(abbr, format, slashp - format); + strncpy(abbr, format, slashp - format); abbr[slashp - format] = '\0'; } if (!doquotes) @@ -1910,7 +1910,7 @@ stringoffset(char *result, zic_t offset) result[0] = '\0'; if (offset < 0) { - (void) strcpy(result, "-"); + strcpy(result, "-"); offset = -offset; } seconds = offset % SECSPERMIN; @@ -1922,11 +1922,11 @@ stringoffset(char *result, zic_t offset) result[0] = '\0'; return -1; } - (void) sprintf(end(result), "%d", hours); + sprintf(end(result), "%d", hours); if (minutes != 0 || seconds != 0) { - (void) sprintf(end(result), ":%02d", minutes); + sprintf(end(result), ":%02d", minutes); if (seconds != 0) - (void) sprintf(end(result), ":%02d", seconds); + sprintf(end(result), ":%02d", seconds); } return 0; } @@ -1949,9 +1949,9 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff, total += len_months[0][month]; /* Omit the "J" in Jan and Feb, as that's shorter. */ if (rp->r_month <= 1) - (void) sprintf(result, "%d", total + rp->r_dayofmonth - 1); + sprintf(result, "%d", total + rp->r_dayofmonth - 1); else - (void) sprintf(result, "J%d", total + rp->r_dayofmonth); + sprintf(result, "J%d", total + rp->r_dayofmonth); } else { register int week; register int wday = rp->r_wday; @@ -1978,7 +1978,7 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff, } else return -1; /* "cannot happen" */ if (wday < 0) wday += DAYSPERWEEK; - (void) sprintf(result, "M%d.%d.%d", + sprintf(result, "M%d.%d.%d", rp->r_month + 1, week, wday); } if (rp->r_todisgmt) @@ -1986,7 +1986,7 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff, if (rp->r_todisstd && rp->r_stdoff == 0) tod += dstoff; if (tod != 2 * SECSPERMIN * MINSPERHOUR) { - (void) strcat(result, "/"); + strcat(result, "/"); if (stringoffset(end(result), tod) != 0) return -1; if (tod < 0) { @@ -2108,7 +2108,7 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount) result[0] = '\0'; return -1; } - (void) strcat(result, ","); + strcat(result, ","); c = stringrule(result, dstrp, dstrp->r_stdoff, zp->z_gmtoff); if (c < 0) { result[0] = '\0'; @@ -2116,7 +2116,7 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount) } if (compat < c) compat = c; - (void) strcat(result, ","); + strcat(result, ","); c = stringrule(result, stdrp, dstrp->r_stdoff, zp->z_gmtoff); if (c < 0) { result[0] = '\0'; @@ -2383,7 +2383,7 @@ outzone(const struct zone * const zpfirst, const int zonecount) zp->z_format != NULL && strchr(zp->z_format, '%') == NULL && strchr(zp->z_format, '/') == NULL) - (void) strcpy(startbuf, zp->z_format); + strcpy(startbuf, zp->z_format); eat(zp->z_filename, zp->z_linenum); if (*startbuf == '\0') error(_("can't determine time zone abbreviation to use just after until time")); @@ -2460,7 +2460,7 @@ addtt(const zic_t starttime, int type) ttisstds[0] = ttisstds[type]; ttisgmts[0] = ttisgmts[type]; if (abbrinds[type] != 0) - (void) strcpy(chars, &chars[abbrinds[type]]); + strcpy(chars, &chars[abbrinds[type]]); abbrinds[0] = 0; charcnt = strlen(chars) + 1; typecnt = 1; @@ -2583,7 +2583,7 @@ yearistype(const int year, const char *const type) if (type == NULL || *type == '\0') return TRUE; buf = erealloc(buf, 132 + strlen(yitcommand) + strlen(type)); - (void) sprintf(buf, "%s %d %s", yitcommand, year, type); + sprintf(buf, "%s %d %s", yitcommand, year, type); result = system(buf); if (WIFEXITED(result)) switch (WEXITSTATUS(result)) { case 0: @@ -2592,7 +2592,7 @@ yearistype(const int year, const char *const type) return FALSE; } error(_("Wild result from command execution")); - (void) fprintf(stderr, _("%s: command was '%s', result was %d\n"), + fprintf(stderr, _("%s: command was '%s', result was %d\n"), progname, buf, result); for ( ; ; ) exit(EXIT_FAILURE); @@ -2888,7 +2888,7 @@ mp = _("time zone abbreviation differs from POSIX standard"); error(_("too many, or too long, time zone abbreviations")); exit(EXIT_FAILURE); } - (void) strcpy(&chars[charcnt], string); + strcpy(&chars[charcnt], string); charcnt += i; } @@ -2920,7 +2920,7 @@ mkdirs(char *argname) if (mkdir(name, MKDIR_UMASK) != 0) { int err = errno; if (itsdir(name) <= 0) { - (void) fprintf(stderr, + fprintf(stderr, _("%s: Can't create directory" " %s: %s\n"), progname, name, strerror(err)); -- 1.9.1
* zdump.c: Include <errno.h>. (errout): New static var. (my_localtime) [!TYPECHECK] (abbrok): Set it. (close_file): New function. (usage, main): Use it. (main): Prefer 'return X;' to 'exit(X);'. Check for stderr output error. --- zdump.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/zdump.c b/zdump.c index cdcde5a..e9a42fd 100644 --- a/zdump.c +++ b/zdump.c @@ -24,6 +24,7 @@ #include "time.h" /* for struct tm */ #include "stdlib.h" /* for exit, malloc, atoi */ #include "limits.h" /* for CHAR_BIT, LLONG_MAX */ +#include <errno.h> /* ** Substitutes for pre-C99 compilers. @@ -206,6 +207,7 @@ static time_t const absolute_max_time = static size_t longest; static char * progname; static int warned; +static int errout; static char *abbr(struct tm *); static intmax_t delta(struct tm *, struct tm *) ATTRIBUTE_PURE; @@ -264,6 +266,7 @@ my_localtime(time_t *tp) fprintf(stderr, " -> "); fprintf(stderr, tformat(), t); fprintf(stderr, "\n"); + errout = TRUE; } } return tmp; @@ -302,7 +305,21 @@ abbrok(const char *const abbrp, const char *const zone) fprintf(stderr, _("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"), progname, zone, abbrp, wp); - warned = TRUE; + warned = errout = TRUE; +} + +static void +close_file(FILE *stream, char const *name) +{ + char const *e = (ferror(stream) ? _("I/O error") + : fclose(stream) != 0 ? strerror(errno) : NULL); + if (e) { + fprintf(stderr, "%s: ", progname); + if (name) + fprintf(stderr, "%s: ", name); + fprintf(stderr, "%s\n", e); + exit(EXIT_FAILURE); + } } static void @@ -313,6 +330,8 @@ _("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n" "\n" "Report bugs to %s.\n"), progname, progname, REPORT_BUGS_TO); + if (status == EXIT_SUCCESS) + close_file(stream, NULL); exit(status); } @@ -348,7 +367,7 @@ main(int argc, char *argv[]) for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { printf("zdump %s%s\n", PKGVERSION, TZVERSION); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } @@ -388,7 +407,7 @@ main(int argc, char *argv[]) } else { fprintf(stderr, _("%s: wild -c argument %s\n"), progname, cutarg); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } if (cutarg != NULL || cuttimes == NULL) { @@ -421,7 +440,7 @@ main(int argc, char *argv[]) fprintf(stderr, _("%s: wild -t argument %s\n"), progname, cuttimes); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } } @@ -440,7 +459,7 @@ main(int argc, char *argv[]) if (fakeenv == NULL || (fakeenv[0] = malloc(longest + 4)) == NULL) { perror(progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } to = 0; strcpy(fakeenv[to++], "TZ="); @@ -506,14 +525,10 @@ main(int argc, char *argv[]) show(argv[i], t, TRUE); } } - if (fflush(stdout) || ferror(stdout)) { - fprintf(stderr, "%s: ", progname); - perror(_("Error writing to standard output")); - exit(EXIT_FAILURE); - } - exit(EXIT_SUCCESS); - /* If exit fails to exit... */ - return EXIT_FAILURE; + close_file(stdout, NULL); + if (errout && (ferror(stderr) || fclose(stderr) != 0)) + return EXIT_FAILURE; + return EXIT_SUCCESS; } static time_t -- 1.9.1
That can be slightly simplified by the attached further patch, since zdump's close_file function always has a null 2nd argument.
* zic.c (warnings): New static var. (warning): Set it here. (size_product, growalloc, main): Translate diagnostic. (verror): Don't increment errors here. (error): Set it here. (close_file): New function. (usage, dolink, infile, writezone): Use it. (usage): Fit diagnostic in output lines better. (main): Prefer 'return X;' to 'exit(X);'. (main, infile, mkdirs): Use 'warning' for warnings. Check for stderr output error. (dolink, mkdirs): Don't assume gettext preserves errno. --- zic.c | 113 ++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 54 insertions(+), 59 deletions(-) diff --git a/zic.c b/zic.c index ea63f76..d230663 100644 --- a/zic.c +++ b/zic.c @@ -135,6 +135,7 @@ static int yearistype(int year, const char * type); static int charcnt; static int errors; +static int warnings; static const char * filename; static int leapcnt; static int leapseen; @@ -364,7 +365,7 @@ static ATTRIBUTE_PURE size_t size_product(size_t nitems, size_t itemsize) { if (SIZE_MAX / itemsize < nitems) - memory_exhausted("size overflow"); + memory_exhausted(_("size overflow")); return nitems * itemsize; } @@ -389,7 +390,7 @@ growalloc(void *ptr, size_t itemsize, int nitems, int *nitems_alloc) else { int amax = INT_MAX < SIZE_MAX ? INT_MAX : SIZE_MAX; if ((amax - 1) / 3 * 2 < *nitems_alloc) - memory_exhausted("int overflow"); + memory_exhausted(_("int overflow")); *nitems_alloc = *nitems_alloc + (*nitems_alloc >> 1) + 1; return erealloc(ptr, size_product(*nitems_alloc, itemsize)); } @@ -429,7 +430,6 @@ verror(const char *const string, va_list args) fprintf(stderr, _(" (rule from \"%s\", line %d)"), rfilename, rlinenum); fprintf(stderr, "\n"); - ++errors; } static void ATTRIBUTE_FORMAT((printf, 1, 2)) @@ -439,6 +439,7 @@ error(const char *const string, ...) va_start(args, string); verror(string, args); va_end(args); + errors = 1; } static void ATTRIBUTE_FORMAT((printf, 1, 2)) @@ -449,19 +450,35 @@ warning(const char *const string, ...) va_start(args, string); verror(string, args); va_end(args); - --errors; + warnings = 1; +} + +static void +close_file(FILE *stream, char const *name) +{ + char const *e = (ferror(stream) ? _("I/O error") + : fclose(stream) != 0 ? strerror(errno) : NULL); + if (e) { + fprintf(stderr, "%s: ", progname); + if (name) + fprintf(stderr, "%s: ", name); + fprintf(stderr, "%s\n", e); + exit(EXIT_FAILURE); + } } static _Noreturn void usage(FILE *stream, int status) { - fprintf(stream, _("%s: usage is %s \ -[ --version ] [ --help ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\ -\t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\ -\n\ -Report bugs to %s.\n"), - progname, progname, REPORT_BUGS_TO); - exit(status); + fprintf(stream, + _("%s: usage is %s [ --version ] [ --help ] [ -v ] \\\n" + "\t[ -l localtime ] [ -p posixrules ] [ -d directory ] \\\n" + "\t[ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\n" + "Report bugs to %s.\n"), + progname, progname, REPORT_BUGS_TO); + if (status == EXIT_SUCCESS) + close_file(stream, NULL); + exit(status); } static const char * psxrules; @@ -491,12 +508,13 @@ main(int argc, char **argv) if (TYPE_BIT(zic_t) < 64) { fprintf(stderr, "%s: %s\n", progname, _("wild compilation-time specification of zic_t")); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { printf("zic %s%s\n", PKGVERSION, TZVERSION); - exit(EXIT_SUCCESS); + close_file(stdout, NULL); + return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } @@ -511,7 +529,7 @@ main(int argc, char **argv) fprintf(stderr, _("%s: More than one -d option specified\n"), progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'l': @@ -521,7 +539,7 @@ _("%s: More than one -d option specified\n"), fprintf(stderr, _("%s: More than one -l option specified\n"), progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'p': @@ -531,7 +549,7 @@ _("%s: More than one -l option specified\n"), fprintf(stderr, _("%s: More than one -p option specified\n"), progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'y': @@ -541,7 +559,7 @@ _("%s: More than one -p option specified\n"), fprintf(stderr, _("%s: More than one -y option specified\n"), progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'L': @@ -551,14 +569,14 @@ _("%s: More than one -y option specified\n"), fprintf(stderr, _("%s: More than one -L option specified\n"), progname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } break; case 'v': noise = TRUE; break; case 's': - printf("%s: -s ignored\n", progname); + warning(_("-s ignored\n")); break; } if (optind == argc - 1 && strcmp(argv[optind], "=") == 0) @@ -576,7 +594,7 @@ _("%s: More than one -L option specified\n"), for (i = optind; i < argc; ++i) infile(argv[i]); if (errors) - exit(EXIT_FAILURE); + return EXIT_FAILURE; associate(); for (i = 0; i < nzones; i = j) { /* @@ -599,14 +617,16 @@ _("%s: More than one -L option specified\n"), warning(_("link to link")); } if (lcltime != NULL) { - eat("command line", 1); + eat(_("command line"), 1); dolink(lcltime, TZDEFAULT); } if (psxrules != NULL) { - eat("command line", 1); + eat(_("command line"), 1); dolink(psxrules, TZDEFRULES); } - return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + if (warnings && (ferror(stderr) || fclose(stderr) != 0)) + return EXIT_FAILURE; + return errors ? EXIT_FAILURE : EXIT_SUCCESS; } static void @@ -695,9 +715,9 @@ dolink(const char *const fromfield, const char *const tofield) */ fromisdir = itsdir(fromname); if (fromisdir) { - int err = fromisdir < 0 ? errno : EPERM; + char const *e = strerror(fromisdir < 0 ? errno : EPERM); fprintf(stderr, _("%s: link from %s failed: %s"), - progname, fromname, strerror(err)); + progname, fromname, e); exit(EXIT_FAILURE); } if (itsdir(toname) <= 0) @@ -753,18 +773,8 @@ warning(_("hard link failed, symbolic link used")); } while ((c = getc(fp)) != EOF) putc(c, tp); - if (ferror(fp) || fclose(fp)) { - fprintf(stderr, - _("%s: Error reading %s\n"), - progname, fromname); - exit(EXIT_FAILURE); - } - if (ferror(tp) || fclose(tp)) { - fprintf(stderr, - _("%s: Error writing %s\n"), - progname, toname); - exit(EXIT_FAILURE); - } + close_file(fp, fromname); + close_file(tp, toname); warning(_("link failed, copy used")); } } @@ -981,7 +991,7 @@ infile(const char *name) break; case LC_LEAP: if (name != leapsec) - fprintf(stderr, + warning( _("%s: Leap line in non leap seconds file %s\n"), progname, name); else inleap(fields, nfields); @@ -996,18 +1006,7 @@ _("%s: panic: Invalid l_value %d\n"), } free(fields); } - if (ferror(fp)) { - fprintf(stderr, _("%s: Error reading %s\n"), - progname, filename); - exit(EXIT_FAILURE); - } - if (fp != stdin && fclose(fp)) { - const char *e = strerror(errno); - - fprintf(stderr, _("%s: Error closing %s: %s\n"), - progname, filename, e); - exit(EXIT_FAILURE); - } + close_file(fp, filename); if (wantcont) error(_("expected continuation line not found")); } @@ -1850,11 +1849,7 @@ writezone(const char *const name, const char *const string, char version) putc(ttisgmts[i], fp); } fprintf(fp, "\n%s\n", string); - if (ferror(fp) || fclose(fp)) { - fprintf(stderr, _("%s: Error writing %s\n"), - progname, fullname); - exit(EXIT_FAILURE); - } + close_file(fp, fullname); free(ats); } @@ -2920,10 +2915,10 @@ mkdirs(char *argname) if (mkdir(name, MKDIR_UMASK) != 0) { int err = errno; if (itsdir(name) <= 0) { - fprintf(stderr, - _("%s: Can't create directory" - " %s: %s\n"), - progname, name, strerror(err)); + char const *e = strerror(err); + warning(_("%s: Can't create directory" + " %s: %s\n"), + progname, name, e); free(name); return -1; } -- 1.9.1
On Tue, Aug 19, 2014 at 8:27 AM, Paul Eggert <eggert@cs.ucla.edu> wrote:
* zic.c (warnings): New static var. (warning): Set it here. (size_product, growalloc, main): Translate diagnostic. (verror): Don't increment errors here. (error): Set it here. (close_file): New function. (usage, dolink, infile, writezone): Use it. (usage): Fit diagnostic in output lines better. (main): Prefer 'return X;' to 'exit(X);'. (main, infile, mkdirs): Use 'warning' for warnings. Check for stderr output error. (dolink, mkdirs): Don't assume gettext preserves errno.
IMO, this would be much better as a number of separate patches: - Translate diagnostic - Replace exit() with return - Extract close_file function and (possibly separately) start using it - Start using warning() for warnings - Introduce warnings variable and start using it Etc, separation of concerns over commits. This makes it much easier to review. Cheers, Dirkjan
Dirkjan Ochtman wrote:
this would be much better as a number of separate patches:
That's debatable. Given a set of closely related patches, I often find it more efficient to review them all at one go rather than one at a time. In this case it also happened to be easier for me to generate and perhaps I'm biased by that, but there it is. More generally, I would rather avoid the bureaucratic overhead of splitting patches unless there's a significant win in doing so. Many patches that I write could technically be split into dozens of niggling little independent changes, but the overall utility of doing it that way would be negative -- certainly for me, and I expect even when reviewer labor is taken into account. While we're on the subject: my apologies for the two Turks & Caicos patches proposed here: http://mm.icann.org/pipermail/tz/2014-August/021471.html http://mm.icann.org/pipermail/tz/2014-August/021471.html These should have been one patch, but I didn't notice the possible simplification in the latter patch until the first one was already published. Arguably the recent proposed changes to zic.c and zdump.c http://mm.icann.org/pipermail/tz/2014-August/021467.html http://mm.icann.org/pipermail/tz/2014-August/021469.html should have been one patch too, but that's a closer call.
On Tue, Aug 19, 2014 at 10:52 AM, Paul Eggert <eggert@cs.ucla.edu> wrote:
That's debatable. Given a set of closely related patches, I often find it more efficient to review them all at one go rather than one at a time. In this case it also happened to be easier for me to generate and perhaps I'm biased by that, but there it is.
I understand that they're easier to generate; I often generate mine in one go, and then split them out with git add -i.
More generally, I would rather avoid the bureaucratic overhead of splitting patches unless there's a significant win in doing so. Many patches that I write could technically be split into dozens of niggling little independent changes, but the overall utility of doing it that way would be negative -- certainly for me, and I expect even when reviewer labor is taken into account.
I've always found that review time on single-purpose refactoring patches is exponentially less than the review time on the combined patch, and I also don't see much overhead in doing it that way. But I guess it depends on what tools you use. Cheers, Dirkjan
participants (2)
-
Dirkjan Ochtman -
Paul Eggert