]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: regularize struct initializers
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 30 Aug 2023 14:39:34 +0000 (07:39 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 31 Aug 2023 03:32:13 +0000 (20:32 -0700)
* 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.

src/chmod.c
src/df.c
src/iopoll.c
src/ls.c
src/pathchk.c
src/printf.c
src/shred.c
src/stat.c
src/timeout.c
src/tr.c
src/wc.c

index de0c5d07c69958762f5063d1ebd6cc14f87716b2..014757d9dfab916c6d7e203c273fe837799e462f 100644 (file)
@@ -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)
index e127fc2dbc787b94a57a476104f86efe958b59dd..c5eb820517f640abb46636c0afa1869cb2182fe5 100644 (file)
--- 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)
index e60e0197eda9dc17fdea64eb3b20d8381c4eb6f2..4599f59a75ffb11c36f9039951fb5392c89898e5 100644 (file)
@@ -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,
index d5ef093eb980a4ca69d5a2e542d6952d9cc326b4..900d993161565ed9f000cd02a69e0df1c3ee1ec9 100644 (file)
--- 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;
index 9614294f4f2fc9f5c427fb942607b3bc79d96340..74ff1fa098b6e8b699b440cc7d3dc4880d8cb6c3 100644 (file)
@@ -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"),
index 063f077360e2e2b395675d9313457d114754810d..9670d80433e6dbecde0c1befc8b0b0af383040b7 100644 (file)
@@ -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;                                                \
index b2cf7220e43007c4b3d734871d23a29548095713..f3d04b27a3ceda3746c249b14eaf137b3d727fd4 100644 (file)
@@ -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;
index dd86450991abcddb6112ea560050f74ea73bd5e1..33929b05b8e6dcc1644537f2b5f7a6128c0e7f4e 100644 (file)
@@ -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)
     {
index d2eedc6e0e9980302927a79c52fb0bc9072a06ec..88a1190d0519618ab8861803acdc35b6e5bade3f 100644 (file)
@@ -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
index db91eb24f344427570bba6a4a38623f420e7616d..625c275832b0ea4498a39f0cd3338caa934499c4 100644 (file)
--- 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)
index 29114c874fa06a08765f77f813a195127eb6512c..41779f55dbaa109462267c0d7293237d555047f7 100644 (file)
--- 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