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;
/* 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];
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. */
}
}
- 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]));
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);
/* 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';
static void
save_buffer (struct buffer_record *buf)
{
- struct buffer_record *p;
-
buf->next = nullptr;
buf->curr_line = buf->line_start;
head = buf;
else
{
+ struct buffer_record *p;
for (p = head; p->next; p = p->next)
/* Do nothing. */ ;
p->next = buf;
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)
{
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 ();
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)
{
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);
}
parse_patterns (argc, optind, argv);
{
- int i;
static int const sig[] =
{
/* The usual suspects. */
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)
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);
}
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;
}
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)];
}
{
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;
int
main (int argc, char **argv)
{
- int i;
int exit_status;
off_t offset;
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. */
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;
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;
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,
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;
}
/* 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;
- }
+ }
}
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;
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;
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;
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
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))
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)
{
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);
}
/* 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))
{
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);
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)
static void
fmt_paragraph (void)
{
- WORD *start, *w;
+ WORD *w;
int len;
COST wcost, best;
int saved_length;
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;
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);
}
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;
}
main (int argc, char **argv)
{
size_t width = 80;
- int i;
int optc;
bool ok;
else
{
ok = true;
- for (i = optind; i < argc; i++)
+ for (int i = optind; i < argc; i++)
ok &= fold_file (argv[i], width);
}
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;
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. */
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)
}
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))
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);
{
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]);
}
}
FILE *fp1, *fp2;
int optc;
int nfiles = 0;
- int i;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
/* 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);
static int
list_signals (bool table, char *const *argv)
{
- int signum;
int status = EXIT_SUCCESS;
char signame[SIG2STR_MAX];
/* 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);
if (argv)
for (; *argv; argv++)
{
- signum = operand2sig (*argv);
+ int signum = operand2sig (*argv);
if (signum < 0)
status = EXIT_FAILURE;
else
}
}
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);
}
if (argv)
for (; *argv; argv++)
{
- signum = operand2sig (*argv);
+ int signum = operand2sig (*argv);
if (signum < 0)
status = EXIT_FAILURE;
else if (c_isdigit (**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);
}
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)
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])
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
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". */
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);
}
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);
}
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);
}
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)
{
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;
/* 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';
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"),
{
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;
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);
/* 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;
{
unsigned char uc = c;
char *s = clump_buff;
- int i;
char esc_buff[4];
int width;
int chars;
if (untabify_input)
{
- for (i = width; i; --i)
+ for (int i = width; i; --i)
*s++ = ' ';
chars = width;
}
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)
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];
}
}
int
main (int argc, char **argv)
{
- char **env;
char *ep, *ap;
- int i;
bool ok;
int optc;
bool opt_nul_terminate_output = false;
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;
}
{
int matches = 0;
- for (i = optind; i < argc; ++i)
+ for (int i = optind; i < argc; ++i)
{
bool matched = false;
if (strchr (argv[i], '='))
continue;
- for (env = environ; *env; ++env)
+ for (char **env = environ; *env; ++env)
{
ep = *env;
ap = argv[i];
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
/* 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
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)
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 */
/* 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)
{
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])
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;
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)
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 */
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;
char **file;
int n_files;
int c;
- int i;
char const *random_source = nullptr;
initialize_main (&argc, &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], "-"))
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;
}
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);
/* 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;
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;
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))
{
/* 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));
}
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];
/* 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;
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;
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];
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;
}
}
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;
}
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)))
{
inittables ();
{
- size_t i;
static int const sig[] =
{
/* The usual suspects. */
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)
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);
{
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)
{
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))
};
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)
{
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;
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);
bool match_found = false;
bool not_set_attr = false;
bool reversed = false;
- int i;
if (! arg)
continue;
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))
{
}
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))
{
static void
display_changed (struct termios *mode)
{
- int i;
bool empty_line;
tcflag_t *bitsp;
unsigned long mask;
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;
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;
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;
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'. */
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;
{
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)
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';
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"))
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;
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;
{
/* 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;
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 =
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);
/* 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]))
{
}
/* 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]));
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;
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;
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--)
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);
}