]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: use C99 initialization syntax for single-variable 'for' loops
authorCollin Funk <collin.funk1@gmail.com>
Mon, 17 Nov 2025 04:23:30 +0000 (20:23 -0800)
committerCollin Funk <collin.funk1@gmail.com>
Tue, 18 Nov 2025 03:10:40 +0000 (19:10 -0800)
* src/chroot.c (parse_additional_groups): Declare variable in the 'for'
clause.
* src/comm.c (compare_files): Likewise.
* src/cp.c (re_protect): Likewise.
* src/csplit.c (save_buffer, find_line, write_to_file)
(split_file, main): Likewise.
* src/dd.c (apply_translations, translate_buffer)
(copy_with_block, main): Likewise.
* src/df.c (selected_fstype, excluded_fstype, filter_mount_list)
(last_device_for_mount, get_device, get_point, get_all_entries)
(main): Likewise.
* src/fmt.c (copy_rest, get_prefix, fmt_paragraph, put_paragraph)
(put_word): Likewise.
* src/fold.c (main): Likewise.
* src/head.c (elide_tail_bytes_pipe, main): Likewise.
* src/install.c (main): Likewise.
* src/join.c (prfields, join, main): Likewise.
* src/kill.c (list_signals): Likewise.
* src/ls.c (main, decode_switches, parse_ls_color, patterns_match):
Likewise.
* src/operand2sig.c (operand2sig): Likewise.
* src/pathchk.c (no_leading_hyphen, validate_file_name): Likewise.
* src/pr.c (char_to_clump): Likewise.
* src/printenv.c (main): Likewise.
* src/ptx.c (initialize_regex, digest_break_file)
(find_occurs_in_text, print_field): Likewise.
* src/remove.c (mark_ancestor_dirs): Likewise.
* src/seq.c (print_numbers): Likewise.
* src/shred.c (do_wipefd, main): Likewise.
* src/sort.c (cleanup, inittables, key_warnings, mergefps)
(check_ordering_compatibility, main): Likewise.
* src/split.c (closeout): Likewise.
* src/stat.c (find_bind_mount, print_it, format_to_mask): Likewise.
* src/stdbuf.c (set_program_path): Likewise.
* src/stty.c (apply_settings, display_changed, display_all)
(recover_mode, sane_mode): Likewise.
* src/system.h (stzncpy): Likewise.
* src/tail.c (pipe_lines): Likewise.
* src/tee.c (tee_files): Likewise.
* src/tr.c (look_up_char_class, get_spec_stats): Likewise.
* src/users.c (list_entries_users): Likewise.

31 files changed:
src/chroot.c
src/comm.c
src/cp.c
src/csplit.c
src/dd.c
src/df.c
src/fmt.c
src/fold.c
src/head.c
src/install.c
src/join.c
src/kill.c
src/ls.c
src/operand2sig.c
src/pathchk.c
src/pr.c
src/printenv.c
src/ptx.c
src/remove.c
src/seq.c
src/shred.c
src/sort.c
src/split.c
src/stat.c
src/stdbuf.c
src/stty.c
src/system.h
src/tail.c
src/tee.c
src/tr.c
src/users.c

index 27cb15e72da505554df57331a8f8dca21e2050c1..67b1cb314a443586acbf1c90195e234c2996cd48 100644 (file)
@@ -99,10 +99,10 @@ parse_additional_groups (char const *groups, GETGROUPS_T **pgids,
   idx_t n_gids_allocated = 0;
   idx_t n_gids = 0;
   char *buffer = xstrdup (groups);
-  char const *tmp;
   int ret = 0;
 
-  for (tmp = strtok (buffer, ","); tmp; tmp = strtok (nullptr, ","))
+  for (char const *tmp = strtok (buffer, ","); tmp;
+       tmp = strtok (nullptr, ","))
     {
       struct group *g;
       uintmax_t value;
index 355f72b691ce4e14ae95d2ba33dea0c7f9e4a61b..ec2b4527003c8d05f647d608b029c9109cdbe190 100644 (file)
@@ -272,12 +272,10 @@ compare_files (char **infiles)
   /* Counters for the summary.  */
   uintmax_t total[] = {0, 0, 0};
 
-  int i, j;
-
   /* Initialize the storage. */
-  for (i = 0; i < 2; i++)
+  for (int i = 0; i < 2; i++)
     {
-      for (j = 0; j < 4; j++)
+      for (int j = 0; j < 4; j++)
         {
           initbuffer (&lba[i][j]);
           all_line[i][j] = &lba[i][j];
@@ -353,7 +351,7 @@ compare_files (char **infiles)
       if (order <= 0)
         fill_up[0] = true;
 
-      for (i = 0; i < 2; i++)
+      for (int i = 0; i < 2; i++)
         if (fill_up[i])
           {
             /* Rotate the buffers for this file. */
@@ -381,7 +379,7 @@ compare_files (char **infiles)
           }
     }
 
-  for (i = 0; i < 2; i++)
+  for (int i = 0; i < 2; i++)
     if (fclose (streams[i]) != 0)
       error (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
 
index 317d667ce0ab57eb3cfbb87a5ee3685c712a2e8f..42a89acd7b22bc4d2b0d2b7a32092e1880c6bfee 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -309,7 +309,6 @@ re_protect (char const *const_dst_name, char const *dst_src_name,
             int dst_dirfd, char const *dst_relname,
             struct dir_attr *attr_list, const struct cp_options *x)
 {
-  struct dir_attr *p;
   char *dst_name;              /* A copy of CONST_DST_NAME we can change. */
 
   ASSIGN_STRDUPA (dst_name, const_dst_name);
@@ -321,7 +320,7 @@ re_protect (char const *const_dst_name, char const *dst_src_name,
   /* Likewise, but with any leading '/'s skipped.  */
   char const *relname = dst_name + (dst_relname - const_dst_name);
 
-  for (p = attr_list; p; p = p->next)
+  for (struct dir_attr *p = attr_list; p; p = p->next)
     {
       dst_name[p->slash_offset] = '\0';
 
index 90468e864f4f461ad9e5c54e787b4ed69cfe2511..3ee89aff3407a7927fe09df1e5954dd96bc5877b 100644 (file)
@@ -423,8 +423,6 @@ get_new_buffer (idx_t min_size)
 static void
 save_buffer (struct buffer_record *buf)
 {
-  struct buffer_record *p;
-
   buf->next = nullptr;
   buf->curr_line = buf->line_start;
 
@@ -432,6 +430,7 @@ save_buffer (struct buffer_record *buf)
     head = buf;
   else
     {
+      struct buffer_record *p;
       for (p = head; p->next; p = p->next)
         /* Do nothing. */ ;
       p->next = buf;
@@ -563,15 +562,13 @@ remove_line (void)
 static struct cstring *
 find_line (intmax_t linenum)
 {
-  struct buffer_record *b;
-
   if (head == nullptr && !load_buffer ())
     return nullptr;
 
   if (linenum < head->start_line)
     return nullptr;
 
-  for (b = head;;)
+  for (struct buffer_record *b = head;;)
     {
       if (linenum < b->start_line + b->num_lines)
         {
@@ -624,7 +621,6 @@ write_to_file (intmax_t last_line, bool ignore, int argnum)
   struct cstring *line;
   intmax_t first_line;         /* First available input line. */
   intmax_t lines;              /* Number of lines to output. */
-  intmax_t i;
 
   first_line = get_first_line_in_buffer ();
 
@@ -637,7 +633,7 @@ write_to_file (intmax_t last_line, bool ignore, int argnum)
 
   lines = last_line - first_line;
 
-  for (i = 0; i < lines; i++)
+  for (intmax_t i = 0; i < lines; i++)
     {
       line = remove_line ();
       if (line == nullptr)
@@ -855,16 +851,15 @@ split_file (void)
 {
   for (idx_t i = 0; i < control_used; i++)
     {
-      intmax_t j;
       if (controls[i].regexpr)
         {
-          for (j = 0; (controls[i].repeat_forever
+          for (intmax_t j = 0; (controls[i].repeat_forever
                        || j <= controls[i].repeat); j++)
             process_regexp (&controls[i], j);
         }
       else
         {
-          for (j = 0; (controls[i].repeat_forever
+          for (intmax_t j = 0; (controls[i].repeat_forever
                        || j <= controls[i].repeat); j++)
             process_line_count (&controls[i], j);
         }
@@ -1370,7 +1365,6 @@ main (int argc, char **argv)
   parse_patterns (argc, optind, argv);
 
   {
-    int i;
     static int const sig[] =
       {
         /* The usual suspects.  */
@@ -1396,7 +1390,7 @@ main (int argc, char **argv)
     struct sigaction act;
 
     sigemptyset (&caught_signals);
-    for (i = 0; i < nsigs; i++)
+    for (int i = 0; i < nsigs; i++)
       {
         sigaction (sig[i], nullptr, &act);
         if (act.sa_handler != SIG_IGN)
@@ -1407,7 +1401,7 @@ main (int argc, char **argv)
     act.sa_mask = caught_signals;
     act.sa_flags = 0;
 
-    for (i = 0; i < nsigs; i++)
+    for (int i = 0; i < nsigs; i++)
       if (sigismember (&caught_signals, sig[i]))
         sigaction (sig[i], &act, nullptr);
   }
index 98f36008905111f61ef60d3914256413f78c200e..a12ef983928f610383de15f35f834da562e19c63 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -1691,20 +1691,18 @@ scanargs (int argc, char *const *argv)
 static void
 apply_translations (void)
 {
-  int i;
-
   if (conversions_mask & C_ASCII)
     translate_charset (ebcdic_to_ascii);
 
   if (conversions_mask & C_UCASE)
     {
-      for (i = 0; i < 256; i++)
+      for (int i = 0; i < 256; i++)
         trans_table[i] = toupper (trans_table[i]);
       translation_needed = true;
     }
   else if (conversions_mask & C_LCASE)
     {
-      for (i = 0; i < 256; i++)
+      for (int i = 0; i < 256; i++)
         trans_table[i] = tolower (trans_table[i]);
       translation_needed = true;
     }
@@ -1729,9 +1727,8 @@ apply_translations (void)
 static void
 translate_buffer (char *buf, idx_t nread)
 {
-  idx_t i;
-  char *cp;
-  for (i = nread, cp = buf; i; i--, cp++)
+  char *cp = buf;
+  for (idx_t i = nread; i; i--, cp++)
     *cp = trans_table[to_uchar (*cp)];
 }
 
@@ -1990,8 +1987,7 @@ copy_with_block (char const *buf, idx_t nread)
         {
           if (col < conversion_blocksize)
             {
-              idx_t j;
-              for (j = col; j < conversion_blocksize; j++)
+              for (idx_t j = col; j < conversion_blocksize; j++)
                 output_char (space_character);
             }
           col = 0;
@@ -2412,7 +2408,6 @@ synchronize_output (void)
 int
 main (int argc, char **argv)
 {
-  int i;
   int exit_status;
   off_t offset;
 
@@ -2435,7 +2430,7 @@ main (int argc, char **argv)
   close_stdout_required = false;
 
   /* Initialize translation table to identity translation. */
-  for (i = 0; i < 256; i++)
+  for (int i = 0; i < 256; i++)
     trans_table[i] = i;
 
   /* Decode arguments. */
index 75e638c5e902d4a3854a092494b5e9690a0d080a..d579553bb65a52781880f909990162fa43c21271 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -638,11 +638,10 @@ ATTRIBUTE_PURE
 static bool
 selected_fstype (char const *fstype)
 {
-  const struct fs_type_list *fsp;
-
   if (fs_select_list == nullptr || fstype == nullptr)
     return true;
-  for (fsp = fs_select_list; fsp; fsp = fsp->fs_next)
+  for (const struct fs_type_list *fsp = fs_select_list; fsp;
+       fsp = fsp->fs_next)
     if (streq (fstype, fsp->fs_name))
       return true;
   return false;
@@ -654,11 +653,10 @@ ATTRIBUTE_PURE
 static bool
 excluded_fstype (char const *fstype)
 {
-  const struct fs_type_list *fsp;
-
   if (fs_exclude_list == nullptr || fstype == nullptr)
     return false;
-  for (fsp = fs_exclude_list; fsp; fsp = fsp->fs_next)
+  for (const struct fs_type_list *fsp = fs_exclude_list; fsp;
+       fsp = fsp->fs_next)
     if (streq (fstype, fsp->fs_name))
       return true;
   return false;
@@ -705,13 +703,11 @@ devlist_for_dev (dev_t dev)
 static void
 filter_mount_list (bool devices_only)
 {
-  struct mount_entry *me;
-
   /* Temporary list to keep entries ordered.  */
   struct devlist *device_list = nullptr;
   int mount_list_size = 0;
 
-  for (me = mount_list; me; me = me->me_next)
+  for (struct mount_entry *me = mount_list; me; me = me->me_next)
     mount_list_size++;
 
   devlist_table = hash_initialize (mount_list_size, nullptr,
@@ -720,7 +716,7 @@ filter_mount_list (bool devices_only)
     xalloc_die ();
 
   /* Sort all 'wanted' entries into the list device_list.  */
-  for (me = mount_list; me;)
+  for (struct mount_entry *me = mount_list; me;)
     {
       struct stat buf;
       struct mount_entry *discard_me = nullptr;
@@ -814,22 +810,22 @@ filter_mount_list (bool devices_only)
     }
 
   /* Finally rebuild the mount_list from the devlist.  */
-  if (! devices_only) {
-    mount_list = nullptr;
-    while (device_list)
-      {
-        /* Add the mount entry.  */
-        me = device_list->me;
-        me->me_next = mount_list;
-        mount_list = me;
-        struct devlist *next = device_list->next;
-        free (device_list);
-        device_list = next;
-      }
-
+  if (! devices_only)
+    {
+      mount_list = nullptr;
+      while (device_list)
+        {
+          /* Add the mount entry.  */
+          struct mount_entry *me = device_list->me;
+          me->me_next = mount_list;
+          mount_list = me;
+          struct devlist *next = device_list->next;
+          free (device_list);
+          device_list = next;
+        }
       hash_free (devlist_table);
       devlist_table = nullptr;
-  }
+    }
 }
 
 
@@ -1239,10 +1235,9 @@ get_dev (char const *device, char const *mount_point, char const *file,
 static char *
 last_device_for_mount (char const *mount)
 {
-  struct mount_entry const *me;
   struct mount_entry const *le = nullptr;
 
-  for (me = mount_list; me; me = me->me_next)
+  for (struct mount_entry const *me = mount_list; me; me = me->me_next)
     {
       if (streq (me->me_mountdir, mount))
         le = me;
@@ -1266,7 +1261,6 @@ last_device_for_mount (char const *mount)
 static bool
 get_device (char const *device)
 {
-  struct mount_entry const *me;
   struct mount_entry const *best_match = nullptr;
   bool best_match_accessible = false;
   bool eclipsed_device = false;
@@ -1277,7 +1271,7 @@ get_device (char const *device)
     device = resolved;
 
   size_t best_match_len = SIZE_MAX;
-  for (me = mount_list; me; me = me->me_next)
+  for (struct mount_entry const *me = mount_list; me; me = me->me_next)
     {
       /* TODO: Should cache canon_dev in the mount_entry struct.  */
       char *devname = me->me_devname;
@@ -1348,7 +1342,6 @@ static void
 get_point (char const *point, const struct stat *statp)
 {
   struct stat device_stats;
-  struct mount_entry *me;
   struct mount_entry const *best_match = nullptr;
 
   /* Calculate the real absolute file name for POINT, and use that to find
@@ -1360,7 +1353,7 @@ get_point (char const *point, const struct stat *statp)
       size_t resolved_len = strlen (resolved);
       size_t best_match_len = 0;
 
-      for (me = mount_list; me; me = me->me_next)
+      for (struct mount_entry *me = mount_list; me; me = me->me_next)
         {
           if (!streq (me->me_type, "lofs")
               && (!best_match || best_match->me_dummy || !me->me_dummy))
@@ -1384,7 +1377,7 @@ get_point (char const *point, const struct stat *statp)
     best_match = nullptr;
 
   if (! best_match)
-    for (me = mount_list; me; me = me->me_next)
+    for (struct mount_entry *me = mount_list; me; me = me->me_next)
       {
         if (me->me_dev == (dev_t) -1)
           {
@@ -1459,11 +1452,9 @@ get_entry (char const *name, struct stat const *statp)
 static void
 get_all_entries (void)
 {
-  struct mount_entry *me;
-
   filter_mount_list (show_all_fs);
 
-  for (me = mount_list; me; me = me->me_next)
+  for (struct mount_entry *me = mount_list; me; me = me->me_next)
     get_dev (me->me_devname, me->me_mountdir, nullptr, nullptr, me->me_type,
              me->me_dummy, me->me_remote, nullptr, true);
 }
@@ -1728,11 +1719,11 @@ main (int argc, char **argv)
   /* Fail if the same file system type was both selected and excluded.  */
   {
     bool match = false;
-    struct fs_type_list *fs_incl;
-    for (fs_incl = fs_select_list; fs_incl; fs_incl = fs_incl->fs_next)
+    for (struct fs_type_list *fs_incl = fs_select_list; fs_incl;
+         fs_incl = fs_incl->fs_next)
       {
-        struct fs_type_list *fs_excl;
-        for (fs_excl = fs_exclude_list; fs_excl; fs_excl = fs_excl->fs_next)
+        for (struct fs_type_list *fs_excl = fs_exclude_list; fs_excl;
+             fs_excl = fs_excl->fs_next)
           {
             if (streq (fs_incl->fs_name, fs_excl->fs_name))
               {
index 7a02205a84cf75978406f4500370a61cb4b97e54..921c2fea29459ba74d2721b24eff92a7f92218cc 100644 (file)
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -636,13 +636,11 @@ get_paragraph (FILE *f)
 static int
 copy_rest (FILE *f, int c)
 {
-  char const *s;
-
   out_column = 0;
   if (in_column > next_prefix_indent || (c != '\n' && c != EOF))
     {
       put_space (next_prefix_indent);
-      for (s = prefix; out_column != in_column && *s; out_column++)
+      for (char const *s = prefix; out_column != in_column && *s; out_column++)
         putchar (*s++);
       if (c != EOF && c != '\n')
         put_space (in_column - out_column);
@@ -743,9 +741,8 @@ get_prefix (FILE *f)
       prefix_lead_space : in_column;
   else
     {
-      char const *p;
       next_prefix_indent = in_column;
-      for (p = prefix; *p != '\0'; p++)
+      for (char const *p = prefix; *p != '\0'; p++)
         {
           unsigned char pc = *p;
           if (c != pc)
@@ -868,7 +865,7 @@ flush_paragraph (void)
 static void
 fmt_paragraph (void)
 {
-  WORD *start, *w;
+  WORD *w;
   int len;
   COST wcost, best;
   int saved_length;
@@ -877,7 +874,7 @@ fmt_paragraph (void)
   saved_length = word_limit->length;
   word_limit->length = max_width;      /* sentinel */
 
-  for (start = word_limit - 1; start >= word; start--)
+  for (WORD *start = word_limit - 1; start >= word; start--)
     {
       best = MAXCOST;
       len = start == word ? first_indent : other_indent;
@@ -983,10 +980,8 @@ line_cost (WORD *next, int len)
 static void
 put_paragraph (WORD *finish)
 {
-  WORD *w;
-
   put_line (word, first_indent);
-  for (w = word->next_break; w != finish; w = w->next_break)
+  for (WORD *w = word->next_break; w != finish; w = w->next_break)
     put_line (w, other_indent);
 }
 
@@ -1023,11 +1018,8 @@ put_line (WORD *w, int indent)
 static void
 put_word (WORD *w)
 {
-  char const *s;
-  int n;
-
-  s = w->text;
-  for (n = w->length; n != 0; n--)
+  char const *s = w->text;
+  for (int n = w->length; n != 0; n--)
     putchar (*s++);
   out_column += w->length;
 }
index 47ed427dbfdf54e6cfd88fb68872e5c270c218a3..6dbf013e297e9e510ef8eff0d7f1c0e20ed74a28 100644 (file)
@@ -280,7 +280,6 @@ int
 main (int argc, char **argv)
 {
   size_t width = 80;
-  int i;
   int optc;
   bool ok;
 
@@ -343,7 +342,7 @@ main (int argc, char **argv)
   else
     {
       ok = true;
-      for (i = optind; i < argc; i++)
+      for (int i = optind; i < argc; i++)
         ok &= fold_file (argv[i], width);
     }
 
index 127099dfc5e1298d1893727d69d61526fe7385a6..4059ed00092c5e437fc8e9f7eec2eec32b3a2365 100644 (file)
@@ -297,12 +297,11 @@ elide_tail_bytes_pipe (char const *filename, int fd, uintmax_t n_elide,
       bool first = true;
       bool eof = false;
       idx_t n_to_read = READ_BUFSIZE + n_elide;
-      bool i;
       char *b[2];
       b[0] = xnmalloc (2, n_to_read);
       b[1] = b[0] + n_to_read;
 
-      for (i = false; ! eof ; i = !i)
+      for (bool i = false; ! eof ; i = !i)
         {
           idx_t n_read = full_read (fd, b[i], n_to_read);
           idx_t delta = 0;
@@ -911,7 +910,6 @@ main (int argc, char **argv)
   enum header_mode header_mode = multiple_files;
   bool ok = true;
   int c;
-  size_t i;
 
   /* Number of items to output, or to elide from the end.
      UINTMAX_MAX stands for an essentially unlimited number.  */
@@ -1071,7 +1069,7 @@ main (int argc, char **argv)
 
   xset_binary_mode (STDOUT_FILENO, O_BINARY);
 
-  for (i = 0; file_list[i]; ++i)
+  for (size_t i = 0; file_list[i]; ++i)
     ok &= head_file (file_list[i], n_units, count_lines, elide_from_end);
 
   if (have_read_stdin && close (STDIN_FILENO) < 0)
index b01253997fbca58ccdc4234c8eef1038f0b1c325..1c27bd87dcf775d6293affdf2ed6c2206fbc458c 100644 (file)
@@ -1057,9 +1057,8 @@ main (int argc, char **argv)
         }
       else
         {
-          int i;
           dest_info_init (&x);
-          for (i = 0; i < n_files; i++)
+          for (int i = 0; i < n_files; i++)
             if (! install_file_in_dir (file[i], target_directory, &x,
                                        i == 0 && mkdir_and_install,
                                        &target_dirfd))
index e1899a93a24d52e420d21b12f8f560ed85b2a13d..3c1763adf41e1a8b8caffc3feff94f9173d56ed8 100644 (file)
@@ -571,15 +571,14 @@ prfield (idx_t n, struct line const *line)
 static void
 prfields (struct line const *line, idx_t join_field, idx_t autocount)
 {
-  idx_t i;
   idx_t nfields = autoformat ? autocount : line->nfields;
 
-  for (i = 0; i < join_field && i < nfields; ++i)
+  for (idx_t i = 0; i < join_field && i < nfields; ++i)
     {
       fwrite (output_separator, 1, output_seplen, stdout);
       prfield (i, line);
     }
-  for (i = join_field + 1; i < nfields; ++i)
+  for (idx_t i = join_field + 1; i < nfields; ++i)
     {
       fwrite (output_separator, 1, output_seplen, stdout);
       prfield (i, line);
@@ -744,8 +743,7 @@ join (FILE *fp1, FILE *fp2)
         {
           for (idx_t i = 0; i < seq1.count - 1; ++i)
             {
-              idx_t j;
-              for (j = 0; j < seq2.count - 1; ++j)
+              for (idx_t j = 0; j < seq2.count - 1; ++j)
                 prjoin (seq1.lines[i], seq2.lines[j]);
             }
         }
@@ -1009,7 +1007,6 @@ main (int argc, char **argv)
   FILE *fp1, *fp2;
   int optc;
   int nfiles = 0;
-  int i;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -1175,7 +1172,7 @@ main (int argc, char **argv)
 
   /* If "-j1" was specified and it turns out not to have had an argument,
      treat it as "-j 1".  Likewise for -j2.  */
-  for (i = 0; i < 2; i++)
+  for (int i = 0; i < 2; i++)
     if (joption_count[i] != 0)
       {
         set_join_field (&join_field_1, i);
index 27bf02a58ad16fb72ec20e1e77552c24f5419314..ad8c548d5abc4a7c853d1bc50540c0f63483cd08 100644 (file)
@@ -107,7 +107,6 @@ print_table_row (int num_width, int signum,
 static int
 list_signals (bool table, char *const *argv)
 {
-  int signum;
   int status = EXIT_SUCCESS;
   char signame[SIG2STR_MAX];
 
@@ -117,11 +116,11 @@ list_signals (bool table, char *const *argv)
 
       /* Compute the maximum width of a signal number.  */
       int num_width = 1;
-      for (signum = 1; signum <= SIGNUM_BOUND / 10; signum *= 10)
+      for (int signum = 1; signum <= SIGNUM_BOUND / 10; signum *= 10)
         num_width++;
 
       /* Compute the maximum width of a signal name.  */
-      for (signum = 0; signum <= SIGNUM_BOUND; signum++)
+      for (int signum = 0; signum <= SIGNUM_BOUND; signum++)
         if (sig2str (signum, signame) == 0)
           {
             idx_t len = strlen (signame);
@@ -132,7 +131,7 @@ list_signals (bool table, char *const *argv)
       if (argv)
         for (; *argv; argv++)
           {
-            signum = operand2sig (*argv);
+            int signum = operand2sig (*argv);
             if (signum < 0)
               status = EXIT_FAILURE;
             else
@@ -143,7 +142,7 @@ list_signals (bool table, char *const *argv)
               }
           }
       else
-        for (signum = 0; signum <= SIGNUM_BOUND; signum++)
+        for (int signum = 0; signum <= SIGNUM_BOUND; signum++)
           if (sig2str (signum, signame) == 0)
             print_table_row (num_width, signum, name_width, signame);
     }
@@ -152,7 +151,7 @@ list_signals (bool table, char *const *argv)
       if (argv)
         for (; *argv; argv++)
           {
-            signum = operand2sig (*argv);
+            int signum = operand2sig (*argv);
             if (signum < 0)
               status = EXIT_FAILURE;
             else if (c_isdigit (**argv))
@@ -166,7 +165,7 @@ list_signals (bool table, char *const *argv)
               printf ("%d\n", signum);
           }
       else
-        for (signum = 0; signum <= SIGNUM_BOUND; signum++)
+        for (int signum = 0; signum <= SIGNUM_BOUND; signum++)
           if (sig2str (signum, signame) == 0)
             puts (signame);
     }
index 7144d0d9accf8e57a3863553b7aa717d51436ee8..22d9fe9db71ed0fe7be10367103def9943d18ac0 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1627,15 +1627,13 @@ signal_setup (bool init)
   static bool caught_sig[nsigs];
 #endif
 
-  int j;
-
   if (init)
     {
 #if SA_NOCLDSTOP
       struct sigaction act;
 
       sigemptyset (&caught_signals);
-      for (j = 0; j < nsigs; j++)
+      for (int j = 0; j < nsigs; j++)
         {
           sigaction (sig[j], nullptr, &act);
           if (act.sa_handler != SIG_IGN)
@@ -1645,14 +1643,14 @@ signal_setup (bool init)
       act.sa_mask = caught_signals;
       act.sa_flags = SA_RESTART;
 
-      for (j = 0; j < nsigs; j++)
+      for (int j = 0; j < nsigs; j++)
         if (sigismember (&caught_signals, sig[j]))
           {
             act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
             sigaction (sig[j], &act, nullptr);
           }
 #else
-      for (j = 0; j < nsigs; j++)
+      for (int j = 0; j < nsigs; j++)
         {
           caught_sig[j] = (signal (sig[j], SIG_IGN) != SIG_IGN);
           if (caught_sig[j])
@@ -1666,11 +1664,11 @@ signal_setup (bool init)
   else /* restore.  */
     {
 #if SA_NOCLDSTOP
-      for (j = 0; j < nsigs; j++)
+      for (int j = 0; j < nsigs; j++)
         if (sigismember (&caught_signals, sig[j]))
           signal (sig[j], SIG_DFL);
 #else
-      for (j = 0; j < nsigs; j++)
+      for (int j = 0; j < nsigs; j++)
         if (caught_sig[j])
           signal (sig[j], SIG_DFL);
 #endif
@@ -1864,7 +1862,6 @@ main (int argc, char **argv)
 
   if (print_with_color && used_color)
     {
-      int j;
 
       /* Skip the restore when it would be a no-op, i.e.,
          when left is "\033[" and right is "m".  */
@@ -1882,9 +1879,9 @@ main (int argc, char **argv)
          This can process signals out of order, but there doesn't seem to
          be an easy way to do them in order, and the order isn't that
          important anyway.  */
-      for (j = stop_signal_count; j; j--)
+      for (int j = stop_signal_count; j; j--)
         raise (SIGSTOP);
-      j = interrupt_signal;
+      int j = interrupt_signal;
       if (j)
         raise (j);
     }
@@ -2402,8 +2399,7 @@ decode_switches (int argc, char **argv)
     set_char_quoting (filename_quoting_options, ' ', 1);
   if (file_type <= indicator_style)
     {
-      char const *p;
-      for (p = &"*=>@|"[indicator_style - file_type]; *p; p++)
+      for (char const *p = &"*=>@|"[indicator_style - file_type]; *p; p++)
         set_char_quoting (filename_quoting_options, *p, 1);
     }
 
@@ -2862,15 +2858,13 @@ parse_ls_color (void)
 
   if (state == PS_FAIL)
     {
-      struct color_ext_type *e;
-      struct color_ext_type *e2;
-
       error (0, 0,
              _("unparsable value for LS_COLORS environment variable"));
       free (color_buf);
-      for (e = color_ext_list; e != nullptr; /* empty */)
+      for (struct color_ext_type *e = color_ext_list; e != nullptr;
+           /* empty */)
         {
-          e2 = e;
+          struct color_ext_type *e2 = e;
           e = e->next;
           free (e2);
         }
@@ -2882,14 +2876,13 @@ parse_ls_color (void)
          different cased extensions with separate sequences defined.
          Also set ext.len to SIZE_MAX on any entries that can't
          match due to precedence, to avoid redundant string compares.  */
-      struct color_ext_type *e1;
-
-      for (e1 = color_ext_list; e1 != nullptr; e1 = e1->next)
+      for (struct color_ext_type *e1 = color_ext_list; e1 != nullptr;
+           e1 = e1->next)
         {
-          struct color_ext_type *e2;
           bool case_ignored = false;
 
-          for (e2 = e1->next; e2 != nullptr; e2 = e2->next)
+          for (struct color_ext_type *e2 = e1->next; e2 != nullptr;
+               e2 = e2->next)
             {
               if (e2->ext.len < SIZE_MAX && e1->ext.len == e2->ext.len)
                 {
@@ -3179,8 +3172,7 @@ add_ignore_pattern (char const *pattern)
 static bool
 patterns_match (struct ignore_pattern const *patterns, char const *file)
 {
-  struct ignore_pattern const *p;
-  for (p = patterns; p; p = p->next)
+  for (struct ignore_pattern const *p = patterns; p; p = p->next)
     if (fnmatch (p->pattern, file, FNM_PERIOD) == 0)
       return true;
   return false;
index 9c69de633784d8d4037a4eb69526f2a5516e9958..47c22b3be6be04a800f5b9a510ea8db6084cc054 100644 (file)
@@ -68,8 +68,7 @@ operand2sig (char const *operand)
       /* Convert signal to upper case in the C locale, not in the
          current locale.  Don't assume ASCII; it might be EBCDIC.  */
       char *upcased = xstrdup (operand);
-      char *p;
-      for (p = upcased; *p; p++)
+      for (char *p = upcased; *p; p++)
         if (strchr ("abcdefghijklmnopqrstuvwxyz", *p))
           *p += 'A' - 'a';
 
index 38095d040d347112b1578d827f49d7fbf6450454..823137f7d3a15abbf19abd57a24f8973ec1ad37a 100644 (file)
@@ -160,9 +160,7 @@ main (int argc, char **argv)
 static bool
 no_leading_hyphen (char const *file)
 {
-  char const *p;
-
-  for (p = file;  (p = strchr (p, '-'));  p++)
+  for (char const *p = file;  (p = strchr (p, '-'));  p++)
     if (p == file || p[-1] == '/')
       {
         error (0, 0, _("leading '-' in a component of file name %s"),
@@ -250,9 +248,6 @@ validate_file_name (char *file, bool check_basic_portability,
 {
   idx_t filelen = strlen (file);
 
-  /* Start of file name component being checked.  */
-  char *start;
-
   /* True if component lengths need to be checked.  */
   bool check_component_lengths;
 
@@ -334,7 +329,7 @@ validate_file_name (char *file, bool check_basic_portability,
   check_component_lengths = check_basic_portability;
   if (! check_component_lengths && ! file_exists)
     {
-      for (start = file; *(start = component_start (start)); )
+      for (char *start = file; *(start = component_start (start)); )
         {
           size_t length = component_len (start);
 
@@ -359,7 +354,7 @@ validate_file_name (char *file, bool check_basic_portability,
       /* If nonzero, the known limit on file name components.  */
       idx_t known_name_max = check_basic_portability ? _POSIX_NAME_MAX : 0;
 
-      for (start = file; *(start = component_start (start)); )
+      for (char *start = file; *(start = component_start (start)); )
         {
           idx_t length;
 
index 10b8c528f217dff77b5355dce018f6e9b46ad76e..17c43b170c9c58f9c42efd334bbd5c0774a8166d 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -2649,7 +2649,6 @@ char_to_clump (char c)
 {
   unsigned char uc = c;
   char *s = clump_buff;
-  int i;
   char esc_buff[4];
   int width;
   int chars;
@@ -2664,7 +2663,7 @@ char_to_clump (char c)
 
       if (untabify_input)
         {
-          for (i = width; i; --i)
+          for (int i = width; i; --i)
             *s++ = ' ';
           chars = width;
         }
@@ -2683,7 +2682,7 @@ char_to_clump (char c)
           chars = 4;
           *s++ = '\\';
           sprintf (esc_buff, "%03o", uc);
-          for (i = 0; i <= 2; ++i)
+          for (int i = 0; i <= 2; ++i)
             *s++ = esc_buff[i];
         }
       else if (use_cntrl_prefix)
@@ -2701,7 +2700,7 @@ char_to_clump (char c)
               chars = 4;
               *s++ = '\\';
               sprintf (esc_buff, "%03o", uc);
-              for (i = 0; i <= 2; ++i)
+              for (int i = 0; i <= 2; ++i)
                 *s++ = esc_buff[i];
             }
         }
index e3d2f5de5ac4ca347c42905213d23078598885f9..bc99dd87eae76dff949fdfc3e3c1d5a8bda4e8f0 100644 (file)
@@ -80,9 +80,7 @@ If no VARIABLE is specified, print name and value pairs for them all.\n\
 int
 main (int argc, char **argv)
 {
-  char **env;
   char *ep, *ap;
-  int i;
   bool ok;
   int optc;
   bool opt_nul_terminate_output = false;
@@ -112,7 +110,7 @@ main (int argc, char **argv)
 
   if (optind >= argc)
     {
-      for (env = environ; *env != nullptr; ++env)
+      for (char **env = environ; *env != nullptr; ++env)
         printf ("%s%c", *env, opt_nul_terminate_output ? '\0' : '\n');
       ok = true;
     }
@@ -120,7 +118,7 @@ main (int argc, char **argv)
     {
       int matches = 0;
 
-      for (i = optind; i < argc; ++i)
+      for (int i = optind; i < argc; ++i)
         {
           bool matched = false;
 
@@ -128,7 +126,7 @@ main (int argc, char **argv)
           if (strchr (argv[i], '='))
             continue;
 
-          for (env = environ; *env; ++env)
+          for (char **env = environ; *env; ++env)
             {
               ep = *env;
               ap = argv[i];
index 463f508c7959faede98ac8e480496e4fc690f269..4de8a736130638d342a6e5f49fb5d9c63ff6c516 100644 (file)
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -425,12 +425,10 @@ compile_regex (struct regex_data *regex)
 static void
 initialize_regex (void)
 {
-  int character;               /* character value */
-
   /* Initialize the case folding table.  */
 
   if (ignore_case)
-    for (character = 0; character < CHAR_SET_SIZE; character++)
+    for (int character = 0; character < CHAR_SET_SIZE; character++)
       folded_chars[character] = toupper (character);
 
   /* Unless the user already provided a description of the end of line or
@@ -470,7 +468,7 @@ initialize_regex (void)
 
           /* Simulate \w+.  */
 
-          for (character = 0; character < CHAR_SET_SIZE; character++)
+          for (int character = 0; character < CHAR_SET_SIZE; character++)
             word_fastmap[character] = !! isalpha (character);
         }
       else
@@ -631,14 +629,14 @@ static void
 digest_break_file (char const *file_name)
 {
   BLOCK file_contents;         /* to receive a copy of the file */
-  char *cursor;                        /* cursor in file copy */
 
   swallow_file_in_memory (file_name, &file_contents);
 
   /* Make the fastmap and record the file contents in it.  */
 
   memset (word_fastmap, 1, CHAR_SET_SIZE);
-  for (cursor = file_contents.start; cursor < file_contents.end; cursor++)
+  for (char *cursor = file_contents.start; cursor < file_contents.end;
+       cursor++)
     word_fastmap[to_uchar (*cursor)] = 0;
 
   if (!gnu_extensions)
@@ -724,8 +722,7 @@ digest_word_file (char const *file_name, WORD_TABLE *table)
 static void
 find_occurs_in_text (int file_index)
 {
-  char *cursor;                        /* for scanning the source text */
-  char *scan;                  /* for scanning the source text also */
+  char *scan;                  /* for scanning the source text */
   char *line_start;            /* start of the current input line */
   char *line_scan;             /* newlines scanned until this point */
   idx_t reference_length;      /* length of reference in input mode */
@@ -766,7 +763,7 @@ find_occurs_in_text (int file_index)
 
   /* Process the whole buffer, one line or one sentence at a time.  */
 
-  for (cursor = text_buffer->start;
+  for (char *cursor = text_buffer->start;
        cursor < text_buffer->end;
        cursor = next_context_start)
     {
@@ -1011,12 +1008,10 @@ print_spaces (ptrdiff_t number)
 static void
 print_field (BLOCK field)
 {
-  char *cursor;                        /* Cursor in field to print */
-
   /* Whitespace is not really compressed.  Instead, each white space
      character (tab, vt, ht etc.) is printed as one single space.  */
 
-  for (cursor = field.start; cursor < field.end; cursor++)
+  for (char *cursor = field.start; cursor < field.end; cursor++)
     {
       unsigned char character = *cursor;
       if (edited_flag[character])
index 86226b1d378754dba9df0773f2240aa507214550..136f12635ce1b5ebf8c85c7d41a47df2f152b8ff 100644 (file)
@@ -375,8 +375,8 @@ fts_skip_tree (FTS *fts, FTSENT *ent)
 static void
 mark_ancestor_dirs (FTSENT *ent)
 {
-  FTSENT *p;
-  for (p = ent->fts_parent; FTS_ROOTLEVEL <= p->fts_level; p = p->fts_parent)
+  for (FTSENT *p = ent->fts_parent; FTS_ROOTLEVEL <= p->fts_level;
+       p = p->fts_parent)
     {
       if (p->fts_number)
         break;
index c3b9a4830e3a488a62d6a6c901745edf04e12066..32aea0fa6e3dd5740267c4604ff7c8c619c08501 100644 (file)
--- a/src/seq.c
+++ b/src/seq.c
@@ -300,9 +300,8 @@ print_numbers (char const *fmt, struct layout layout,
   if (! out_of_range)
     {
       long double x = first;
-      long double i;
 
-      for (i = 1; ; i++)
+      for (long double i = 1; ; i++)
         {
           long double x0 = x;
           if (printf (fmt, x) < 0)
index a054aa5ce5a1953d56ea23e11fcba8d032b29ec2..be2fa9f2be2f6e2bd28cc3078b760f91d9c92fbc 100644 (file)
@@ -818,7 +818,6 @@ static bool
 do_wipefd (int fd, char const *qname, struct randint_source *s,
            struct Options const *flags)
 {
-  size_t i;
   struct stat st;
   off_t size;          /* Size to write, size to read */
   off_t i_size = 0;    /* For small files, initial size to overwrite inode */
@@ -921,7 +920,7 @@ do_wipefd (int fd, char const *qname, struct randint_source *s,
       else
         break;
 
-      for (i = 0; i < flags->n_iterations + flags->zero_fill; i++)
+      for (size_t i = 0; i < flags->n_iterations + flags->zero_fill; i++)
         {
           int err = 0;
           int type = i < flags->n_iterations ? passarray[i] : 0;
@@ -1169,7 +1168,6 @@ main (int argc, char **argv)
   char **file;
   int n_files;
   int c;
-  int i;
   char const *random_source = nullptr;
 
   initialize_main (&argc, &argv);
@@ -1253,7 +1251,7 @@ main (int argc, char **argv)
            quotef (random_source ? random_source : "getrandom"));
   atexit (clear_random_data);
 
-  for (i = 0; i < n_files; i++)
+  for (int i = 0; i < n_files; i++)
     {
       char *qname = xstrdup (quotef (file[i]));
       if (streq (file[i], "-"))
index ed16c2217240a94b3403bdabcdedd79752b4c873..a74470bf8ec6b15e1f023d42e617c374e592bf45 100644 (file)
@@ -391,9 +391,7 @@ static struct tempnode *volatile *temptail = &temphead;
 static void
 cleanup (void)
 {
-  struct tempnode const *node;
-
-  for (node = temphead; node; node = node->next)
+  for (struct tempnode const *node = temphead; node; node = node->next)
     unlink (node->name);
   temphead = nullptr;
 }
@@ -1360,9 +1358,7 @@ struct_month_cmp (void const *m1, void const *m2)
 static void
 inittables (void)
 {
-  size_t i;
-
-  for (i = 0; i < UCHAR_LIM; ++i)
+  for (size_t i = 0; i < UCHAR_LIM; ++i)
     {
       blanks[i] = i == '\n' || isblank (i);
       nondictionary[i] = ! blanks[i] && ! isalnum (i);
@@ -1374,7 +1370,7 @@ inittables (void)
   /* If we're not in the "C" locale, read different names for months.  */
   if (hard_LC_TIME)
     {
-      for (i = 0; i < MONTHS_PER_YEAR; i++)
+      for (size_t i = 0; i < MONTHS_PER_YEAR; i++)
         {
           char const *s;
           size_t s_len;
@@ -2556,7 +2552,6 @@ key_to_opts (struct keyfield const *key, char *opts)
 static void
 key_warnings (struct keyfield const *gkey, bool gkey_only)
 {
-  struct keyfield const *key;
   struct keyfield ugkey = *gkey;
   unsigned long keynum = 1;
   bool basic_numeric_field = false;
@@ -2564,7 +2559,7 @@ key_warnings (struct keyfield const *gkey, bool gkey_only)
   bool basic_numeric_field_span = false;
   bool general_numeric_field_span = false;
 
-  for (key = keylist; key; key = key->next, keynum++)
+  for (struct keyfield *key = keylist; key; key = key->next, keynum++)
     {
       if (key_numeric (key))
         {
@@ -3161,14 +3156,12 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles,
                                 /* Table representing a permutation of fps,
                                    such that cur[ord[0]] is the smallest line
                                    and will be next output. */
-  size_t i;
-  size_t j;
   size_t t;
   struct keyfield const *key = keylist;
   saved.text = nullptr;
 
   /* Read initial lines from each input file. */
-  for (i = 0; i < nfiles; )
+  for (size_t i = 0; i < nfiles; )
     {
       initbuf (&buffer[i], sizeof (struct line),
                MAX (merge_buffer_size, sort_size / nfiles));
@@ -3190,7 +3183,7 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles,
             }
           free (buffer[i].buf);
           --nfiles;
-          for (j = i; j < nfiles; ++j)
+          for (size_t j = i; j < nfiles; ++j)
             {
               files[j] = files[j + 1];
               fps[j] = fps[j + 1];
@@ -3201,9 +3194,9 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles,
   /* Set up the ord table according to comparisons among input lines.
      Since this only reorders two items if one is strictly greater than
      the other, it is stable. */
-  for (i = 0; i < nfiles; ++i)
+  for (size_t i = 0; i < nfiles; ++i)
     ord[i] = i;
-  for (i = 1; i < nfiles; ++i)
+  for (size_t i = 1; i < nfiles; ++i)
     if (0 < compare (cur[ord[i - 1]], cur[ord[i]]))
       t = ord[i - 1], ord[i - 1] = ord[i], ord[i] = t, i = 0;
 
@@ -3265,7 +3258,7 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles,
           else
             {
               /* We reached EOF on fps[ord[0]].  */
-              for (i = 1; i < nfiles; ++i)
+              for (size_t i = 1; i < nfiles; ++i)
                 if (ord[i] > ord[0])
                   --ord[i];
               --nfiles;
@@ -3276,7 +3269,7 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles,
                   zaptemp (files[ord[0]].name);
                 }
               free (buffer[ord[0]].buf);
-              for (i = ord[0]; i < nfiles; ++i)
+              for (size_t i = ord[0]; i < nfiles; ++i)
                 {
                   fps[i] = fps[i + 1];
                   files[i] = files[i + 1];
@@ -3284,7 +3277,7 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles,
                   cur[i] = cur[i + 1];
                   base[i] = base[i + 1];
                 }
-              for (i = 0; i < nfiles; ++i)
+              for (size_t i = 0; i < nfiles; ++i)
                 ord[i] = ord[i + 1];
               continue;
             }
@@ -3312,7 +3305,7 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles,
           }
 
         count_of_smaller_lines = lo - 1;
-        for (j = 0; j < count_of_smaller_lines; j++)
+        for (size_t j = 0; j < count_of_smaller_lines; j++)
           ord[j] = ord[j + 1];
         ord[count_of_smaller_lines] = ord0;
       }
@@ -4277,9 +4270,7 @@ incompatible_options (char const *opts)
 static void
 check_ordering_compatibility (void)
 {
-  struct keyfield *key;
-
-  for (key = keylist; key; key = key->next)
+  for (struct keyfield *key = keylist; key; key = key->next)
     if (1 < (key->numeric + key->general_numeric + key->human_numeric
              + key->month + (key->version | key->random | !!key->ignore)))
       {
@@ -4456,7 +4447,6 @@ main (int argc, char **argv)
   inittables ();
 
   {
-    size_t i;
     static int const sig[] =
       {
         /* The usual suspects.  */
@@ -4483,7 +4473,7 @@ main (int argc, char **argv)
     struct sigaction act;
 
     sigemptyset (&caught_signals);
-    for (i = 0; i < nsigs; i++)
+    for (size_t i = 0; i < nsigs; i++)
       {
         sigaction (sig[i], nullptr, &act);
         if (act.sa_handler != SIG_IGN)
@@ -4494,11 +4484,11 @@ main (int argc, char **argv)
     act.sa_mask = caught_signals;
     act.sa_flags = 0;
 
-    for (i = 0; i < nsigs; i++)
+    for (size_t i = 0; i < nsigs; i++)
       if (sigismember (&caught_signals, sig[i]))
         sigaction (sig[i], &act, nullptr);
 #else
-    for (i = 0; i < nsigs; i++)
+    for (size_t i = 0; i < nsigs; i++)
       if (signal (sig[i], SIG_IGN) != SIG_IGN)
         {
           signal (sig[i], sighandler);
index 3d15091139709e2816e969926c7c5f2c300d32db..d383f1ef90e0647fe2f93e58cc6f84feafecb05c 100644 (file)
@@ -587,8 +587,7 @@ closeout (FILE *fp, int fd, pid_t pid, char const *name)
     {
       if (fp == nullptr && close (fd) < 0)
         error (EXIT_FAILURE, errno, "%s", quotef (name));
-      int j;
-      for (j = 0; j < n_open_pipes; ++j)
+      for (int j = 0; j < n_open_pipes; ++j)
         {
           if (open_pipes[j] == fd)
             {
index ea213f3d59f9fb059dd362737a7e427c95b8c97d..6a723af0db8dccc6d4597e9f5a79a1029ab22c95 100644 (file)
@@ -963,8 +963,7 @@ find_bind_mount (char const * name)
   if (stat (name, &name_stats) != 0)
     return nullptr;
 
-  struct mount_entry *me;
-  for (me = mount_list; me; me = me->me_next)
+  for (struct mount_entry *me = mount_list; me; me = me->me_next)
     {
       if (me->me_dummy && me->me_devname[0] == '/'
           && streq (me->me_mountdir, name))
@@ -1145,8 +1144,7 @@ print_it (char const *format, int fd, char const *filename,
     };
   size_t n_alloc = strlen (format) + MAX_ADDITIONAL_BYTES + 1;
   char *dest = xmalloc (n_alloc);
-  char const *b;
-  for (b = format; *b; b++)
+  for (char const *b = format; *b; b++)
     {
       switch (*b)
         {
@@ -1347,9 +1345,8 @@ static unsigned int
 format_to_mask (char const *format)
 {
   unsigned int mask = 0;
-  char const *b;
 
-  for (b = format; *b; b++)
+  for (char const *b = format; *b; b++)
     {
       if (*b != '%')
         continue;
index c3d72ce5f54d13a218610b491688c2b24b6972a9..33671311d7e237a82358834d9dcc27145b08d3d3 100644 (file)
@@ -146,9 +146,8 @@ set_program_path (char const *arg)
         program_path = dir_name (path);
       else if ((path = getenv ("PATH")))
         {
-          char *dir;
           path = xstrdup (path);
-          for (dir = strtok (path, ":"); dir != nullptr;
+          for (char *dir = strtok (path, ":"); dir != nullptr;
                dir = strtok (nullptr, ":"))
             {
               char *candidate = file_name_concat (dir, arg, nullptr);
index 919e32bb315a0a73c202ce16db2f826f88509a16..e1d4d77057d90268cd866a3ddf0de128c7733d2e 100644 (file)
@@ -1115,7 +1115,6 @@ apply_settings (bool checking, char const *device_name,
       bool match_found = false;
       bool not_set_attr = false;
       bool reversed = false;
-      int i;
 
       if (! arg)
         continue;
@@ -1130,7 +1129,7 @@ apply_settings (bool checking, char const *device_name,
           tcsetattr_options = reversed ? TCSANOW : TCSADRAIN;
           continue;
         }
-      for (i = 0; mode_info[i].name != nullptr; ++i)
+      for (int i = 0; mode_info[i].name != nullptr; ++i)
         {
           if (streq (arg, mode_info[i].name))
             {
@@ -1151,7 +1150,7 @@ apply_settings (bool checking, char const *device_name,
         }
       if (!match_found)
         {
-          for (i = 0; control_info[i].name != nullptr; ++i)
+          for (int i = 0; control_info[i].name != nullptr; ++i)
             {
               if (streq (arg, control_info[i].name))
                 {
@@ -1907,7 +1906,6 @@ display_settings (enum output_type output_type, struct termios *mode,
 static void
 display_changed (struct termios *mode)
 {
-  int i;
   bool empty_line;
   tcflag_t *bitsp;
   unsigned long mask;
@@ -1921,7 +1919,7 @@ display_changed (struct termios *mode)
   current_col = 0;
 
   empty_line = true;
-  for (i = 0; !streq (control_info[i].name, "min"); ++i)
+  for (int i = 0; !streq (control_info[i].name, "min"); ++i)
     {
       if (mode->c_cc[control_info[i].offset] == control_info[i].saneval)
         continue;
@@ -1959,7 +1957,7 @@ display_changed (struct termios *mode)
   current_col = 0;
 
   empty_line = true;
-  for (i = 0; mode_info[i].name != nullptr; ++i)
+  for (int i = 0; mode_info[i].name != nullptr; ++i)
     {
       if (mode_info[i].flags & OMIT)
         continue;
@@ -1998,7 +1996,6 @@ display_changed (struct termios *mode)
 static void
 display_all (struct termios *mode, char const *device_name)
 {
-  int i;
   tcflag_t *bitsp;
   unsigned long mask;
   enum mode_type prev_type = control;
@@ -2013,7 +2010,7 @@ display_all (struct termios *mode, char const *device_name)
   putchar ('\n');
   current_col = 0;
 
-  for (i = 0; ! streq (control_info[i].name, "min"); ++i)
+  for (int i = 0; ! streq (control_info[i].name, "min"); ++i)
     {
 #ifdef VFLUSHO
       /* 'flush' is the deprecated equivalent of 'discard'.  */
@@ -2045,7 +2042,7 @@ display_all (struct termios *mode, char const *device_name)
     putchar ('\n');
   current_col = 0;
 
-  for (i = 0; mode_info[i].name != nullptr; ++i)
+  for (int i = 0; mode_info[i].name != nullptr; ++i)
     {
       if (mode_info[i].flags & OMIT)
         continue;
@@ -2145,8 +2142,7 @@ recover_mode (char const *arg, struct termios *mode)
 {
   tcflag_t flag[4];
   char const *s = arg;
-  size_t i;
-  for (i = 0; i < 4; i++)
+  for (size_t i = 0; i < 4; i++)
     {
       char *p;
       if (strtoul_tcflag_t (s, 16, &p, flag + i, ':') != 0)
@@ -2158,7 +2154,7 @@ recover_mode (char const *arg, struct termios *mode)
   mode->c_cflag = flag[2];
   mode->c_lflag = flag[3];
 
-  for (i = 0; i < NCCS; ++i)
+  for (size_t i = 0; i < NCCS; ++i)
     {
       char *p;
       char delim = i < NCCS - 1 ? ':' : '\0';
@@ -2234,10 +2230,9 @@ string_to_baud (char const *arg)
 static void
 sane_mode (struct termios *mode)
 {
-  int i;
   tcflag_t *bitsp;
 
-  for (i = 0; control_info[i].name; ++i)
+  for (int i = 0; control_info[i].name; ++i)
     {
 #if VMIN == VEOF
       if (streq (control_info[i].name, "min"))
@@ -2246,7 +2241,7 @@ sane_mode (struct termios *mode)
       mode->c_cc[control_info[i].offset] = control_info[i].saneval;
     }
 
-  for (i = 0; mode_info[i].name != nullptr; ++i)
+  for (int i = 0; mode_info[i].name != nullptr; ++i)
     {
       if (mode_info[i].flags & NO_SETATTR)
         continue;
index b8612ff5e3656b1bb087e3771664bc2d1b1ebeb8..ca64de8d909b8e24bb4b9d1a5599ffb0907fd99a 100644 (file)
@@ -764,8 +764,7 @@ write_error (void)
 static inline char *
 stzncpy (char *restrict dest, char const *restrict src, size_t len)
 {
-  size_t i;
-  for (i = 0; i < len && *src; i++)
+  for (size_t i = 0; i < len && *src; i++)
     *dest++ = *src++;
   *dest = 0;
   return dest;
index bfe6efe6c3cfc7badec2edc29af9389125f8173c..add8887d6c5fe22541bdb90ed13654d594e37efa 100644 (file)
@@ -733,8 +733,7 @@ pipe_lines (char const *prettyname, int fd, count_t n_lines)
       {
         /* Skip 'total_lines' - 'n_lines' newlines.  We made sure that
            'total_lines' - 'n_lines' <= 'tmp->nlines'.  */
-        idx_t j;
-        for (j = total_lines - n_lines; j; --j)
+        for (idx_t j = total_lines - n_lines; j; --j)
           {
             beg = rawmemchr (beg, line_end);
             ++beg;
index dc55b2cc265c27d6e97e29da8f9631476fd6944b..992963eb603cacf63a1b5c446dfd1cee29b68d35 100644 (file)
--- a/src/tee.c
+++ b/src/tee.c
@@ -230,7 +230,6 @@ tee_files (int nfiles, char **files, bool pipe_check)
   bool *out_pollable IF_LINT ( = nullptr);
   char buffer[BUFSIZ];
   ssize_t bytes_read = 0;
-  int i;
   int first_out = 0;  /* idx of first non-null output in descriptors */
   bool ok = true;
   char const *mode_string =
@@ -256,7 +255,7 @@ tee_files (int nfiles, char **files, bool pipe_check)
   setvbuf (stdout, nullptr, _IONBF, 0);
   n_outputs++;
 
-  for (i = 1; i <= nfiles; i++)
+  for (int i = 1; i <= nfiles; i++)
     {
       /* Do not treat "-" specially - as mandated by POSIX.  */
        descriptors[i] = fopen (files[i], mode_string);
@@ -311,7 +310,7 @@ tee_files (int nfiles, char **files, bool pipe_check)
 
       /* Write to all NFILES + 1 descriptors.
          Standard output is the first one.  */
-      for (i = 0; i <= nfiles; i++)
+      for (int i = 0; i <= nfiles; i++)
         if (descriptors[i]
             && ! fwrite_wait (buffer, bytes_read, descriptors[i]))
           {
@@ -330,7 +329,7 @@ tee_files (int nfiles, char **files, bool pipe_check)
     }
 
   /* Close the files, but not standard output.  */
-  for (i = 1; i <= nfiles; i++)
+  for (int i = 1; i <= nfiles; i++)
     if (descriptors[i] && ! fclose_wait (descriptors[i]))
       {
         error (0, errno, "%s", quotef (files[i]));
index 26776395f57971403df5a07eab7e54d804872b22..21b4de6699ba74e91dc88cc03925e29d54f1bb30 100644 (file)
--- a/src/tr.c
+++ b/src/tr.c
@@ -543,9 +543,7 @@ ATTRIBUTE_PURE
 static enum Char_class
 look_up_char_class (char const *class_str, size_t len)
 {
-  enum Char_class i;
-
-  for (i = 0; i < countof (char_class_name); i++)
+  for (enum Char_class i = 0; i < countof (char_class_name); i++)
     if (STREQ_LEN (class_str, char_class_name[i], len)
         && strlen (char_class_name[i]) == len)
       return i;
@@ -1234,14 +1232,13 @@ validate_case_classes (struct Spec_list *s1, struct Spec_list *s2)
 static void
 get_spec_stats (struct Spec_list *s)
 {
-  struct List_element *p;
   count length = 0;
 
   s->n_indefinite_repeats = 0;
   s->has_equiv_class = false;
   s->has_restricted_char_class = false;
   s->has_char_class = false;
-  for (p = s->head->next; p; p = p->next)
+  for (struct List_element *p = s->head->next; p; p = p->next)
     {
       count len = 0;
 
index 5e298acd572393ea8bc60b112e313b8dcb4c8c61..3191d5b0b4a3c052f7208841d0de0f624870168c 100644 (file)
@@ -45,7 +45,6 @@ static void
 list_entries_users (idx_t n, STRUCT_UTMP const *this)
 {
   char **u = xinmalloc (n, sizeof *u);
-  idx_t i;
   idx_t n_entries = 0;
 
   while (n--)
@@ -64,14 +63,14 @@ list_entries_users (idx_t n, STRUCT_UTMP const *this)
 
   qsort (u, n_entries, sizeof (u[0]), userid_compare);
 
-  for (i = 0; i < n_entries; i++)
+  for (idx_t i = 0; i < n_entries; i++)
     {
       char c = (i < n_entries - 1 ? ' ' : '\n');
       fputs (u[i], stdout);
       putchar (c);
     }
 
-  for (i = 0; i < n_entries; i++)
+  for (idx_t i = 0; i < n_entries; i++)
     free (u[i]);
   free (u);
 }