[PROPOSED 1/5] * zic.8: fix minus typo
--- zic.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zic.8 b/zic.8 index 0cd0781..e8816e5 100644 --- a/zic.8 +++ b/zic.8 @@ -145,7 +145,7 @@ outputs data intended only for nonnegative timestamps that fit into 31-bit signed integers. On platforms with GNU .BR date , -.q "zic \-r @$(date +%s)" +.q "zic \*-r @$(date +%s)" omits data intended for past timestamps. Although this option typically reduces the output file's size, the size can increase due to the need to represent the timestamp range -- 2.34.1
In preparing the recent zic.c patch I found it hard to follow the inconsistent indenting within #if and #ifdef blocks. Make it more consistent. This changes only white space. --- asctime.c | 8 ++++---- date.c | 8 ++++---- localtime.c | 26 +++++++++++++------------- private.h | 48 ++++++++++++++++++++++++------------------------ strftime.c | 10 +++++----- tzfile.h | 14 +++++++------- zdump.c | 10 +++++----- zic.c | 12 ++++++------ 8 files changed, 68 insertions(+), 68 deletions(-) diff --git a/asctime.c b/asctime.c index 56c54b3..68fbb80 100644 --- a/asctime.c +++ b/asctime.c @@ -35,9 +35,9 @@ ** but many implementations pad anyway; most likely the standards are buggy. */ #ifdef __GNUC__ -#define ASCTIME_FMT "%s %s%3d %2.2d:%2.2d:%2.2d %-4s\n" +# define ASCTIME_FMT "%s %s%3d %2.2d:%2.2d:%2.2d %-4s\n" #else /* !defined __GNUC__ */ -#define ASCTIME_FMT "%s %s%3d %02.2d:%02.2d:%02.2d %-4s\n" +# define ASCTIME_FMT "%s %s%3d %02.2d:%02.2d:%02.2d %-4s\n" #endif /* !defined __GNUC__ */ /* ** For years that are more than four digits we put extra spaces before the year @@ -46,9 +46,9 @@ ** that no output is better than wrong output). */ #ifdef __GNUC__ -#define ASCTIME_FMT_B "%s %s%3d %2.2d:%2.2d:%2.2d %s\n" +# define ASCTIME_FMT_B "%s %s%3d %2.2d:%2.2d:%2.2d %s\n" #else /* !defined __GNUC__ */ -#define ASCTIME_FMT_B "%s %s%3d %02.2d:%02.2d:%02.2d %s\n" +# define ASCTIME_FMT_B "%s %s%3d %02.2d:%02.2d:%02.2d %s\n" #endif /* !defined __GNUC__ */ #define STD_ASCTIME_BUF_SIZE 26 diff --git a/date.c b/date.c index b04d3f2..4c72b21 100644 --- a/date.c +++ b/date.c @@ -36,11 +36,11 @@ */ #ifndef TM_YEAR_BASE -#define TM_YEAR_BASE 1900 +# define TM_YEAR_BASE 1900 #endif /* !defined TM_YEAR_BASE */ #ifndef SECSPERMIN -#define SECSPERMIN 60 +# define SECSPERMIN 60 #endif /* !defined SECSPERMIN */ #if !HAVE_POSIX_DECLS @@ -70,9 +70,9 @@ main(const int argc, char *argv[]) setlocale(LC_ALL, ""); #endif /* defined(LC_ALL) */ #if HAVE_GETTEXT -#ifdef TZ_DOMAINDIR +# ifdef TZ_DOMAINDIR bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); -#endif /* defined(TEXTDOMAINDIR) */ +# endif /* defined(TEXTDOMAINDIR) */ textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ t = time(NULL); diff --git a/localtime.c b/localtime.c index 3db7821..6380146 100644 --- a/localtime.c +++ b/localtime.c @@ -29,16 +29,16 @@ static void unlock(void) { } #endif #ifndef TZ_ABBR_MAX_LEN -#define TZ_ABBR_MAX_LEN 16 +# define TZ_ABBR_MAX_LEN 16 #endif /* !defined TZ_ABBR_MAX_LEN */ #ifndef TZ_ABBR_CHAR_SET -#define TZ_ABBR_CHAR_SET \ +# define TZ_ABBR_CHAR_SET \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._" #endif /* !defined TZ_ABBR_CHAR_SET */ #ifndef TZ_ABBR_ERR_CHAR -#define TZ_ABBR_ERR_CHAR '_' +# define TZ_ABBR_ERR_CHAR '_' #endif /* !defined TZ_ABBR_ERR_CHAR */ /* @@ -46,10 +46,10 @@ static void unlock(void) { } */ #ifdef O_BINARY -#define OPEN_MODE (O_RDONLY | O_BINARY) +# define OPEN_MODE (O_RDONLY | O_BINARY) #endif /* defined O_BINARY */ #ifndef O_BINARY -#define OPEN_MODE O_RDONLY +# define OPEN_MODE O_RDONLY #endif /* !defined O_BINARY */ #ifndef WILDABBR @@ -72,7 +72,7 @@ static void unlock(void) { } ** manual page of what this "time zone abbreviation" means (doing this so ** that tzname[0] has the "normal" length of three characters). */ -#define WILDABBR " " +# define WILDABBR " " #endif /* !defined WILDABBR */ static const char wildabbr[] = WILDABBR; @@ -86,7 +86,7 @@ static const char gmt[] = "GMT"; ** for historical reasons, US rules are a common default. */ #ifndef TZDEFRULESTRING -#define TZDEFRULESTRING ",M3.2.0,M11.1.0" +# define TZDEFRULESTRING ",M3.2.0,M11.1.0" #endif struct ttinfo { /* time type information */ @@ -112,10 +112,10 @@ static char const UNSPEC[] = "-00"; enum { CHARS_EXTRA = max(sizeof UNSPEC, 2) - 1 }; #ifdef TZNAME_MAX -#define MY_TZNAME_MAX TZNAME_MAX +# define MY_TZNAME_MAX TZNAME_MAX #endif /* defined TZNAME_MAX */ #ifndef TZNAME_MAX -#define MY_TZNAME_MAX 255 +# define MY_TZNAME_MAX 255 #endif /* !defined TZNAME_MAX */ struct state { @@ -171,12 +171,12 @@ static struct state * gmtptr; #ifndef ALL_STATE static struct state lclmem; static struct state gmtmem; -#define lclptr (&lclmem) -#define gmtptr (&gmtmem) +# define lclptr (&lclmem) +# define gmtptr (&gmtmem) #endif /* State Farm */ #ifndef TZ_STRLEN_MAX -#define TZ_STRLEN_MAX 255 +# define TZ_STRLEN_MAX 255 #endif /* !defined TZ_STRLEN_MAX */ static char lcl_TZname[TZ_STRLEN_MAX + 1]; @@ -1860,7 +1860,7 @@ ctime_r(const time_t *timep, char *buf) */ #ifndef WRONG -#define WRONG (-1) +# define WRONG (-1) #endif /* !defined WRONG */ /* diff --git a/private.h b/private.h index b083c1b..ff98608 100644 --- a/private.h +++ b/private.h @@ -36,7 +36,7 @@ */ #ifndef HAVE_DECL_ASCTIME_R -#define HAVE_DECL_ASCTIME_R 1 +# define HAVE_DECL_ASCTIME_R 1 #endif #if !defined HAVE_GENERIC && defined __has_extension @@ -55,51 +55,51 @@ #endif #ifndef HAVE_GETTEXT -#define HAVE_GETTEXT 0 +# define HAVE_GETTEXT 0 #endif /* !defined HAVE_GETTEXT */ #ifndef HAVE_INCOMPATIBLE_CTIME_R -#define HAVE_INCOMPATIBLE_CTIME_R 0 +# define HAVE_INCOMPATIBLE_CTIME_R 0 #endif #ifndef HAVE_LINK -#define HAVE_LINK 1 +# define HAVE_LINK 1 #endif /* !defined HAVE_LINK */ #ifndef HAVE_MALLOC_ERRNO -#define HAVE_MALLOC_ERRNO 1 +# define HAVE_MALLOC_ERRNO 1 #endif #ifndef HAVE_POSIX_DECLS -#define HAVE_POSIX_DECLS 1 +# define HAVE_POSIX_DECLS 1 #endif #ifndef HAVE_STDBOOL_H -#define HAVE_STDBOOL_H (199901 <= __STDC_VERSION__) +# define HAVE_STDBOOL_H (199901 <= __STDC_VERSION__) #endif #ifndef HAVE_STRDUP -#define HAVE_STRDUP 1 +# define HAVE_STRDUP 1 #endif #ifndef HAVE_STRTOLL -#define HAVE_STRTOLL 1 +# define HAVE_STRTOLL 1 #endif #ifndef HAVE_SYMLINK -#define HAVE_SYMLINK 1 +# define HAVE_SYMLINK 1 #endif /* !defined HAVE_SYMLINK */ #ifndef HAVE_SYS_STAT_H -#define HAVE_SYS_STAT_H 1 +# define HAVE_SYS_STAT_H 1 #endif /* !defined HAVE_SYS_STAT_H */ #ifndef HAVE_UNISTD_H -#define HAVE_UNISTD_H 1 +# define HAVE_UNISTD_H 1 #endif /* !defined HAVE_UNISTD_H */ #ifndef HAVE_UTMPX_H -#define HAVE_UTMPX_H 1 +# define HAVE_UTMPX_H 1 #endif /* !defined HAVE_UTMPX_H */ #ifndef NETBSD_INSPIRED @@ -107,8 +107,8 @@ #endif #if HAVE_INCOMPATIBLE_CTIME_R -#define asctime_r _incompatible_asctime_r -#define ctime_r _incompatible_ctime_r +# define asctime_r _incompatible_asctime_r +# define ctime_r _incompatible_ctime_r #endif /* HAVE_INCOMPATIBLE_CTIME_R */ /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems. */ @@ -182,11 +182,11 @@ #endif #if HAVE_GETTEXT -#include <libintl.h> +# include <libintl.h> #endif /* HAVE_GETTEXT */ #if HAVE_UNISTD_H -#include <unistd.h> /* for R_OK, and other POSIX goodness */ +# include <unistd.h> /* for R_OK, and other POSIX goodness */ #endif /* HAVE_UNISTD_H */ #ifndef HAVE_STRFTIME_L @@ -222,7 +222,7 @@ #endif #ifndef R_OK -#define R_OK 4 +# define R_OK 4 #endif /* !defined R_OK */ /* @@ -232,14 +232,14 @@ ** stdint.h, even with pre-C99 compilers. */ #ifndef HAVE_STDINT_H -#define HAVE_STDINT_H \ +# define HAVE_STDINT_H \ (199901 <= __STDC_VERSION__ \ - || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \ + || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \ || __CYGWIN__ || INTMAX_MAX) #endif /* !defined HAVE_STDINT_H */ #if HAVE_STDINT_H -#include <stdint.h> +# include <stdint.h> #endif /* !HAVE_STDINT_H */ #ifndef HAVE_INTTYPES_H @@ -358,14 +358,14 @@ typedef unsigned long uintmax_t; #endif #ifndef INT32_MAX -#define INT32_MAX 0x7fffffff +# define INT32_MAX 0x7fffffff #endif /* !defined INT32_MAX */ #ifndef INT32_MIN -#define INT32_MIN (-1 - INT32_MAX) +# define INT32_MIN (-1 - INT32_MAX) #endif /* !defined INT32_MIN */ #ifndef SIZE_MAX -#define SIZE_MAX ((size_t) -1) +# define SIZE_MAX ((size_t) -1) #endif #if 3 <= __GNUC__ diff --git a/strftime.c b/strftime.c index 56e762b..7425a64 100644 --- a/strftime.c +++ b/strftime.c @@ -113,7 +113,7 @@ static char * _fmt(const char *, const struct tm *, char *, const char *, static char * _yconv(int, int, bool, bool, char *, char const *); #ifndef YEAR_2000_NAME -#define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS" +# define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS" #endif /* !defined YEAR_2000_NAME */ #if HAVE_STRFTIME_L @@ -551,15 +551,15 @@ label: # endif negative = diff < 0; if (diff == 0) { -#ifdef TM_ZONE +# ifdef TM_ZONE negative = t->TM_ZONE[0] == '-'; -#else +# else negative = t->tm_isdst < 0; -# if HAVE_TZNAME +# if HAVE_TZNAME if (tzname[t->tm_isdst != 0][0] == '-') negative = true; +# endif # endif -#endif } if (negative) { sign = "-"; diff --git a/tzfile.h b/tzfile.h index 9c3ea4e..6b18d6b 100644 --- a/tzfile.h +++ b/tzfile.h @@ -22,15 +22,15 @@ */ #ifndef TZDIR -#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ +# define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ #endif /* !defined TZDIR */ #ifndef TZDEFAULT -#define TZDEFAULT "/etc/localtime" +# define TZDEFAULT "/etc/localtime" #endif /* !defined TZDEFAULT */ #ifndef TZDEFRULES -#define TZDEFRULES "posixrules" +# define TZDEFRULES "posixrules" #endif /* !defined TZDEFRULES */ @@ -103,21 +103,21 @@ struct tzhead { */ #ifndef TZ_MAX_TIMES -#define TZ_MAX_TIMES 2000 +# define TZ_MAX_TIMES 2000 #endif /* !defined TZ_MAX_TIMES */ #ifndef TZ_MAX_TYPES /* This must be at least 17 for Europe/Samara and Europe/Vilnius. */ -#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ +# define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ #endif /* !defined TZ_MAX_TYPES */ #ifndef TZ_MAX_CHARS -#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ +# define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ /* (limited by what unsigned chars can hold) */ #endif /* !defined TZ_MAX_CHARS */ #ifndef TZ_MAX_LEAPS -#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ +# define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ #endif /* !defined TZ_MAX_LEAPS */ #endif /* !defined TZFILE_H */ diff --git a/zdump.c b/zdump.c index b10f574..b153812 100644 --- a/zdump.c +++ b/zdump.c @@ -35,11 +35,11 @@ #endif #ifndef ZDUMP_LO_YEAR -#define ZDUMP_LO_YEAR (-500) +# define ZDUMP_LO_YEAR (-500) #endif /* !defined ZDUMP_LO_YEAR */ #ifndef ZDUMP_HI_YEAR -#define ZDUMP_HI_YEAR 2500 +# define ZDUMP_HI_YEAR 2500 #endif /* !defined ZDUMP_HI_YEAR */ #define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR) @@ -72,7 +72,7 @@ enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 }; #endif #if HAVE_GETTEXT -#include <locale.h> /* for setlocale */ +# include <locale.h> /* for setlocale */ #endif /* HAVE_GETTEXT */ #if ! HAVE_LOCALTIME_RZ @@ -450,9 +450,9 @@ main(int argc, char *argv[]) cuthitime = absolute_max_time; #if HAVE_GETTEXT setlocale(LC_ALL, ""); -#ifdef TZ_DOMAINDIR +# ifdef TZ_DOMAINDIR bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); -#endif /* defined TEXTDOMAINDIR */ +# endif /* defined TEXTDOMAINDIR */ textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ progname = argv[0]; diff --git a/zic.c b/zic.c index e081c3d..7742422 100644 --- a/zic.c +++ b/zic.c @@ -29,7 +29,7 @@ typedef int_fast64_t zic_t; #define SCNdZIC SCNdFAST64 #ifndef ZIC_MAX_ABBR_LEN_WO_WARN -#define ZIC_MAX_ABBR_LEN_WO_WARN 6 +# define ZIC_MAX_ABBR_LEN_WO_WARN 6 #endif /* !defined ZIC_MAX_ABBR_LEN_WO_WARN */ #ifdef HAVE_DIRECT_H @@ -40,12 +40,12 @@ typedef int_fast64_t zic_t; #endif #if HAVE_SYS_STAT_H -#include <sys/stat.h> +# include <sys/stat.h> #endif #ifdef S_IRUSR -#define MKDIR_UMASK (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) +# define MKDIR_UMASK (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) #else -#define MKDIR_UMASK 0755 +# define MKDIR_UMASK 0755 #endif /* The maximum ptrdiff_t value, for pre-C99 platforms. */ @@ -765,9 +765,9 @@ main(int argc, char **argv) #endif #if HAVE_GETTEXT setlocale(LC_ALL, ""); -#ifdef TZ_DOMAINDIR +# ifdef TZ_DOMAINDIR bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); -#endif /* defined TEXTDOMAINDIR */ +# endif /* defined TEXTDOMAINDIR */ textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ progname = argv[0]; -- 2.34.1
* date.c (TM_YEAR_BASE, SECSPERMIN): Remove duplicate macros. --- date.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/date.c b/date.c index 4c72b21..5c511ba 100644 --- a/date.c +++ b/date.c @@ -31,18 +31,6 @@ #include <locale.h> #include <stdio.h> -/* -** The two things date knows about time are. . . -*/ - -#ifndef TM_YEAR_BASE -# define TM_YEAR_BASE 1900 -#endif /* !defined TM_YEAR_BASE */ - -#ifndef SECSPERMIN -# define SECSPERMIN 60 -#endif /* !defined SECSPERMIN */ - #if !HAVE_POSIX_DECLS extern char * optarg; extern int optind; -- 2.34.1
Some compiler debugging formats do not represent C macros, making it more of a pain to debug at the source-code level. The macros in question mostly predate C89 when macros were more portable than enums, but it’s safe to use enums now. * asctime.c (ASCTIME_FMT, ASCTIME_FMT_B, STD_ASCTIME_BUF_SIZE): * date.c (INCR): * localtime.c (lclptr, gmtptr) [!ALL_STATE]: * private.h (SECSPERMIN, MINSPERHOUR, HOURSPERDAY) (DAYSPERWEEK, DAYSPERNYEAR, DAYSPERLYEAR, SECSPERHOUR) (MONSPERYEAR, YEARSPERREPEAT, TM_SUNDAY, TM_MONDAY, TM_TUESDAY) (TM_WEDNESDAY, TM_THURSDAY, TM_FRIDAY, TM_SATURDAY, TM_JANUARY) (TM_FEBRUARY, TM_MARCH, TM_APRIL, TM_MAY, TM_JUNE, TM_JULY) (TM_AUGUST, TM_SEPTEMBER, TM_OCTOBER, TM_NOVEMBER, TM_DECEMBER) (TM_YEAR_BASE, TM_WDAY_BASE, EPOCH_YEAR, EPOCH_WDAY): * strftime.c (Locale, DIVISOR): * zdump.c (DIVISOR): * zic.c (DC_DOM, DC_DOWGEQ, DC_DOWLEQ, LC_RULE, LC_ZONE) (LC_LINK, LC_LEAP, LC_EXPIRES, ZF_NAME, ZF_STDOFF, ZF_RULE) (ZF_FORMAT, ZF_TILYEAR, ZF_TILMONTH, ZF_TILDAY, ZF_TILTIME) (ZONE_MINFIELDS, ZONE_MAXFIELDS, ZFC_STDOFF, ZFC_RULE) (ZFC_FORMAT, ZFC_TILYEAR, ZFC_TILMONTH, ZFC_TILDAY, ZFC_TILTIME) (ZONEC_MINFIELDS, ZONEC_MAXFIELDS, RF_NAME, RF_LOYEAR) (RF_HIYEAR, RF_COMMAND, RF_MONTH, RF_DAY, RF_TOD, RF_SAVE) (RF_ABBRVAR, RULE_FIELDS, LF_TARGET, LF_LINKNAME, LINK_FIELDS) (LP_YEAR, LP_MONTH, LP_DAY, LP_TIME, LP_CORR, LP_ROLL) (LEAP_FIELDS, EXPIRES_FIELDS, MAX_FIELDS, YR_MINIMUM) (YR_MAXIMUM, YR_ONLY, TIME_T_BITS_IN_FILE): Replace macros with ordinary identifiers when this is easy. * asctime.c (MAX_ASCTIME_BUF_SIZE): * localtime.c (OPEN_MODE): Remove these macros. All uses removed. * localtime.c (O_BINARY): Define to 0 if not defined. --- asctime.c | 26 +++++----- date.c | 3 +- localtime.c | 15 +++--- private.h | 78 ++++++++++++++++-------------- strftime.c | 6 +-- zdump.c | 2 +- zic.c | 135 ++++++++++++++++++++++++++++++---------------------- 7 files changed, 143 insertions(+), 122 deletions(-) diff --git a/asctime.c b/asctime.c index 68fbb80..fd3b038 100644 --- a/asctime.c +++ b/asctime.c @@ -35,10 +35,10 @@ ** but many implementations pad anyway; most likely the standards are buggy. */ #ifdef __GNUC__ -# define ASCTIME_FMT "%s %s%3d %2.2d:%2.2d:%2.2d %-4s\n" -#else /* !defined __GNUC__ */ -# define ASCTIME_FMT "%s %s%3d %02.2d:%02.2d:%02.2d %-4s\n" -#endif /* !defined __GNUC__ */ +static char const ASCTIME_FMT[] = "%s %s%3d %2.2d:%2.2d:%2.2d %-4s\n"; +#else +static char const ASCTIME_FMT[] = "%s %s%3d %02.2d:%02.2d:%02.2d %-4s\n"; +#endif /* ** For years that are more than four digits we put extra spaces before the year ** so that code trying to overwrite the newline won't end up overwriting @@ -46,12 +46,12 @@ ** that no output is better than wrong output). */ #ifdef __GNUC__ -# define ASCTIME_FMT_B "%s %s%3d %2.2d:%2.2d:%2.2d %s\n" -#else /* !defined __GNUC__ */ -# define ASCTIME_FMT_B "%s %s%3d %02.2d:%02.2d:%02.2d %s\n" -#endif /* !defined __GNUC__ */ +static char const ASCTIME_FMT_B[] = "%s %s%3d %2.2d:%2.2d:%2.2d %s\n"; +#else +static char const ASCTIME_FMT_B[] = "%s %s%3d %02.2d:%02.2d:%02.2d %s\n"; +#endif -#define STD_ASCTIME_BUF_SIZE 26 +enum { STD_ASCTIME_BUF_SIZE = 26 }; /* ** Big enough for something such as ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n @@ -59,12 +59,10 @@ ** seven explicit spaces, two explicit colons, a newline, ** and a trailing NUL byte). ** The values above are for systems where an int is 32 bits and are provided -** as an example; the define below calculates the maximum for the system at +** as an example; the size expression below is a bound for the system at ** hand. */ -#define MAX_ASCTIME_BUF_SIZE (2*3+5*INT_STRLEN_MAXIMUM(int)+7+2+1+1) - -static char buf_asctime[MAX_ASCTIME_BUF_SIZE]; +static char buf_asctime[2*3 + 5*INT_STRLEN_MAXIMUM(int) + 7 + 2 + 1 + 1]; char * asctime_r(register const struct tm *timeptr, char *buf) @@ -79,7 +77,7 @@ asctime_r(register const struct tm *timeptr, char *buf) register const char * wn; register const char * mn; char year[INT_STRLEN_MAXIMUM(int) + 2]; - char result[MAX_ASCTIME_BUF_SIZE]; + char result[sizeof buf_asctime]; if (timeptr == NULL) { errno = EINVAL; diff --git a/date.c b/date.c index 5c511ba..56e6c87 100644 --- a/date.c +++ b/date.c @@ -180,8 +180,6 @@ display(char const *format, time_t now) } } -#define INCR 1024 - static void timeout(FILE *fp, char const *format, struct tm const *tmp) { @@ -189,6 +187,7 @@ timeout(FILE *fp, char const *format, struct tm const *tmp) size_t result; size_t size; struct tm tm; + int INCR = 1024; if (!tmp) { fprintf(stderr, _("date: error: time out of range\n")); diff --git a/localtime.c b/localtime.c index 6380146..7de9d9d 100644 --- a/localtime.c +++ b/localtime.c @@ -42,15 +42,12 @@ static void unlock(void) { } #endif /* !defined TZ_ABBR_ERR_CHAR */ /* -** SunOS 4.1.1 headers lack O_BINARY. +** Support non-POSIX platforms that distinguish between text and binary files. */ -#ifdef O_BINARY -# define OPEN_MODE (O_RDONLY | O_BINARY) -#endif /* defined O_BINARY */ #ifndef O_BINARY -# define OPEN_MODE O_RDONLY -#endif /* !defined O_BINARY */ +# define O_BINARY 0 +#endif #ifndef WILDABBR /* @@ -171,8 +168,8 @@ static struct state * gmtptr; #ifndef ALL_STATE static struct state lclmem; static struct state gmtmem; -# define lclptr (&lclmem) -# define gmtptr (&gmtmem) +static struct state *const lclptr = &lclmem; +static struct state *const gmtptr = &gmtmem; #endif /* State Farm */ #ifndef TZ_STRLEN_MAX @@ -451,7 +448,7 @@ tzloadbody(char const *name, struct state *sp, bool doextend, } if (doaccess && access(name, R_OK) != 0) return errno; - fid = open(name, OPEN_MODE); + fid = open(name, O_RDONLY | O_BINARY); if (fid < 0) return errno; diff --git a/private.h b/private.h index ff98608..9b9389f 100644 --- a/private.h +++ b/private.h @@ -742,47 +742,55 @@ char *ctime_r(time_t const *, char *); /* Handy macros that are independent of tzfile implementation. */ -#define SECSPERMIN 60 -#define MINSPERHOUR 60 -#define HOURSPERDAY 24 -#define DAYSPERWEEK 7 -#define DAYSPERNYEAR 365 -#define DAYSPERLYEAR 366 -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) +enum { + SECSPERMIN = 60, + MINSPERHOUR = 60, + SECSPERHOUR = SECSPERMIN * MINSPERHOUR, + HOURSPERDAY = 24, + DAYSPERWEEK = 7, + DAYSPERNYEAR = 365, + DAYSPERLYEAR = DAYSPERNYEAR + 1, + MONSPERYEAR = 12, + YEARSPERREPEAT = 400 /* years before a Gregorian repeat */ +}; + #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY) -#define MONSPERYEAR 12 -#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ #define DAYSPERREPEAT ((int_fast32_t) 400 * 365 + 100 - 4 + 1) #define SECSPERREPEAT ((int_fast64_t) DAYSPERREPEAT * SECSPERDAY) #define AVGSECSPERYEAR (SECSPERREPEAT / YEARSPERREPEAT) -#define TM_SUNDAY 0 -#define TM_MONDAY 1 -#define TM_TUESDAY 2 -#define TM_WEDNESDAY 3 -#define TM_THURSDAY 4 -#define TM_FRIDAY 5 -#define TM_SATURDAY 6 - -#define TM_JANUARY 0 -#define TM_FEBRUARY 1 -#define TM_MARCH 2 -#define TM_APRIL 3 -#define TM_MAY 4 -#define TM_JUNE 5 -#define TM_JULY 6 -#define TM_AUGUST 7 -#define TM_SEPTEMBER 8 -#define TM_OCTOBER 9 -#define TM_NOVEMBER 10 -#define TM_DECEMBER 11 - -#define TM_YEAR_BASE 1900 -#define TM_WDAY_BASE TM_MONDAY - -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY TM_THURSDAY +enum { + TM_SUNDAY, + TM_MONDAY, + TM_TUESDAY, + TM_WEDNESDAY, + TM_THURSDAY, + TM_FRIDAY, + TM_SATURDAY +}; + +enum { + TM_JANUARY, + TM_FEBRUARY, + TM_MARCH, + TM_APRIL, + TM_MAY, + TM_JUNE, + TM_JULY, + TM_AUGUST, + TM_SEPTEMBER, + TM_OCTOBER, + TM_NOVEMBER, + TM_DECEMBER +}; + +enum { + TM_YEAR_BASE = 1900, + TM_WDAY_BASE = TM_MONDAY, + EPOCH_YEAR = 1970, + EPOCH_WDAY = TM_THURSDAY +}; #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) diff --git a/strftime.c b/strftime.c index 7425a64..deba2b5 100644 --- a/strftime.c +++ b/strftime.c @@ -56,8 +56,6 @@ struct lc_time_T { const char * date_fmt; }; -#define Locale (&C_time_locale) - static const struct lc_time_T C_time_locale = { { "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -164,6 +162,8 @@ static char * _fmt(const char *format, const struct tm *t, char *pt, const char *ptlim, enum warn *warnp) { + struct lc_time_T const *Locale = &C_time_locale; + for ( ; *format; ++format) { if (*format == '%') { label: @@ -626,7 +626,7 @@ _yconv(int a, int b, bool convert_top, bool convert_yy, register int lead; register int trail; -#define DIVISOR 100 + int DIVISOR = 100; trail = a % DIVISOR + b % DIVISOR; lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR; trail %= DIVISOR; diff --git a/zdump.c b/zdump.c index b153812..a63a343 100644 --- a/zdump.c +++ b/zdump.c @@ -1193,6 +1193,7 @@ dumptime(register const struct tm *timeptr) }; register int lead; register int trail; + int DIVISOR = 10; /* ** The packaged localtime_rz and gmtime_r never put out-of-range @@ -1208,7 +1209,6 @@ dumptime(register const struct tm *timeptr) ? mon_name[timeptr->tm_mon] : "???"), timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); -#define DIVISOR 10 trail = timeptr->tm_year % DIVISOR + TM_YEAR_BASE % DIVISOR; lead = timeptr->tm_year / DIVISOR + TM_YEAR_BASE / DIVISOR + trail / DIVISOR; diff --git a/zic.c b/zic.c index 7742422..a29f679 100644 --- a/zic.c +++ b/zic.c @@ -96,12 +96,13 @@ struct rule { }; /* -** r_dycode r_dayofmonth r_wday +** r_dycode r_dayofmonth r_wday */ - -#define DC_DOM 0 /* 1..31 */ /* unused */ -#define DC_DOWGEQ 1 /* 1..31 */ /* 0..6 (Sun..Sat) */ -#define DC_DOWLEQ 2 /* 1..31 */ /* 0..6 (Sun..Sat) */ +enum { + DC_DOM, /* 1..31 */ /* unused */ + DC_DOWGEQ, /* 1..31 */ /* 0..6 (Sun..Sat) */ + DC_DOWLEQ /* 1..31 */ /* 0..6 (Sun..Sat) */ +}; struct zone { const char * z_filename; @@ -213,89 +214,107 @@ static int unspecifiedtype; ** Line codes. */ -#define LC_RULE 0 -#define LC_ZONE 1 -#define LC_LINK 2 -#define LC_LEAP 3 -#define LC_EXPIRES 4 +enum { + LC_RULE, + LC_ZONE, + LC_LINK, + LC_LEAP, + LC_EXPIRES +}; /* ** Which fields are which on a Zone line. */ -#define ZF_NAME 1 -#define ZF_STDOFF 2 -#define ZF_RULE 3 -#define ZF_FORMAT 4 -#define ZF_TILYEAR 5 -#define ZF_TILMONTH 6 -#define ZF_TILDAY 7 -#define ZF_TILTIME 8 -#define ZONE_MINFIELDS 5 -#define ZONE_MAXFIELDS 9 +enum { + ZF_NAME = 1, + ZF_STDOFF, + ZF_RULE, + ZF_FORMAT, + ZF_TILYEAR, + ZF_TILMONTH, + ZF_TILDAY, + ZF_TILTIME, + ZONE_MAXFIELDS, + ZONE_MINFIELDS = ZF_TILYEAR +}; /* ** Which fields are which on a Zone continuation line. */ -#define ZFC_STDOFF 0 -#define ZFC_RULE 1 -#define ZFC_FORMAT 2 -#define ZFC_TILYEAR 3 -#define ZFC_TILMONTH 4 -#define ZFC_TILDAY 5 -#define ZFC_TILTIME 6 -#define ZONEC_MINFIELDS 3 -#define ZONEC_MAXFIELDS 7 +enum { + ZFC_STDOFF, + ZFC_RULE, + ZFC_FORMAT, + ZFC_TILYEAR, + ZFC_TILMONTH, + ZFC_TILDAY, + ZFC_TILTIME, + ZONEC_MAXFIELDS, + ZONEC_MINFIELDS = ZFC_TILYEAR +}; /* ** Which files are which on a Rule line. */ -#define RF_NAME 1 -#define RF_LOYEAR 2 -#define RF_HIYEAR 3 -#define RF_COMMAND 4 -#define RF_MONTH 5 -#define RF_DAY 6 -#define RF_TOD 7 -#define RF_SAVE 8 -#define RF_ABBRVAR 9 -#define RULE_FIELDS 10 +enum { + RF_NAME = 1, + RF_LOYEAR, + RF_HIYEAR, + RF_COMMAND, + RF_MONTH, + RF_DAY, + RF_TOD, + RF_SAVE, + RF_ABBRVAR, + RULE_FIELDS +}; /* ** Which fields are which on a Link line. */ -#define LF_TARGET 1 -#define LF_LINKNAME 2 -#define LINK_FIELDS 3 +enum { + LF_TARGET = 1, + LF_LINKNAME, + LINK_FIELDS +}; /* ** Which fields are which on a Leap line. */ -#define LP_YEAR 1 -#define LP_MONTH 2 -#define LP_DAY 3 -#define LP_TIME 4 -#define LP_CORR 5 -#define LP_ROLL 6 -#define LEAP_FIELDS 7 - -/* Expires lines are like Leap lines, except without CORR and ROLL fields. */ -#define EXPIRES_FIELDS 5 +enum { + LP_YEAR = 1, + LP_MONTH, + LP_DAY, + LP_TIME, + LP_CORR, + LP_ROLL, + LEAP_FIELDS, + + /* Expires lines are like Leap lines, except without CORR and ROLL fields. */ + EXPIRES_FIELDS = LP_TIME + 1 +}; -/* The maximum number of fields on any of the above lines. */ -#define MAX_FIELDS RULE_FIELDS +/* The maximum number of fields on any of the above lines. + (The "+"s pacify gcc -Wenum-compare.) */ +enum { + MAX_FIELDS = max(max(+RULE_FIELDS, +LINK_FIELDS), + max(+LEAP_FIELDS, +EXPIRES_FIELDS)) +}; /* ** Year synonyms. */ -#define YR_MINIMUM 0 -#define YR_MAXIMUM 1 -#define YR_ONLY 2 +enum { + YR_MINIMUM, + YR_MAXIMUM, + YR_ONLY +}; static struct rule * rules; static ptrdiff_t nrules; /* number of rules */ @@ -671,7 +690,7 @@ check_for_signal(void) } } -#define TIME_T_BITS_IN_FILE 64 +enum { TIME_T_BITS_IN_FILE = 64 }; /* The minimum and maximum values representable in a TZif file. */ static zic_t const min_time = MINVAL(zic_t, TIME_T_BITS_IN_FILE); -- 2.34.1
* asctime.c (ASCTIME_FMT, ASCTIME_FMT_B): Don’t worry about portability to pre-C89 C libraries. They are no longer of practical importance, and we can assume at least C89 by now. Also, don’t worry about warnings from ancient GCC. They were just warnings anyway, and they were warning about pre-C89 portability. --- asctime.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/asctime.c b/asctime.c index fd3b038..f0159f8 100644 --- a/asctime.c +++ b/asctime.c @@ -16,12 +16,6 @@ #include "private.h" #include <stdio.h> -/* -** Some systems only handle "%.2d"; others only handle "%02d"; -** "%02.2d" makes (most) everybody happy. -** At least some versions of gcc warn about the %02.2d; -** we conditionalize below to avoid the warning. -*/ /* ** All years associated with 32-bit time_t values are exactly four digits long; ** some years associated with 64-bit time_t values are not. @@ -34,22 +28,14 @@ ** The ISO C and POSIX standards prohibit padding the year, ** but many implementations pad anyway; most likely the standards are buggy. */ -#ifdef __GNUC__ -static char const ASCTIME_FMT[] = "%s %s%3d %2.2d:%2.2d:%2.2d %-4s\n"; -#else -static char const ASCTIME_FMT[] = "%s %s%3d %02.2d:%02.2d:%02.2d %-4s\n"; -#endif +static char const ASCTIME_FMT[] = "%s %s%3d %.2d:%.2d:%.2d %-4s\n"; /* ** For years that are more than four digits we put extra spaces before the year ** so that code trying to overwrite the newline won't end up overwriting ** a digit within a year and truncating the year (operating on the assumption ** that no output is better than wrong output). */ -#ifdef __GNUC__ -static char const ASCTIME_FMT_B[] = "%s %s%3d %2.2d:%2.2d:%2.2d %s\n"; -#else -static char const ASCTIME_FMT_B[] = "%s %s%3d %02.2d:%02.2d:%02.2d %s\n"; -#endif +static char const ASCTIME_FMT_B[] = "%s %s%3d %.2d:%.2d:%.2d %s\n"; enum { STD_ASCTIME_BUF_SIZE = 26 }; /* -- 2.34.1
participants (1)
-
Paul Eggert