From: Paul Eggert Date: Wed, 30 Aug 2023 14:39:34 +0000 (-0700) Subject: maint: regularize struct initializers X-Git-Tag: v9.5~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0326b0473837aae21fbf4c60674a5fcf85d9bf1;p=thirdparty%2Fcoreutils.git maint: regularize struct initializers * src/chmod.c (process_file): * src/df.c (replace_invalid_chars): * src/iopoll.c (iopoll_internal): * src/ls.c (quote_name_buf): * src/pathchk.c (portable_chars_only): * src/printf.c (STRTOX): * src/shred.c (main): * src/stat.c (neg_to_zero, do_stat): * src/timeout.c (settimeout): * src/tr.c (card_of_complement): * src/wc.c (wc): Prefer ‘{0}’ to initialize everything to zero. * src/stat.c (do_stat): * src/timeout.c (settimeout): Do not assume the usual order for struct members, as POSIX does not guarantee this. --- diff --git a/src/chmod.c b/src/chmod.c index de0c5d07c6..014757d9df 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -205,7 +205,7 @@ process_file (FTS *fts, FTSENT *ent) char const *file_full_name = ent->fts_path; char const *file = ent->fts_accpath; const struct stat *file_stats = ent->fts_statp; - struct change_status ch = { 0, }; + struct change_status ch = {0}; ch.status = CH_NO_STAT; switch (ent->fts_info) diff --git a/src/df.c b/src/df.c index e127fc2dbc..c5eb820517 100644 --- a/src/df.c +++ b/src/df.c @@ -319,7 +319,7 @@ replace_invalid_chars (char *cell) { char *srcend = cell + strlen (cell); char *dst = cell; - mbstate_t mbstate = { 0, }; + mbstate_t mbstate = {0}; size_t n; for (char *src = cell; src != srcend; src += n) diff --git a/src/iopoll.c b/src/iopoll.c index e60e0197ed..4599f59a75 100644 --- a/src/iopoll.c +++ b/src/iopoll.c @@ -113,7 +113,7 @@ iopoll_internal (int fdin, int fdout, bool block, bool broken_output) if (0 <= fdout) FD_SET (fdout, &fds); - struct timeval delay = { .tv_sec = 0, .tv_usec = 0 }; + struct timeval delay = {0}; ret = select (nfds, broken_output ? &fds : nullptr, broken_output ? nullptr : &fds, diff --git a/src/ls.c b/src/ls.c index d5ef093eb9..900d993161 100644 --- a/src/ls.c +++ b/src/ls.c @@ -4608,7 +4608,7 @@ quote_name_buf (char **inbuf, size_t bufsize, char *name, reach its end, replacing each non-printable multibyte character with a single question mark. */ { - mbstate_t mbstate = { 0, }; + mbstate_t mbstate = {0}; do { wchar_t wc; diff --git a/src/pathchk.c b/src/pathchk.c index 9614294f4f..74ff1fa098 100644 --- a/src/pathchk.c +++ b/src/pathchk.c @@ -188,7 +188,7 @@ portable_chars_only (char const *file, size_t filelen) if (*invalid) { - mbstate_t mbstate = { 0, }; + mbstate_t mbstate = {0}; size_t charlen = mbrlen (invalid, filelen - validlen, &mbstate); error (0, 0, _("non-portable character %s in file name %s"), diff --git a/src/printf.c b/src/printf.c index 063f077360..9670d80433 100644 --- a/src/printf.c +++ b/src/printf.c @@ -172,7 +172,7 @@ FUNC_NAME (char const *s) \ \ if (MB_CUR_MAX > 1 && *(s + 1)) \ { \ - mbstate_t mbstate = { 0, }; \ + mbstate_t mbstate = {0}; \ wchar_t wc; \ size_t slen = strlen (s); \ ssize_t bytes; \ diff --git a/src/shred.c b/src/shred.c index b2cf7220e4..f3d04b27a3 100644 --- a/src/shred.c +++ b/src/shred.c @@ -1161,7 +1161,7 @@ int main (int argc, char **argv) { bool ok = true; - struct Options flags = { 0, }; + struct Options flags = {0}; char **file; int n_files; int c; diff --git a/src/stat.c b/src/stat.c index dd86450991..33929b05b8 100644 --- a/src/stat.c +++ b/src/stat.c @@ -1039,7 +1039,7 @@ neg_to_zero (struct timespec ts) { if (0 <= ts.tv_nsec) return ts; - struct timespec z = {0, 0}; + struct timespec z = {0}; return z; } @@ -1370,11 +1370,11 @@ do_stat (char const *filename, char const *format, char const *format2) int fd = STREQ (filename, "-") ? 0 : AT_FDCWD; int flags = 0; struct stat st; - struct statx stx = { 0, }; + struct statx stx = {0}; char const *pathname = filename; struct print_args pa; pa.st = &st; - pa.btime = (struct timespec) {-1, -1}; + pa.btime = (struct timespec) {.tv_sec = -1, .tv_nsec = -1}; if (AT_FDCWD != fd) { @@ -1460,7 +1460,7 @@ do_stat (char const *filename, char const *format, struct stat statbuf; struct print_args pa; pa.st = &statbuf; - pa.btime = (struct timespec) {-1, -1}; + pa.btime = (struct timespec) {.tv_sec = -1, .tv_nsec = -1}; if (0 <= fd) { diff --git a/src/timeout.c b/src/timeout.c index d2eedc6e0e..88a1190d05 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -117,7 +117,7 @@ settimeout (double duration, bool warn) /* timer_settime() provides potentially nanosecond resolution. */ struct timespec ts = dtotimespec (duration); - struct itimerspec its = { {0, 0}, ts }; + struct itimerspec its = {.it_interval = {0}, .it_value = ts}; timer_t timerid; if (timer_create (CLOCK_REALTIME, nullptr, &timerid) == 0) { @@ -151,7 +151,7 @@ settimeout (double duration, bool warn) else tv.tv_usec--; } - struct itimerval it = { {0, 0}, tv }; + struct itimerval it = {.it_interval = {0}, .it_value = tv }; if (setitimer (ITIMER_REAL, &it, nullptr) == 0) return; else @@ -447,7 +447,7 @@ disable_core_dumps (void) #elif HAVE_SETRLIMIT && defined RLIMIT_CORE /* Note this doesn't disable processing by a filter in /proc/sys/kernel/core_pattern on Linux. */ - if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0,0}) == 0) + if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0}) == 0) return true; #else diff --git a/src/tr.c b/src/tr.c index db91eb24f3..625c275832 100644 --- a/src/tr.c +++ b/src/tr.c @@ -1138,7 +1138,7 @@ card_of_complement (struct Spec_list *s) { int c; int cardinality = N_CHARS; - bool in_set[N_CHARS] = { 0, }; + bool in_set[N_CHARS] = {0}; s->state = BEGIN_STATE; while ((c = get_next (s, nullptr)) != -1) diff --git a/src/wc.c b/src/wc.c index 29114c874f..41779f55db 100644 --- a/src/wc.c +++ b/src/wc.c @@ -452,7 +452,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos) { bool in_word = false; uintmax_t linepos = 0; - mbstate_t state = { 0, }; + mbstate_t state = {0}; bool in_shift = false; # if SUPPORT_OLD_MBRTOWC /* Back-up the state before each multibyte character conversion and