* bootstrap.conf (gnulib_modules): Add nullptr.
In code, prefer nullptr to NULL where either will do.
mkostemp
mkstemp
mktime
+ nullptr
modechange
mountlist
mpsort
Parse the initial prefix of NPTR as a floating-point number in the
current locale or in the C locale (preferring the locale that
yields the longer parse, or the current locale if there is a tie).
- If ENDPTR is not NULL, set *ENDPTR to the first unused byte, or to
+ If ENDPTR is non-null, set *ENDPTR to the first unused byte, or to
NPTR if the prefix cannot be parsed.
If successful, return a number without changing errno.
heap->array = xnmalloc (n_reserve, sizeof *(heap->array));
- heap->array[0] = NULL;
+ heap->array[0] = nullptr;
heap->capacity = n_reserve;
heap->count = 0;
heap->compare = compare ? compare : heap_default_compare;
void *top;
if (heap->count == 0)
- return NULL;
+ return nullptr;
top = heap->array[1];
heap->array[1] = heap->array[heap->count--];
{
size_t ret = SIZE_MAX;
size_t src_size = strlen (src) + 1;
- char *newstr = NULL;
- wchar_t *str_wc = NULL;
+ char *newstr = nullptr;
+ wchar_t *str_wc = nullptr;
char const *str_to_print = src;
size_t n_cols = src_size - 1;
size_t n_used_bytes = n_cols; /* Not including NUL */
of screen columns used. */
if (!(flags & MBA_UNIBYTE_ONLY) && MB_CUR_MAX > 1)
{
- size_t src_chars = mbstowcs (NULL, src, 0);
+ size_t src_chars = mbstowcs (nullptr, src, 0);
if (src_chars == SIZE_MAX)
{
if (flags & MBA_UNIBYTE_FALLBACK)
}
src_chars += 1; /* make space for NUL */
str_wc = malloc (src_chars * sizeof (wchar_t));
- if (str_wc == NULL)
+ if (str_wc == nullptr)
{
if (flags & MBA_UNIBYTE_FALLBACK)
goto mbsalign_unibyte;
{
/* May have increased the size by converting
\t to \uFFFD for example. */
- src_size = wcstombs (NULL, str_wc, 0) + 1;
+ src_size = wcstombs (nullptr, str_wc, 0) + 1;
}
newstr = malloc (src_size);
- if (newstr == NULL)
+ if (newstr == nullptr)
{
if (flags & MBA_UNIBYTE_FALLBACK)
goto mbsalign_unibyte;
/* A wrapper around mbsalign() to dynamically allocate the
minimum amount of memory to store the result.
- Return NULL on failure. */
+ Return nullptr on failure. */
char *
ambsalign (char const *src, size_t *width, mbs_align_t align, int flags)
size_t orig_width = *width;
size_t size = *width; /* Start with enough for unibyte mode. */
size_t req = size;
- char *buf = NULL;
+ char *buf = nullptr;
while (req >= size)
{
char *nbuf;
size = req + 1; /* Space for NUL. */
nbuf = realloc (buf, size);
- if (nbuf == NULL)
+ if (nbuf == nullptr)
{
free (buf);
- buf = NULL;
+ buf = nullptr;
break;
}
buf = nbuf;
if (req == SIZE_MAX)
{
free (buf);
- buf = NULL;
+ buf = nullptr;
break;
}
}
main (int argc, char **argv)
{
randint i;
- randint n = strtoumax (argv[1], NULL, 10);
- randint choices = strtoumax (argv[2], NULL, 10);
+ randint n = strtoumax (argv[1], nullptr, 10);
+ randint choices = strtoumax (argv[2], nullptr, 10);
char const *name = argv[3];
struct randint_source *ints = randint_all_new (name, SIZE_MAX);
}
/* Create a new randint_source by creating a randread_source from
- NAME and ESTIMATED_BYTES. Return NULL (setting errno) if
+ NAME and ESTIMATED_BYTES. Return nullptr (setting errno) if
unsuccessful. */
struct randint_source *
randint_all_new (char const *name, size_t bytes_bound)
{
struct randread_source *source = randread_new (name, bytes_bound);
- return (source ? randint_new (source) : NULL);
+ return (source ? randint_new (source) : nullptr);
}
/* Return the random data source of *S. */
static sparse_map *
sparse_new (size_t size_hint)
{
- return hash_initialize (size_hint, NULL, sparse_hash_, sparse_cmp_, free);
+ return hash_initialize (size_hint, nullptr, sparse_hash_, sparse_cmp_, free);
}
/* Swap the values for I and J. If a value is not already present
/* From R, allocate and return a malloc'd array of the first H elements
of a random permutation of N elements. H must not exceed N.
- Return NULL if H is zero. */
+ Return nullptr if H is zero. */
size_t *
randperm_new (struct randint_source *r, size_t h, size_t n)
switch (h)
{
case 0:
- v = NULL;
+ v = nullptr;
break;
case 1:
if (sparse)
{
sv = sparse_new (h * 2);
- if (sv == NULL)
+ if (sv == nullptr)
xalloc_die ();
v = xnmalloc (h, sizeof *v);
}
else
{
- sv = NULL; /* To placate GCC's -Wuninitialized. */
+ sv = nullptr; /* To placate GCC's -Wuninitialized. */
v = xnmalloc (n, sizeof *v);
for (i = 0; i < n; i++)
v[i] = i;
default handler. Unless a non-default handler is used, NAME's
lifetime should be at least that of the returned value.
- Return NULL (setting errno) on failure. */
+ Return nullptr (setting errno) on failure. */
struct randread_source *
randread_new (char const *name, size_t bytes_bound)
{
if (bytes_bound == 0)
- return simple_new (NULL, NULL);
+ return simple_new (nullptr, nullptr);
else
{
- FILE *source = NULL;
+ FILE *source = nullptr;
struct randread_source *s;
if (name)
if (! (source = fopen_safer (name, "rb")))
- return NULL;
+ return nullptr;
s = simple_new (source, name);
int e = errno;
randread_free_body (s);
errno = e;
- return NULL;
+ return nullptr;
}
isaac_seed (&s->buf.isaac.state);
}
#include <stdlib.h>
/* Call lstat to get the device and inode numbers for '/'.
- Upon failure, return NULL. Otherwise, set the members of
+ Upon failure, return nullptr. Otherwise, set the members of
*ROOT_D_I accordingly and return ROOT_D_I. */
struct dev_ino *
get_root_dev_ino (struct dev_ino *root_d_i)
{
struct stat statbuf;
if (lstat ("/", &statbuf))
- return NULL;
+ return nullptr;
root_d_i->st_ino = statbuf.st_ino;
root_d_i->st_dev = statbuf.st_dev;
return root_d_i;
is_smack_enabled (void)
{
#ifdef HAVE_SMACK
- return smack_smackfs_path () != NULL;
+ return smack_smackfs_path () != nullptr;
#else
return false;
#endif
strtol_error s_err;
__xdectoint_t tnum;
- s_err = __xstrtol (n_str, NULL, base, &tnum, suffixes);
+ s_err = __xstrtol (n_str, nullptr, base, &tnum, suffixes);
if (s_err == LONGINT_OK)
{
int (*compar) (const FTSENT **, const FTSENT **))
{
FTS *fts = fts_open (argv, options | FTS_CWDFD, compar);
- if (fts == NULL)
+ if (fts == nullptr)
{
/* This can fail in two ways: out of memory or with errno==EINVAL,
which indicates it was called with invalid bit_flags. */
fdadvise (fileno (stdin), 0, 0, FADVISE_RANDOM);
/* Ignored. */
- fadvise (NULL, FADVISE_RANDOM);
+ fadvise (nullptr, FADVISE_RANDOM);
/* Invalid. */
fdadvise (42, 0, 0, FADVISE_RANDOM);
/* If invoked with a positive argument, run a benchmark;
if with a negative, run a do-nothing benchmark. */
- for (iterations = argc <= 1 ? 0 : strtol (argv[1], NULL, 10);
+ for (iterations = argc <= 1 ? 0 : strtol (argv[1], nullptr, 10);
iterations != 0;
iterations += (iterations < 0 ? 1 : -1))
if (0 <= iterations)
static struct option const longopts[] =
{
- {"multiple", no_argument, NULL, 'a'},
- {"suffix", required_argument, NULL, 's'},
- {"zero", no_argument, NULL, 'z'},
+ {"multiple", no_argument, nullptr, 'a'},
+ {"suffix", required_argument, nullptr, 's'},
+ {"zero", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
*np = '\0';
}
-/* Perform the basename operation on STRING. If SUFFIX is non-NULL, remove
+/* Perform the basename operation on STRING. If SUFFIX is non-null, remove
the trailing SUFFIX. Finally, output the result string. */
static void
{
bool multiple_names = false;
bool use_nuls = false;
- char const *suffix = NULL;
+ char const *suffix = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
while (true)
{
- int c = getopt_long (argc, argv, "+as:z", longopts, NULL);
+ int c = getopt_long (argc, argv, "+as:z", longopts, nullptr);
if (c == -1)
break;
}
else
perform_basename (argv[optind],
- optind + 2 == argc ? argv[optind + 1] : NULL, use_nuls);
+ optind + 2 == argc ? argv[optind + 1] : nullptr,
+ use_nuls);
return EXIT_SUCCESS;
}
#endif
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
static bool
isz85 (char ch)
{
- return c_isalnum (ch) || (strchr (".-:+=^!/*?&<>()[]{}@%$#", ch) != NULL);
+ return c_isalnum (ch) || strchr (".-:+=^!/*?&<>()[]{}@%$#", ch) != nullptr;
}
static char const z85_encoding[85] =
outbuf = xmalloc (DEC_BLOCKSIZE);
#if BASE_TYPE == 42
- ctx.inbuf = NULL;
+ ctx.inbuf = nullptr;
#endif
base_decode_ctx_init (&ctx);
atexit (close_stdout);
- while ((opt = getopt_long (argc, argv, "diw:", long_options, NULL)) != -1)
+ while ((opt = getopt_long (argc, argv, "diw:", long_options, nullptr)) != -1)
switch (opt)
{
case 'd':
case 'w':
{
intmax_t w;
- strtol_error s_err = xstrtoimax (optarg, NULL, 10, &w, "");
+ strtol_error s_err = xstrtoimax (optarg, nullptr, 10, &w, "");
if (LONGINT_OVERFLOW < s_err || w < 0)
die (EXIT_FAILURE, 0, "%s: %s",
_("invalid wrap size"), quote (optarg));
else
{
input_fh = fopen (infile, "rb");
- if (input_fh == NULL)
+ if (input_fh == nullptr)
die (EXIT_FAILURE, errno, "%s", quotef (infile));
}
while( 1 )
{
int option_index = 0;
- char *end = NULL;
+ char *end = nullptr;
unsigned long outbits;
static struct option long_options[] = {
{ "help", no_argument, 0, 0 },
{ "tag", no_argument, 0, 0 },
- { NULL, 0, NULL, 0 }
+ { nullptr, 0, nullptr, 0 }
};
c = getopt_long( argc, argv, "a:l:", long_options, &option_index );
for( i = optind; i < argc; ++i )
{
- FILE *f = NULL;
+ FILE *f = nullptr;
if( argv[i][0] == '-' && argv[i][1] == '\0' )
f = stdin;
else
unsupported or the input file seems empty. */
for (bool some_copied = false; ; some_copied = true)
- switch (copy_file_range (input_desc, NULL, STDOUT_FILENO, NULL,
+ switch (copy_file_range (input_desc, nullptr, STDOUT_FILENO, nullptr,
copy_max, 0))
{
case 0:
static struct option const long_options[] =
{
- {"number-nonblank", no_argument, NULL, 'b'},
- {"number", no_argument, NULL, 'n'},
- {"squeeze-blank", no_argument, NULL, 's'},
- {"show-nonprinting", no_argument, NULL, 'v'},
- {"show-ends", no_argument, NULL, 'E'},
- {"show-tabs", no_argument, NULL, 'T'},
- {"show-all", no_argument, NULL, 'A'},
+ {"number-nonblank", no_argument, nullptr, 'b'},
+ {"number", no_argument, nullptr, 'n'},
+ {"squeeze-blank", no_argument, nullptr, 's'},
+ {"show-nonprinting", no_argument, nullptr, 'v'},
+ {"show-ends", no_argument, nullptr, 'E'},
+ {"show-tabs", no_argument, nullptr, 'T'},
+ {"show-all", no_argument, nullptr, 'A'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
initialize_main (&argc, &argv);
/* Parse command line options. */
int c;
- while ((c = getopt_long (argc, argv, "benstuvAET", long_options, NULL))
+ while ((c = getopt_long (argc, argv, "benstuvAET", long_options, nullptr))
!= -1)
{
switch (c)
out_isreg && S_ISREG (stat_buf.st_mode) ? copy_cat () : 0;
if (copy_cat_status != 0)
{
- inbuf = NULL;
+ inbuf = nullptr;
ok &= 0 < copy_cat_status;
}
else
static bool verbose;
/* Pointer to the device and inode numbers of '/', when --recursive.
- Otherwise NULL. */
+ Otherwise nullptr. */
static struct dev_ino *root_dev_ino;
/* The name of the context file is being given. */
static struct option const long_options[] =
{
- {"recursive", no_argument, NULL, 'R'},
- {"dereference", no_argument, NULL, DEREFERENCE_OPTION},
- {"no-dereference", no_argument, NULL, 'h'},
- {"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
- {"preserve-root", no_argument, NULL, PRESERVE_ROOT},
- {"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
- {"user", required_argument, NULL, 'u'},
- {"role", required_argument, NULL, 'r'},
- {"type", required_argument, NULL, 't'},
- {"range", required_argument, NULL, 'l'},
- {"verbose", no_argument, NULL, 'v'},
+ {"recursive", no_argument, nullptr, 'R'},
+ {"dereference", no_argument, nullptr, DEREFERENCE_OPTION},
+ {"no-dereference", no_argument, nullptr, 'h'},
+ {"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
+ {"preserve-root", no_argument, nullptr, PRESERVE_ROOT},
+ {"reference", required_argument, nullptr, REFERENCE_FILE_OPTION},
+ {"user", required_argument, nullptr, 'u'},
+ {"role", required_argument, nullptr, 'r'},
+ {"type", required_argument, nullptr, 't'},
+ {"range", required_argument, nullptr, 'l'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Given a security context, CONTEXT, derive a context_t (*RET),
static int
change_file_context (int fd, char const *file)
{
- char *file_context = NULL;
+ char *file_context = nullptr;
context_t context IF_LINT (= 0);
char const * context_string;
int errors = 0;
- if (specified_context == NULL)
+ if (specified_context == nullptr)
{
int status = (affect_symlink_referent
? getfileconat (fd, file, &file_context)
/* If the file doesn't have a context, and we're not setting all of
the context components, there isn't really an obvious default.
Thus, we just give up. */
- if (file_context == NULL)
+ if (file_context == nullptr)
{
error (0, 0, _("can't apply partial context to unlabeled file %s"),
quoteaf (file));
context_string = specified_context;
}
- if (file_context == NULL || ! STREQ (context_string, file_context))
+ if (file_context == nullptr || ! STREQ (context_string, file_context))
{
int fail = (affect_symlink_referent
? setfileconat (fd, file, context_string)
}
}
- if (specified_context == NULL)
+ if (specified_context == nullptr)
{
context_free (context);
freecon (file_context);
}
/* Recursively operate on the specified FILES (the last entry
- of which is NULL). BIT_FLAGS controls how fts works.
+ of which is null). BIT_FLAGS controls how fts works.
Return true if successful. */
static bool
{
bool ok = true;
- FTS *fts = xfts_open (files, bit_flags, NULL);
+ FTS *fts = xfts_open (files, bit_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
- if (ent == NULL)
+ if (ent == nullptr)
{
if (errno != 0)
{
bool ok;
bool preserve_root = false;
bool component_specified = false;
- char *reference_file = NULL;
+ char *reference_file = nullptr;
int optc;
initialize_main (&argc, &argv);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "HLPRhvu:r:t:l:", long_options, NULL))
+ while ((optc = getopt_long (argc, argv, "HLPRhvu:r:t:l:",
+ long_options, nullptr))
!= -1)
{
switch (optc)
if (reference_file)
{
- char *ref_context = NULL;
+ char *ref_context = nullptr;
if (getfilecon (reference_file, &ref_context) < 0)
die (EXIT_FAILURE, errno, _("failed to get security context of %s"),
else if (component_specified)
{
/* FIXME: it's already null, so this is a no-op. */
- specified_context = NULL;
+ specified_context = nullptr;
}
else
{
{
static struct dev_ino dev_ino_buf;
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
- if (root_dev_ino == NULL)
+ if (root_dev_ino == nullptr)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
else
{
- root_dev_ino = NULL;
+ root_dev_ino = nullptr;
}
ok = process_files (argv + optind, bit_flags | FTS_NOSTAT);
static struct option const long_options[] =
{
- {"recursive", no_argument, NULL, 'R'},
- {"changes", no_argument, NULL, 'c'},
- {"dereference", no_argument, NULL, DEREFERENCE_OPTION},
- {"no-dereference", no_argument, NULL, 'h'},
- {"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
- {"preserve-root", no_argument, NULL, PRESERVE_ROOT},
- {"quiet", no_argument, NULL, 'f'},
- {"silent", no_argument, NULL, 'f'},
- {"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
- {"verbose", no_argument, NULL, 'v'},
+ {"recursive", no_argument, nullptr, 'R'},
+ {"changes", no_argument, nullptr, 'c'},
+ {"dereference", no_argument, nullptr, DEREFERENCE_OPTION},
+ {"no-dereference", no_argument, nullptr, 'h'},
+ {"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
+ {"preserve-root", no_argument, nullptr, PRESERVE_ROOT},
+ {"quiet", no_argument, nullptr, 'f'},
+ {"silent", no_argument, nullptr, 'f'},
+ {"reference", required_argument, nullptr, REFERENCE_FILE_OPTION},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Return the group ID of NAME, or -1 if no name was specified. */
else
{
uintmax_t tmp;
- if (! (xstrtoumax (name, NULL, 10, &tmp, "") == LONGINT_OK
+ if (! (xstrtoumax (name, nullptr, 10, &tmp, "") == LONGINT_OK
&& tmp <= GID_T_MAX))
die (EXIT_FAILURE, 0, _("invalid group: %s"),
quote (name));
chopt_init (&chopt);
- while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL))
+ while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, nullptr))
!= -1)
{
switch (optc)
else
{
char *group_name = argv[optind++];
- chopt.group_name = (*group_name ? xstrdup (group_name) : NULL);
+ chopt.group_name = (*group_name ? xstrdup (group_name) : nullptr);
gid = parse_group (group_name);
}
{
static struct dev_ino dev_ino_buf;
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
- if (chopt.root_dev_ino == NULL)
+ if (chopt.root_dev_ino == nullptr)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
static enum Verbosity verbosity = V_off;
/* Pointer to the device and inode numbers of '/', when --recursive.
- Otherwise NULL. */
+ Otherwise nullptr. */
static struct dev_ino *root_dev_ino;
/* For long options that have no equivalent short option, use a
static struct option const long_options[] =
{
- {"changes", no_argument, NULL, 'c'},
- {"recursive", no_argument, NULL, 'R'},
- {"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
- {"preserve-root", no_argument, NULL, PRESERVE_ROOT},
- {"quiet", no_argument, NULL, 'f'},
- {"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
- {"silent", no_argument, NULL, 'f'},
- {"verbose", no_argument, NULL, 'v'},
+ {"changes", no_argument, nullptr, 'c'},
+ {"recursive", no_argument, nullptr, 'R'},
+ {"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
+ {"preserve-root", no_argument, nullptr, PRESERVE_ROOT},
+ {"quiet", no_argument, nullptr, 'f'},
+ {"reference", required_argument, nullptr, REFERENCE_FILE_OPTION},
+ {"silent", no_argument, nullptr, 'f'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Return true if the chmodable permission bits of FILE changed.
{
ch.old_mode = file_stats->st_mode;
ch.new_mode = mode_adjust (ch.old_mode, S_ISDIR (ch.old_mode) != 0,
- umask_value, change, NULL);
+ umask_value, change, nullptr);
if (chmodat (fts->fts_cwd_fd, file, ch.new_mode) == 0)
ch.status = CH_SUCCEEDED;
else
if (CH_NO_CHANGE_REQUESTED <= ch.status && diagnose_surprises)
{
mode_t naively_expected_mode =
- mode_adjust (ch.old_mode, S_ISDIR (ch.old_mode) != 0, 0, change, NULL);
+ mode_adjust (ch.old_mode, S_ISDIR (ch.old_mode) != 0,
+ 0, change, nullptr);
if (ch.new_mode & ~naively_expected_mode)
{
char new_perms[12];
}
/* Recursively change the modes of the specified FILES (the last entry
- of which is NULL). BIT_FLAGS controls how fts works.
+ of which is null). BIT_FLAGS controls how fts works.
Return true if successful. */
static bool
{
bool ok = true;
- FTS *fts = xfts_open (files, bit_flags, NULL);
+ FTS *fts = xfts_open (files, bit_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
- if (ent == NULL)
+ if (ent == nullptr)
{
if (errno != 0)
{
int
main (int argc, char **argv)
{
- char *mode = NULL;
+ char *mode = nullptr;
idx_t mode_len = 0;
idx_t mode_alloc = 0;
bool ok;
bool preserve_root = false;
- char const *reference_file = NULL;
+ char const *reference_file = nullptr;
int c;
initialize_main (&argc, &argv);
while ((c = getopt_long (argc, argv,
("Rcfvr::w::x::X::s::t::u::g::o::a::,::+::=::"
"0::1::2::3::4::5::6::7::"),
- long_options, NULL))
+ long_options, nullptr))
!= -1)
{
switch (c)
{
static struct dev_ino dev_ino_buf;
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
- if (root_dev_ino == NULL)
+ if (root_dev_ino == nullptr)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
else
{
- root_dev_ino = NULL;
+ root_dev_ino = nullptr;
}
ok = process_files (argv + optind,
chopt_init (struct Chown_option *chopt)
{
chopt->verbosity = V_off;
- chopt->root_dev_ino = NULL;
+ chopt->root_dev_ino = nullptr;
chopt->affect_symlink_referent = true;
chopt->recurse = false;
chopt->force_silent = false;
- chopt->user_name = NULL;
- chopt->group_name = NULL;
+ chopt->user_name = nullptr;
+ chopt->group_name = nullptr;
}
extern void
static char *
user_group_str (char const *user, char const *group)
{
- char *spec = NULL;
+ char *spec = nullptr;
if (user)
{
}
/* Tell the user how/if the user and group of FILE have been changed.
- If USER is NULL, give the group-oriented messages.
+ If USER is null, give the group-oriented messages.
CHANGED describes what (if anything) has happened. */
static void
}
spec = user_group_str (user, group);
- old_spec = user_group_str (user ? old_user : NULL, group ? old_group : NULL);
+ old_spec = user_group_str (user ? old_user : nullptr,
+ group ? old_group : nullptr);
switch (changed)
{
: _("failed to change ownership of %s\n"));
free (old_spec);
old_spec = spec;
- spec = NULL;
+ spec = nullptr;
}
break;
case CH_NO_CHANGE_REQUESTED:
if (!ok)
{
do_chown = false;
- file_stats = NULL;
+ file_stats = nullptr;
}
else if (required_uid == (uid_t) -1 && required_gid == (gid_t) -1
&& chopt->verbosity == V_off
: !symlink_changed ? CH_NOT_APPLIED
: !changed ? CH_NO_CHANGE_REQUESTED
: CH_SUCCEEDED);
- char *old_usr = file_stats ? uid_to_name (file_stats->st_uid) : NULL;
- char *old_grp = file_stats ? gid_to_name (file_stats->st_gid) : NULL;
+ char *old_usr = (file_stats
+ ? uid_to_name (file_stats->st_uid) : nullptr);
+ char *old_grp = (file_stats
+ ? gid_to_name (file_stats->st_gid) : nullptr);
char *new_usr = chopt->user_name
? chopt->user_name : uid != -1
- ? uid_to_str (uid) : NULL;
+ ? uid_to_str (uid) : nullptr;
char *new_grp = chopt->group_name
? chopt->group_name : gid != -1
- ? gid_to_str (gid) : NULL;
+ ? gid_to_str (gid) : nullptr;
describe_change (file_full_name, ch_status,
old_usr, old_grp,
new_usr, new_grp);
? 0
: FTS_NOSTAT);
- FTS *fts = xfts_open (files, bit_flags | stat_flags, NULL);
+ FTS *fts = xfts_open (files, bit_flags | stat_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
- if (ent == NULL)
+ if (ent == nullptr)
{
if (errno != 0)
{
bool recurse;
/* Pointer to the device and inode numbers of '/', when --recursive.
- Need not be freed. Otherwise NULL. */
+ Need not be freed. Otherwise nullptr. */
struct dev_ino *root_dev_ino;
/* This corresponds to the --dereference (opposite of -h) option. */
static struct option const long_options[] =
{
- {"recursive", no_argument, NULL, 'R'},
- {"changes", no_argument, NULL, 'c'},
- {"dereference", no_argument, NULL, DEREFERENCE_OPTION},
- {"from", required_argument, NULL, FROM_OPTION},
- {"no-dereference", no_argument, NULL, 'h'},
- {"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
- {"preserve-root", no_argument, NULL, PRESERVE_ROOT},
- {"quiet", no_argument, NULL, 'f'},
- {"silent", no_argument, NULL, 'f'},
- {"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
- {"verbose", no_argument, NULL, 'v'},
+ {"recursive", no_argument, nullptr, 'R'},
+ {"changes", no_argument, nullptr, 'c'},
+ {"dereference", no_argument, nullptr, DEREFERENCE_OPTION},
+ {"from", required_argument, nullptr, FROM_OPTION},
+ {"no-dereference", no_argument, nullptr, 'h'},
+ {"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
+ {"preserve-root", no_argument, nullptr, PRESERVE_ROOT},
+ {"quiet", no_argument, nullptr, 'f'},
+ {"silent", no_argument, nullptr, 'f'},
+ {"reference", required_argument, nullptr, REFERENCE_FILE_OPTION},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
chopt_init (&chopt);
- while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL))
+ while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, nullptr))
!= -1)
{
switch (optc)
bool warn;
char const *e = parse_user_spec_warn (optarg,
&required_uid, &required_gid,
- NULL, NULL, &warn);
+ nullptr, nullptr, &warn);
if (e)
error (warn ? 0 : EXIT_FAILURE, 0, "%s: %s", e, quote (optarg));
break;
{
static struct dev_ino dev_ino_buf;
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
- if (chopt.root_dev_ino == NULL)
+ if (chopt.root_dev_ino == nullptr)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
static struct option const long_opts[] =
{
- {"groups", required_argument, NULL, GROUPS},
- {"userspec", required_argument, NULL, USERSPEC},
- {"skip-chdir", no_argument, NULL, SKIP_CHDIR},
+ {"groups", required_argument, nullptr, GROUPS},
+ {"userspec", required_argument, nullptr, USERSPEC},
+ {"skip-chdir", no_argument, nullptr, SKIP_CHDIR},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
#if ! HAVE_SETGROUPS
parse_additional_groups (char const *groups, GETGROUPS_T **pgids,
size_t *pn_gids, bool show_errors)
{
- GETGROUPS_T *gids = NULL;
+ GETGROUPS_T *gids = nullptr;
size_t n_gids_allocated = 0;
size_t n_gids = 0;
char *buffer = xstrdup (groups);
char const *tmp;
int ret = 0;
- for (tmp = strtok (buffer, ","); tmp; tmp = strtok (NULL, ","))
+ for (tmp = strtok (buffer, ","); tmp; tmp = strtok (nullptr, ","))
{
struct group *g;
uintmax_t value;
- if (xstrtoumax (tmp, NULL, 10, &value, "") == LONGINT_OK
+ if (xstrtoumax (tmp, nullptr, 10, &value, "") == LONGINT_OK
&& value <= MAXGID)
{
while (isspace (to_uchar (*tmp)))
{
/* Handle the case where the name is numeric. */
g = getgrnam (tmp);
- if (g != NULL)
+ if (g != nullptr)
value = g->gr_gid;
}
/* Flag that we've got a group from the number. */
- g = (struct group *) (intptr_t) ! NULL;
+ g = (struct group *) (intptr_t) ! nullptr;
}
else
{
g = getgrnam (tmp);
- if (g != NULL)
+ if (g != nullptr)
value = g->gr_gid;
}
- if (g == NULL)
+ if (g == nullptr)
{
ret = -1;
int c;
/* Input user and groups spec. */
- char *userspec = NULL;
- char const *username = NULL;
- char const *groups = NULL;
+ char *userspec = nullptr;
+ char const *username = nullptr;
+ char const *groups = nullptr;
bool skip_chdir = false;
/* Parsed user and group IDs. */
uid_t uid = -1;
gid_t gid = -1;
- GETGROUPS_T *out_gids = NULL;
+ GETGROUPS_T *out_gids = nullptr;
size_t n_gids = 0;
initialize_main (&argc, &argv);
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "+", long_opts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "+", long_opts, nullptr)) != -1)
{
switch (c)
{
Within chroot lookup is the main justification for having
the --user option supported by the chroot command itself. */
if (userspec)
- ignore_value (parse_user_spec (userspec, &uid, &gid, NULL, NULL));
+ ignore_value (parse_user_spec (userspec, &uid, &gid, nullptr, nullptr));
/* If no gid is supplied or looked up, do so now.
Also lookup the username for use with getgroups. */
{
/* No command. Run an interactive shell. */
char *shell = getenv ("SHELL");
- if (shell == NULL)
+ if (shell == nullptr)
shell = bad_cast ("/bin/sh");
argv[0] = shell;
argv[1] = bad_cast ("-i");
- argv[2] = NULL;
+ argv[2] = nullptr;
}
else
{
{
bool warn;
char const *err = parse_user_spec_warn (userspec, &uid, &gid,
- NULL, NULL, &warn);
+ nullptr, nullptr, &warn);
if (err)
error (warn ? 0 : EXIT_CANCELED, 0, "%s", (err));
}
}
GETGROUPS_T *gids = out_gids;
- GETGROUPS_T *in_gids = NULL;
+ GETGROUPS_T *in_gids = nullptr;
if (groups && *groups)
{
if (parse_additional_groups (groups, &in_gids, &n_gids, !n_gids) != 0)
static struct option const long_options[] =
{
- {"check-order", no_argument, NULL, CHECK_ORDER_OPTION},
- {"nocheck-order", no_argument, NULL, NOCHECK_ORDER_OPTION},
- {"output-delimiter", required_argument, NULL, OUTPUT_DELIMITER_OPTION},
- {"total", no_argument, NULL, TOTAL_OPTION},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"check-order", no_argument, nullptr, CHECK_ORDER_OPTION},
+ {"nocheck-order", no_argument, nullptr, NOCHECK_ORDER_OPTION},
+ {"output-delimiter", required_argument, nullptr, OUTPUT_DELIMITER_OPTION},
+ {"total", no_argument, nullptr, TOTAL_OPTION},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
struct linebuffer lba[2][4];
/* thisline[i] points to the linebuffer holding the next available line
- in file i, or is NULL if there are no lines left in that file. */
+ in file i, or is null if there are no lines left in that file. */
struct linebuffer *thisline[2];
/* all_line[i][alt[i][0]] also points to the linebuffer holding the
check_input_order = CHECK_ORDER_DEFAULT;
total_option = false;
- while ((c = getopt_long (argc, argv, "123z", long_options, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "123z", long_options, nullptr)) != -1)
switch (c)
{
case '1':
(SSIZE_MAX, SIZE_MAX) truncated to a value that is
surely aligned well. */
ssize_t copy_max = MIN (SSIZE_MAX, SIZE_MAX) >> 30 << 30;
- ssize_t n_copied = copy_file_range (src_fd, NULL, dest_fd, NULL,
+ ssize_t n_copied = copy_file_range (src_fd, nullptr, dest_fd, nullptr,
MIN (max_n_read, copy_max), 0);
if (n_copied == 0)
{
/* Attempt to use a relatively large calloc'd source buffer for
efficiency, but if that allocation fails, resort to a smaller
statically allocated one. */
- if (zeros == NULL)
+ if (zeros == nullptr)
{
static char fallback[1024];
zeros = calloc (nz, 1);
- if (zeros == NULL)
+ if (zeros == nullptr)
{
zeros = fallback;
nz = sizeof fallback;
bool some_errors = (!all_errors && !x->reduce_diagnostics);
int (*check) (char const *, struct error_context *)
= (x->preserve_security_context || x->set_security_context
- ? check_selinux_attr : NULL);
+ ? check_selinux_attr : nullptr);
# if 4 < __GNUC__ + (8 <= __GNUC_MINOR__)
/* Pacify gcc -Wsuggest-attribute=format through at least GCC 11.2.1. */
.quote = copy_attr_quote,
.quote_free = copy_attr_free
})
- : NULL);
+ : nullptr);
# if 4 < __GNUC__ + (8 <= __GNUC_MINOR__)
# pragma GCC diagnostic pop
# endif
bool ok = true;
name_space = savedir (src_name_in, SAVEDIR_SORT_FASTREAD);
- if (name_space == NULL)
+ if (name_space == nullptr)
{
/* This diagnostic is a bit vague because savedir can fail in
several different ways. */
while (*namep != '\0')
{
bool local_copy_into_self;
- char *src_name = file_name_concat (src_name_in, namep, NULL);
- char *dst_name = file_name_concat (dst_name_in, namep, NULL);
+ char *src_name = file_name_concat (src_name_in, namep, nullptr);
+ char *dst_name = file_name_concat (dst_name_in, namep, nullptr);
bool first_dir_created = *first_dir_created_per_command_line_arg;
bool rename_succeeded;
file_t file = (dest_desc < 0
? file_name_lookup (dst_name, 0, 0)
: getdport (dest_desc));
- if (file == MACH_PORT_NULL)
+ if (file == MACH_PORT_nullptr)
error (0, errno, _("failed to lookup file %s"), quoteaf (dst_name));
else
{
mode_t dst_mode, mode_t omitted_permissions, bool *new_dst,
struct stat const *src_sb)
{
- char *buf = NULL;
+ char *buf = nullptr;
int dest_desc;
int dest_errno;
int source_desc;
{
x->dest_info
= hash_initialize (DEST_INFO_INITIAL_CAPACITY,
- NULL,
+ nullptr,
triple_hash,
triple_compare,
triple_free);
*/
x->src_info
= hash_initialize (DEST_INFO_INITIAL_CAPACITY,
- NULL,
+ nullptr,
triple_hash_no_name,
triple_compare,
triple_free);
}
/* Print --verbose output on standard output, e.g. 'new' -> 'old'.
- If BACKUP_DST_NAME is non-NULL, then also indicate that it is
+ If BACKUP_DST_NAME is non-null, then also indicate that it is
the name of a backup file. */
static void
emit_verbose (char const *src, char const *dst, char const *backup_dst_name)
putchar ('\n');
}
-/* A wrapper around "setfscreatecon (NULL)" that exits upon failure. */
+/* A wrapper around "setfscreatecon (nullptr)" that exits upon failure. */
static void
restore_default_fscreatecon_or_die (void)
{
- if (setfscreatecon (NULL) != 0)
+ if (setfscreatecon (nullptr) != 0)
die (EXIT_FAILURE, errno,
_("failed to restore the default file creation context"));
}
if (0 < err)
{
- char *a_src_name = NULL;
+ char *a_src_name = nullptr;
if (!src_name)
src_name = a_src_name = subst_suffix (dst_name, dst_relname,
src_relname);
mode_t dst_mode_bits;
mode_t omitted_permissions;
bool restore_dst_mode = false;
- char *earlier_file = NULL;
- char *dst_backup = NULL;
+ char *earlier_file = nullptr;
+ char *dst_backup = nullptr;
char const *drelname = *dst_relname ? dst_relname : ".";
bool delayed_ok;
bool copied_as_regular = false;
/* Detect the case in which the same source file appears more than
once on the command line and no backup option has been selected.
If so, simply warn and don't copy it the second time.
- This check is enabled only if x->src_info is non-NULL. */
+ This check is enabled only if x->src_info is non-null. */
if (command_line_arg && x->src_info)
{
if ( ! S_ISDIR (src_mode)
{
/* Note we currently replace DST_NAME unconditionally,
even if it was a newer separate file. */
- if (! create_hard_link (NULL, dst_dirfd, earlier_file,
+ if (! create_hard_link (nullptr, dst_dirfd, earlier_file,
dst_name, dst_dirfd, dst_relname,
true,
x->verbose, dereference))
We'll use that info to detect this problem: cp -R dir dir. */
if (rename_errno == 0)
- earlier_file = NULL;
+ earlier_file = nullptr;
else if (x->recursive && S_ISDIR (src_mode))
{
if (command_line_arg)
}
else
{
- if (! create_hard_link (NULL, dst_dirfd, earlier_file,
+ if (! create_hard_link (nullptr, dst_dirfd, earlier_file,
dst_name, dst_dirfd, dst_relname,
true, x->verbose, dereference))
goto un_backup;
if (x->move_mode)
printf (_("created directory %s\n"), quoteaf (dst_name));
else
- emit_verbose (src_name, dst_name, NULL);
+ emit_verbose (src_name, dst_name, nullptr);
}
}
else
{
char *src_link_val = areadlink_with_size (src_name, src_sb.st_size);
dest_is_symlink = true;
- if (src_link_val == NULL)
+ if (src_link_val == nullptr)
{
error (0, errno, _("cannot read symbolic link %s"),
quoteaf (src_name));
remove the entry associating the source dev/ino with the
destination file name, so we don't try to 'preserve' a link
to a file we didn't create. */
- if (earlier_file == NULL)
+ if (earlier_file == nullptr)
forget_created (src_sb.st_ino, src_sb.st_dev);
if (dst_backup)
bool first_dir_created_per_command_line_arg = false;
return copy_internal (src_name, dst_name, dst_dirfd, dst_relname,
- nonexistent_dst, NULL, NULL,
+ nonexistent_dst, nullptr, nullptr,
options, true,
&first_dir_created_per_command_line_arg,
copy_into_self, rename_succeeded);
rm -rf a b c; mkdir a b c; touch a/f b/f; mv a/f b/f c
For now, it protects only regular files when copying (i.e., not renaming).
When renaming, it protects all non-directories.
- Use dest_info_init to initialize it, or set it to NULL to disable
+ Use dest_info_init to initialize it, or set it to nullptr to disable
this feature. */
Hash_table *dest_info;
{
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static void
launch_program (char const *prog_name, int prog_argc, char **prog_argv)
{
- int (*prog_main) (int, char **) = NULL;
+ int (*prog_main) (int, char **) = nullptr;
/* Ensure that at least one parameter was passed. */
if (!prog_argc || !prog_argv || !prog_argv[0] || !prog_name)
if (argc >= 2)
{
size_t nskip = 0;
- char *arg_name = NULL;
+ char *arg_name = nullptr;
/* If calling coreutils directly, the "script" name isn't passed.
Distinguish the two cases with a -shebang suffix. */
textdomain (PACKAGE);
atexit (close_stdout);
- if ((optc = getopt_long (argc, argv, "", long_options, NULL)) != -1)
+ if ((optc = getopt_long (argc, argv, "", long_options, nullptr)) != -1)
switch (optc)
{
case_GETOPT_HELP_CHAR;
probe.st_ino = ino;
probe.st_dev = dev;
- probe.name = NULL;
+ probe.name = nullptr;
ent = hash_remove (src_to_dest, &probe);
if (ent)
}
/* If INO/DEV correspond to an already-copied source file, return the
- name of the corresponding destination file. Otherwise, return NULL. */
+ name of the corresponding destination file. Otherwise, return nullptr. */
extern char *
src_to_dest_lookup (ino_t ino, dev_t dev)
ent.st_ino = ino;
ent.st_dev = dev;
e = hash_lookup (src_to_dest, &ent);
- return e ? e->name : NULL;
+ return e ? e->name : nullptr;
}
/* Add file NAME, copied from inode number INO and device number DEV,
to the list of files we have copied.
- Return NULL if inserted, otherwise non-NULL. */
+ Return nullptr if inserted, otherwise a non-null pointer. */
extern char *
remember_copied (char const *name, ino_t ino, dev_t dev)
ent->st_dev = dev;
ent_from_table = hash_insert (src_to_dest, ent);
- if (ent_from_table == NULL)
+ if (ent_from_table == nullptr)
{
/* Insertion failed due to lack of memory. */
xalloc_die ();
}
/* New key; insertion succeeded. */
- return NULL;
+ return nullptr;
}
/* Initialize the hash table. */
extern void
hash_init (void)
{
- src_to_dest = hash_initialize (INITIAL_TABLE_SIZE, NULL,
+ src_to_dest = hash_initialize (INITIAL_TABLE_SIZE, nullptr,
src_to_dest_hash,
src_to_dest_compare,
src_to_dest_free);
- if (src_to_dest == NULL)
+ if (src_to_dest == nullptr)
xalloc_die ();
}
static char const *const sparse_type_string[] =
{
- "never", "auto", "always", NULL
+ "never", "auto", "always", nullptr
};
static enum Sparse_type const sparse_type[] =
{
static char const *const reflink_type_string[] =
{
- "auto", "always", "never", NULL
+ "auto", "always", "never", nullptr
};
static enum Reflink_type const reflink_type[] =
{
static char const *const update_type_string[] =
{
- "all", "none", "older", NULL
+ "all", "none", "older", nullptr
};
static enum Update_type const update_type[] =
{
static struct option const long_opts[] =
{
- {"archive", no_argument, NULL, 'a'},
- {"attributes-only", no_argument, NULL, ATTRIBUTES_ONLY_OPTION},
- {"backup", optional_argument, NULL, 'b'},
- {"copy-contents", no_argument, NULL, COPY_CONTENTS_OPTION},
- {"debug", no_argument, NULL, DEBUG_OPTION},
- {"dereference", no_argument, NULL, 'L'},
- {"force", no_argument, NULL, 'f'},
- {"interactive", no_argument, NULL, 'i'},
- {"link", no_argument, NULL, 'l'},
- {"no-clobber", no_argument, NULL, 'n'},
- {"no-dereference", no_argument, NULL, 'P'},
- {"no-preserve", required_argument, NULL, NO_PRESERVE_ATTRIBUTES_OPTION},
- {"no-target-directory", no_argument, NULL, 'T'},
- {"one-file-system", no_argument, NULL, 'x'},
- {"parents", no_argument, NULL, PARENTS_OPTION},
- {"path", no_argument, NULL, PARENTS_OPTION}, /* Deprecated. */
- {"preserve", optional_argument, NULL, PRESERVE_ATTRIBUTES_OPTION},
- {"recursive", no_argument, NULL, 'R'},
- {"remove-destination", no_argument, NULL, UNLINK_DEST_BEFORE_OPENING},
- {"sparse", required_argument, NULL, SPARSE_OPTION},
- {"reflink", optional_argument, NULL, REFLINK_OPTION},
- {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
- {"suffix", required_argument, NULL, 'S'},
- {"symbolic-link", no_argument, NULL, 's'},
- {"target-directory", required_argument, NULL, 't'},
- {"update", optional_argument, NULL, 'u'},
- {"verbose", no_argument, NULL, 'v'},
+ {"archive", no_argument, nullptr, 'a'},
+ {"attributes-only", no_argument, nullptr, ATTRIBUTES_ONLY_OPTION},
+ {"backup", optional_argument, nullptr, 'b'},
+ {"copy-contents", no_argument, nullptr, COPY_CONTENTS_OPTION},
+ {"debug", no_argument, nullptr, DEBUG_OPTION},
+ {"dereference", no_argument, nullptr, 'L'},
+ {"force", no_argument, nullptr, 'f'},
+ {"interactive", no_argument, nullptr, 'i'},
+ {"link", no_argument, nullptr, 'l'},
+ {"no-clobber", no_argument, nullptr, 'n'},
+ {"no-dereference", no_argument, nullptr, 'P'},
+ {"no-preserve", required_argument, nullptr, NO_PRESERVE_ATTRIBUTES_OPTION},
+ {"no-target-directory", no_argument, nullptr, 'T'},
+ {"one-file-system", no_argument, nullptr, 'x'},
+ {"parents", no_argument, nullptr, PARENTS_OPTION},
+ {"path", no_argument, nullptr, PARENTS_OPTION}, /* Deprecated. */
+ {"preserve", optional_argument, nullptr, PRESERVE_ATTRIBUTES_OPTION},
+ {"recursive", no_argument, nullptr, 'R'},
+ {"remove-destination", no_argument, nullptr, UNLINK_DEST_BEFORE_OPENING},
+ {"sparse", required_argument, nullptr, SPARSE_OPTION},
+ {"reflink", optional_argument, nullptr, REFLINK_OPTION},
+ {"strip-trailing-slashes", no_argument, nullptr,
+ STRIP_TRAILING_SLASHES_OPTION},
+ {"suffix", required_argument, nullptr, 'S'},
+ {"symbolic-link", no_argument, nullptr, 's'},
+ {"target-directory", required_argument, nullptr, 't'},
+ {"update", optional_argument, nullptr, 'u'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_SELINUX_CONTEXT_OPTION_DECL},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
char *dst_dir; /* Leading directory of DIR. */
idx_t dirlen = dir_len (const_dir);
- *attr_list = NULL;
+ *attr_list = nullptr;
/* Succeed immediately if the parent of CONST_DIR must already exist,
as the target directory has already been checked. */
}
else
{
- if (verbose_fmt_string != NULL)
+ if (verbose_fmt_string != nullptr)
printf (verbose_fmt_string, src, dir);
}
parent_exists =
(make_dir_parents_private
(dst_name, arg_in_concat - dst_name, target_dirfd,
- (x->verbose ? "%s -> %s\n" : NULL),
+ (x->verbose ? "%s -> %s\n" : nullptr),
&attr_list, &new_dst, x));
}
else
bool copy_into_self;
ok &= copy (arg, dst_name, target_dirfd, dst_relname,
- new_dst, x, ©_into_self, NULL);
+ new_dst, x, ©_into_self, nullptr);
if (parents_option)
ok &= re_protect (dst_name, arg_in_concat, target_dirfd,
x = &x_tmp;
}
- ok = copy (source, dest, AT_FDCWD, dest, -new_dst, x, &unused, NULL);
+ ok = copy (source, dest, AT_FDCWD, dest, -new_dst, x, &unused, nullptr);
}
return ok;
x->explicit_no_preserve_mode = false;
x->preserve_security_context = false; /* -a or --preserve=context. */
x->require_preserve_context = false; /* --preserve=context. */
- x->set_security_context = NULL; /* -Z, set sys default context. */
+ x->set_security_context = nullptr; /* -Z, set sys default context. */
x->preserve_xattr = false;
x->reduce_diagnostics = false;
x->require_preserve_xattr = false;
in general one cannot do that safely, give the current semantics of
open's O_EXCL flag, (which POSIX doesn't even allow cp to use, btw).
But POSIX requires it. */
- x->open_dangling_dest_symlink = getenv ("POSIXLY_CORRECT") != NULL;
+ x->open_dangling_dest_symlink = getenv ("POSIXLY_CORRECT") != nullptr;
- x->dest_info = NULL;
- x->src_info = NULL;
+ x->dest_info = nullptr;
+ x->src_info = nullptr;
}
/* Given a string, ARG, containing a comma-separated list of arguments
static char const *const preserve_args[] =
{
"mode", "timestamps",
- "ownership", "links", "context", "xattr", "all", NULL
+ "ownership", "links", "context", "xattr", "all", nullptr
};
ARGMATCH_VERIFY (preserve_args, preserve_vals);
int c;
bool ok;
bool make_backups = false;
- char const *backup_suffix = NULL;
- char *version_control_string = NULL;
+ char const *backup_suffix = nullptr;
+ char *version_control_string = nullptr;
struct cp_options x;
bool copy_contents = false;
- char *target_directory = NULL;
+ char *target_directory = nullptr;
bool no_target_directory = false;
- char const *scontext = NULL;
+ char const *scontext = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
cp_option_init (&x);
while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ",
- long_opts, NULL))
+ long_opts, nullptr))
!= -1)
{
switch (c)
break;
case REFLINK_OPTION:
- if (optarg == NULL)
+ if (optarg == nullptr)
x.reflink_mode = REFLINK_ALWAYS;
else
x.reflink_mode = XARGMATCH ("--reflink", optarg,
break;
case PRESERVE_ATTRIBUTES_OPTION:
- if (optarg == NULL)
+ if (optarg == nullptr)
{
/* Fall through to the case for 'p' below. */
}
break;
case 'u':
- if (optarg == NULL)
+ if (optarg == nullptr)
x.update = true;
else if (x.interactive != I_ALWAYS_NO) /* -n takes precedence. */
{
else
{
x.set_security_context = selabel_open (SELABEL_CTX_FILE,
- NULL, 0);
+ nullptr, 0);
if (! x.set_security_context)
error (0, errno, _("warning: ignoring --context"));
}
/* FIXME: This handles new files. But what about existing files?
I.e., if updating a tree, new files would have the specified context,
but shouldn't existing files be updated for consistency like this?
- if (scontext && !restorecon (NULL, dst_path, 0))
+ if (scontext && !restorecon (nullptr, dst_path, 0))
error (...);
*/
if (scontext && setfscreatecon (scontext) < 0)
static void save_line_to_file (const struct cstring *line);
/* Start of buffer list. */
-static struct buffer_record *head = NULL;
+static struct buffer_record *head = nullptr;
/* Partially read line. */
-static char *hold_area = NULL;
+static char *hold_area = nullptr;
/* Number of bytes in 'hold_area'. */
static idx_t hold_count = 0;
static bool have_read_eof = false;
/* Name of output files. */
-static char *volatile filename_space = NULL;
+static char *volatile filename_space = nullptr;
/* Prefix part of output file names. */
-static char const *volatile prefix = NULL;
+static char const *volatile prefix = nullptr;
/* Suffix part of output file names. */
-static char *volatile suffix = NULL;
+static char *volatile suffix = nullptr;
/* Number of digits to use in output file names. */
static int volatile digits = 2;
static intmax_t bytes_written;
/* Output file pointer. */
-static FILE *output_stream = NULL;
+static FILE *output_stream = nullptr;
/* Output file name. */
-static char *output_filename = NULL;
+static char *output_filename = nullptr;
/* Perhaps it would be cleaner to pass arg values instead of indexes. */
static char **global_argv;
static struct option const longopts[] =
{
- {"digits", required_argument, NULL, 'n'},
- {"quiet", no_argument, NULL, 'q'},
- {"silent", no_argument, NULL, 's'},
- {"keep-files", no_argument, NULL, 'k'},
- {"elide-empty-files", no_argument, NULL, 'z'},
- {"prefix", required_argument, NULL, 'f'},
- {"suffix-format", required_argument, NULL, 'b'},
- {"suppress-matched", no_argument, NULL, SUPPRESS_MATCHED_OPTION},
+ {"digits", required_argument, nullptr, 'n'},
+ {"quiet", no_argument, nullptr, 'q'},
+ {"silent", no_argument, nullptr, 's'},
+ {"keep-files", no_argument, nullptr, 'k'},
+ {"elide-empty-files", no_argument, nullptr, 'z'},
+ {"prefix", required_argument, nullptr, 'f'},
+ {"suffix-format", required_argument, nullptr, 'b'},
+ {"suppress-matched", no_argument, nullptr, SUPPRESS_MATCHED_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Optionally remove files created so far; then exit.
sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
delete_all_files (false);
- sigprocmask (SIG_SETMASK, &oldset, NULL);
+ sigprocmask (SIG_SETMASK, &oldset, nullptr);
}
static _Noreturn void
{
struct line *p = xmalloc (sizeof *p);
- p->next = NULL;
+ p->next = nullptr;
clear_line_control (p);
return p;
struct line *l;
/* If there is no existing area to keep line info, get some. */
- if (b->line_start == NULL)
+ if (b->line_start == nullptr)
b->line_start = b->curr_line = new_line_control ();
/* If existing area for lines is full, get more. */
{
struct buffer_record *new_buffer = xmalloc (sizeof *new_buffer);
new_buffer->bytes_alloc = 0;
- new_buffer->buffer = xpalloc (NULL, &new_buffer->bytes_alloc, min_size,
+ new_buffer->buffer = xpalloc (nullptr, &new_buffer->bytes_alloc, min_size,
-1, 1);
new_buffer->bytes_used = 0;
new_buffer->start_line = new_buffer->first_available = last_line_number + 1;
new_buffer->num_lines = 0;
- new_buffer->line_start = new_buffer->curr_line = NULL;
- new_buffer->next = NULL;
+ new_buffer->line_start = new_buffer->curr_line = nullptr;
+ new_buffer->next = nullptr;
return new_buffer;
}
{
struct buffer_record *p;
- buf->next = NULL;
+ buf->next = nullptr;
buf->curr_line = buf->line_start;
- if (head == NULL)
+ if (head == nullptr)
head = buf;
else
{
static intmax_t
get_first_line_in_buffer (void)
{
- if (head == NULL && !load_buffer ())
+ if (head == nullptr && !load_buffer ())
die (EXIT_FAILURE, errno, _("input disappeared"));
return head->first_available;
/* Return a pointer to the logical first line in the buffer and make the
next line the logical first line.
- Return NULL if there is no more input. */
+ Return nullptr if there is no more input. */
static struct cstring *
remove_line (void)
{
- /* If non-NULL, this is the buffer for which the previous call
+ /* If non-null, this is the buffer for which the previous call
returned the final line. So now, presuming that line has been
processed, we can free the buffer and reset this pointer. */
- static struct buffer_record *prev_buf = NULL;
+ static struct buffer_record *prev_buf = nullptr;
struct cstring *line; /* Return value. */
struct line *l; /* For convenience. */
if (prev_buf)
{
free_buffer (prev_buf);
- prev_buf = NULL;
+ prev_buf = nullptr;
}
- if (head == NULL && !load_buffer ())
- return NULL;
+ if (head == nullptr && !load_buffer ())
+ return nullptr;
if (current_line < head->first_available)
current_line = head->first_available;
{
/* Go on to the next line record. */
head->curr_line = l->next;
- if (head->curr_line == NULL || head->curr_line->used == 0)
+ if (head->curr_line == nullptr || head->curr_line->used == 0)
{
/* Go on to the next data block.
but first record the current one so we can free it
}
/* Search the buffers for line LINENUM, reading more input if necessary.
- Return a pointer to the line, or NULL if it is not found in the file. */
+ Return a pointer to the line, or nullptr if it is not found in the file. */
static struct cstring *
find_line (intmax_t linenum)
{
struct buffer_record *b;
- if (head == NULL && !load_buffer ())
- return NULL;
+ if (head == nullptr && !load_buffer ())
+ return nullptr;
if (linenum < head->start_line)
- return NULL;
+ return nullptr;
for (b = head;;)
{
}
return &l->starts[offset];
}
- if (b->next == NULL && !load_buffer ())
- return NULL;
+ if (b->next == nullptr && !load_buffer ())
+ return nullptr;
b = b->next; /* Try the next data block. */
}
}
static bool
no_more_lines (void)
{
- return find_line (current_line + 1) == NULL;
+ return find_line (current_line + 1) == nullptr;
}
/* Open NAME as standard input. */
for (i = 0; i < lines; i++)
{
line = remove_line ();
- if (line == NULL)
+ if (line == nullptr)
{
error (0, 0, _("%s: line number out of range"),
quote (global_argv[argnum]));
{
struct cstring *line;
- while ((line = remove_line ()) != NULL)
+ while ((line = remove_line ()) != nullptr)
save_line_to_file (line);
}
while (linenum++ < last_line_to_save)
{
struct cstring *line = remove_line ();
- if (line == NULL)
+ if (line == nullptr)
handle_line_error (p, repetition);
save_line_to_file (line);
}
while (true)
{
line = find_line (++current_line);
- if (line == NULL)
+ if (line == nullptr)
{
if (p->repeat_forever)
{
if (line->str[line_len - 1] == '\n')
line_len--;
ret = re_search (&p->re_compiled, line->str, line_len,
- 0, line_len, NULL);
+ 0, line_len, nullptr);
if (ret == -2)
{
error (0, 0, _("error in regular expression search"));
while (true)
{
line = find_line (++current_line);
- if (line == NULL)
+ if (line == nullptr)
{
if (p->repeat_forever)
{
if (line->str[line_len - 1] == '\n')
line_len--;
ret = re_search (&p->re_compiled, line->str, line_len,
- 0, line_len, NULL);
+ 0, line_len, nullptr);
if (ret == -2)
{
error (0, 0, _("error in regular expression search"));
sigset_t oldset;
sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
output_stream = fopen (output_filename, "w");
- fopen_ok = (output_stream != NULL);
+ fopen_ok = (output_stream != nullptr);
fopen_errno = errno;
files_created = nfiles + fopen_ok;
- sigprocmask (SIG_SETMASK, &oldset, NULL);
+ sigprocmask (SIG_SETMASK, &oldset, nullptr);
}
if (! fopen_ok)
if (ferror (output_stream))
{
error (0, 0, _("write error for %s"), quoteaf (output_filename));
- output_stream = NULL;
+ output_stream = nullptr;
cleanup_fatal ();
}
if (fclose (output_stream) != 0)
{
error (0, errno, "%s", quotef (output_filename));
- output_stream = NULL;
+ output_stream = nullptr;
cleanup_fatal ();
}
if (bytes_written == 0 && elide_empty_files)
unlink_ok = (unlink (output_filename) == 0);
unlink_errno = errno;
files_created--;
- sigprocmask (SIG_SETMASK, &oldset, NULL);
+ sigprocmask (SIG_SETMASK, &oldset, nullptr);
if (! unlink_ok && unlink_errno != ENOENT)
error (0, unlink_errno, "%s", quotef (output_filename));
fprintf (stdout, "%s\n", imaxtostr (bytes_written, buf));
}
}
- output_stream = NULL;
+ output_stream = nullptr;
}
}
if (l != line->len)
{
error (0, errno, _("write error for %s"), quoteaf (output_filename));
- output_stream = NULL;
+ output_stream = nullptr;
cleanup_fatal ();
}
bytes_written += line->len;
static void
check_for_offset (struct control *p, char const *str, char const *num)
{
- if (xstrtoimax (num, NULL, 10, &p->offset, "") != LONGINT_OK)
+ if (xstrtoimax (num, nullptr, 10, &p->offset, "") != LONGINT_OK)
die (EXIT_FAILURE, 0, _("%s: integer expected after delimiter"),
quote (str));
}
else
{
uintmax_t val;
- if (xstrtoumax (str + 1, NULL, 10, &val, "") != LONGINT_OK
+ if (xstrtoumax (str + 1, nullptr, 10, &val, "") != LONGINT_OK
|| INTMAX_MAX < val)
{
die (EXIT_FAILURE, 0,
char const *err;
closing_delim = strrchr (str + 1, delim);
- if (closing_delim == NULL)
+ if (closing_delim == nullptr)
die (EXIT_FAILURE, 0,
_("%s: closing delimiter '%c' missing"), str, delim);
p->ignore = ignore;
p->regexpr = true;
- p->re_compiled.buffer = NULL;
+ p->re_compiled.buffer = nullptr;
p->re_compiled.allocated = 0;
p->re_compiled.fastmap = xmalloc (UCHAR_MAX + 1);
- p->re_compiled.translate = NULL;
+ p->re_compiled.translate = nullptr;
re_syntax_options =
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
err = re_compile_pattern (str + 1, len, &p->re_compiled);
p->argnum = i;
uintmax_t val;
- if (xstrtoumax (argv[i], NULL, 10, &val, "") != LONGINT_OK
+ if (xstrtoumax (argv[i], nullptr, 10, &val, "") != LONGINT_OK
|| INTMAX_MAX < val)
die (EXIT_FAILURE, 0, _("%s: invalid pattern"), quote (argv[i]));
if (val == 0)
die (EXIT_FAILURE, 0,
_("missing %% conversion specification in suffix"));
- int maxlen = snprintf (NULL, 0, format, INT_MAX);
+ int maxlen = snprintf (nullptr, 0, format, INT_MAX);
if (maxlen < 0)
xalloc_die ();
return maxlen;
atexit (close_stdout);
global_argv = argv;
- controls = NULL;
+ controls = nullptr;
control_used = 0;
suppress_count = false;
remove_files = true;
suppress_matched = false;
prefix = DEFAULT_PREFIX;
- while ((optc = getopt_long (argc, argv, "f:b:kn:sqz", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "f:b:kn:sqz", longopts, nullptr))
+ != -1)
switch (optc)
{
case 'f':
sigemptyset (&caught_signals);
for (i = 0; i < nsigs; i++)
{
- sigaction (sig[i], NULL, &act);
+ sigaction (sig[i], nullptr, &act);
if (act.sa_handler != SIG_IGN)
sigaddset (&caught_signals, sig[i]);
}
for (i = 0; i < nsigs; i++)
if (sigismember (&caught_signals, sig[i]))
- sigaction (sig[i], &act, NULL);
+ sigaction (sig[i], &act, nullptr);
}
split_file ();
static struct option const longopts[] =
{
- {"bytes", required_argument, NULL, 'b'},
- {"characters", required_argument, NULL, 'c'},
- {"fields", required_argument, NULL, 'f'},
- {"delimiter", required_argument, NULL, 'd'},
- {"only-delimited", no_argument, NULL, 's'},
- {"output-delimiter", required_argument, NULL, OUTPUT_DELIMITER_OPTION},
- {"complement", no_argument, NULL, COMPLEMENT_OPTION},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"bytes", required_argument, nullptr, 'b'},
+ {"characters", required_argument, nullptr, 'c'},
+ {"fields", required_argument, nullptr, 'f'},
+ {"delimiter", required_argument, nullptr, 'd'},
+ {"only-delimited", no_argument, nullptr, 's'},
+ {"output-delimiter", required_argument, nullptr, OUTPUT_DELIMITER_OPTION},
+ {"complement", no_argument, nullptr, COMPLEMENT_OPTION},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
if (len < 0)
{
free (field_1_buffer);
- field_1_buffer = NULL;
+ field_1_buffer = nullptr;
if (ferror (stream) || feof (stream))
break;
xalloc_die ();
else
{
stream = fopen (file, "r");
- if (stream == NULL)
+ if (stream == nullptr)
{
error (0, errno, "%s", quotef (file));
return false;
bool ok;
bool delim_specified = false;
bool byte_mode = false;
- char *spec_list_string = NULL;
+ char *spec_list_string = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
delim = '\0';
have_read_stdin = false;
- while ((optc = getopt_long (argc, argv, "b:c:d:f:nsz", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "b:c:d:f:nsz", longopts, nullptr))
+ != -1)
{
switch (optc)
{
if (!delim_specified)
delim = '\t';
- if (output_delimiter_string == NULL)
+ if (output_delimiter_string == nullptr)
{
output_delimiter_default[0] = delim;
output_delimiter_string = output_delimiter_default;
/* Put "hours" and "minutes" first, since they aren't valid for
--rfc-3339. */
"hours", "minutes",
- "date", "seconds", "ns", NULL
+ "date", "seconds", "ns", nullptr
};
static enum Time_spec const time_spec[] =
{
static struct option const long_options[] =
{
- {"date", required_argument, NULL, 'd'},
- {"debug", no_argument, NULL, DEBUG_DATE_PARSING_OPTION},
- {"file", required_argument, NULL, 'f'},
- {"iso-8601", optional_argument, NULL, 'I'},
- {"reference", required_argument, NULL, 'r'},
- {"resolution", no_argument, NULL, RESOLUTION_OPTION},
- {"rfc-email", no_argument, NULL, 'R'},
- {"rfc-822", no_argument, NULL, 'R'},
- {"rfc-2822", no_argument, NULL, 'R'},
- {"rfc-3339", required_argument, NULL, RFC_3339_OPTION},
- {"set", required_argument, NULL, 's'},
- {"uct", no_argument, NULL, 'u'},
- {"utc", no_argument, NULL, 'u'},
- {"universal", no_argument, NULL, 'u'},
+ {"date", required_argument, nullptr, 'd'},
+ {"debug", no_argument, nullptr, DEBUG_DATE_PARSING_OPTION},
+ {"file", required_argument, nullptr, 'f'},
+ {"iso-8601", optional_argument, nullptr, 'I'},
+ {"reference", required_argument, nullptr, 'r'},
+ {"resolution", no_argument, nullptr, RESOLUTION_OPTION},
+ {"rfc-email", no_argument, nullptr, 'R'},
+ {"rfc-822", no_argument, nullptr, 'R'},
+ {"rfc-2822", no_argument, nullptr, 'R'},
+ {"rfc-3339", required_argument, nullptr, RFC_3339_OPTION},
+ {"set", required_argument, nullptr, 's'},
+ {"uct", no_argument, nullptr, 'u'},
+ {"utc", no_argument, nullptr, 'u'},
+ {"universal", no_argument, nullptr, 'u'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* flags for parse_datetime2 */
/* Return a newly allocated copy of FORMAT with each "%-N" adjusted to
be "%9N", "%6N", or whatever other resolution is appropriate for
- the current platform. If no "%-N" appears, return NULL. */
+ the current platform. If no "%-N" appears, return nullptr. */
static char *
adjust_resolution (char const *format)
{
- char *copy = NULL;
+ char *copy = nullptr;
for (char const *f = format; *f; f++)
if (f[0] == '%')
else
{
in_stream = fopen (input_filename, "r");
- if (in_stream == NULL)
+ if (in_stream == nullptr)
{
die (EXIT_FAILURE, errno, "%s", quotef (input_filename));
}
}
- line = NULL;
+ line = nullptr;
buflen = 0;
ok = true;
while (true)
break;
}
- if (! parse_datetime2 (&when, line, NULL,
+ if (! parse_datetime2 (&when, line, nullptr,
parse_datetime_flags, tz, tzstring))
{
if (line[line_length - 1] == '\n')
main (int argc, char **argv)
{
int optc;
- char const *datestr = NULL;
- char const *set_datestr = NULL;
+ char const *datestr = nullptr;
+ char const *set_datestr = nullptr;
struct timespec when;
bool set_date = false;
- char const *format = NULL;
+ char const *format = nullptr;
bool get_resolution = false;
- char *batch_file = NULL;
- char *reference = NULL;
+ char *batch_file = nullptr;
+ char *reference = nullptr;
struct stat refstats;
bool ok;
bool discarded_datestr = false;
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, short_options, long_options, NULL))
+ while ((optc = getopt_long (argc, argv, short_options, long_options, nullptr))
!= -1)
{
- char const *new_format = NULL;
+ char const *new_format = nullptr;
switch (optc)
{
char const *tzstring = getenv ("TZ");
timezone_t tz = tzalloc (tzstring);
- if (batch_file != NULL)
+ if (batch_file != nullptr)
ok = batch_convert (batch_file, format_res, tz, tzstring);
else
{
else
{
/* (option_specified_date || set_date) */
- if (reference != NULL)
+ if (reference != nullptr)
{
if (stat (reference, &refstats) != 0)
die (EXIT_FAILURE, errno, "%s", quotef (reference));
{
if (set_datestr)
datestr = set_datestr;
- valid_date = parse_datetime2 (&when, datestr, NULL,
+ valid_date = parse_datetime2 (&when, datestr, nullptr,
parse_datetime_flags,
tz, tzstring);
}
STATUS_PROGRESS = 4
};
-/* The name of the input file, or NULL for the standard input. */
-static char const *input_file = NULL;
+/* The name of the input file, or nullptr for the standard input. */
+static char const *input_file = nullptr;
-/* The name of the output file, or NULL for the standard output. */
-static char const *output_file = NULL;
+/* The name of the output file, or nullptr for the standard output. */
+static char const *output_file = nullptr;
/* The page size on this host. */
static idx_t page_size;
sigemptyset (&caught_signals);
if (catch_siginfo)
sigaddset (&caught_signals, SIGINFO);
- sigaction (SIGINT, NULL, &act);
+ sigaction (SIGINT, nullptr, &act);
if (act.sa_handler != SIG_IGN)
sigaddset (&caught_signals, SIGINT);
act.sa_mask = caught_signals;
handle EINTR explicitly in iftruncate etc.
to avoid blocking on noncommitted read/write calls. */
act.sa_flags = 0;
- sigaction (SIGINFO, &act, NULL);
+ sigaction (SIGINFO, &act, nullptr);
}
if (sigismember (&caught_signals, SIGINT))
{
act.sa_handler = interrupt_handler;
act.sa_flags = SA_NODEFER | SA_RESETHAND;
- sigaction (SIGINT, &act, NULL);
+ sigaction (SIGINT, &act, nullptr);
}
#else
if (infos)
info_signal_count = infos - 1;
- sigprocmask (SIG_SETMASK, &oldset, NULL);
+ sigprocmask (SIG_SETMASK, &oldset, nullptr);
if (interrupt)
cleanup ();
char const *name = argv[i];
char const *val = strchr (name, '=');
- if (val == NULL)
+ if (val == nullptr)
{
diagnose (0, _("unrecognized operand %s"), quoteaf (name));
usage (EXIT_FAILURE);
bool has_B = !!strchr (val, 'B');
intmax_t n_min = 0;
intmax_t n_max = INTMAX_MAX;
- idx_t *converted_idx = NULL;
+ idx_t *converted_idx = nullptr;
/* Maximum blocksize. Keep it smaller than IDX_MAX, so that
it fits into blocksize vars even if 1 is added for conv=swab.
page_size = getpagesize ();
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE, Version,
- true, usage, AUTHORS, (char const *) NULL);
+ true, usage, AUTHORS,
+ (char const *) nullptr);
close_stdout_required = false;
/* Initialize translation table to identity translation. */
apply_translations ();
- if (input_file == NULL)
+ if (input_file == nullptr)
{
input_file = _("standard input");
set_fd_flags (STDIN_FILENO, input_flags, input_file);
input_offset = MAX (0, offset);
input_seek_errno = errno;
- if (output_file == NULL)
+ if (output_file == nullptr)
{
output_file = _("standard output");
set_fd_flags (STDOUT_FILENO, output_flags, output_file);
};
/* Linked list of file system types to display.
- If 'fs_select_list' is NULL, list all types.
+ If 'fs_select_list' is null, list all types.
This table is generated dynamically from command-line options,
rather than hardcoding into the program what it thinks are the
valid file system types; let the user specify any file system type
display_field_t field;
char const *arg;
field_type_t field_type;
- char const *caption;/* NULL means to use the default header of this field. */
+ char const *caption;/* nullptr means use default header of this field. */
size_t width; /* Auto adjusted (up) widths used to align columns. */
mbs_align_t align; /* Alignment for this field. */
bool used;
static struct option const long_options[] =
{
- {"all", no_argument, NULL, 'a'},
- {"block-size", required_argument, NULL, 'B'},
- {"inodes", no_argument, NULL, 'i'},
- {"human-readable", no_argument, NULL, 'h'},
- {"si", no_argument, NULL, 'H'},
- {"local", no_argument, NULL, 'l'},
- {"output", optional_argument, NULL, OUTPUT_OPTION},
- {"portability", no_argument, NULL, 'P'},
- {"print-type", no_argument, NULL, 'T'},
- {"sync", no_argument, NULL, SYNC_OPTION},
- {"no-sync", no_argument, NULL, NO_SYNC_OPTION},
- {"total", no_argument, NULL, TOTAL_OPTION},
- {"type", required_argument, NULL, 't'},
- {"exclude-type", required_argument, NULL, 'x'},
+ {"all", no_argument, nullptr, 'a'},
+ {"block-size", required_argument, nullptr, 'B'},
+ {"inodes", no_argument, nullptr, 'i'},
+ {"human-readable", no_argument, nullptr, 'h'},
+ {"si", no_argument, nullptr, 'H'},
+ {"local", no_argument, nullptr, 'l'},
+ {"output", optional_argument, nullptr, OUTPUT_OPTION},
+ {"portability", no_argument, nullptr, 'P'},
+ {"print-type", no_argument, nullptr, 'T'},
+ {"sync", no_argument, nullptr, SYNC_OPTION},
+ {"no-sync", no_argument, nullptr, NO_SYNC_OPTION},
+ {"total", no_argument, nullptr, TOTAL_OPTION},
+ {"type", required_argument, nullptr, 't'},
+ {"exclude-type", required_argument, nullptr, 'x'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Stat FILE and put the results into *ST. Return 0 if successful, an
ncolumns++;
columns = xnrealloc (columns, ncolumns, sizeof (struct field_data_t *));
columns[ncolumns - 1] = &field_data[f];
- if (c != NULL)
+ if (c != nullptr)
columns[ncolumns - 1]->caption = c;
if (field_data[f].used)
case IPCENT_FIELD:
case TARGET_FIELD:
case FILE_FIELD:
- alloc_field (field, NULL);
+ alloc_field (field, nullptr);
break;
case SIZE_FIELD:
switch (header_mode)
{
case DEFAULT_MODE:
- alloc_field (SOURCE_FIELD, NULL);
+ alloc_field (SOURCE_FIELD, nullptr);
if (print_type)
- alloc_field (FSTYPE_FIELD, NULL);
- alloc_field (SIZE_FIELD, NULL);
- alloc_field (USED_FIELD, NULL);
- alloc_field (AVAIL_FIELD, NULL);
- alloc_field (PCENT_FIELD, NULL);
- alloc_field (TARGET_FIELD, NULL);
+ alloc_field (FSTYPE_FIELD, nullptr);
+ alloc_field (SIZE_FIELD, nullptr);
+ alloc_field (USED_FIELD, nullptr);
+ alloc_field (AVAIL_FIELD, nullptr);
+ alloc_field (PCENT_FIELD, nullptr);
+ alloc_field (TARGET_FIELD, nullptr);
break;
case HUMAN_MODE:
- alloc_field (SOURCE_FIELD, NULL);
+ alloc_field (SOURCE_FIELD, nullptr);
if (print_type)
- alloc_field (FSTYPE_FIELD, NULL);
+ alloc_field (FSTYPE_FIELD, nullptr);
alloc_field (SIZE_FIELD, N_("Size"));
- alloc_field (USED_FIELD, NULL);
+ alloc_field (USED_FIELD, nullptr);
alloc_field (AVAIL_FIELD, N_("Avail"));
- alloc_field (PCENT_FIELD, NULL);
- alloc_field (TARGET_FIELD, NULL);
+ alloc_field (PCENT_FIELD, nullptr);
+ alloc_field (TARGET_FIELD, nullptr);
break;
case INODES_MODE:
- alloc_field (SOURCE_FIELD, NULL);
+ alloc_field (SOURCE_FIELD, nullptr);
if (print_type)
- alloc_field (FSTYPE_FIELD, NULL);
- alloc_field (ITOTAL_FIELD, NULL);
- alloc_field (IUSED_FIELD, NULL);
- alloc_field (IAVAIL_FIELD, NULL);
- alloc_field (IPCENT_FIELD, NULL);
- alloc_field (TARGET_FIELD, NULL);
+ alloc_field (FSTYPE_FIELD, nullptr);
+ alloc_field (ITOTAL_FIELD, nullptr);
+ alloc_field (IUSED_FIELD, nullptr);
+ alloc_field (IAVAIL_FIELD, nullptr);
+ alloc_field (IPCENT_FIELD, nullptr);
+ alloc_field (TARGET_FIELD, nullptr);
break;
case POSIX_MODE:
- alloc_field (SOURCE_FIELD, NULL);
+ alloc_field (SOURCE_FIELD, nullptr);
if (print_type)
- alloc_field (FSTYPE_FIELD, NULL);
- alloc_field (SIZE_FIELD, NULL);
- alloc_field (USED_FIELD, NULL);
- alloc_field (AVAIL_FIELD, NULL);
+ alloc_field (FSTYPE_FIELD, nullptr);
+ alloc_field (SIZE_FIELD, nullptr);
+ alloc_field (USED_FIELD, nullptr);
+ alloc_field (AVAIL_FIELD, nullptr);
alloc_field (PCENT_FIELD, N_("Capacity"));
- alloc_field (TARGET_FIELD, NULL);
+ alloc_field (TARGET_FIELD, nullptr);
break;
case OUTPUT_MODE:
for (col = 0; col < ncolumns; col++)
{
- char *cell = NULL;
+ char *cell = nullptr;
char const *header = _(columns[col]->caption);
if (columns[col]->field == SIZE_FIELD
/* TRANSLATORS: this is the "1K-blocks" header in "df" output. */
if (asprintf (&cell, _("%s-%s"), num, header) == -1)
- cell = NULL;
+ cell = nullptr;
}
else if (header_mode == POSIX_MODE && columns[col]->field == SIZE_FIELD)
{
/* TRANSLATORS: this is the "1024-blocks" header in "df -P". */
if (asprintf (&cell, _("%s-%s"), num, header) == -1)
- cell = NULL;
+ cell = nullptr;
}
else
cell = strdup (header);
{
const struct fs_type_list *fsp;
- if (fs_select_list == NULL || fstype == NULL)
+ if (fs_select_list == nullptr || fstype == nullptr)
return true;
for (fsp = fs_select_list; fsp; fsp = fsp->fs_next)
if (STREQ (fstype, fsp->fs_name))
{
const struct fs_type_list *fsp;
- if (fs_exclude_list == NULL || fstype == NULL)
+ if (fs_exclude_list == nullptr || fstype == nullptr)
return false;
for (fsp = fs_exclude_list; fsp; fsp = fsp->fs_next)
if (STREQ (fstype, fsp->fs_name))
static struct devlist *
devlist_for_dev (dev_t dev)
{
- if (devlist_table == NULL)
- return NULL;
+ if (devlist_table == nullptr)
+ return nullptr;
struct devlist dev_entry;
dev_entry.dev_num = dev;
struct devlist *found = hash_lookup (devlist_table, &dev_entry);
- if (found == NULL)
- return NULL;
+ if (found == nullptr)
+ return nullptr;
/* Return the last devlist entry we have seen with this dev_num */
return found->seen_last;
struct mount_entry *me;
/* Temporary list to keep entries ordered. */
- struct devlist *device_list = NULL;
+ struct devlist *device_list = nullptr;
int mount_list_size = 0;
for (me = mount_list; me; me = me->me_next)
mount_list_size++;
- devlist_table = hash_initialize (mount_list_size, NULL,
- devlist_hash, devlist_compare, NULL);
- if (devlist_table == NULL)
+ devlist_table = hash_initialize (mount_list_size, nullptr,
+ devlist_hash, devlist_compare, nullptr);
+ if (devlist_table == nullptr)
xalloc_die ();
/* Sort all 'wanted' entries into the list device_list. */
for (me = mount_list; me;)
{
struct stat buf;
- struct mount_entry *discard_me = NULL;
+ struct mount_entry *discard_me = nullptr;
/* Avoid stating remote file systems as that may hang.
On Linux we probably have me_dev populated from /proc/self/mountinfo,
bool target_nearer_root = strlen (seen_dev->me->me_mountdir)
> strlen (me->me_mountdir);
/* With bind mounts, prefer items nearer the root of the source */
- bool source_below_root = seen_dev->me->me_mntroot != NULL
- && me->me_mntroot != NULL
+ bool source_below_root = seen_dev->me->me_mntroot != nullptr
+ && me->me_mntroot != nullptr
&& (strlen (seen_dev->me->me_mntroot)
< strlen (me->me_mntroot));
if (! print_grand_total
device_list = devlist;
struct devlist *hash_entry = hash_insert (devlist_table, devlist);
- if (hash_entry == NULL)
+ if (hash_entry == nullptr)
xalloc_die ();
/* Ensure lookups use this latest devlist. */
hash_entry->seen_last = devlist;
/* Finally rebuild the mount_list from the devlist. */
if (! devices_only) {
- mount_list = NULL;
+ mount_list = nullptr;
while (device_list)
{
/* Add the mount entry. */
}
hash_free (devlist_table);
- devlist_table = NULL;
+ devlist_table = nullptr;
}
}
/* Search a mount entry list for device id DEV.
- Return the corresponding mount entry if found or NULL if not. */
+ Return the corresponding mount entry if found or nullptr if not. */
ATTRIBUTE_PURE
static struct mount_entry const *
if (dl)
return dl->me;
- return NULL;
+ return nullptr;
}
/* Return true if N is a known integer value. On many file systems,
}
/* Obtain a space listing for the device with absolute file name DEVICE.
- If MOUNT_POINT is non-NULL, it is the name of the root of the
+ If MOUNT_POINT is non-null, it is the name of the root of the
file system on DEVICE.
If STAT_FILE is non-null, it is the name of a file within the file
system that the user originally asked for; this provides better
diagnostics, and sometimes it provides better results on networked
file systems that give different free-space results depending on
where in the file system you probe.
- If FSTYPE is non-NULL, it is the type of the file system on DEVICE.
- If MOUNT_POINT is non-NULL, then DEVICE may be NULL -- certain systems may
+ If FSTYPE is non-null, it is the type of the file system on DEVICE.
+ If MOUNT_POINT is non-null, then DEVICE may be null -- certain systems may
not be able to produce statistics in this case.
ME_DUMMY and ME_REMOTE are the mount entry flags.
Caller must set PROCESS_ALL to true when iterating over all entries, as
if (!force_fsu && mount_point && ! IS_ABSOLUTE_FILE_NAME (mount_point))
return;
- /* If MOUNT_POINT is NULL, then the file system is not mounted, and this
+ /* If MOUNT_POINT is null, then the file system is not mounted, and this
program reports on the file system that the special file is on.
It would be better to report on the unmounted file system,
but statfs doesn't do that on most systems. */
v = &inode_values;
break;
case OTHER_FLD:
- v = NULL;
+ v = nullptr;
break;
default:
- v = NULL; /* Avoid warnings where assert() is not __noreturn__. */
+ v = nullptr; /* Avoid warnings where assert() is not __noreturn__. */
assert (!"bad field_type");
}
if (0 <= pct)
{
if (asprintf (&cell, "%.0f%%", pct) == -1)
- cell = NULL;
+ cell = nullptr;
}
else
cell = strdup ("-");
}
/* Scan the mount list returning the _last_ device found for MOUNT.
- NULL is returned if MOUNT not found. The result is malloced. */
+ nullptr is returned if MOUNT not found. The result is malloced. */
static char *
last_device_for_mount (char const *mount)
{
struct mount_entry const *me;
- struct mount_entry const *le = NULL;
+ struct mount_entry const *le = nullptr;
for (me = mount_list; me; me = me->me_next)
{
return xstrdup (le->me_devname);
}
else
- return NULL;
+ return nullptr;
}
/* If DEVICE corresponds to a mount point, show its usage
get_device (char const *device)
{
struct mount_entry const *me;
- struct mount_entry const *best_match = NULL;
+ struct mount_entry const *best_match = nullptr;
bool best_match_accessible = false;
bool eclipsed_device = false;
char const *file = device;
if (best_match)
{
- get_dev (best_match->me_devname, best_match->me_mountdir, file, NULL,
+ get_dev (best_match->me_devname, best_match->me_mountdir, file, nullptr,
best_match->me_type, best_match->me_dummy,
- best_match->me_remote, NULL, false);
+ best_match->me_remote, nullptr, false);
return true;
}
else if (eclipsed_device)
{
struct stat device_stats;
struct mount_entry *me;
- struct mount_entry const *best_match = NULL;
+ struct mount_entry const *best_match = nullptr;
/* Calculate the real absolute file name for POINT, and use that to find
the mount point. This avoids statting unavailable mount points,
if (best_match
&& (stat (best_match->me_mountdir, &device_stats) != 0
|| device_stats.st_dev != statp->st_dev))
- best_match = NULL;
+ best_match = nullptr;
if (! best_match)
for (me = mount_list; me; me = me->me_next)
if (best_match)
get_dev (best_match->me_devname, best_match->me_mountdir, point, point,
best_match->me_type, best_match->me_dummy, best_match->me_remote,
- NULL, false);
+ nullptr, false);
else
{
/* We couldn't find the mount entry corresponding to POINT. Go ahead and
char *mp = find_mount_point (point, statp);
if (mp)
{
- get_dev (NULL, mp, point, NULL, NULL, false, false, NULL, false);
+ get_dev (nullptr, mp, point, nullptr, nullptr,
+ false, false, nullptr, false);
free (mp);
}
}
filter_mount_list (show_all_fs);
for (me = mount_list; me; me = me->me_next)
- get_dev (me->me_devname, me->me_mountdir, NULL, NULL, me->me_type,
- me->me_dummy, me->me_remote, NULL, true);
+ get_dev (me->me_devname, me->me_mountdir, nullptr, nullptr, me->me_type,
+ me->me_dummy, me->me_remote, nullptr, true);
}
/* Add FSTYPE to the list of file system types to display. */
int
main (int argc, char **argv)
{
- struct stat *stats = NULL;
+ struct stat *stats = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
atexit (close_stdout);
- fs_select_list = NULL;
- fs_exclude_list = NULL;
+ fs_select_list = nullptr;
+ fs_exclude_list = nullptr;
show_all_fs = false;
show_listed_fs = false;
human_output_opts = -1;
{
error (0, err, "%s", quotef (argv[i]));
exit_status = EXIT_FAILURE;
- argv[i] = NULL;
+ argv[i] = nullptr;
}
}
}
mount_list =
- read_file_system_list ((fs_select_list != NULL
- || fs_exclude_list != NULL
+ read_file_system_list ((fs_select_list != nullptr
+ || fs_exclude_list != nullptr
|| print_type
|| field_data[FSTYPE_FIELD].used
|| show_local_fs));
- if (mount_list == NULL)
+ if (mount_list == nullptr)
{
/* Couldn't read the table of mounted file systems.
Fail if df was invoked with no file name arguments,
if ( ! (optind < argc)
|| (show_all_fs
|| show_local_fs
- || fs_select_list != NULL
- || fs_exclude_list != NULL))
+ || fs_select_list != nullptr
+ || fs_exclude_list != nullptr))
{
status = EXIT_FAILURE;
}
if (print_grand_total)
get_dev ("total",
(field_data[SOURCE_FIELD].used ? "-" : "total"),
- NULL, NULL, NULL, false, false, &grand_fsu, false);
+ nullptr, nullptr, nullptr, false, false, &grand_fsu, false);
print_table ();
}
static char const *const algorithm_args[] =
{
"bsd", "sysv", "crc", "md5", "sha1", "sha224",
- "sha256", "sha384", "sha512", "blake2b", "sm3", NULL
+ "sha256", "sha384", "sha512", "blake2b", "sm3", nullptr
};
static enum Algorithm const algorithm_types[] =
{
static char const *const algorithm_tags[] =
{
"BSD", "SYSV", "CRC", "MD5", "SHA1", "SHA224",
- "SHA256", "SHA384", "SHA512", "BLAKE2b", "SM3", NULL
+ "SHA256", "SHA384", "SHA512", "BLAKE2b", "SM3", nullptr
};
static int const algorithm_bits[] =
{
static struct option const long_options[] =
{
#if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
- { "length", required_argument, NULL, 'l'},
+ { "length", required_argument, nullptr, 'l'},
#endif
#if !HASH_ALGO_SUM
- { "check", no_argument, NULL, 'c' },
- { "ignore-missing", no_argument, NULL, IGNORE_MISSING_OPTION},
- { "quiet", no_argument, NULL, QUIET_OPTION },
- { "status", no_argument, NULL, STATUS_OPTION },
- { "warn", no_argument, NULL, 'w' },
- { "strict", no_argument, NULL, STRICT_OPTION },
- { "tag", no_argument, NULL, TAG_OPTION },
- { "zero", no_argument, NULL, 'z' },
+ { "check", no_argument, nullptr, 'c' },
+ { "ignore-missing", no_argument, nullptr, IGNORE_MISSING_OPTION},
+ { "quiet", no_argument, nullptr, QUIET_OPTION },
+ { "status", no_argument, nullptr, STATUS_OPTION },
+ { "warn", no_argument, nullptr, 'w' },
+ { "strict", no_argument, nullptr, STRICT_OPTION },
+ { "tag", no_argument, nullptr, TAG_OPTION },
+ { "zero", no_argument, nullptr, 'z' },
# if HASH_ALGO_CKSUM
- { "algorithm", required_argument, NULL, 'a'},
- { "base64", no_argument, NULL, 'b' },
- { "debug", no_argument, NULL, DEBUG_PROGRAM_OPTION},
- { "raw", no_argument, NULL, RAW_OPTION},
- { "untagged", no_argument, NULL, UNTAG_OPTION },
+ { "algorithm", required_argument, nullptr, 'a'},
+ { "base64", no_argument, nullptr, 'b' },
+ { "debug", no_argument, nullptr, DEBUG_PROGRAM_OPTION},
+ { "raw", no_argument, nullptr, RAW_OPTION},
+ { "untagged", no_argument, nullptr, UNTAG_OPTION },
# else
- { "binary", no_argument, NULL, 'b' },
- { "text", no_argument, NULL, 't' },
+ { "binary", no_argument, nullptr, 'b' },
+ { "text", no_argument, nullptr, 't' },
# endif
#else
- {"sysv", no_argument, NULL, 's'},
+ {"sysv", no_argument, nullptr, 's'},
#endif
{ GETOPT_HELP_OPTION_DECL },
{ GETOPT_VERSION_OPTION_DECL },
- { NULL, 0, NULL, 0 }
+ { nullptr, 0, nullptr, 0 }
};
void
and each "\\\\" with a single backslash, NUL-terminate it and return S.
If S is not a valid escaped file name, i.e., if it ends with an odd number
of backslashes or if it contains a backslash followed by anything other
- than "n" or another backslash, return NULL. */
+ than "n" or another backslash, return nullptr. */
static char *
filename_unescape (char *s, size_t s_len)
if (i == s_len - 1)
{
/* File name ends with an unescaped backslash: invalid. */
- return NULL;
+ return nullptr;
}
++i;
switch (s[i])
break;
default:
/* Only '\', 'n' or 'r' may follow a backslash. */
- return NULL;
+ return nullptr;
}
break;
case '\0':
/* The file name may not contain a NUL. */
- return NULL;
+ return nullptr;
default:
*dst++ = s[i];
*file_name = s;
- if (escaped_filename && filename_unescape (s, i) == NULL)
+ if (escaped_filename && filename_unescape (s, i) == nullptr)
return false;
s[i++] = '\0';
{
uintmax_t length;
char *siend;
- if (! (xstrtoumax (s + i, &siend, 0, &length, NULL) == LONGINT_OK
+ if (! (xstrtoumax (s + i, &siend, 0, &length, nullptr) == LONGINT_OK
&& 0 < length && length <= digest_length
&& length % 8 == 0))
return false;
*file_name = &s[i];
if (escaped_filename)
- return filename_unescape (&s[i], s_len - i) != NULL;
+ return filename_unescape (&s[i], s_len - i) != nullptr;
return true;
}
else
{
fp = fopen (filename, (O_BINARY && *binary ? "rb" : "r"));
- if (fp == NULL)
+ if (fp == nullptr)
{
if (ignore_missing && errno == ENOENT)
{
else
{
checkfile_stream = fopen (checkfile_name, "r");
- if (checkfile_stream == NULL)
+ if (checkfile_stream == nullptr)
{
error (0, errno, "%s", quotef (checkfile_name));
return false;
}
line_number = 0;
- line = NULL;
+ line = nullptr;
line_chars_allocated = 0;
do
{
/* Line buffer stdout to ensure lines are written atomically and immediately
so that processes running in parallel do not intersperse their output. */
- setvbuf (stdout, NULL, _IOLBF, 0);
+ setvbuf (stdout, nullptr, _IOLBF, 0);
#if HASH_ALGO_SUM
char const *short_opts = "rs";
char const *short_opts = "bctwz";
#endif
- while ((opt = getopt_long (argc, argv, short_opts, long_options, NULL)) != -1)
+ while ((opt = getopt_long (argc, argv, short_opts, long_options, nullptr))
+ != -1)
switch (opt)
{
#if HASH_ALGO_CKSUM
"CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE",
"END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY",
"OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY",
- "MULTIHARDLINK", "CLRTOEOL", NULL
+ "MULTIHARDLINK", "CLRTOEOL", nullptr
};
static char const *const ls_codes[] =
{
"no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi",
"so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec",
- "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "mh", "cl", NULL
+ "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "mh", "cl",
+ nullptr
};
static_assert (ARRAY_CARDINALITY (slack_codes) == ARRAY_CARDINALITY (ls_codes));
static struct option const long_options[] =
{
- {"bourne-shell", no_argument, NULL, 'b'},
- {"sh", no_argument, NULL, 'b'},
- {"csh", no_argument, NULL, 'c'},
- {"c-shell", no_argument, NULL, 'c'},
- {"print-database", no_argument, NULL, 'p'},
- {"print-ls-colors", no_argument, NULL, PRINT_LS_COLORS_OPTION},
+ {"bourne-shell", no_argument, nullptr, 'b'},
+ {"sh", no_argument, nullptr, 'b'},
+ {"csh", no_argument, nullptr, 'c'},
+ {"c-shell", no_argument, nullptr, 'c'},
+ {"print-database", no_argument, nullptr, 'p'},
+ {"print-ls-colors", no_argument, nullptr, PRINT_LS_COLORS_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
char *shell;
shell = getenv ("SHELL");
- if (shell == NULL || *shell == '\0')
+ if (shell == nullptr || *shell == '\0')
return SHELL_SYNTAX_UNKNOWN;
shell = last_component (shell);
char const *keyword_start;
char const *arg_start;
- *keyword = NULL;
- *arg = NULL;
+ *keyword = nullptr;
+ *arg = nullptr;
for (p = line; isspace (to_uchar (*p)); ++p)
continue;
{
size_t line_number = 0;
char const *next_G_line = G_line;
- char *input_line = NULL;
+ char *input_line = nullptr;
size_t input_line_size = 0;
char const *line;
char const *term;
/* Get terminal type */
term = getenv ("TERM");
- if (term == NULL || *term == '\0')
+ if (term == nullptr || *term == '\0')
term = "none";
/* Also match $COLORTERM. */
colorterm = getenv ("COLORTERM");
- if (colorterm == NULL)
+ if (colorterm == nullptr)
colorterm = ""; /* Doesn't match default "?*" */
while (true)
parse_line (line, &keywd, &arg);
- if (keywd == NULL)
+ if (keywd == nullptr)
continue;
- if (arg == NULL)
+ if (arg == nullptr)
{
error (0, 0, _("%s:%lu: invalid line; missing second token"),
quotef (filename), (unsigned long int) line_number);
{
int i;
- for (i = 0; slack_codes[i] != NULL; ++i)
+ for (i = 0; slack_codes[i] != nullptr; ++i)
if (c_strcasecmp (keywd, slack_codes[i]) == 0)
break;
- if (slack_codes[i] != NULL)
+ if (slack_codes[i] != nullptr)
append_entry (0, ls_codes[i], arg);
else
unrecognized = true;
{
bool ok;
- if (! STREQ (filename, "-") && freopen (filename, "r", stdin) == NULL)
+ if (! STREQ (filename, "-") && freopen (filename, "r", stdin) == nullptr)
{
error (0, errno, "%s", quotef (filename));
return false;
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "bcp", long_options, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "bcp", long_options, nullptr)) != -1)
switch (optc)
{
case 'b': /* Bourne shell syntax. */
obstack_init (&lsc_obstack);
if (argc == 0)
- ok = dc_parse_stream (NULL, NULL);
+ ok = dc_parse_stream (nullptr, nullptr);
else
ok = dc_parse_file (argv[0]);
static struct option const longopts[] =
{
- {"zero", no_argument, NULL, 'z'},
+ {"zero", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
while (true)
{
- int c = getopt_long (argc, argv, "z", longopts, NULL);
+ int c = getopt_long (argc, argv, "z", longopts, nullptr);
if (c == -1)
break;
static enum time_type time_type = time_mtime;
/* User specified date / time style */
-static char const *time_style = NULL;
+static char const *time_style = nullptr;
/* Format used to display date / time. Controlled by --time-style */
-static char const *time_format = NULL;
+static char const *time_format = nullptr;
/* The local time zone rules, as per the TZ environment variable. */
static timezone_t localtz;
static struct option const long_options[] =
{
- {"all", no_argument, NULL, 'a'},
- {"apparent-size", no_argument, NULL, APPARENT_SIZE_OPTION},
- {"block-size", required_argument, NULL, 'B'},
- {"bytes", no_argument, NULL, 'b'},
- {"count-links", no_argument, NULL, 'l'},
- /* {"-debug", no_argument, NULL, FTS_DEBUG}, */
- {"dereference", no_argument, NULL, 'L'},
- {"dereference-args", no_argument, NULL, 'D'},
- {"exclude", required_argument, NULL, EXCLUDE_OPTION},
- {"exclude-from", required_argument, NULL, 'X'},
- {"files0-from", required_argument, NULL, FILES0_FROM_OPTION},
- {"human-readable", no_argument, NULL, 'h'},
- {"inodes", no_argument, NULL, INODES_OPTION},
- {"si", no_argument, NULL, HUMAN_SI_OPTION},
- {"max-depth", required_argument, NULL, 'd'},
- {"null", no_argument, NULL, '0'},
- {"no-dereference", no_argument, NULL, 'P'},
- {"one-file-system", no_argument, NULL, 'x'},
- {"separate-dirs", no_argument, NULL, 'S'},
- {"summarize", no_argument, NULL, 's'},
- {"total", no_argument, NULL, 'c'},
- {"threshold", required_argument, NULL, 't'},
- {"time", optional_argument, NULL, TIME_OPTION},
- {"time-style", required_argument, NULL, TIME_STYLE_OPTION},
+ {"all", no_argument, nullptr, 'a'},
+ {"apparent-size", no_argument, nullptr, APPARENT_SIZE_OPTION},
+ {"block-size", required_argument, nullptr, 'B'},
+ {"bytes", no_argument, nullptr, 'b'},
+ {"count-links", no_argument, nullptr, 'l'},
+ /* {"-debug", no_argument, nullptr, FTS_DEBUG}, */
+ {"dereference", no_argument, nullptr, 'L'},
+ {"dereference-args", no_argument, nullptr, 'D'},
+ {"exclude", required_argument, nullptr, EXCLUDE_OPTION},
+ {"exclude-from", required_argument, nullptr, 'X'},
+ {"files0-from", required_argument, nullptr, FILES0_FROM_OPTION},
+ {"human-readable", no_argument, nullptr, 'h'},
+ {"inodes", no_argument, nullptr, INODES_OPTION},
+ {"si", no_argument, nullptr, HUMAN_SI_OPTION},
+ {"max-depth", required_argument, nullptr, 'd'},
+ {"null", no_argument, nullptr, '0'},
+ {"no-dereference", no_argument, nullptr, 'P'},
+ {"one-file-system", no_argument, nullptr, 'x'},
+ {"separate-dirs", no_argument, nullptr, 'S'},
+ {"summarize", no_argument, nullptr, 's'},
+ {"total", no_argument, nullptr, 'c'},
+ {"threshold", required_argument, nullptr, 't'},
+ {"time", optional_argument, nullptr, TIME_OPTION},
+ {"time-style", required_argument, nullptr, TIME_STYLE_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static char const *const time_args[] =
{
- "atime", "access", "use", "ctime", "status", NULL
+ "atime", "access", "use", "ctime", "status", nullptr
};
static enum time_type const time_types[] =
{
static char const *const time_style_args[] =
{
- "full-iso", "long-iso", "iso", NULL
+ "full-iso", "long-iso", "iso", nullptr
};
static enum time_style const time_style_types[] =
{
}
/* Recursively print the sizes of the directories (and, if selected, files)
- named in FILES, the last entry of which is NULL.
+ named in FILES, the last entry of which is null.
BIT_FLAGS controls how fts works.
Return true if successful. */
if (*files)
{
- FTS *fts = xfts_open (files, bit_flags, NULL);
+ FTS *fts = xfts_open (files, bit_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
- if (ent == NULL)
+ if (ent == nullptr)
{
if (errno != 0)
{
char *cwd_only[2];
bool max_depth_specified = false;
bool ok = true;
- char *files_from = NULL;
+ char *files_from = nullptr;
/* Bit flags that control how fts works. */
int bit_flags = FTS_NOSTAT;
bool opt_summarize_only = false;
cwd_only[0] = bad_cast (".");
- cwd_only[1] = NULL;
+ cwd_only[1] = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
case 'd': /* --max-depth=N */
{
uintmax_t tmp;
- if (xstrtoumax (optarg, NULL, 0, &tmp, "") == LONGINT_OK
+ if (xstrtoumax (optarg, nullptr, 0, &tmp, "") == LONGINT_OK
&& tmp <= SIZE_MAX)
{
max_depth_specified = true;
case 't':
{
enum strtol_error e;
- e = xstrtoimax (optarg, NULL, 0, &opt_threshold, "kKmMGTPEZYRQ0");
+ e = xstrtoimax (optarg, nullptr, 0, &opt_threshold,
+ "kKmMGTPEZYRQ0");
if (e != LONGINT_OK)
xstrtol_fatal (e, oi, c, long_options, optarg);
if (opt_threshold == 0 && *optarg == '-')
bit_flags |= FTS_TIGHT_CYCLE_CHECK;
bit_flags |= symlink_deref_bits;
- static char *temp_argv[] = { NULL, NULL };
+ static char *temp_argv[] = { nullptr, nullptr };
while (true)
{
among many, knowing the record number may help.
FIXME: currently print the record number only with
--files0-from=FILE. Maybe do it for argv, too? */
- if (files_from == NULL)
+ if (files_from == nullptr)
error (0, 0, "%s", _("invalid zero-length file name"));
else
{
if (STREQ (argv[1], "--version"))
{
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
- (char *) NULL);
+ (char *) nullptr);
return EXIT_SUCCESS;
}
}
static struct option const longopts[] =
{
- {"ignore-environment", no_argument, NULL, 'i'},
- {"null", no_argument, NULL, '0'},
- {"unset", required_argument, NULL, 'u'},
- {"chdir", required_argument, NULL, 'C'},
- {"default-signal", optional_argument, NULL, DEFAULT_SIGNAL_OPTION},
- {"ignore-signal", optional_argument, NULL, IGNORE_SIGNAL_OPTION},
- {"block-signal", optional_argument, NULL, BLOCK_SIGNAL_OPTION},
- {"list-signal-handling", no_argument, NULL, LIST_SIGNAL_HANDLING_OPTION},
- {"debug", no_argument, NULL, 'v'},
- {"split-string", required_argument, NULL, 'S'},
+ {"ignore-environment", no_argument, nullptr, 'i'},
+ {"null", no_argument, nullptr, '0'},
+ {"unset", required_argument, nullptr, 'u'},
+ {"chdir", required_argument, nullptr, 'C'},
+ {"default-signal", optional_argument, nullptr, DEFAULT_SIGNAL_OPTION},
+ {"ignore-signal", optional_argument, nullptr, IGNORE_SIGNAL_OPTION},
+ {"block-signal", optional_argument, nullptr, BLOCK_SIGNAL_OPTION},
+ {"list-signal-handling", no_argument, nullptr, LIST_SIGNAL_HANDLING_OPTION},
+ {"debug", no_argument, nullptr, 'v'},
+ {"split-string", required_argument, nullptr, 'S'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
}
}
-/* Return a pointer to the end of a valid ${VARNAME} string, or NULL.
+/* Return a pointer to the end of a valid ${VARNAME} string, or nullptr.
'str' should point to the '$' character.
First letter in VARNAME must be alpha or underscore,
rest of letters are alnum or underscore.
return end;
}
- return NULL;
+ return nullptr;
}
/* Return a pointer to a static buffer containing the VARNAME as
extracted from a '${VARNAME}' string.
The returned string will be NUL terminated.
The returned pointer should not be freed.
- Return NULL if not a valid ${VARNAME} syntax. */
+ Return nullptr if not a valid ${VARNAME} syntax. */
static char *
extract_varname (char const *str)
{
p = scan_varname (str);
if (!p)
- return NULL;
+ return nullptr;
/* -2 and +2 (below) account for the '${' prefix. */
i = p - str - 2;
argv[1] = "-S-i -C/tmp A=B"
argv[2] = "foo"
argv[3] = "bar"
- argv[4] = NULL
+ argv[4] = nullptr
This function will modify argv to be:
argv[0] = "env"
argv[1] = "-i"
argv[3] = "A=B"
argv[4] = "foo"
argv[5] = "bar"
- argv[6] = NULL
+ argv[6] = nullptr
argc will be updated from 4 to 6.
optind will be reset to 0 to force getopt_long to rescan all arguments. */
static void
signals[signum] = set_default ? DEFAULT : IGNORE;
- opt_sig = strtok (NULL, ",");
+ opt_sig = strtok (nullptr, ",");
}
free (optarg_writable);
bool set_to_default = (signals[i] == DEFAULT
|| signals[i] == DEFAULT_NOERR);
- int sig_err = sigaction (i, NULL, &act);
+ int sig_err = sigaction (i, nullptr, &act);
if (sig_err && !ignore_errors)
die (EXIT_CANCELED, errno,
if (! sig_err)
{
act.sa_handler = set_to_default ? SIG_DFL : SIG_IGN;
- sig_err = sigaction (i, &act, NULL);
+ sig_err = sigaction (i, &act, nullptr);
if (sig_err && !ignore_errors)
die (EXIT_CANCELED, errno,
_("failed to set signal action for signal %d"), i);
sigaddset (block ? &block_signals : &unblock_signals, signum);
sigdelset (block ? &unblock_signals : &block_signals, signum);
- opt_sig = strtok (NULL, ",");
+ opt_sig = strtok (nullptr, ",");
}
free (optarg_writable);
sigemptyset (&set);
- if (sigprocmask (0, NULL, &set))
+ if (sigprocmask (0, nullptr, &set))
die (EXIT_CANCELED, errno, _("failed to get signal process mask"));
for (int i = 1; i <= SIGNUM_BOUND; i++)
}
else
{
- debug_act = NULL;
+ debug_act = nullptr;
}
if (dev_debug && debug_act)
}
}
- if (sigprocmask (SIG_SETMASK, &set, NULL))
+ if (sigprocmask (SIG_SETMASK, &set, nullptr))
die (EXIT_CANCELED, errno, _("failed to set signal process mask"));
}
char signame[SIG2STR_MAX];
sigemptyset (&set);
- if (sigprocmask (0, NULL, &set))
+ if (sigprocmask (0, nullptr, &set))
die (EXIT_CANCELED, errno, _("failed to get signal process mask"));
for (int i = 1; i <= SIGNUM_BOUND; i++)
{
struct sigaction act;
- if (sigaction (i, NULL, &act))
+ if (sigaction (i, nullptr, &act))
continue;
char const *ignored = act.sa_handler == SIG_IGN ? "IGNORE" : "";
int optc;
bool ignore_environment = false;
bool opt_nul_terminate_output = false;
- char const *newdir = NULL;
+ char const *newdir = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
initialize_signals ();
- while ((optc = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, shortopts, longopts, nullptr)) != -1)
{
switch (optc)
{
if (ignore_environment)
{
devmsg ("cleaning environ\n");
- static char *dummy_environ[] = { NULL };
+ static char *dummy_environ[] = { nullptr };
environ = dummy_environ;
}
else
/* Array of the explicit column numbers of the tab stops;
after 'tab_list' is exhausted, each additional tab is replaced
by a space. The first column is column 0. */
-static uintmax_t *tab_list = NULL;
+static uintmax_t *tab_list = nullptr;
/* The number of allocated entries in 'tab_list'. */
static size_t n_tabs_allocated = 0;
static size_t first_free_tab = 0;
/* Null-terminated array of input filenames. */
-static char **file_list = NULL;
+static char **file_list = nullptr;
/* Default for 'file_list' if no files are given on the command line. */
static char *stdin_argv[] =
{
- (char *) "-", NULL
+ (char *) "-", nullptr
};
/* True if we have ever read standard input. */
uintmax_t tabval = 0;
bool extend_tabval = false;
bool increment_tabval = false;
- char const *num_start = NULL;
+ char const *num_start = nullptr;
bool ok = true;
for (; *stops; stops++)
file_list = list;
}
-/* Close the old stream pointer FP if it is non-NULL,
+/* Close the old stream pointer FP if it is non-null,
and return a new one opened to read the next input file.
Open a filename of '-' as the standard input.
- Return NULL if there are no more input files. */
+ Return nullptr if there are no more input files. */
extern FILE *
next_file (FILE *fp)
}
}
- while ((file = *file_list++) != NULL)
+ while ((file = *file_list++) != nullptr)
{
if (STREQ (file, "-"))
{
error (0, errno, "%s", quotef (file));
exit_status = EXIT_FAILURE;
}
- return NULL;
+ return nullptr;
}
/* */
extern void
set_file_list (char **file_list);
-/* Close the old stream pointer FP if it is non-NULL,
+/* Close the old stream pointer FP if it is non-null,
and return a new one opened to read the next input file.
Open a filename of '-' as the standard input.
- Return NULL if there are no more input files. */
+ Return nullptr if there are no more input files. */
extern FILE *
next_file (FILE *fp);
static struct option const longopts[] =
{
- {"tabs", required_argument, NULL, 't'},
- {"initial", no_argument, NULL, 'i'},
+ {"tabs", required_argument, nullptr, 't'},
+ {"initial", no_argument, nullptr, 'i'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
expand (void)
{
/* Input stream. */
- FILE *fp = next_file (NULL);
+ FILE *fp = next_file (nullptr);
if (!fp)
return;
atexit (close_stdout);
convert_entire_line = true;
- while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, shortopts, longopts, nullptr)) != -1)
{
switch (c)
{
finalize_tab_stops ();
- set_file_list ((optind < argc) ? &argv[optind] : NULL);
+ set_file_list (optind < argc ? &argv[optind] : nullptr);
expand ();
atexit (close_stdout);
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
- usage, AUTHORS, (char const *) NULL);
+ usage, AUTHORS, (char const *) nullptr);
/* The above handles --help and --version.
Since there is no other invocation of getopt, handle '--' here. */
{
case integer:
{
- char *s = mpz_get_str (NULL, 10, v->u.i);
+ char *s = mpz_get_str (nullptr, 10, v->u.i);
mpz_clear (v->u.i);
v->u.s = s;
v->type = string;
}
/* Return true and advance if the next token matches STR exactly.
- STR must not be NULL. */
+ STR must not be null. */
static bool
nextarg (char const *str)
{
- if (*args == NULL)
+ if (*args == nullptr)
return false;
else
{
tostring (pv);
re_regs.num_regs = 0;
- re_regs.start = NULL;
- re_regs.end = NULL;
+ re_regs.start = nullptr;
+ re_regs.end = nullptr;
- re_buffer.buffer = NULL;
+ re_buffer.buffer = nullptr;
re_buffer.allocated = 0;
re_buffer.fastmap = fastmap;
- re_buffer.translate = NULL;
+ re_buffer.translate = nullptr;
re_syntax_options =
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
errmsg = re_compile_pattern (pv->u.s, strlen (pv->u.s), &re_buffer);
free (re_regs.start);
free (re_regs.end);
}
- re_buffer.fastmap = NULL;
+ re_buffer.fastmap = nullptr;
regfree (&re_buffer);
return v;
}
static struct option const long_options[] =
{
- {"exponents", no_argument, NULL, 'h'},
- {"-debug", no_argument, NULL, DEV_DEBUG_OPTION},
+ {"exponents", no_argument, nullptr, 'h'},
+ {"-debug", no_argument, nullptr, DEV_DEBUG_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* If true, use p^e output format. */
static void
mp_factor_init (struct mp_factors *factors)
{
- factors->p = NULL;
- factors->e = NULL;
+ factors->p = nullptr;
+ factors->e = nullptr;
factors->nfactors = 0;
}
if (mpz_cmp_ui (n, (long) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) < 0)
return true;
- mpz_inits (q, a, nm1, tmp, NULL);
+ mpz_inits (q, a, nm1, tmp, nullptr);
/* Precomputation for Miller-Rabin. */
mpz_sub_ui (nm1, n, 1);
if (flag_prove_primality)
mp_factor_clear (&factors);
ret2:
- mpz_clears (q, a, nm1, tmp, NULL);
+ mpz_clears (q, a, nm1, tmp, nullptr);
return is_prime;
}
devmsg ("[pollard-rho (%lu)] ", a);
- mpz_inits (t, t2, NULL);
+ mpz_inits (t, t2, nullptr);
mpz_init_set_si (y, 2);
mpz_init_set_si (x, 2);
mpz_init_set_si (z, 2);
mpz_mod (y, y, n);
}
- mpz_clears (P, t2, t, z, x, y, NULL);
+ mpz_clears (P, t2, t, z, x, y, nullptr);
}
#if USE_SQUFOF
atexit (lbuf_flush);
int c;
- while ((c = getopt_long (argc, argv, "h", long_options, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "h", long_options, nullptr)) != -1)
{
switch (c)
{
/* Return the root mountpoint of the file system on which FILE exists, in
malloced storage. FILE_STAT should be the result of stating FILE.
- Give a diagnostic and return NULL if unable to determine the mount point.
+ Give a diagnostic and return nullptr if unable to determine the mount point.
Exit if unable to restore current working directory. */
extern char *
find_mount_point (char const *file, struct stat const *file_stat)
{
struct saved_cwd cwd;
struct stat last_stat;
- char *mp = NULL; /* The malloc'd mount point. */
+ char *mp = nullptr; /* The malloc'd mount point. */
if (save_cwd (&cwd) != 0)
{
error (0, errno, _("cannot get current directory"));
- return NULL;
+ return nullptr;
}
if (S_ISDIR (file_stat->st_mode))
if (chdir (file) < 0)
{
error (0, errno, _("cannot change to directory %s"), quoteaf (file));
- return NULL;
+ return nullptr;
}
}
else
if (chdir (dir) < 0)
{
error (0, errno, _("cannot change to directory %s"), quoteaf (dir));
- return NULL;
+ return nullptr;
}
if (stat (".", &last_stat) < 0)
/* Extra ctype(3)-style macros. */
-#define isopen(c) (strchr ("(['`\"", c) != NULL)
-#define isclose(c) (strchr (")]'\"", c) != NULL)
-#define isperiod(c) (strchr (".?!", c) != NULL)
+#define isopen(c) (strchr ("(['`\"", c) != nullptr)
+#define isclose(c) (strchr (")]'\"", c) != nullptr)
+#define isperiod(c) (strchr (".?!", c) != nullptr)
/* Size of a tab stop, for expansion on input and re-introduction on
output. */
static struct option const long_options[] =
{
- {"crown-margin", no_argument, NULL, 'c'},
- {"prefix", required_argument, NULL, 'p'},
- {"split-only", no_argument, NULL, 's'},
- {"tagged-paragraph", no_argument, NULL, 't'},
- {"uniform-spacing", no_argument, NULL, 'u'},
- {"width", required_argument, NULL, 'w'},
- {"goal", required_argument, NULL, 'g'},
+ {"crown-margin", no_argument, nullptr, 'c'},
+ {"prefix", required_argument, nullptr, 'p'},
+ {"split-only", no_argument, nullptr, 's'},
+ {"tagged-paragraph", no_argument, nullptr, 't'},
+ {"uniform-spacing", no_argument, nullptr, 'u'},
+ {"width", required_argument, nullptr, 'w'},
+ {"goal", required_argument, nullptr, 'g'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0},
+ {nullptr, 0, nullptr, 0},
};
int
{
int optchar;
bool ok = true;
- char const *max_width_option = NULL;
- char const *goal_width_option = NULL;
+ char const *max_width_option = nullptr;
+ char const *goal_width_option = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
}
while ((optchar = getopt_long (argc, argv, "0123456789cstuw:p:g:",
- long_options, NULL))
+ long_options, nullptr))
!= -1)
switch (optchar)
{
/* Limit goal_width to max_width. */
goal_width = xdectoumax (goal_width_option, 0, max_width, "",
_("invalid width"), 0);
- if (max_width_option == NULL)
+ if (max_width_option == nullptr)
max_width = goal_width + 10;
}
else
{
FILE *in_stream;
in_stream = fopen (file, "r");
- if (in_stream != NULL)
+ if (in_stream != nullptr)
ok &= fmt (in_stream, file);
else
{
static struct option const longopts[] =
{
- {"bytes", no_argument, NULL, 'b'},
- {"spaces", no_argument, NULL, 's'},
- {"width", required_argument, NULL, 'w'},
+ {"bytes", no_argument, nullptr, 'b'},
+ {"spaces", no_argument, nullptr, 's'},
+ {"width", required_argument, nullptr, 'w'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
int c;
size_t column = 0; /* Screen column where next char will go. */
size_t offset_out = 0; /* Index in 'line_out' for next char. */
- static char *line_out = NULL;
+ static char *line_out = nullptr;
static size_t allocated_out = 0;
int saved_errno;
else
istream = fopen (filename, "r");
- if (istream == NULL)
+ if (istream == nullptr)
{
error (0, errno, "%s", quotef (filename));
return false;
break_spaces = count_bytes = have_read_stdin = false;
- while ((optc = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, shortopts, longopts, nullptr)) != -1)
{
char optargbuf[2];
enum { smallsize = 256 };
/* Return a template for a file in the same directory as DSTNAME.
- Use BUF if the template fits, otherwise use malloc and return NULL
+ Use BUF if the template fits, otherwise use malloc and return nullptr
(setting errno) if unsuccessful. */
static char *
atexit (close_stdout);
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
- VERSION, true, usage, AUTHORS, NULL);
+ VERSION, true, usage, AUTHORS,
+ (char const *) nullptr);
#define print_int(TYPE) \
sprintf (limit + 1, "%"PRIuMAX, (uintmax_t) TYPE##_MAX); \
bool use_names, char delim)
{
bool ok = true;
- struct passwd *pwd = NULL;
+ struct passwd *pwd = nullptr;
if (username)
{
pwd = getpwuid (ruid);
- if (pwd == NULL)
+ if (pwd == nullptr)
ok = false;
}
extern bool
print_group (gid_t gid, bool use_name)
{
- struct group *grp = NULL;
+ struct group *grp = nullptr;
bool ok = true;
if (use_name)
{
grp = getgrgid (gid);
- if (grp == NULL)
+ if (grp == nullptr)
{
error (0, 0, _("cannot find name for group ID %lu"),
(unsigned long int) gid);
{
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
/* Processing the arguments this way makes groups.c behave differently to
* groups.sh if one of the arguments is "--".
*/
- while ((optc = getopt_long (argc, argv, "", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "", longopts, nullptr)) != -1)
{
switch (optc)
{
if (rgid == NO_GID && errno)
die (EXIT_FAILURE, errno, _("cannot get real GID"));
- if (!print_group_list (NULL, ruid, rgid, egid, true, ' '))
+ if (!print_group_list (nullptr, ruid, rgid, egid, true, ' '))
ok = false;
putchar ('\n');
}
for ( ; optind < argc; optind++)
{
struct passwd *pwd = getpwnam (argv[optind]);
- if (pwd == NULL)
+ if (pwd == nullptr)
{
error (0, 0, _("%s: no such user"), quote (argv[optind]));
ok = false;
static struct option const long_options[] =
{
- {"bytes", required_argument, NULL, 'c'},
- {"lines", required_argument, NULL, 'n'},
- {"-presume-input-pipe", no_argument, NULL,
+ {"bytes", required_argument, nullptr, 'c'},
+ {"lines", required_argument, nullptr, 'n'},
+ {"-presume-input-pipe", no_argument, nullptr,
PRESUME_INPUT_PIPE_OPTION}, /* do not document */
- {"quiet", no_argument, NULL, 'q'},
- {"silent", no_argument, NULL, 'q'},
- {"verbose", no_argument, NULL, 'v'},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"quiet", no_argument, nullptr, 'q'},
+ {"silent", no_argument, nullptr, 'q'},
+ {"verbose", no_argument, nullptr, 'v'},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
size_t n_read;
bool buffered_enough;
size_t i, i_next;
- char **b = NULL;
+ char **b = nullptr;
/* Round n_elide up to a multiple of READ_BUFSIZE. */
size_t rem = READ_BUFSIZE - (n_elide % READ_BUFSIZE);
size_t n_elide_round = n_elide + rem;
first = last = xmalloc (sizeof (LBUFFER));
first->nbytes = first->nlines = 0;
- first->next = NULL;
+ first->next = nullptr;
tmp = xmalloc (sizeof (LBUFFER));
/* Always read into a fresh buffer.
tmp->nbytes = n_read;
tmp->nlines = 0;
- tmp->next = NULL;
+ tmp->next = nullptr;
/* Count the number of newlines just read. */
{
{
char const *nl;
nl = memrchr (buffer, line_end, n);
- if (nl == NULL)
+ if (nl == nullptr)
break;
n = nl - buffer;
}
/* Initializer for file_list if no file-arguments
were specified on the command line. */
- static char const *const default_file_list[] = {"-", NULL};
+ static char const *const default_file_list[] = {"-", nullptr};
char const *const *file_list;
initialize_main (&argc, &argv);
argc--;
}
- while ((c = getopt_long (argc, argv, "c:n:qvz0123456789", long_options, NULL))
+ while ((c = getopt_long (argc, argv, "c:n:qvz0123456789",
+ long_options, nullptr))
!= -1)
{
switch (c)
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (optind < argc)
{
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (optind + 1 < argc)
{
else
{
hostname = xgethostname ();
- if (hostname == NULL)
+ if (hostname == nullptr)
die (EXIT_FAILURE, errno, _("cannot determine hostname"));
puts (hostname);
}
/* The SELinux context. Start with a known invalid value so print_full_info
knows when 'context' has not been set to a meaningful value. */
-static char *context = NULL;
+static char *context = nullptr;
static void print_user (uid_t uid);
static void print_full_info (char const *username);
static struct option const longopts[] =
{
- {"context", no_argument, NULL, 'Z'},
- {"group", no_argument, NULL, 'g'},
- {"groups", no_argument, NULL, 'G'},
- {"name", no_argument, NULL, 'n'},
- {"real", no_argument, NULL, 'r'},
- {"user", no_argument, NULL, 'u'},
- {"zero", no_argument, NULL, 'z'},
+ {"context", no_argument, nullptr, 'Z'},
+ {"group", no_argument, nullptr, 'g'},
+ {"groups", no_argument, nullptr, 'G'},
+ {"name", no_argument, nullptr, 'n'},
+ {"real", no_argument, nullptr, 'r'},
+ {"user", no_argument, nullptr, 'u'},
+ {"zero", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "agnruzGZ", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "agnruzGZ", longopts, nullptr)) != -1)
{
switch (optc)
{
/* For each username/userid to get its pw_name field */
for (; optind < n_ids; optind++)
{
- char *pw_name = NULL;
- struct passwd *pwd = NULL;
+ char *pw_name = nullptr;
+ struct passwd *pwd = nullptr;
char const *spec = argv[optind];
/* Disallow an empty spec here as parse_user_spec() doesn't
give an error for that as it seems it's a valid way to
specify a noop or "reset special bits" depending on the system. */
if (*spec)
{
- if (parse_user_spec (spec, &euid, NULL, &pw_name, NULL) == NULL)
+ if (! parse_user_spec (spec, &euid, nullptr, &pw_name, nullptr))
pwd = pw_name ? getpwnam (pw_name) : getpwuid (euid);
}
- if (pwd == NULL)
+ if (pwd == nullptr)
{
error (0, errno, _("%s: no such user"), quote (spec));
ok &= false;
if (rgid == NO_GID && errno)
die (EXIT_FAILURE, errno, _("cannot get real GID"));
}
- print_stuff (NULL);
+ print_stuff (nullptr);
}
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
static void
print_user (uid_t uid)
{
- struct passwd *pwd = NULL;
+ struct passwd *pwd = nullptr;
if (use_name)
{
pwd = getpwuid (uid);
- if (pwd == NULL)
+ if (pwd == nullptr)
{
error (0, 0, _("cannot find name for user ID %s"),
uidtostr (uid));
# define endpwent() ((void) 0)
#endif
-/* The user name that will own the files, or NULL to make the owner
+/* The user name that will own the files, or nullptr to make the owner
the current user ID. */
static char *owner_name;
/* The user ID corresponding to 'owner_name'. */
static uid_t owner_id;
-/* The group name that will own the files, or NULL to make the group
+/* The group name that will own the files, or nullptr to make the group
the current group ID. */
static char *group_name;
static struct option const long_options[] =
{
- {"backup", optional_argument, NULL, 'b'},
- {"compare", no_argument, NULL, 'C'},
+ {"backup", optional_argument, nullptr, 'b'},
+ {"compare", no_argument, nullptr, 'C'},
{GETOPT_SELINUX_CONTEXT_OPTION_DECL},
- {"debug", no_argument, NULL, DEBUG_OPTION},
- {"directory", no_argument, NULL, 'd'},
- {"group", required_argument, NULL, 'g'},
- {"mode", required_argument, NULL, 'm'},
- {"no-target-directory", no_argument, NULL, 'T'},
- {"owner", required_argument, NULL, 'o'},
- {"preserve-timestamps", no_argument, NULL, 'p'},
- {"preserve-context", no_argument, NULL, PRESERVE_CONTEXT_OPTION},
- {"strip", no_argument, NULL, 's'},
- {"strip-program", required_argument, NULL, STRIP_PROGRAM_OPTION},
- {"suffix", required_argument, NULL, 'S'},
- {"target-directory", required_argument, NULL, 't'},
- {"verbose", no_argument, NULL, 'v'},
+ {"debug", no_argument, nullptr, DEBUG_OPTION},
+ {"directory", no_argument, nullptr, 'd'},
+ {"group", required_argument, nullptr, 'g'},
+ {"mode", required_argument, nullptr, 'm'},
+ {"no-target-directory", no_argument, nullptr, 'T'},
+ {"owner", required_argument, nullptr, 'o'},
+ {"preserve-timestamps", no_argument, nullptr, 'p'},
+ {"preserve-context", no_argument, nullptr, PRESERVE_CONTEXT_OPTION},
+ {"strip", no_argument, nullptr, 's'},
+ {"strip-program", required_argument, nullptr, STRIP_PROGRAM_OPTION},
+ {"suffix", required_argument, nullptr, 'S'},
+ {"target-directory", required_argument, nullptr, 't'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Compare content of opened files using file descriptors A_FD and B_FD. Return
/* compare SELinux context if preserving */
if (selinux_enabled && x->preserve_security_context)
{
- char *file_scontext = NULL;
- char *to_scontext = NULL;
+ char *file_scontext = nullptr;
+ char *to_scontext = nullptr;
bool scontext_match;
if (getfilecon (src_name, &file_scontext) == -1)
x->update = false;
x->require_preserve_context = false; /* Not used by install currently. */
x->preserve_security_context = false; /* Whether to copy context from src. */
- x->set_security_context = NULL; /* Whether to set sys default context. */
+ x->set_security_context = nullptr; /* Whether to set sys default context. */
x->preserve_xattr = false;
x->verbose = false;
- x->dest_info = NULL;
- x->src_info = NULL;
+ x->dest_info = nullptr;
+ x->src_info = nullptr;
}
static struct selabel_handle *
if (!initialized)
{
initialized = true;
- hnd = selabel_open (SELABEL_CTX_FILE, NULL, 0);
+ hnd = selabel_open (SELABEL_CTX_FILE, nullptr, 0);
if (!hnd)
error (0, errno, _("warning: security labeling handle failed"));
}
setdefaultfilecon (char const *file)
{
struct stat st;
- char *scontext = NULL;
+ char *scontext = nullptr;
if (selinux_enabled != 1)
{
However, since !x->recursive, the call to "copy" will fail if FROM
is a directory. */
- return copy (from, to, to_dirfd, to_relname, 0, x, ©_into_self, NULL);
+ return copy (from, to, to_dirfd, to_relname, 0, x, ©_into_self, nullptr);
}
/* Set the attributes of file or directory NAME aka DIRFD+RELNAME.
{
char const *safe_name = name;
if (name && *name == '-')
- safe_name = file_name_concat (".", name, NULL);
- execlp (strip_program, strip_program, safe_name, NULL);
+ safe_name = file_name_concat (".", name, nullptr);
+ execlp (strip_program, strip_program, safe_name, nullptr);
die (EXIT_FAILURE, errno, _("cannot run %s"), quoteaf (strip_program));
}
default: /* Parent. */
if (owner_name)
{
pw = getpwnam (owner_name);
- if (pw == NULL)
+ if (pw == nullptr)
{
uintmax_t tmp;
- if (xstrtoumax (owner_name, NULL, 0, &tmp, "") != LONGINT_OK
+ if (xstrtoumax (owner_name, nullptr, 0, &tmp, "") != LONGINT_OK
|| UID_T_MAX < tmp)
die (EXIT_FAILURE, 0, _("invalid user %s"),
quote (owner_name));
if (group_name)
{
gr = getgrnam (group_name);
- if (gr == NULL)
+ if (gr == nullptr)
{
uintmax_t tmp;
- if (xstrtoumax (group_name, NULL, 0, &tmp, "") != LONGINT_OK
+ if (xstrtoumax (group_name, nullptr, 0, &tmp, "") != LONGINT_OK
|| GID_T_MAX < tmp)
die (EXIT_FAILURE, 0, _("invalid group %s"),
quote (group_name));
{
int optc;
int exit_status = EXIT_SUCCESS;
- char const *specified_mode = NULL;
+ char const *specified_mode = nullptr;
bool make_backups = false;
- char const *backup_suffix = NULL;
- char *version_control_string = NULL;
+ char const *backup_suffix = nullptr;
+ char *version_control_string = nullptr;
bool mkdir_and_install = false;
struct cp_options x;
- char const *target_directory = NULL;
+ char const *target_directory = nullptr;
bool no_target_directory = false;
int n_files;
char **file;
bool strip_program_specified = false;
- char const *scontext = NULL;
+ char const *scontext = nullptr;
/* set iff kernel has extra selinux system calls */
selinux_enabled = (0 < is_selinux_enabled ());
cp_option_init (&x);
- owner_name = NULL;
- group_name = NULL;
+ owner_name = nullptr;
+ group_name = nullptr;
strip_files = false;
dir_arg = false;
umask (0);
while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z", long_options,
- NULL)) != -1)
+ nullptr))
+ != -1)
{
switch (optc)
{
struct mode_change *change = mode_compile (specified_mode);
if (!change)
die (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode));
- mode = mode_adjust (0, false, 0, change, NULL);
+ mode = mode_adjust (0, false, 0, change, nullptr);
dir_mode = mode_adjust (0, true, 0, change, &dir_mode_bits);
free (change);
}
struct timeval delay = { .tv_sec = 0, .tv_usec = 0 };
ret = select (nfds,
- broken_output ? &fds : NULL,
- broken_output ? NULL : &fds,
- NULL, block ? NULL : &delay);
+ broken_output ? &fds : nullptr,
+ broken_output ? nullptr : &fds,
+ nullptr, block ? nullptr : &delay);
if (ret < 0)
continue;
};
/* The previous line read from each file. */
-static struct line *prevline[2] = {NULL, NULL};
+static struct line *prevline[2] = {nullptr, nullptr};
/* The number of lines read from each file. */
static uintmax_t line_no[2] = {0, 0};
/* This provides an extra line buffer for each file. We need these if we
try to read two consecutive lines into the same buffer, since we don't
want to overwrite the previous buffer before we check order. */
-static struct line *spareline[2] = {NULL, NULL};
+static struct line *spareline[2] = {nullptr, nullptr};
/* True if the LC_COLLATE locale is hard. */
static bool hard_LC_COLLATE;
static struct option const longopts[] =
{
- {"ignore-case", no_argument, NULL, 'i'},
- {"check-order", no_argument, NULL, CHECK_ORDER_OPTION},
- {"nocheck-order", no_argument, NULL, NOCHECK_ORDER_OPTION},
- {"zero-terminated", no_argument, NULL, 'z'},
- {"header", no_argument, NULL, HEADER_LINE_OPTION},
+ {"ignore-case", no_argument, nullptr, 'i'},
+ {"check-order", no_argument, nullptr, CHECK_ORDER_OPTION},
+ {"nocheck-order", no_argument, nullptr, NOCHECK_ORDER_OPTION},
+ {"zero-terminated", no_argument, nullptr, 'z'},
+ {"header", no_argument, nullptr, HEADER_LINE_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Used to print non-joining lines */
if (0 <= tab && tab != '\n')
{
char *sep;
- for (; (sep = memchr (ptr, tab, lim - ptr)) != NULL; ptr = sep + 1)
+ for (; (sep = memchr (ptr, tab, lim - ptr)) != nullptr; ptr = sep + 1)
extract_field (line, ptr, sep - ptr);
}
else if (tab < 0)
static void
freeline (struct line *line)
{
- if (line == NULL)
+ if (line == nullptr)
return;
free (line->fields);
- line->fields = NULL;
+ line->fields = nullptr;
free (line->buf.buffer);
- line->buf.buffer = NULL;
+ line->buf.buffer = nullptr;
}
/* Return <0 if the join field in LINE1 compares less than the one in LINE2;
}
else
{
- beg1 = NULL;
+ beg1 = nullptr;
len1 = 0;
}
}
else
{
- beg2 = NULL;
+ beg2 = nullptr;
len2 = 0;
}
{
seq->count = 0;
seq->alloc = 0;
- seq->lines = NULL;
+ seq->lines = nullptr;
}
/* Read a line from FP and add it to SEQ. Return true if successful. */
{
seq->lines = X2NREALLOC (seq->lines, &seq->alloc);
for (size_t i = seq->count; i < seq->alloc; i++)
- seq->lines[i] = NULL;
+ seq->lines[i] = nullptr;
}
if (get_line (fp, &seq->lines[seq->count], whichfile))
}
prfield (field, line);
o = o->next;
- if (o == NULL)
+ if (o == nullptr)
break;
putchar (output_separator);
}
struct line const *hline1 = seq1.count ? seq1.lines[0] : &uni_blank;
struct line const *hline2 = seq2.count ? seq2.lines[0] : &uni_blank;
prjoin (hline1, hline2);
- prevline[0] = NULL;
- prevline[1] = NULL;
+ prevline[0] = nullptr;
+ prevline[1] = nullptr;
if (seq1.count)
advance_seq (fp1, &seq1, true, 1);
if (seq2.count)
tail ends of both inputs to verify that they are in order. We
skip the rest of the tail once we have issued a warning for that
file, unless we actually need to print the unpairable lines. */
- struct line *line = NULL;
+ struct line *line = nullptr;
bool checktail = false;
if (check_input_order != CHECK_ORDER_DISABLED
o = xmalloc (sizeof *o);
o->file = file;
o->field = field;
- o->next = NULL;
+ o->next = nullptr;
/* Add to the end of the list so the fields are in the right order. */
outlist_end->next = o;
size_t result;
uintmax_t val;
- strtol_error s_err = xstrtoumax (str, NULL, 10, &val, "");
+ strtol_error s_err = xstrtoumax (str, nullptr, 10, &val, "");
if (s_err == LONGINT_OVERFLOW || (s_err == LONGINT_OK && SIZE_MAX < val))
val = SIZE_MAX;
else if (s_err != LONGINT_OK || val == 0)
check_input_order = CHECK_ORDER_DEFAULT;
while ((optc = getopt_long (argc, argv, "-a:e:i1:2:j:o:t:v:z",
- longopts, NULL))
+ longopts, nullptr))
!= -1)
{
optc_status = MUST_BE_OPERAND;
case 'a':
{
unsigned long int val;
- if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK
+ if (xstrtoul (optarg, nullptr, 10, &val, "") != LONGINT_OK
|| (val != 1 && val != 2))
die (EXIT_FAILURE, 0,
_("invalid field number: %s"), quote (optarg));
static struct option const long_options[] =
{
- {"list", no_argument, NULL, 'l'},
- {"signal", required_argument, NULL, 's'},
- {"table", no_argument, NULL, 't'},
+ {"list", no_argument, nullptr, 'l'},
+ {"signal", required_argument, nullptr, 's'},
+ {"table", no_argument, nullptr, 't'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, short_options, long_options, NULL))
+ while ((optc = getopt_long (argc, argv, short_options, long_options, nullptr))
!= -1)
switch (optc)
{
}
return (list
- ? list_signals (table, optind < argc ? argv + optind : NULL)
+ ? list_signals (table, optind < argc ? argv + optind : nullptr)
: send_signals (signum, argv + optind));
}
the buffer size, and more problematically does not give any indication
that the new size request was ignored:
- setvbuf (stdout, NULL, _IOFBF, 8192);
+ setvbuf (stdout, nullptr, _IOFBF, 8192);
The ISO C99 standard section 7.19.5.6 on the setvbuf function says:
buffer allocation as usual. If it is not zero, then except for
unbuffered files, the buf argument should point to a buffer at least size
bytes long; this buffer will be used instead of the current buffer. (If
- the size argument is not zero but buf is NULL, a buffer of the given size
+ the size argument is not zero but buf is null, a buffer of the given size
will be allocated immediately, and released on close. This is an extension
- to ANSI C; portable code should use a size of 0 with any NULL buffer.)
+ to ANSI C; portable code should use a size of 0 with any null buffer.)
--------------------
Another issue is that on glibc-2.7 the following doesn't buffer
the first write if it's greater than 1 byte.
static char const *
fileno_to_name (const int fd)
{
- char const *ret = NULL;
+ char const *ret = nullptr;
switch (fd)
{
static void
apply_mode (FILE *stream, char const *mode)
{
- char *buf = NULL;
+ char *buf = nullptr;
int setvbuf_mode;
uintmax_t size = 0;
return;
}
- buf = size <= SIZE_MAX ? malloc (size) : NULL;
+ buf = size <= SIZE_MAX ? malloc (size) : nullptr;
if (!buf)
{
/* We could defer the allocation to libc, however since
- glibc currently ignores the combination of NULL buffer
+ glibc currently ignores the combination of null buffer
with non zero size, we'll fail here. */
fprintf (stderr,
_("failed to allocate a %" PRIuMAX
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (argc < optind + 2)
{
static struct option const long_options[] =
{
- {"backup", optional_argument, NULL, 'b'},
- {"directory", no_argument, NULL, 'F'},
- {"no-dereference", no_argument, NULL, 'n'},
- {"no-target-directory", no_argument, NULL, 'T'},
- {"force", no_argument, NULL, 'f'},
- {"interactive", no_argument, NULL, 'i'},
- {"suffix", required_argument, NULL, 'S'},
- {"target-directory", required_argument, NULL, 't'},
- {"logical", no_argument, NULL, 'L'},
- {"physical", no_argument, NULL, 'P'},
- {"relative", no_argument, NULL, 'r'},
- {"symbolic", no_argument, NULL, 's'},
- {"verbose", no_argument, NULL, 'v'},
+ {"backup", optional_argument, nullptr, 'b'},
+ {"directory", no_argument, nullptr, 'F'},
+ {"no-dereference", no_argument, nullptr, 'n'},
+ {"no-target-directory", no_argument, nullptr, 'T'},
+ {"force", no_argument, nullptr, 'f'},
+ {"interactive", no_argument, nullptr, 'i'},
+ {"suffix", required_argument, nullptr, 'S'},
+ {"target-directory", required_argument, nullptr, 't'},
+ {"logical", no_argument, nullptr, 'L'},
+ {"physical", no_argument, nullptr, 'P'},
+ {"relative", no_argument, nullptr, 'r'},
+ {"symbolic", no_argument, nullptr, 's'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Return an errno value for a system call that returned STATUS.
char *realdest = canonicalize_filename_mode (targetdir, CAN_MISSING);
char *realfrom = canonicalize_filename_mode (from, CAN_MISSING);
- char *relative_from = NULL;
+ char *relative_from = nullptr;
if (realdest && realfrom)
{
/* Write to a PATH_MAX buffer. */
if (!relpath (realfrom, realdest, relative_from, PATH_MAX))
{
free (relative_from);
- relative_from = NULL;
+ relative_from = nullptr;
}
}
{
struct stat source_stats;
int source_status = 1;
- char *backup_base = NULL;
- char *rel_source = NULL;
+ char *backup_base = nullptr;
+ char *rel_source = nullptr;
int nofollow_flag = logical ? 0 : AT_SYMLINK_NOFOLLOW;
if (link_errno < 0)
link_errno = atomic_link (source, destdir_fd, dest_base);
{
int rename_errno = errno;
free (backup_base);
- backup_base = NULL;
+ backup_base = nullptr;
if (rename_errno != ENOENT)
{
error (0, rename_errno, _("cannot backup %s"),
if (backup_base)
{
char *backup = backup_base;
- void *alloc = NULL;
+ void *alloc = nullptr;
ptrdiff_t destdirlen = dest_base - dest;
if (0 < destdirlen)
{
int c;
bool ok;
bool make_backups = false;
- char const *backup_suffix = NULL;
- char *version_control_string = NULL;
- char const *target_directory = NULL;
+ char const *backup_suffix = nullptr;
+ char *version_control_string = nullptr;
+ char const *target_directory = nullptr;
int destdir_fd;
bool no_target_directory = false;
int n_files;
symbolic_link = remove_existing_files = interactive = verbose
= hard_dir_link = false;
- while ((c = getopt_long (argc, argv, "bdfinrst:vFLPS:T", long_options, NULL))
+ while ((c = getopt_long (argc, argv, "bdfinrst:vFLPS:T",
+ long_options, nullptr))
!= -1)
{
switch (c)
&& backup_type != numbered_backups)
{
dest_set = hash_initialize (DEST_INFO_INITIAL_CAPACITY,
- NULL,
+ nullptr,
triple_hash,
triple_compare,
triple_free);
- if (dest_set == NULL)
+ if (dest_set == nullptr)
xalloc_die ();
}
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (optind < argc)
{
static char const *const time_style_args[] =
{
- "full-iso", "long-iso", "iso", "locale", NULL
+ "full-iso", "long-iso", "iso", "locale", nullptr
};
static enum time_style const time_style_types[] =
{
/* Names of indicator styles. */
static char const *const indicator_style_args[] =
{
- "none", "slash", "file-type", "classify", NULL
+ "none", "slash", "file-type", "classify", nullptr
};
static enum indicator_style const indicator_style_types[] =
{
{
"lc", "rc", "ec", "rs", "no", "fi", "di", "ln", "pi", "so",
"bd", "cd", "mi", "or", "ex", "do", "su", "sg", "st",
- "ow", "tw", "ca", "mh", "cl", NULL
+ "ow", "tw", "ca", "mh", "cl", nullptr
};
struct color_ext_type
{
{ LEN_STR_PAIR ("\033[") }, /* lc: Left of color sequence */
{ LEN_STR_PAIR ("m") }, /* rc: Right of color sequence */
- { 0, NULL }, /* ec: End color (replaces lc+rs+rc) */
+ { 0, nullptr }, /* ec: End color (replaces lc+rs+rc) */
{ LEN_STR_PAIR ("0") }, /* rs: Reset to ordinary colors */
- { 0, NULL }, /* no: Normal */
- { 0, NULL }, /* fi: File: default */
+ { 0, nullptr }, /* no: Normal */
+ { 0, nullptr }, /* fi: File: default */
{ LEN_STR_PAIR ("01;34") }, /* di: Directory: bright blue */
{ LEN_STR_PAIR ("01;36") }, /* ln: Symlink: bright cyan */
{ LEN_STR_PAIR ("33") }, /* pi: Pipe: yellow/brown */
{ LEN_STR_PAIR ("01;35") }, /* so: Socket: bright magenta */
{ LEN_STR_PAIR ("01;33") }, /* bd: Block device: bright yellow */
{ LEN_STR_PAIR ("01;33") }, /* cd: Char device: bright yellow */
- { 0, NULL }, /* mi: Missing file: undefined */
- { 0, NULL }, /* or: Orphaned symlink: undefined */
+ { 0, nullptr }, /* mi: Missing file: undefined */
+ { 0, nullptr }, /* or: Orphaned symlink: undefined */
{ LEN_STR_PAIR ("01;32") }, /* ex: Executable: bright green */
{ LEN_STR_PAIR ("01;35") }, /* do: Door: bright magenta */
{ LEN_STR_PAIR ("37;41") }, /* su: setuid: white on red */
{ LEN_STR_PAIR ("37;44") }, /* st: sticky: black on blue */
{ LEN_STR_PAIR ("34;42") }, /* ow: other-writable: blue on green */
{ LEN_STR_PAIR ("30;42") }, /* tw: ow w/ sticky: black on green */
- { 0, NULL }, /* ca: disabled by default */
- { 0, NULL }, /* mh: disabled by default */
+ { 0, nullptr }, /* ca: disabled by default */
+ { 0, nullptr }, /* mh: disabled by default */
{ LEN_STR_PAIR ("\033[K") }, /* cl: clear to end of line */
};
/* A list mapping file extensions to corresponding display sequence. */
-static struct color_ext_type *color_ext_list = NULL;
+static struct color_ext_type *color_ext_list = nullptr;
/* Buffer for color sequences */
static char *color_buf;
static struct option const long_options[] =
{
- {"all", no_argument, NULL, 'a'},
- {"escape", no_argument, NULL, 'b'},
- {"directory", no_argument, NULL, 'd'},
- {"dired", no_argument, NULL, 'D'},
- {"full-time", no_argument, NULL, FULL_TIME_OPTION},
- {"group-directories-first", no_argument, NULL,
+ {"all", no_argument, nullptr, 'a'},
+ {"escape", no_argument, nullptr, 'b'},
+ {"directory", no_argument, nullptr, 'd'},
+ {"dired", no_argument, nullptr, 'D'},
+ {"full-time", no_argument, nullptr, FULL_TIME_OPTION},
+ {"group-directories-first", no_argument, nullptr,
GROUP_DIRECTORIES_FIRST_OPTION},
- {"human-readable", no_argument, NULL, 'h'},
- {"inode", no_argument, NULL, 'i'},
- {"kibibytes", no_argument, NULL, 'k'},
- {"numeric-uid-gid", no_argument, NULL, 'n'},
- {"no-group", no_argument, NULL, 'G'},
- {"hide-control-chars", no_argument, NULL, 'q'},
- {"reverse", no_argument, NULL, 'r'},
- {"size", no_argument, NULL, 's'},
- {"width", required_argument, NULL, 'w'},
- {"almost-all", no_argument, NULL, 'A'},
- {"ignore-backups", no_argument, NULL, 'B'},
- {"classify", optional_argument, NULL, 'F'},
- {"file-type", no_argument, NULL, FILE_TYPE_INDICATOR_OPTION},
- {"si", no_argument, NULL, SI_OPTION},
- {"dereference-command-line", no_argument, NULL, 'H'},
- {"dereference-command-line-symlink-to-dir", no_argument, NULL,
+ {"human-readable", no_argument, nullptr, 'h'},
+ {"inode", no_argument, nullptr, 'i'},
+ {"kibibytes", no_argument, nullptr, 'k'},
+ {"numeric-uid-gid", no_argument, nullptr, 'n'},
+ {"no-group", no_argument, nullptr, 'G'},
+ {"hide-control-chars", no_argument, nullptr, 'q'},
+ {"reverse", no_argument, nullptr, 'r'},
+ {"size", no_argument, nullptr, 's'},
+ {"width", required_argument, nullptr, 'w'},
+ {"almost-all", no_argument, nullptr, 'A'},
+ {"ignore-backups", no_argument, nullptr, 'B'},
+ {"classify", optional_argument, nullptr, 'F'},
+ {"file-type", no_argument, nullptr, FILE_TYPE_INDICATOR_OPTION},
+ {"si", no_argument, nullptr, SI_OPTION},
+ {"dereference-command-line", no_argument, nullptr, 'H'},
+ {"dereference-command-line-symlink-to-dir", no_argument, nullptr,
DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION},
- {"hide", required_argument, NULL, HIDE_OPTION},
- {"ignore", required_argument, NULL, 'I'},
- {"indicator-style", required_argument, NULL, INDICATOR_STYLE_OPTION},
- {"dereference", no_argument, NULL, 'L'},
- {"literal", no_argument, NULL, 'N'},
- {"quote-name", no_argument, NULL, 'Q'},
- {"quoting-style", required_argument, NULL, QUOTING_STYLE_OPTION},
- {"recursive", no_argument, NULL, 'R'},
- {"format", required_argument, NULL, FORMAT_OPTION},
- {"show-control-chars", no_argument, NULL, SHOW_CONTROL_CHARS_OPTION},
- {"sort", required_argument, NULL, SORT_OPTION},
- {"tabsize", required_argument, NULL, 'T'},
- {"time", required_argument, NULL, TIME_OPTION},
- {"time-style", required_argument, NULL, TIME_STYLE_OPTION},
- {"zero", no_argument, NULL, ZERO_OPTION},
- {"color", optional_argument, NULL, COLOR_OPTION},
- {"hyperlink", optional_argument, NULL, HYPERLINK_OPTION},
- {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
+ {"hide", required_argument, nullptr, HIDE_OPTION},
+ {"ignore", required_argument, nullptr, 'I'},
+ {"indicator-style", required_argument, nullptr, INDICATOR_STYLE_OPTION},
+ {"dereference", no_argument, nullptr, 'L'},
+ {"literal", no_argument, nullptr, 'N'},
+ {"quote-name", no_argument, nullptr, 'Q'},
+ {"quoting-style", required_argument, nullptr, QUOTING_STYLE_OPTION},
+ {"recursive", no_argument, nullptr, 'R'},
+ {"format", required_argument, nullptr, FORMAT_OPTION},
+ {"show-control-chars", no_argument, nullptr, SHOW_CONTROL_CHARS_OPTION},
+ {"sort", required_argument, nullptr, SORT_OPTION},
+ {"tabsize", required_argument, nullptr, 'T'},
+ {"time", required_argument, nullptr, TIME_OPTION},
+ {"time-style", required_argument, nullptr, TIME_STYLE_OPTION},
+ {"zero", no_argument, nullptr, ZERO_OPTION},
+ {"color", optional_argument, nullptr, COLOR_OPTION},
+ {"hyperlink", optional_argument, nullptr, HYPERLINK_OPTION},
+ {"block-size", required_argument, nullptr, BLOCK_SIZE_OPTION},
{"context", no_argument, 0, 'Z'},
- {"author", no_argument, NULL, AUTHOR_OPTION},
+ {"author", no_argument, nullptr, AUTHOR_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static char const *const format_args[] =
{
"verbose", "long", "commas", "horizontal", "across",
- "vertical", "single-column", NULL
+ "vertical", "single-column", nullptr
};
static enum format const format_types[] =
{
static char const *const sort_args[] =
{
- "none", "time", "size", "extension", "version", "width", NULL
+ "none", "time", "size", "extension", "version", "width", nullptr
};
static enum sort_type const sort_types[] =
{
"ctime", "status",
"mtime", "modification",
"birth", "creation",
- NULL
+ nullptr
};
static enum time_type const time_types[] =
{
/* force and none are for compatibility with another color-ls version */
"always", "yes", "force",
"never", "no", "none",
- "auto", "tty", "if-tty", NULL
+ "auto", "tty", "if-tty", nullptr
};
static enum when_type const when_types[] =
{
}
#endif
-/* Return the address of the first plain %b spec in FMT, or NULL if
+/* Return the address of the first plain %b spec in FMT, or nullptr if
there is no such spec. %5b etc. do not match, so that user
widths/flags are honored. */
case 'b': return fmt;
case '%': fmt++; break;
}
- return NULL;
+ return nullptr;
}
static char RFC3986[256];
/* Attempt to insert this entry into the table. */
ent_from_table = hash_insert (active_dir_set, ent);
- if (ent_from_table == NULL)
+ if (ent_from_table == nullptr)
{
/* Insertion failed due to lack of memory. */
xalloc_die ();
/* Exit or suspend the program. */
raise (sig);
- sigprocmask (SIG_SETMASK, &oldset, NULL);
+ sigprocmask (SIG_SETMASK, &oldset, nullptr);
/* If execution reaches here, then the program has been
continued (after being suspended). */
sigemptyset (&caught_signals);
for (j = 0; j < nsigs; j++)
{
- sigaction (sig[j], NULL, &act);
+ sigaction (sig[j], nullptr, &act);
if (act.sa_handler != SIG_IGN)
sigaddset (&caught_signals, sig[j]);
}
if (sigismember (&caught_signals, sig[j]))
{
act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
- sigaction (sig[j], &act, NULL);
+ sigaction (sig[j], &act, nullptr);
}
#else
for (j = 0; j < nsigs; j++)
exit_status = EXIT_SUCCESS;
print_dir_name = true;
- pending_dirs = NULL;
+ pending_dirs = nullptr;
current_time.tv_sec = TYPE_MINIMUM (time_t);
current_time.tv_nsec = -1;
detect any directory cycles. */
if (recursive)
{
- active_dir_set = hash_initialize (INITIAL_TABLE_SIZE, NULL,
+ active_dir_set = hash_initialize (INITIAL_TABLE_SIZE, nullptr,
dev_ino_hash,
dev_ino_compare,
dev_ino_free);
- if (active_dir_set == NULL)
+ if (active_dir_set == nullptr)
xalloc_die ();
obstack_init (&dev_ino_obstack);
if (immediate_dirs)
gobble_file (".", directory, NOT_AN_INODE_NUMBER, true, "");
else
- queue_directory (".", NULL, true);
+ queue_directory (".", nullptr, true);
}
else
do
{
sort_files ();
if (!immediate_dirs)
- extract_dirs_from_files (NULL, true);
+ extract_dirs_from_files (nullptr, true);
/* 'cwd_n_used' might be zero now. */
}
if (LOOP_DETECT)
{
- if (thispend->name == NULL)
+ if (thispend->name == nullptr)
{
- /* thispend->name == NULL means this is a marker entry
+ /* thispend->name == nullptr means this is a marker entry
indicating we've finished processing the directory.
Use its dev/ino numbers to remove the corresponding
entry from the active_dir_set hash table. */
/* Treat too-large values as if they were 0, which is
effectively infinity. */
- switch (xstrtoumax (spec, NULL, 0, &val, ""))
+ switch (xstrtoumax (spec, nullptr, 0, &val, ""))
{
case LONGINT_OK:
return val <= MIN (PTRDIFF_MAX, SIZE_MAX) ? val : 0;
static int
decode_switches (int argc, char **argv)
{
- char *time_style_option = NULL;
+ char *time_style_option = nullptr;
/* These variables are false or -1 unless a switch says otherwise. */
bool kibibytes_specified = false;
if (p)
{
uintmax_t tmp;
- if (xstrtoumax (p, NULL, 0, &tmp, "") == LONGINT_OK
+ if (xstrtoumax (p, nullptr, 0, &tmp, "") == LONGINT_OK
&& tmp <= SIZE_MAX)
tabsize = tmp;
else
? (stdout_isatty () ? shell_escape_quoting_style : -1)
: escape_quoting_style);
if (0 <= qs)
- set_quoting_style (NULL, qs);
- qs = get_quoting_style (NULL);
+ set_quoting_style (nullptr, qs);
+ qs = get_quoting_style (nullptr);
align_variable_outer_quotes
= ((format == long_format
|| ((format == many_per_line || format == horizontal) && line_length))
&& (qs == shell_quoting_style
|| qs == shell_escape_quoting_style
|| qs == c_maybe_quoting_style));
- filename_quoting_options = clone_quoting_options (NULL);
+ filename_quoting_options = clone_quoting_options (nullptr);
if (qs == escape_quoting_style)
set_char_quoting (filename_quoting_options, ' ', 1);
if (file_type <= indicator_style)
set_char_quoting (filename_quoting_options, *p, 1);
}
- dirname_quoting_options = clone_quoting_options (NULL);
+ dirname_quoting_options = clone_quoting_options (nullptr);
set_char_quoting (dirname_quoting_options, ':', 1);
/* --dired is meaningful only with --format=long (-l) and sans --hyperlink.
{
for (int i = 0; i < 2; i++)
long_time_format[i] =
- dcgettext (NULL, long_time_format[i], LC_TIME);
+ dcgettext (nullptr, long_time_format[i], LC_TIME);
}
}
}
char label[3]; /* Indicator label */
struct color_ext_type *ext; /* Extension we are working on */
- if ((p = getenv ("LS_COLORS")) == NULL || *p == '\0')
+ if ((p = getenv ("LS_COLORS")) == nullptr || *p == '\0')
{
/* LS_COLORS takes precedence, but if that's not set then
honor the COLORTERM and TERM env variables so that
return;
}
- ext = NULL;
+ ext = nullptr;
strcpy (label, "??");
/* This is an overly conservative estimate, but any possible
state = PS_FAIL; /* Assume failure... */
if (*(p++) == '=')/* It *should* be... */
{
- for (ind_no = 0; indicator_name[ind_no] != NULL; ++ind_no)
+ for (ind_no = 0; indicator_name[ind_no] != nullptr; ++ind_no)
{
if (STREQ (label, indicator_name[ind_no]))
{
error (0, 0,
_("unparsable value for LS_COLORS environment variable"));
free (color_buf);
- for (e = color_ext_list; e != NULL; /* empty */)
+ for (e = color_ext_list; e != nullptr; /* empty */)
{
e2 = e;
e = e->next;
match due to precedence, to avoid redundant string compares. */
struct color_ext_type *e1;
- for (e1 = color_ext_list; e1 != NULL; e1 = e1->next)
+ for (e1 = color_ext_list; e1 != nullptr; e1 = e1->next)
{
struct color_ext_type *e2;
bool case_ignored = false;
- for (e2 = e1->next; e2 != NULL; e2 = e2->next)
+ for (e2 = e1->next; e2 != nullptr; e2 = e2->next)
{
if (e2->ext.len < SIZE_MAX && e1->ext.len == e2->ext.len)
{
If REALNAME is nonzero, it will be used instead of NAME when the
directory name is printed. This allows symbolic links to directories
to be treated as regular directories but still be listed under their
- real names. NAME == NULL is used to insert a marker entry for the
+ real names. NAME == nullptr is used to insert a marker entry for the
directory named in REALNAME.
- If NAME is non-NULL, we use its dev/ino information to save
+ If NAME is non-null, we use its dev/ino information to save
a call to stat -- when doing a recursive (-R) traversal.
COMMAND_LINE_ARG means this directory was mentioned on the command line. */
queue_directory (char const *name, char const *realname, bool command_line_arg)
{
struct pending *new = xmalloc (sizeof *new);
- new->realname = realname ? xstrdup (realname) : NULL;
- new->name = name ? xstrdup (name) : NULL;
+ new->realname = realname ? xstrdup (realname) : nullptr;
+ new->name = name ? xstrdup (name) : nullptr;
new->command_line_arg = command_line_arg;
new->next = pending_dirs;
pending_dirs = new;
first = false;
dired_indent ();
- char *absolute_name = NULL;
+ char *absolute_name = nullptr;
if (print_hyperlink)
{
absolute_name = canonicalize_filename_mode (name, CAN_MISSING);
_("error canonicalizing %s"), name);
}
quote_name (realname ? realname : name, dirname_quoting_options, -1,
- NULL, true, &subdired_obstack, absolute_name);
+ nullptr, true, &subdired_obstack, absolute_name);
free (absolute_name);
bool has_cap;
cap_t cap_d = cap_get_file (name);
- if (cap_d == NULL)
+ if (cap_d == nullptr)
return false;
- result = cap_to_text (cap_d, NULL);
+ result = cap_to_text (cap_d, nullptr);
cap_free (cap_d);
if (!result)
return false;
get_link_name (char const *filename, struct fileinfo *f, bool command_line_arg)
{
f->linkname = areadlink_with_size (filename, f->stat.st_size);
- if (f->linkname == NULL)
+ if (f->linkname == nullptr)
file_failure (command_line_arg, _("cannot read symbolic link %s"),
filename);
}
{
size_t i;
size_t j;
- bool ignore_dot_and_dot_dot = (dirname != NULL);
+ bool ignore_dot_and_dot_dot = (dirname != nullptr);
if (dirname && LOOP_DETECT)
{
/* Insert a marker entry first. When we dequeue this marker entry,
we'll know that DIRNAME has been processed and may be removed
from the set of active directories. */
- queue_directory (NULL, dirname, false);
+ queue_directory (nullptr, dirname, false);
}
/* Queue the directories last one first, because queueing reverses the
queue_directory (f->name, f->linkname, command_line_arg);
else
{
- char *name = file_name_concat (dirname, f->name, NULL);
+ char *name = file_name_concat (dirname, f->name, nullptr);
queue_directory (name, f->linkname, command_line_arg);
free (name);
}
{ rev_xstrcoll_version, rev_xstrcoll_df_version },
},
- /* We use NULL for the strcmp variants of version comparison
+ /* We use nullptr for the strcmp variants of version comparison
since as explained in cmp_version definition, version comparison
does not rely on xstrcoll, so it will never longjmp, and never
need to try the strcmp fallback. */
{
- { NULL, NULL },
- { NULL, NULL },
+ { nullptr, nullptr },
+ { nullptr, nullptr },
}
},
format_user (uid_t u, int width, bool stat_ok)
{
format_user_or_group (! stat_ok ? "?" :
- (numeric_ids ? NULL : getuser (u)), u, width);
+ (numeric_ids ? nullptr : getuser (u)), u, width);
}
/* Likewise, for groups. */
format_group (gid_t g, int width, bool stat_ok)
{
format_user_or_group (! stat_ok ? "?" :
- (numeric_ids ? NULL : getgroup (g)), g, width);
+ (numeric_ids ? nullptr : getgroup (g)), g, width);
}
/* Return the number of columns that format_user_or_group will print. */
return MAX (0, len);
}
else
- return snprintf (NULL, 0, "%"PRIuMAX, id);
+ return snprintf (nullptr, 0, "%"PRIuMAX, id);
}
/* Return the number of columns that format_user will print. */
static int
format_user_width (uid_t u)
{
- return format_user_or_group_width (numeric_ids ? NULL : getuser (u), u);
+ return format_user_or_group_width (numeric_ids ? nullptr : getuser (u), u);
}
/* Likewise, for groups. */
static int
format_group_width (gid_t g)
{
- return format_user_or_group_width (numeric_ids ? NULL : getgroup (g), g);
+ return format_user_or_group_width (numeric_ids ? nullptr : getgroup (g), g);
}
/* Return a pointer to a formatted version of F->stat.st_ino,
if (f->linkname)
{
dired_outstring (" -> ");
- print_name_with_quoting (f, true, NULL, (p - buf) + w + 4);
+ print_name_with_quoting (f, true, nullptr, (p - buf) + w + 4);
if (indicator_style != none)
print_type_indicator (true, f->linkmode, unknown);
}
print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
}
-/* Write to *BUF a quoted representation of the file name NAME, if non-NULL,
+/* Write to *BUF a quoted representation of the file name NAME, if non-null,
using OPTIONS to control quoting. *BUF is set to NAME if no quoting
is required. *BUF is allocated if more space required (and the original
*BUF is not deallocated).
Store the number of screen columns occupied by NAME's quoted
- representation into WIDTH, if non-NULL.
+ representation into WIDTH, if non-null.
Store into PAD whether an initial space is needed for padding.
Return the number of bytes in *BUF. */
displayed_width = len;
}
}
- else if (width != NULL)
+ else if (width != nullptr)
{
if (MB_CUR_MAX > 1)
displayed_width = mbsnwidth (buf, len, 0);
not actually part of the name. */
*pad = (align_variable_outer_quotes && cwd_some_quoted && ! quoted);
- if (width != NULL)
+ if (width != nullptr)
*width = displayed_width;
*inbuf = buf;
bool pad;
len = quote_name_buf (&buf, sizeof smallbuf, (char *) name, options,
- needs_general_quoting, NULL, &pad);
+ needs_general_quoting, nullptr, &pad);
if (pad && allow_pad)
dired_outbyte (' ');
{
char const *name = symlink_target ? f->linkname : f->name;
- const struct bin_str *color = print_with_color ?
- get_color_indicator (f, symlink_target) : NULL;
+ const struct bin_str *color
+ = print_with_color ? get_color_indicator (f, symlink_target) : nullptr;
bool used_color_this_time = (print_with_color
&& (color || is_colored (C_NORM)));
static void
prep_non_filename_text (void)
{
- if (color_indicator[C_END].string != NULL)
+ if (color_indicator[C_END].string != nullptr)
put_indicator (&color_indicator[C_END]);
else
{
if (print_scontext)
printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
- size_t width = print_name_with_quoting (f, false, NULL, start_col);
+ size_t width = print_name_with_quoting (f, false, nullptr, start_col);
if (indicator_style != none)
width += print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
put_indicator (&color_indicator[C_RIGHT]);
}
- return ind != NULL;
+ return ind != nullptr;
}
-/* Returns color indicator or NULL if none. */
+/* Returns color indicator or nullptr if none. */
ATTRIBUTE_PURE
static const struct bin_str*
get_color_indicator (const struct fileinfo *f, bool symlink_target)
}
/* Check the file's suffix only if still classified as C_FILE. */
- ext = NULL;
+ ext = nullptr;
if (type == C_FILE)
{
/* Test if NAME has a recognized suffix. */
len = strlen (name);
name += len; /* Pointer to final \0. */
- for (ext = color_ext_list; ext != NULL; ext = ext->next)
+ for (ext = color_ext_list; ext != nullptr; ext = ext->next)
{
if (ext->ext.len <= len)
{
const struct bin_str *const s
= ext ? &(ext->seq) : &color_indicator[type];
- return s->string ? s : NULL;
+ return s->string ? s : nullptr;
}
/* Output a color indicator (which may contain nulls). */
static struct option const longopts[] =
{
{GETOPT_SELINUX_CONTEXT_OPTION_DECL},
- {"mode", required_argument, NULL, 'm'},
- {"parents", no_argument, NULL, 'p'},
- {"verbose", no_argument, NULL, 'v'},
+ {"mode", required_argument, nullptr, 'm'},
+ {"parents", no_argument, nullptr, 'p'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
/* Options passed to subsidiary functions. */
struct mkdir_options
{
- /* Function to make an ancestor, or NULL if ancestors should not be
+ /* Function to make an ancestor, or nullptr if ancestors should not be
made. */
int (*make_ancestor_function) (char const *, char const *, void *);
int
main (int argc, char **argv)
{
- char const *specified_mode = NULL;
+ char const *specified_mode = nullptr;
int optc;
- char const *scontext = NULL;
+ char const *scontext = nullptr;
struct mkdir_options options;
- options.make_ancestor_function = NULL;
+ options.make_ancestor_function = nullptr;
options.mode = S_IRWXUGO;
options.mode_bits = 0;
- options.created_directory_format = NULL;
- options.set_security_context = NULL;
+ options.created_directory_format = nullptr;
+ options.set_security_context = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "pm:vZ", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "pm:vZ", longopts, nullptr)) != -1)
{
switch (optc)
{
else
{
options.set_security_context = selabel_open (SELABEL_CTX_FILE,
- NULL, 0);
+ nullptr, 0);
if (! options.set_security_context)
error (0, errno, _("warning: ignoring --context"));
}
static struct option const longopts[] =
{
{GETOPT_SELINUX_CONTEXT_OPTION_DECL},
- {"mode", required_argument, NULL, 'm'},
+ {"mode", required_argument, nullptr, 'm'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
main (int argc, char **argv)
{
mode_t newmode;
- char const *specified_mode = NULL;
+ char const *specified_mode = nullptr;
int exit_status = EXIT_SUCCESS;
int optc;
- char const *scontext = NULL;
- struct selabel_handle *set_security_context = NULL;
+ char const *scontext = nullptr;
+ struct selabel_handle *set_security_context = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "m:Z", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "m:Z", longopts, nullptr)) != -1)
{
switch (optc)
{
else
{
set_security_context = selabel_open (SELABEL_CTX_FILE,
- NULL, 0);
+ nullptr, 0);
if (! set_security_context)
error (0, errno, _("warning: ignoring --context"));
}
die (EXIT_FAILURE, 0, _("invalid mode"));
umask_value = umask (0);
umask (umask_value);
- newmode = mode_adjust (newmode, false, umask_value, change, NULL);
+ newmode = mode_adjust (newmode, false, umask_value, change, nullptr);
free (change);
if (newmode & ~S_IRWXUGO)
die (EXIT_FAILURE, 0,
static struct option const longopts[] =
{
{GETOPT_SELINUX_CONTEXT_OPTION_DECL},
- {"mode", required_argument, NULL, 'm'},
+ {"mode", required_argument, nullptr, 'm'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
main (int argc, char **argv)
{
mode_t newmode;
- char const *specified_mode = NULL;
+ char const *specified_mode = nullptr;
int optc;
size_t expected_operands;
mode_t node_type;
- char const *scontext = NULL;
- struct selabel_handle *set_security_context = NULL;
+ char const *scontext = nullptr;
+ struct selabel_handle *set_security_context = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "m:Z", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "m:Z", longopts, nullptr)) != -1)
{
switch (optc)
{
else
{
set_security_context = selabel_open (SELABEL_CTX_FILE,
- NULL, 0);
+ nullptr, 0);
if (! set_security_context)
error (0, errno, _("warning: ignoring --context"));
}
die (EXIT_FAILURE, 0, _("invalid mode"));
umask_value = umask (0);
umask (umask_value);
- newmode = mode_adjust (newmode, false, umask_value, change, NULL);
+ newmode = mode_adjust (newmode, false, umask_value, change, nullptr);
free (change);
if (newmode & ~S_IRWXUGO)
die (EXIT_FAILURE, 0,
uintmax_t i_major, i_minor;
dev_t device;
- if (xstrtoumax (s_major, NULL, 0, &i_major, "") != LONGINT_OK
+ if (xstrtoumax (s_major, nullptr, 0, &i_major, "") != LONGINT_OK
|| i_major != (major_t) i_major)
die (EXIT_FAILURE, 0,
_("invalid major device number %s"), quote (s_major));
- if (xstrtoumax (s_minor, NULL, 0, &i_minor, "") != LONGINT_OK
+ if (xstrtoumax (s_minor, nullptr, 0, &i_minor, "") != LONGINT_OK
|| i_minor != (minor_t) i_minor)
die (EXIT_FAILURE, 0,
_("invalid minor device number %s"), quote (s_minor));
static struct option const longopts[] =
{
- {"directory", no_argument, NULL, 'd'},
- {"quiet", no_argument, NULL, 'q'},
- {"dry-run", no_argument, NULL, 'u'},
- {"suffix", required_argument, NULL, SUFFIX_OPTION},
- {"tmpdir", optional_argument, NULL, 'p'},
+ {"directory", no_argument, nullptr, 'd'},
+ {"quiet", no_argument, nullptr, 'q'},
+ {"dry-run", no_argument, nullptr, 'u'},
+ {"suffix", required_argument, nullptr, SUFFIX_OPTION},
+ {"tmpdir", optional_argument, nullptr, 'p'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
main (int argc, char **argv)
{
char const *dest_dir;
- char const *dest_dir_arg = NULL;
+ char const *dest_dir_arg = nullptr;
bool suppress_file_err = false;
int c;
unsigned int n_args;
char *template;
- char *suffix = NULL;
+ char *suffix = nullptr;
bool use_dest_dir = false;
bool deprecated_t_option = false;
bool create_directory = false;
atexit (maybe_close_stdout);
- while ((c = getopt_long (argc, argv, "dp:qtuV", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "dp:qtuV", longopts, nullptr)) != -1)
{
switch (c)
{
quote (template));
}
- dest_name = file_name_concat (dest_dir, template, NULL);
+ dest_name = file_name_concat (dest_dir, template, nullptr);
free (template);
template = dest_name;
/* Note that suffix is now invalid. */
static char const *const update_type_string[] =
{
- "all", "none", "older", NULL
+ "all", "none", "older", nullptr
};
static enum Update_type const update_type[] =
{
static struct option const long_options[] =
{
- {"backup", optional_argument, NULL, 'b'},
- {"context", no_argument, NULL, 'Z'},
- {"debug", no_argument, NULL, DEBUG_OPTION},
- {"force", no_argument, NULL, 'f'},
- {"interactive", no_argument, NULL, 'i'},
- {"no-clobber", no_argument, NULL, 'n'},
- {"no-copy", no_argument, NULL, NO_COPY_OPTION},
- {"no-target-directory", no_argument, NULL, 'T'},
- {"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
- {"suffix", required_argument, NULL, 'S'},
- {"target-directory", required_argument, NULL, 't'},
- {"update", optional_argument, NULL, 'u'},
- {"verbose", no_argument, NULL, 'v'},
+ {"backup", optional_argument, nullptr, 'b'},
+ {"context", no_argument, nullptr, 'Z'},
+ {"debug", no_argument, nullptr, DEBUG_OPTION},
+ {"force", no_argument, nullptr, 'f'},
+ {"interactive", no_argument, nullptr, 'i'},
+ {"no-clobber", no_argument, nullptr, 'n'},
+ {"no-copy", no_argument, nullptr, NO_COPY_OPTION},
+ {"no-target-directory", no_argument, nullptr, 'T'},
+ {"strip-trailing-slashes", no_argument, nullptr,
+ STRIP_TRAILING_SLASHES_OPTION},
+ {"suffix", required_argument, nullptr, 'S'},
+ {"target-directory", required_argument, nullptr, 't'},
+ {"update", optional_argument, nullptr, 'u'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static void
{
static struct dev_ino dev_ino_buf;
x->root_dev_ino = get_root_dev_ino (&dev_ino_buf);
- if (x->root_dev_ino == NULL)
+ if (x->root_dev_ino == nullptr)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
x->preserve_timestamps = true;
x->explicit_no_preserve_mode= false;
x->preserve_security_context = selinux_enabled;
- x->set_security_context = NULL;
+ x->set_security_context = nullptr;
x->reduce_diagnostics = false;
x->data_copy_required = true;
x->require_preserve = false; /* FIXME: maybe make this an option */
x->open_dangling_dest_symlink = false;
x->update = false;
x->verbose = false;
- x->dest_info = NULL;
- x->src_info = NULL;
+ x->dest_info = nullptr;
+ x->src_info = nullptr;
}
/* Move SOURCE onto DEST aka DEST_DIRFD+DEST_RELNAME.
copied-into-self directory, DEST ('b/b' in the example),
and failing. */
- dir_to_remove = NULL;
+ dir_to_remove = nullptr;
ok = false;
}
else if (rename_succeeded)
{
/* No need to remove anything. SOURCE was successfully
renamed to DEST. Or the user declined to rename a file. */
- dir_to_remove = NULL;
+ dir_to_remove = nullptr;
}
else
{
dir_to_remove = source;
}
- if (dir_to_remove != NULL)
+ if (dir_to_remove != nullptr)
{
struct rm_options rm_options;
enum RM_status status;
rm_option_init (&rm_options);
rm_options.verbose = x->verbose;
dir[0] = dir_to_remove;
- dir[1] = NULL;
+ dir[1] = nullptr;
status = rm ((void *) dir, &rm_options);
assert (VALID_STATUS (status));
int c;
bool ok;
bool make_backups = false;
- char const *backup_suffix = NULL;
- char *version_control_string = NULL;
+ char const *backup_suffix = nullptr;
+ char *version_control_string = nullptr;
struct cp_options x;
bool remove_trailing_slashes = false;
- char const *target_directory = NULL;
+ char const *target_directory = nullptr;
bool no_target_directory = false;
int n_files;
char **file;
/* Try to disable the ability to unlink a directory. */
priv_set_remove_linkdir ();
- while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL))
+ while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, nullptr))
!= -1)
{
switch (c)
no_target_directory = true;
break;
case 'u':
- if (optarg == NULL)
+ if (optarg == nullptr)
x.update = true;
else if (x.interactive != I_ALWAYS_NO) /* -n takes precedence. */
{
if (selinux_enabled)
{
x.preserve_security_context = false;
- x.set_security_context = selabel_open (SELABEL_CTX_FILE, NULL, 0);
+ x.set_security_context = selabel_open (SELABEL_CTX_FILE,
+ nullptr, 0);
if (! x.set_security_context)
error (0, errno, _("warning: ignoring --context"));
}
static struct option const longopts[] =
{
- {"adjustment", required_argument, NULL, 'n'},
+ {"adjustment", required_argument, nullptr, 'n'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
{
int current_niceness;
int adjustment = 10;
- char const *adjustment_given = NULL;
+ char const *adjustment_given = nullptr;
bool ok;
int i;
/* Initialize getopt_long's internal state. */
optind = 0;
- c = getopt_long (fake_argc, fake_argv, "+n:", longopts, NULL);
+ c = getopt_long (fake_argc, fake_argv, "+n:", longopts, nullptr);
i += optind - 1;
switch (c)
"setpriority" and "nice" do. */
enum { MIN_ADJUSTMENT = 1 - 2 * NZERO, MAX_ADJUSTMENT = 2 * NZERO - 1 };
long int tmp;
- if (LONGINT_OVERFLOW < xstrtol (adjustment_given, NULL, 10, &tmp, ""))
+ if (LONGINT_OVERFLOW < xstrtol (adjustment_given, nullptr, 10, &tmp, ""))
die (EXIT_CANCELED, 0, _("invalid adjustment %s"),
quote (adjustment_given));
adjustment = MAX (MIN_ADJUSTMENT, MIN (tmp, MAX_ADJUSTMENT));
static char footer_fastmap[UCHAR_MAX + 1];
/* Pointer to current regex, if any. */
-static struct re_pattern_buffer *current_regex = NULL;
+static struct re_pattern_buffer *current_regex = nullptr;
/* Separator string to print after line number (-s). */
static char const *separator_str = "\t";
static char *section_del = DEFAULT_SECTION_DELIMITERS;
/* Header delimiter string. */
-static char *header_del = NULL;
+static char *header_del = nullptr;
/* Header section delimiter length. */
static size_t header_del_len;
/* Body delimiter string. */
-static char *body_del = NULL;
+static char *body_del = nullptr;
/* Body section delimiter length. */
static size_t body_del_len;
/* Footer delimiter string. */
-static char *footer_del = NULL;
+static char *footer_del = nullptr;
/* Footer section delimiter length. */
static size_t footer_del_len;
static struct linebuffer line_buf;
/* printf format string for unnumbered lines. */
-static char *print_no_line_fmt = NULL;
+static char *print_no_line_fmt = nullptr;
/* Starting line number on each page (-v). */
static intmax_t starting_line_number = 1;
static struct option const longopts[] =
{
- {"header-numbering", required_argument, NULL, 'h'},
- {"body-numbering", required_argument, NULL, 'b'},
- {"footer-numbering", required_argument, NULL, 'f'},
- {"starting-line-number", required_argument, NULL, 'v'},
- {"line-increment", required_argument, NULL, 'i'},
- {"no-renumber", no_argument, NULL, 'p'},
- {"join-blank-lines", required_argument, NULL, 'l'},
- {"number-separator", required_argument, NULL, 's'},
- {"number-width", required_argument, NULL, 'w'},
- {"number-format", required_argument, NULL, 'n'},
- {"section-delimiter", required_argument, NULL, 'd'},
+ {"header-numbering", required_argument, nullptr, 'h'},
+ {"body-numbering", required_argument, nullptr, 'b'},
+ {"footer-numbering", required_argument, nullptr, 'f'},
+ {"starting-line-number", required_argument, nullptr, 'v'},
+ {"line-increment", required_argument, nullptr, 'i'},
+ {"no-renumber", no_argument, nullptr, 'p'},
+ {"join-blank-lines", required_argument, nullptr, 'l'},
+ {"number-separator", required_argument, nullptr, 's'},
+ {"number-width", required_argument, nullptr, 'w'},
+ {"number-format", required_argument, nullptr, 'n'},
+ {"section-delimiter", required_argument, nullptr, 'd'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Print a usage message and quit. */
break;
case 'p':
*typep = optarg++;
- regexp->buffer = NULL;
+ regexp->buffer = nullptr;
regexp->allocated = 0;
regexp->fastmap = fastmap;
- regexp->translate = NULL;
+ regexp->translate = nullptr;
re_syntax_options =
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
errmsg = re_compile_pattern (optarg, strlen (optarg), regexp);
break;
case 'p':
switch (re_search (current_regex, line_buf.buffer, line_buf.length - 1,
- 0, line_buf.length - 1, NULL))
+ 0, line_buf.length - 1, nullptr))
{
case -2:
die (EXIT_FAILURE, errno, _("error in regular expression search"));
else
{
stream = fopen (file, "r");
- if (stream == NULL)
+ if (stream == nullptr)
{
error (0, errno, "%s", quotef (file));
return false;
have_read_stdin = false;
while ((c = getopt_long (argc, argv, "h:b:f:v:i:pl:s:w:n:d:", longopts,
- NULL)) != -1)
+ nullptr))
+ != -1)
{
switch (c)
{
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, false, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (argc <= optind)
{
$HOME/nohup.out without redirecting anything. */
if (redirecting_stdout || (redirecting_stderr && stdout_is_closed))
{
- char *in_home = NULL;
+ char *in_home = nullptr;
char const *file = "nohup.out";
int flags = O_CREAT | O_WRONLY | O_APPEND;
mode_t mode = S_IRUSR | S_IWUSR;
char const *home = getenv ("HOME");
if (home)
{
- in_home = file_name_concat (home, file, NULL);
+ in_home = file_name_concat (home, file, nullptr);
out_fd = (redirecting_stdout
? fd_reopen (STDOUT_FILENO, in_home, flags, mode)
: open (in_home, flags, mode));
static struct option const longopts[] =
{
- {"all", no_argument, NULL, ALL_OPTION},
- {"ignore", required_argument, NULL, IGNORE_OPTION},
+ {"all", no_argument, nullptr, ALL_OPTION},
+ {"ignore", required_argument, nullptr, IGNORE_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
while (true)
{
- int c = getopt_long (argc, argv, "", longopts, NULL);
+ int c = getopt_long (argc, argv, "", longopts, nullptr);
if (c == -1)
break;
switch (c)
static char const *const scale_from_args[] =
{
- "none", "auto", "si", "iec", "iec-i", NULL
+ "none", "auto", "si", "iec", "iec-i", nullptr
};
static enum scale_type const scale_from_types[] =
static char const *const scale_to_args[] =
{
- "none", "si", "iec", "iec-i", NULL
+ "none", "si", "iec", "iec-i", nullptr
};
static enum scale_type const scale_to_types[] =
static char const *const round_args[] =
{
- "up", "down", "from-zero", "towards-zero", "nearest", NULL
+ "up", "down", "from-zero", "towards-zero", "nearest", nullptr
};
static enum round_type const round_types[] =
static char const *const inval_args[] =
{
- "abort", "fail", "warn", "ignore", NULL
+ "abort", "fail", "warn", "ignore", nullptr
};
static enum inval_type const inval_types[] =
static struct option const longopts[] =
{
- {"from", required_argument, NULL, FROM_OPTION},
- {"from-unit", required_argument, NULL, FROM_UNIT_OPTION},
- {"to", required_argument, NULL, TO_OPTION},
- {"to-unit", required_argument, NULL, TO_UNIT_OPTION},
- {"round", required_argument, NULL, ROUND_OPTION},
- {"padding", required_argument, NULL, PADDING_OPTION},
- {"suffix", required_argument, NULL, SUFFIX_OPTION},
- {"grouping", no_argument, NULL, GROUPING_OPTION},
- {"delimiter", required_argument, NULL, 'd'},
- {"field", required_argument, NULL, FIELD_OPTION},
- {"debug", no_argument, NULL, DEBUG_OPTION},
- {"-debug", no_argument, NULL, DEV_DEBUG_OPTION},
- {"header", optional_argument, NULL, HEADER_OPTION},
- {"format", required_argument, NULL, FORMAT_OPTION},
- {"invalid", required_argument, NULL, INVALID_OPTION},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"from", required_argument, nullptr, FROM_OPTION},
+ {"from-unit", required_argument, nullptr, FROM_UNIT_OPTION},
+ {"to", required_argument, nullptr, TO_OPTION},
+ {"to-unit", required_argument, nullptr, TO_UNIT_OPTION},
+ {"round", required_argument, nullptr, ROUND_OPTION},
+ {"padding", required_argument, nullptr, PADDING_OPTION},
+ {"suffix", required_argument, nullptr, SUFFIX_OPTION},
+ {"grouping", no_argument, nullptr, GROUPING_OPTION},
+ {"delimiter", required_argument, nullptr, 'd'},
+ {"field", required_argument, nullptr, FIELD_OPTION},
+ {"debug", no_argument, nullptr, DEBUG_OPTION},
+ {"-debug", no_argument, nullptr, DEV_DEBUG_OPTION},
+ {"header", optional_argument, nullptr, HEADER_OPTION},
+ {"format", required_argument, nullptr, FORMAT_OPTION},
+ {"invalid", required_argument, nullptr, INVALID_OPTION},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* If delimiter has this value, blanks separate fields. */
static enum scale_type scale_to = scale_none;
static enum round_type round_style = round_from_zero;
static enum inval_type inval_style = inval_abort;
-static char const *suffix = NULL;
+static char const *suffix = nullptr;
static uintmax_t from_unit_size = 1;
static uintmax_t to_unit_size = 1;
static int grouping = 0;
-static char *padding_buffer = NULL;
+static char *padding_buffer = nullptr;
static size_t padding_buffer_size = 0;
static long int padding_width = 0;
static long int zero_padding_width = 0;
static long int user_precision = -1;
-static char const *format_str = NULL;
-static char *format_str_prefix = NULL;
-static char *format_str_suffix = NULL;
+static char const *format_str = nullptr;
+static char *format_str_prefix = nullptr;
+static char *format_str_suffix = nullptr;
/* By default, any conversion error will terminate the program. */
static int conv_exit_code = EXIT_CONVERSION_WARNINGS;
static inline bool
valid_suffix (const char suf)
{
- return strchr (valid_suffixes, suf) != NULL;
+ return strchr (valid_suffixes, suf) != nullptr;
}
static inline int
static void
simple_strtod_fatal (enum simple_strtod_error err, char const *input_str)
{
- char const *msgid = NULL;
+ char const *msgid = nullptr;
switch (err)
{
{
strtol_error s_err;
char const *c_string = n_string;
- char *t_string = NULL;
+ char *t_string = nullptr;
size_t n_len = strlen (n_string);
- char *end = NULL;
+ char *end = nullptr;
uintmax_t n;
char const *suffixes = valid_suffixes;
size_t prefix_len = 0;
size_t suffix_pos;
long int pad = 0;
- char *endptr = NULL;
+ char *endptr = nullptr;
bool zero_padding = false;
for (i = 0; !(fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
parse_human_number (char const *str, long double /*output */ *value,
size_t *precision)
{
- char *ptr = NULL;
+ char *ptr = nullptr;
enum simple_strtod_error e =
simple_strtod_human (str, &ptr, value, precision, scale_from);
#endif
decimal_point = nl_langinfo (RADIXCHAR);
- if (decimal_point == NULL || strlen (decimal_point) == 0)
+ if (decimal_point == nullptr || strlen (decimal_point) == 0)
decimal_point = ".";
decimal_point_length = strlen (decimal_point);
while (true)
{
- int c = getopt_long (argc, argv, "d:z", longopts, NULL);
+ int c = getopt_long (argc, argv, "d:z", longopts, nullptr);
if (c == -1)
break;
break;
case PADDING_OPTION:
- if (xstrtol (optarg, NULL, 10, &padding_width, "") != LONGINT_OK
+ if (xstrtol (optarg, nullptr, 10, &padding_width, "") != LONGINT_OK
|| padding_width == 0 || padding_width < -LONG_MAX)
die (EXIT_FAILURE, 0, _("invalid padding value %s"),
quote (optarg));
case HEADER_OPTION:
if (optarg)
{
- if (xstrtoumax (optarg, NULL, 10, &header, "") != LONGINT_OK
+ if (xstrtoumax (optarg, nullptr, 10, &header, "") != LONGINT_OK
|| header == 0)
die (EXIT_FAILURE, 0, _("invalid header value %s"),
quote (optarg));
}
}
- if (format_str != NULL && grouping)
+ if (format_str != nullptr && grouping)
die (EXIT_FAILURE, 0, _("--grouping cannot be combined with --format"));
if (debug && ! locale_ok)
/* Warn about no-op. */
if (debug && scale_from == scale_none && scale_to == scale_none
- && !grouping && (padding_width == 0) && (format_str == NULL))
+ && !grouping && (padding_width == 0) && (format_str == nullptr))
error (0, 0, _("no conversion option specified"));
if (format_str)
}
else
{
- char *line = NULL;
+ char *line = nullptr;
size_t line_allocated = 0;
ssize_t len;
It differs from file_list[-1] only when file_list[-1] is "-". */
static char const *input_filename;
-/* A NULL-terminated list of the file-arguments from the command line. */
+/* A null-terminated list of the file-arguments from the command line. */
static char const *const *file_list;
/* Initializer for file_list if no file-arguments
were specified on the command line. */
-static char const *const default_file_list[] = {"-", NULL};
+static char const *const default_file_list[] = {"-", nullptr};
/* The input stream associated with the current file. */
static FILE *in_stream;
static char const *const endian_args[] =
{
- "little", "big", NULL
+ "little", "big", nullptr
};
static enum endian_type const endian_types[] =
static struct option const long_options[] =
{
- {"skip-bytes", required_argument, NULL, 'j'},
- {"address-radix", required_argument, NULL, 'A'},
- {"read-bytes", required_argument, NULL, 'N'},
- {"format", required_argument, NULL, 't'},
- {"output-duplicates", no_argument, NULL, 'v'},
- {"strings", optional_argument, NULL, 'S'},
- {"traditional", no_argument, NULL, TRADITIONAL_OPTION},
- {"width", optional_argument, NULL, 'w'},
- {"endian", required_argument, NULL, ENDIAN_OPTION },
+ {"skip-bytes", required_argument, nullptr, 'j'},
+ {"address-radix", required_argument, nullptr, 'A'},
+ {"read-bytes", required_argument, nullptr, 'N'},
+ {"format", required_argument, nullptr, 't'},
+ {"output-duplicates", no_argument, nullptr, 'v'},
+ {"strings", optional_argument, nullptr, 'S'},
+ {"traditional", no_argument, nullptr, TRADITIONAL_OPTION},
+ {"width", optional_argument, nullptr, 'w'},
+ {"endian", required_argument, nullptr, ENDIAN_OPTION },
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
/* If S points to a single valid modern od format string, put
a description of that format in *TSPEC, make *NEXT point at the
- character following the just-decoded format (if *NEXT is non-NULL),
+ character following the just-decoded format (if *NEXT is non-null),
and return true. If S is not valid, don't modify *NEXT or *TSPEC,
give a diagnostic, and return false. For example, if S were
"d4afL" *NEXT would be set to "afL" and *TSPEC would be
char c;
int field_width;
- assert (tspec != NULL);
+ assert (tspec != nullptr);
switch (*s)
{
if (tspec->hexl_mode_trailer)
s++;
- if (next != NULL)
+ if (next != nullptr)
*next = s;
return true;
do
{
input_filename = *file_list;
- if (input_filename == NULL)
+ if (input_filename == nullptr)
return ok;
++file_list;
else
{
in_stream = fopen (input_filename, (O_BINARY ? "rb" : "r"));
- if (in_stream == NULL)
+ if (in_stream == nullptr)
{
error (0, errno, "%s", quotef (input_filename));
ok = false;
}
}
}
- while (in_stream == NULL);
+ while (in_stream == nullptr);
if (limit_bytes_to_format && !flag_dump_strings)
- setvbuf (in_stream, NULL, _IONBF, 0);
+ setvbuf (in_stream, nullptr, _IONBF, 0);
return ok;
}
{
bool ok = true;
- if (in_stream != NULL)
+ if (in_stream != nullptr)
{
if (!ferror (in_stream))
in_errno = 0;
ok = false;
}
- in_stream = NULL;
+ in_stream = nullptr;
}
if (ferror (stdout))
decode_format_string (char const *s)
{
char const *s_orig = s;
- assert (s != NULL);
+ assert (s != nullptr);
while (*s != '\0')
{
if (n_skip == 0)
return true;
- while (in_stream != NULL) /* EOF. */
+ while (in_stream != nullptr) /* EOF. */
{
struct stat file_stats;
*c = EOF;
- while (in_stream != NULL) /* EOF. */
+ while (in_stream != nullptr) /* EOF. */
{
*c = fgetc (in_stream);
*n_bytes_in_buffer = 0;
- while (in_stream != NULL) /* EOF. */
+ while (in_stream != nullptr) /* EOF. */
{
size_t n_needed;
size_t n_read;
/* Determine the radix we'll use to interpret S. If there is a '.',
it's decimal, otherwise, if the string begins with '0X'or '0x',
it's hexadecimal, else octal. */
- if (strchr (s, '.') != NULL)
+ if (strchr (s, '.') != nullptr)
radix = 10;
else
{
radix = 8;
}
- return xstrtoumax (s, NULL, radix, offset, "Bb") == LONGINT_OK;
+ return xstrtoumax (s, nullptr, radix, offset, "Bb") == LONGINT_OK;
}
/* Read a chunk of size BYTES_PER_BLOCK from the input files, write the
n_specs = 0;
n_specs_allocated = 0;
- spec = NULL;
+ spec = nullptr;
format_address = format_address_std;
address_base = 8;
case 'j':
modern = true;
- s_err = xstrtoumax (optarg, NULL, 0, &n_bytes_to_skip, multipliers);
+ s_err = xstrtoumax (optarg, nullptr, 0,
+ &n_bytes_to_skip, multipliers);
if (s_err != LONGINT_OK)
xstrtol_fatal (s_err, oi, c, long_options, optarg);
break;
modern = true;
limit_bytes_to_format = true;
- s_err = xstrtoumax (optarg, NULL, 0, &max_bytes_to_format,
+ s_err = xstrtoumax (optarg, nullptr, 0, &max_bytes_to_format,
multipliers);
if (s_err != LONGINT_OK)
xstrtol_fatal (s_err, oi, c, long_options, optarg);
case 'S':
modern = true;
- if (optarg == NULL)
+ if (optarg == nullptr)
string_min = 3;
else
{
- s_err = xstrtoumax (optarg, NULL, 0, &tmp, multipliers);
+ s_err = xstrtoumax (optarg, nullptr, 0, &tmp, multipliers);
if (s_err != LONGINT_OK)
xstrtol_fatal (s_err, oi, c, long_options, optarg);
case 'w':
modern = true;
width_specified = true;
- if (optarg == NULL)
+ if (optarg == nullptr)
{
desired_width = 32;
}
else
{
uintmax_t w_tmp;
- s_err = xstrtoumax (optarg, NULL, 10, &w_tmp, "");
+ s_err = xstrtoumax (optarg, nullptr, 10, &w_tmp, "");
if (s_err != LONGINT_OK)
xstrtol_fatal (s_err, oi, c, long_options, optarg);
if (SIZE_MAX < w_tmp)
/* open the first input file */
ok = open_next_file ();
- if (in_stream == NULL)
+ if (in_stream == nullptr)
goto cleanup;
/* skip over any unwanted header bytes */
ok &= skip (n_bytes_to_skip);
- if (in_stream == NULL)
+ if (in_stream == nullptr)
goto cleanup;
pseudo_offset = (flag_pseudo_start ? pseudo_start - n_bytes_to_skip : 0);
static struct option const longopts[] =
{
- {"serial", no_argument, NULL, 's'},
- {"delimiters", required_argument, NULL, 'd'},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"serial", no_argument, nullptr, 's'},
+ {"delimiters", required_argument, nullptr, 'd'},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Set globals delims and delim_end. Copy STRPTR to DELIMS, converting
store the delimiters for closed files. */
char *delbuf = xmalloc (nfiles + 2);
- /* Streams open to the files to process; NULL if the corresponding
+ /* Streams open to the files to process; null if the corresponding
stream is closed. */
FILE **fileptr = xnmalloc (nfiles + 1, sizeof *fileptr);
else
{
fileptr[files_open] = fopen (fnamptr[files_open], "r");
- if (fileptr[files_open] == NULL)
+ if (fileptr[files_open] == nullptr)
die (EXIT_FAILURE, errno, "%s", quotef (fnamptr[files_open]));
else if (fileno (fileptr[files_open]) == STDIN_FILENO)
opened_stdin = true;
ok = false;
}
- fileptr[i] = NULL;
+ fileptr[i] = nullptr;
files_open--;
}
else
{
fileptr = fopen (*fnamptr, "r");
- if (fileptr == NULL)
+ if (fileptr == nullptr)
{
error (0, errno, "%s", quotef (*fnamptr));
ok = false;
have_read_stdin = false;
serial_merge = false;
- while ((optc = getopt_long (argc, argv, "d:sz", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "d:sz", longopts, nullptr)) != -1)
{
switch (optc)
{
static struct option const longopts[] =
{
- {"portability", no_argument, NULL, PORTABILITY_OPTION},
+ {"portability", no_argument, nullptr, PORTABILITY_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "+pP", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "+pP", longopts, nullptr)) != -1)
{
switch (optc)
{
{
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Count and return the number of ampersands in STR. */
stzncpy (name, UT_USER (utmp_ent), UT_USER_SIZE);
pw = getpwnam (name);
- if (pw == NULL)
+ if (pw == nullptr)
/* TRANSLATORS: Real name is unknown; at most 19 characters. */
printf (" %19s", _(" ???"));
else
if (include_where && utmp_ent->ut_host[0])
{
char ut_host[sizeof (utmp_ent->ut_host) + 1];
- char *host = NULL;
- char *display = NULL;
+ char *host = nullptr;
+ char *display = nullptr;
/* Copy the host name into UT_HOST, and ensure it's nul terminated. */
stzncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
printf ("%-28s", name);
printf (_("In real life: "));
- if (pw == NULL)
+ if (pw == nullptr)
{
/* TRANSLATORS: Real name is unknown; no hard limit. */
printf (" %s", _("???\n"));
const int argc_names, char *const argv_names[])
{
size_t n_users;
- STRUCT_UTMP *utmp_buf = NULL;
+ STRUCT_UTMP *utmp_buf = nullptr;
if (read_utmp (filename, &n_users, &utmp_buf, 0) != 0)
die (EXIT_FAILURE, errno, "%s", quotef (filename));
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "sfwiqbhlp", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "sfwiqbhlp", longopts, nullptr))
+ != -1)
{
switch (optc)
{
static struct option const long_options[] =
{
- {"pages", required_argument, NULL, PAGES_OPTION},
- {"columns", required_argument, NULL, COLUMNS_OPTION},
- {"across", no_argument, NULL, 'a'},
- {"show-control-chars", no_argument, NULL, 'c'},
- {"double-space", no_argument, NULL, 'd'},
- {"date-format", required_argument, NULL, 'D'},
- {"expand-tabs", optional_argument, NULL, 'e'},
- {"form-feed", no_argument, NULL, 'f'},
- {"header", required_argument, NULL, 'h'},
- {"output-tabs", optional_argument, NULL, 'i'},
- {"join-lines", no_argument, NULL, 'J'},
- {"length", required_argument, NULL, 'l'},
- {"merge", no_argument, NULL, 'm'},
- {"number-lines", optional_argument, NULL, 'n'},
- {"first-line-number", required_argument, NULL, 'N'},
- {"indent", required_argument, NULL, 'o'},
- {"no-file-warnings", no_argument, NULL, 'r'},
- {"separator", optional_argument, NULL, 's'},
- {"sep-string", optional_argument, NULL, 'S'},
- {"omit-header", no_argument, NULL, 't'},
- {"omit-pagination", no_argument, NULL, 'T'},
- {"show-nonprinting", no_argument, NULL, 'v'},
- {"width", required_argument, NULL, 'w'},
- {"page-width", required_argument, NULL, 'W'},
+ {"pages", required_argument, nullptr, PAGES_OPTION},
+ {"columns", required_argument, nullptr, COLUMNS_OPTION},
+ {"across", no_argument, nullptr, 'a'},
+ {"show-control-chars", no_argument, nullptr, 'c'},
+ {"double-space", no_argument, nullptr, 'd'},
+ {"date-format", required_argument, nullptr, 'D'},
+ {"expand-tabs", optional_argument, nullptr, 'e'},
+ {"form-feed", no_argument, nullptr, 'f'},
+ {"header", required_argument, nullptr, 'h'},
+ {"output-tabs", optional_argument, nullptr, 'i'},
+ {"join-lines", no_argument, nullptr, 'J'},
+ {"length", required_argument, nullptr, 'l'},
+ {"merge", no_argument, nullptr, 'm'},
+ {"number-lines", optional_argument, nullptr, 'n'},
+ {"first-line-number", required_argument, nullptr, 'N'},
+ {"indent", required_argument, nullptr, 'o'},
+ {"no-file-warnings", no_argument, nullptr, 'r'},
+ {"separator", optional_argument, nullptr, 's'},
+ {"sep-string", optional_argument, nullptr, 'S'},
+ {"omit-header", no_argument, nullptr, 't'},
+ {"omit-pagination", no_argument, nullptr, 'T'},
+ {"show-nonprinting", no_argument, nullptr, 'v'},
+ {"width", required_argument, nullptr, 'w'},
+ {"page-width", required_argument, nullptr, 'W'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static _Noreturn void
char **file_names;
/* Accumulate the digits of old-style options like -99. */
- char *column_count_string = NULL;
+ char *column_count_string = nullptr;
size_t n_digits = 0;
size_t n_alloc = 0;
n_files = 0;
file_names = (argc > 1
? xnmalloc (argc - 1, sizeof (char *))
- : NULL);
+ : nullptr);
while (true)
{
short-named option syntax, e.g., -9, ensure that this
long-name-specified value overrides it. */
free (column_count_string);
- column_count_string = NULL;
+ column_count_string = nullptr;
n_alloc = 0;
break;
}
if (n_files == 0)
{
/* No file arguments specified; read from standard input. */
- print_files (0, NULL);
+ print_files (0, nullptr);
}
else
{
if (*arg)
{
long int tmp_long;
- strtol_error e = xstrtol (arg, NULL, 10, &tmp_long, "");
+ strtol_error e = xstrtol (arg, nullptr, 10, &tmp_long, "");
if (e == LONGINT_OK)
{
if (tmp_long <= 0)
p->name = name;
p->fp = fopen (name, "r");
}
- if (p->fp == NULL)
+ if (p->fp == nullptr)
{
failed_opens = true;
if (!ignore_failed_opens)
static void
init_header (char const *filename, int desc)
{
- char *buf = NULL;
+ char *buf = nullptr;
struct stat st;
struct timespec t;
int ns;
if (localtime_rz (localtz, &t.tv_sec, &tm))
{
size_t bufsize
- = nstrftime (NULL, SIZE_MAX, date_format, &tm, localtz, ns) + 1;
+ = nstrftime (nullptr, SIZE_MAX, date_format, &tm, localtz, ns) + 1;
buf = xmalloc (bufsize);
nstrftime (buf, bufsize, date_format, &tm, localtz, ns);
}
static struct option const longopts[] =
{
- {"null", no_argument, NULL, '0'},
+ {"null", no_argument, nullptr, '0'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
initialize_exit_failure (PRINTENV_FAILURE);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "+iu:0", longopts, nullptr)) != -1)
{
switch (optc)
{
if (optind >= argc)
{
- for (env = environ; *env != NULL; ++env)
+ for (env = environ; *env != nullptr; ++env)
printf ("%s%c", *env, opt_nul_terminate_output ? '\0' : '\n');
ok = true;
}
exit_status = EXIT_SUCCESS;
- posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
+ posixly_correct = (getenv ("POSIXLY_CORRECT") != nullptr);
/* We directly parse options, rather than use parse_long_options, in
order to avoid accepting abbreviations. */
if (STREQ (argv[1], "--version"))
{
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
- (char *) NULL);
+ (char *) nullptr);
return EXIT_SUCCESS;
}
}
/* output format */
static bool ignore_case = false; /* fold lower to upper for sorting */
-static char const *break_file = NULL; /* name of the 'Break chars' file */
-static char const *only_file = NULL; /* name of the 'Only words' file */
-static char const *ignore_file = NULL; /* name of the 'Ignore words' file */
+static char const *break_file = nullptr; /* name of the 'Break chars' file */
+static char const *only_file = nullptr; /* name of the 'Only words' file */
+static char const *ignore_file = nullptr; /* name of the 'Ignore words' file */
/* Options that use regular expressions. */
struct regex_data
if (word_regex.string) \
{ \
regoff_t count; \
- count = re_match (&word_regex.pattern, cursor, limit - cursor, 0, NULL); \
+ count = re_match (&word_regex.pattern, cursor, limit - cursor, \
+ 0, nullptr); \
if (count == -2) \
matcher_error (); \
cursor += count == -1 ? 1 : count; \
char const *string = regex->string;
char const *message;
- pattern->buffer = NULL;
+ pattern->buffer = nullptr;
pattern->allocated = 0;
pattern->fastmap = regex->fastmap;
- pattern->translate = ignore_case ? folded_chars : NULL;
+ pattern->translate = ignore_case ? folded_chars : nullptr;
message = re_compile_pattern (string, strlen (string), pattern);
if (message)
/* Unless the user already provided a description of the end of line or
end of sentence sequence, select an end of line sequence to compile.
If the user provided an empty definition, thus disabling end of line
- or sentence feature, make it NULL to speed up tests. If GNU
+ or sentence feature, make it null to speed up tests. If GNU
extensions are enabled, use end of sentence like in GNU emacs. If
disabled, use end of lines. */
if (context_regex.string)
{
if (!*context_regex.string)
- context_regex.string = NULL;
+ context_regex.string = nullptr;
}
else if (gnu_extensions && !input_reference)
context_regex.string = "[.?!][]\"')}]*\\($\\|\t\\| \\)[ \t\n]*";
/*------------------------------------------------------------------------.
| This routine will attempt to swallow a whole file name FILE_NAME into a |
| contiguous region of memory and return a description of it into BLOCK. |
-| Standard input is assumed whenever FILE_NAME is NULL, empty or "-". |
+| Standard input is assumed whenever FILE_NAME is null, empty or "-". |
| |
| Previously, in some cases, white space compression was attempted while |
| inputting text. This was defeating some regexps like default end of |
{
size_t used_length; /* used length in memory buffer */
- /* As special cases, a file name which is NULL or "-" indicates standard
+ /* As special cases, a file name which is null or "-" indicates standard
input, which is already opened. In all other cases, open the file from
its name. */
bool using_stdin = !file_name || !*file_name || STREQ (file_name, "-");
swallow_file_in_memory (file_name, &file_contents);
- table->start = NULL;
+ table->start = nullptr;
table->alloc = 0;
table->length = 0;
before_max_width = half_line_width - gap_size;
keyafter_max_width = half_line_width;
- /* If truncation_string is the empty string, make it NULL to speed up
+ /* If truncation_string is the empty string, make it null to speed up
tests. In this case, truncation_string_length will never get used, so
there is no need to set it. */
if (truncation_string && *truncation_string)
truncation_string_length = strlen (truncation_string);
else
- truncation_string = NULL;
+ truncation_string = nullptr;
if (gnu_extensions)
{
/* No place left for a tail field. */
- tail.start = NULL;
- tail.end = NULL;
+ tail.start = nullptr;
+ tail.end = nullptr;
tail_truncation = false;
}
/* No place left for a head field. */
- head.start = NULL;
- head.end = NULL;
+ head.start = nullptr;
+ head.end = nullptr;
head_truncation = false;
}
line contexts or references are not used, in which case these variables
would never be computed. */
- tail.start = NULL;
- tail.end = NULL;
+ tail.start = nullptr;
+ tail.end = nullptr;
tail_truncation = false;
- head.start = NULL;
- head.end = NULL;
+ head.start = nullptr;
+ head.end = nullptr;
head_truncation = false;
/* Loop over all keyword occurrences. */
/* Long options equivalences. */
static struct option const long_options[] =
{
- {"auto-reference", no_argument, NULL, 'A'},
- {"break-file", required_argument, NULL, 'b'},
- {"flag-truncation", required_argument, NULL, 'F'},
- {"ignore-case", no_argument, NULL, 'f'},
- {"gap-size", required_argument, NULL, 'g'},
- {"ignore-file", required_argument, NULL, 'i'},
- {"macro-name", required_argument, NULL, 'M'},
- {"only-file", required_argument, NULL, 'o'},
- {"references", no_argument, NULL, 'r'},
- {"right-side-refs", no_argument, NULL, 'R'},
- {"format", required_argument, NULL, 10},
- {"sentence-regexp", required_argument, NULL, 'S'},
- {"traditional", no_argument, NULL, 'G'},
- {"typeset-mode", no_argument, NULL, 't'},
- {"width", required_argument, NULL, 'w'},
- {"word-regexp", required_argument, NULL, 'W'},
+ {"auto-reference", no_argument, nullptr, 'A'},
+ {"break-file", required_argument, nullptr, 'b'},
+ {"flag-truncation", required_argument, nullptr, 'F'},
+ {"ignore-case", no_argument, nullptr, 'f'},
+ {"gap-size", required_argument, nullptr, 'g'},
+ {"ignore-file", required_argument, nullptr, 'i'},
+ {"macro-name", required_argument, nullptr, 'M'},
+ {"only-file", required_argument, nullptr, 'o'},
+ {"references", no_argument, nullptr, 'r'},
+ {"right-side-refs", no_argument, nullptr, 'R'},
+ {"format", required_argument, nullptr, 10},
+ {"sentence-regexp", required_argument, nullptr, 'S'},
+ {"traditional", no_argument, nullptr, 'G'},
+ {"typeset-mode", no_argument, nullptr, 't'},
+ {"width", required_argument, nullptr, 'w'},
+ {"word-regexp", required_argument, nullptr, 'W'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0},
+ {nullptr, 0, nullptr, 0},
};
static char const *const format_args[] =
{
- "roff", "tex", NULL
+ "roff", "tex", nullptr
};
static enum Format const format_vals[] =
atexit (close_stdout);
#if HAVE_SETCHRCLASS
- setchrclass (NULL);
+ setchrclass (nullptr);
#endif
while (optchar = getopt_long (argc, argv, "AF:GM:ORS:TW:b:i:fg:o:trw:",
- long_options, NULL),
+ long_options, nullptr),
optchar != EOF)
{
switch (optchar)
case 'g':
{
intmax_t tmp;
- if (! (xstrtoimax (optarg, NULL, 0, &tmp, "") == LONGINT_OK
+ if (! (xstrtoimax (optarg, nullptr, 0, &tmp, "") == LONGINT_OK
&& 0 < tmp && tmp <= PTRDIFF_MAX))
die (EXIT_FAILURE, 0, _("invalid gap width: %s"),
quote (optarg));
case 'w':
{
intmax_t tmp;
- if (! (xstrtoimax (optarg, NULL, 0, &tmp, "") == LONGINT_OK
+ if (! (xstrtoimax (optarg, nullptr, 0, &tmp, "") == LONGINT_OK
&& 0 < tmp && tmp <= PTRDIFF_MAX))
die (EXIT_FAILURE, 0, _("invalid line width: %s"),
quote (optarg));
word_regex.string = optarg;
unescape_string (optarg);
if (!*word_regex.string)
- word_regex.string = NULL;
+ word_regex.string = nullptr;
break;
case 10:
file_line_count = xmalloc (sizeof *file_line_count);
text_buffers = xmalloc (sizeof *text_buffers);
number_input_files = 1;
- input_file_name[0] = NULL;
+ input_file_name[0] = nullptr;
}
else if (gnu_extensions)
{
for (file_index = 0; file_index < number_input_files; file_index++)
{
if (!*argv[optind] || STREQ (argv[optind], "-"))
- input_file_name[file_index] = NULL;
+ input_file_name[file_index] = nullptr;
else
input_file_name[file_index] = argv[optind];
optind++;
file_line_count = xmalloc (sizeof *file_line_count);
text_buffers = xmalloc (sizeof *text_buffers);
if (!*argv[optind] || STREQ (argv[optind], "-"))
- input_file_name[0] = NULL;
+ input_file_name[0] = nullptr;
else
input_file_name[0] = argv[optind];
optind++;
digest_break_file (break_file);
/* Read 'Ignore words' file and 'Only words' files, if any. If any of
- these files is empty, reset the name of the file to NULL, to avoid
+ these files is empty, reset the name of the file to null, to avoid
unnecessary calls to search_table. */
if (ignore_file)
{
digest_word_file (ignore_file, &ignore_table);
if (ignore_table.length == 0)
- ignore_file = NULL;
+ ignore_file = nullptr;
}
if (only_file)
{
digest_word_file (only_file, &only_table);
if (only_table.length == 0)
- only_file = NULL;
+ only_file = nullptr;
}
/* Prepare to study all the input files. */
static struct option const longopts[] =
{
- {"logical", no_argument, NULL, 'L'},
- {"physical", no_argument, NULL, 'P'},
+ {"logical", no_argument, nullptr, 'L'},
+ {"physical", no_argument, nullptr, 'P'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
bool found;
dirp = opendir ("..");
- if (dirp == NULL)
+ if (dirp == nullptr)
die (EXIT_FAILURE, errno, _("cannot open directory %s"),
quote (nth_parent (parent_height)));
ino_t ino;
errno = 0;
- if ((dp = readdir_ignoring_dot_and_dotdot (dirp)) == NULL)
+ if ((dp = readdir_ignoring_dot_and_dotdot (dirp)) == nullptr)
{
if (errno)
{
errno = e;
/* Arrange to give a diagnostic after exiting this loop. */
- dirp = NULL;
+ dirp = nullptr;
}
break;
}
}
}
- if (dirp == NULL || closedir (dirp) != 0)
+ if (dirp == nullptr || closedir (dirp) != 0)
{
/* Note that this diagnostic serves for both readdir
and closedir failures. */
struct dev_ino *root_dev_ino = get_root_dev_ino (&dev_ino_buf);
struct stat dot_sb;
- if (root_dev_ino == NULL)
+ if (root_dev_ino == nullptr)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
/* Return PWD from the environment if it is acceptable for 'pwd -L'
- output, otherwise NULL. */
+ output, otherwise nullptr. */
static char *
logical_getcwd (void)
{
/* Textual validation first. */
if (!wd || wd[0] != '/')
- return NULL;
+ return nullptr;
p = wd;
while ((p = strstr (p, "/.")))
{
if (!p[2] || p[2] == '/'
|| (p[2] == '.' && (!p[3] || p[3] == '/')))
- return NULL;
+ return nullptr;
p++;
}
/* System call validation. */
if (stat (wd, &st1) == 0 && stat (".", &st2) == 0 && SAME_INODE (st1, st2))
return wd;
- return NULL;
+ return nullptr;
}
/* POSIX requires a default of -L, but most scripts expect -P.
Currently shells default to -L, while stand-alone
pwd implementations default to -P. */
- bool logical = (getenv ("POSIXLY_CORRECT") != NULL);
+ bool logical = (getenv ("POSIXLY_CORRECT") != nullptr);
initialize_main (&argc, &argv);
set_program_name (argv[0]);
while (true)
{
- int c = getopt_long (argc, argv, "LP", longopts, NULL);
+ int c = getopt_long (argc, argv, "LP", longopts, nullptr);
if (c == -1)
break;
switch (c)
}
wd = xgetcwd ();
- if (wd != NULL)
+ if (wd != nullptr)
{
puts (wd);
free (wd);
static struct option const longopts[] =
{
- {"canonicalize", no_argument, NULL, 'f'},
- {"canonicalize-existing", no_argument, NULL, 'e'},
- {"canonicalize-missing", no_argument, NULL, 'm'},
- {"no-newline", no_argument, NULL, 'n'},
- {"quiet", no_argument, NULL, 'q'},
- {"silent", no_argument, NULL, 's'},
- {"verbose", no_argument, NULL, 'v'},
- {"zero", no_argument, NULL, 'z'},
+ {"canonicalize", no_argument, nullptr, 'f'},
+ {"canonicalize-existing", no_argument, nullptr, 'e'},
+ {"canonicalize-missing", no_argument, nullptr, 'm'},
+ {"no-newline", no_argument, nullptr, 'n'},
+ {"quiet", no_argument, nullptr, 'q'},
+ {"silent", no_argument, nullptr, 's'},
+ {"verbose", no_argument, nullptr, 'v'},
+ {"zero", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "efmnqsvz", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "efmnqsvz", longopts, nullptr)) != -1)
{
switch (optc)
{
static struct option const longopts[] =
{
- {"canonicalize-existing", no_argument, NULL, 'e'},
- {"canonicalize-missing", no_argument, NULL, 'm'},
- {"relative-to", required_argument, NULL, RELATIVE_TO_OPTION},
- {"relative-base", required_argument, NULL, RELATIVE_BASE_OPTION},
- {"quiet", no_argument, NULL, 'q'},
- {"strip", no_argument, NULL, 's'},
- {"no-symlinks", no_argument, NULL, 's'},
- {"zero", no_argument, NULL, 'z'},
- {"logical", no_argument, NULL, 'L'},
- {"physical", no_argument, NULL, 'P'},
+ {"canonicalize-existing", no_argument, nullptr, 'e'},
+ {"canonicalize-missing", no_argument, nullptr, 'm'},
+ {"relative-to", required_argument, nullptr, RELATIVE_TO_OPTION},
+ {"relative-base", required_argument, nullptr, RELATIVE_BASE_OPTION},
+ {"quiet", no_argument, nullptr, 'q'},
+ {"strip", no_argument, nullptr, 's'},
+ {"no-symlinks", no_argument, nullptr, 's'},
+ {"zero", no_argument, nullptr, 'z'},
+ {"logical", no_argument, nullptr, 'L'},
+ {"physical", no_argument, nullptr, 'P'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
if (!can_relative_to
|| (can_relative_base && !path_prefix (can_relative_base, can_fname))
- || (can_relative_to && !relpath (can_fname, can_relative_to, NULL, 0)))
+ || (can_relative_to && !relpath (can_fname, can_relative_to, nullptr, 0)))
fputs (can_fname, stdout);
putchar (use_nuls ? '\0' : '\n');
{
bool ok = true;
int can_mode = CAN_ALL_BUT_LAST;
- char const *relative_to = NULL;
- char const *relative_base = NULL;
+ char const *relative_to = nullptr;
+ char const *relative_base = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
while (true)
{
- int c = getopt_long (argc, argv, "eLmPqsz", longopts, NULL);
+ int c = getopt_long (argc, argv, "eLmPqsz", longopts, nullptr);
if (c == -1)
break;
switch (c)
{
free (base);
can_relative_base = can_relative_to;
- can_relative_to = NULL;
+ can_relative_to = nullptr;
}
}
}
/* Either output STR to stdout or
- if *PBUF is not NULL then append STR to *PBUF
+ if *PBUF is not null then append STR to *PBUF
and update *PBUF to point to the end of the buffer
and adjust *PLEN to reflect the remaining space.
Return TRUE on failure. */
}
/* Output the relative representation if possible.
- If BUF is non-NULL, write to that buffer rather than to stdout. */
+ If BUF is non-null, write to that buffer rather than to stdout. */
bool
relpath (char const *can_fname, char const *can_reldir, char *buf, size_t len)
{
if (x->preserve_all_root)
{
bool failed = false;
- char *parent = file_name_concat (ent->fts_accpath, "..", NULL);
+ char *parent = file_name_concat (ent->fts_accpath, "..", nullptr);
struct stat statbuf;
if (!parent || lstat (parent, &statbuf))
if (x->one_file_system)
bit_flags |= FTS_XDEV;
- FTS *fts = xfts_open (file, bit_flags, NULL);
+ FTS *fts = xfts_open (file, bit_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
- if (ent == NULL)
+ if (ent == nullptr)
{
if (errno != 0)
{
bool remove_empty_directories;
/* Pointer to the device and inode numbers of '/', when --recursive
- and preserving '/'. Otherwise NULL. */
+ and preserving '/'. Otherwise null. */
struct dev_ino *root_dev_ino;
/* If true, do not traverse into (or remove) any directory that is
static struct option const long_opts[] =
{
- {"force", no_argument, NULL, 'f'},
- {"interactive", optional_argument, NULL, INTERACTIVE_OPTION},
+ {"force", no_argument, nullptr, 'f'},
+ {"interactive", optional_argument, nullptr, INTERACTIVE_OPTION},
- {"one-file-system", no_argument, NULL, ONE_FILE_SYSTEM},
- {"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
- {"preserve-root", optional_argument, NULL, PRESERVE_ROOT},
+ {"one-file-system", no_argument, nullptr, ONE_FILE_SYSTEM},
+ {"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
+ {"preserve-root", optional_argument, nullptr, PRESERVE_ROOT},
/* This is solely for testing. Do not document. */
/* It is relatively difficult to ensure that there is a tty on stdin.
Since rm acts differently depending on that, without this option,
it'd be harder to test the parts of rm that depend on that setting. */
- {"-presume-input-tty", no_argument, NULL, PRESUME_INPUT_TTY_OPTION},
+ {"-presume-input-tty", no_argument, nullptr, PRESUME_INPUT_TTY_OPTION},
- {"recursive", no_argument, NULL, 'r'},
- {"dir", no_argument, NULL, 'd'},
- {"verbose", no_argument, NULL, 'v'},
+ {"recursive", no_argument, nullptr, 'r'},
+ {"dir", no_argument, nullptr, 'd'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static char const *const interactive_args[] =
{
"never", "no", "none",
"once",
- "always", "yes", NULL
+ "always", "yes", nullptr
};
static enum interactive_type const interactive_types[] =
{
x->one_file_system = false;
x->remove_empty_directories = false;
x->recursive = false;
- x->root_dev_ino = NULL;
+ x->root_dev_ino = nullptr;
x->preserve_all_root = false;
x->stdin_tty = isatty (STDIN_FILENO);
x->verbose = false;
/* Try to disable the ability to unlink a directory. */
priv_set_remove_linkdir ();
- while ((c = getopt_long (argc, argv, "dfirvIR", long_opts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "dfirvIR", long_opts, nullptr)) != -1)
{
switch (c)
{
{
static struct dev_ino dev_ino_buf;
x.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
- if (x.root_dev_ino == NULL)
+ if (x.root_dev_ino == nullptr)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
{
/* Don't name this '--force' because it's not close enough in meaning
to e.g. rm's -f option. */
- {"ignore-fail-on-non-empty", no_argument, NULL,
+ {"ignore-fail-on-non-empty", no_argument, nullptr,
IGNORE_FAIL_ON_NON_EMPTY_OPTION},
- {"path", no_argument, NULL, 'p'}, /* Deprecated. */
- {"parents", no_argument, NULL, 'p'},
- {"verbose", no_argument, NULL, 'v'},
+ {"path", no_argument, nullptr, 'p'}, /* Deprecated. */
+ {"parents", no_argument, nullptr, 'p'},
+ {"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Return true if ERROR_NUMBER is one of the values associated
while (true)
{
slash = strrchr (dir, '/');
- if (slash == NULL)
+ if (slash == nullptr)
break;
/* Remove any characters after the slash, skipping any extra
slashes in a row. */
remove_empty_parents = false;
- while ((optc = getopt_long (argc, argv, "pv", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "pv", longopts, nullptr)) != -1)
{
switch (optc)
{
static struct option const long_options[] =
{
- {"role", required_argument, NULL, 'r'},
- {"type", required_argument, NULL, 't'},
- {"user", required_argument, NULL, 'u'},
- {"range", required_argument, NULL, 'l'},
- {"compute", no_argument, NULL, 'c'},
+ {"role", required_argument, nullptr, 'r'},
+ {"type", required_argument, nullptr, 't'},
+ {"user", required_argument, nullptr, 'u'},
+ {"range", required_argument, nullptr, 'l'},
+ {"compute", no_argument, nullptr, 'c'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
int
main (int argc, char **argv)
{
- char *role = NULL;
- char *range = NULL;
- char *user = NULL;
- char *type = NULL;
- char *context = NULL;
- char *cur_context = NULL;
- char *file_context = NULL;
- char *new_context = NULL;
+ char *role = nullptr;
+ char *range = nullptr;
+ char *user = nullptr;
+ char *type = nullptr;
+ char *context = nullptr;
+ char *cur_context = nullptr;
+ char *file_context = nullptr;
+ char *new_context = nullptr;
bool compute_trans = false;
context_t con;
if (setexeccon (context_str (con)) != 0)
die (EXIT_CANCELED, errno, _("unable to set security context %s"),
quote (context_str (con)));
- if (cur_context != NULL)
+ if (cur_context != nullptr)
freecon (cur_context);
(compute_trans ? execv : execvp) (argv[optind], argv + optind);
static int
computecon (char const *path, mode_t mode, char **con)
{
- char *scon = NULL;
- char *tcon = NULL;
+ char *scon = nullptr;
+ char *tcon = nullptr;
security_class_t tclass;
int rc = -1;
char const *path, mode_t mode)
{
int rc = -1;
- char *scon = NULL;
- char *tcon = NULL;
+ char *scon = nullptr;
+ char *tcon = nullptr;
context_t scontext = 0, tcontext = 0;
char const *contype;
char const *constr;
- char *newpath = NULL;
+ char *newpath = nullptr;
if (! IS_ABSOLUTE_FILE_NAME (path))
{
{
int rc = -1;
struct stat sb;
- char *scon = NULL;
- char *tcon = NULL;
+ char *scon = nullptr;
+ char *tcon = nullptr;
context_t scontext = 0, tcontext = 0;
char const *contype;
char const *constr;
restorecon (struct selabel_handle *selabel_handle,
char const *path, bool recurse)
{
- char *newpath = NULL;
+ char *newpath = nullptr;
if (! IS_ABSOLUTE_FILE_NAME (path))
{
return ok;
}
- char const *ftspath[2] = { path, NULL };
- FTS *fts = xfts_open ((char *const *) ftspath, FTS_PHYSICAL, NULL);
+ char const *ftspath[2] = { path, nullptr };
+ FTS *fts = xfts_open ((char *const *) ftspath, FTS_PHYSICAL, nullptr);
int err = 0;
for (FTSENT *ent; (ent = fts_read (fts)); )
static struct option const long_options[] =
{
- { "equal-width", no_argument, NULL, 'w'},
- { "format", required_argument, NULL, 'f'},
- { "separator", required_argument, NULL, 's'},
+ { "equal-width", no_argument, nullptr, 'w'},
+ { "format", required_argument, nullptr, 'f'},
+ { "separator", required_argument, nullptr, 's'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- { NULL, 0, NULL, 0}
+ { nullptr, 0, nullptr, 0}
};
void
{
operand ret;
- if (! xstrtold (arg, NULL, &ret.value, cl_strtold))
+ if (! xstrtold (arg, nullptr, &ret.value, cl_strtold))
{
error (0, 0, _("invalid floating point argument: %s"), quote (arg));
usage (EXIT_FAILURE);
e = strchr (arg, 'E');
if (e)
{
- long exponent = MAX (strtol (e + 1, NULL, 10), -LONG_MAX);
+ long exponent = MAX (strtol (e + 1, nullptr, 10), -LONG_MAX);
ret.precision += exponent < 0 ? -exponent
: - MIN (ret.precision, exponent);
/* Don't account for e.... in the width since this is not output. */
xalloc_die ();
x_str[x_strlen - layout.suffix_len] = '\0';
- if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, cl_strtold)
+ if (xstrtold (x_str + layout.prefix_len, nullptr,
+ &x_val, cl_strtold)
&& x_val == last)
{
- char *x0_str = NULL;
+ char *x0_str = nullptr;
int x0_strlen = asprintf (&x0_str, fmt, x0);
if (x0_strlen < 0)
xalloc_die ();
q = memcpy (q0 + inc_size - q_len, b, q_len + 1);
}
else
- q = q0 = NULL;
+ q = q0 = nullptr;
bool ok = inf || cmp (p, p_len, q, q_len) <= 0;
if (ok)
struct layout layout = { 0, 0 };
/* The printf(3) format used for output. */
- char const *format_str = NULL;
+ char const *format_str = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
break;
}
- optc = getopt_long (argc, argv, "+f:s:w", long_options, NULL);
+ optc = getopt_long (argc, argv, "+f:s:w", long_options, nullptr);
if (optc == -1)
break;
if (format_str)
format_str = long_double_format (format_str, &layout);
- if (format_str != NULL && equal_width)
+ if (format_str != nullptr && equal_width)
{
error (0, 0, _("format string may not be specified"
" when printing equal width strings"));
bool fast_step_ok = false;
if (n_args != 3
|| (all_digits_p (argv[optind + 1])
- && xstrtold (argv[optind + 1], NULL, &step.value, cl_strtold)
+ && xstrtold (argv[optind + 1], nullptr, &step.value, cl_strtold)
&& 0 < step.value && step.value <= SEQ_FAST_STEP_LIMIT))
fast_step_ok = true;
/* Upon any failure, let the more general code deal with it. */
}
- if (format_str == NULL)
+ if (format_str == nullptr)
format_str = get_default_format (first, step, last);
print_numbers (format_str, layout, first.value, step.value, last.value);
struct field_range_pair *c = frp;
size_t n = n_frp;
- frp = NULL;
+ frp = nullptr;
n_frp = 0;
n_frp_allocated = 0;
static char const *const remove_args[] =
{
- "unlink", "wipe", "wipesync", NULL
+ "unlink", "wipe", "wipesync", nullptr
};
static enum remove_method const remove_methods[] =
static struct option const long_opts[] =
{
- {"exact", no_argument, NULL, 'x'},
- {"force", no_argument, NULL, 'f'},
- {"iterations", required_argument, NULL, 'n'},
- {"size", required_argument, NULL, 's'},
- {"random-source", required_argument, NULL, RANDOM_SOURCE_OPTION},
- {"remove", optional_argument, NULL, 'u'},
- {"verbose", no_argument, NULL, 'v'},
- {"zero", no_argument, NULL, 'z'},
+ {"exact", no_argument, nullptr, 'x'},
+ {"force", no_argument, nullptr, 'f'},
+ {"iterations", required_argument, nullptr, 'n'},
+ {"size", required_argument, nullptr, 's'},
+ {"random-source", required_argument, nullptr, RANDOM_SOURCE_OPTION},
+ {"remove", optional_argument, nullptr, 'u'},
+ {"verbose", no_argument, nullptr, 'v'},
+ {"zero", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
if (n)
{
error (0, 0, _("%s: pass %lu/%lu (%s)..."), qname, k, n, pass_string);
- thresh = time (NULL) + VERBOSE_UPDATE;
+ thresh = time (nullptr) + VERBOSE_UPDATE;
previous_human_offset = "";
}
/* Time to print progress? */
if (n && ((done && *previous_human_offset)
- || thresh <= (now = time (NULL))))
+ || thresh <= (now = time (nullptr))))
{
char offset_buf[LONGEST_HUMAN_READABLE + 1];
char size_buf[LONGEST_HUMAN_READABLE + 1];
char const *p = strchr (nameset, name[len]);
/* Given that NAME is composed of bytes from NAMESET,
- P will never be NULL here. */
+ P will never be null here. */
assert (p);
/* If this character has a successor, use it. */
int n_files;
int c;
int i;
- char const *random_source = NULL;
+ char const *random_source = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
flags.n_iterations = DEFAULT_PASSES;
flags.size = -1;
- while ((c = getopt_long (argc, argv, "fn:s:uvxz", long_opts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "fn:s:uvxz", long_opts, nullptr)) != -1)
{
switch (c)
{
break;
case 'u':
- if (optarg == NULL)
+ if (optarg == nullptr)
flags.remove_file = remove_wipesync;
else
flags.remove_file = XARGMATCH ("--remove", optarg,
static struct option const long_opts[] =
{
- {"echo", no_argument, NULL, 'e'},
- {"input-range", required_argument, NULL, 'i'},
- {"head-count", required_argument, NULL, 'n'},
- {"output", required_argument, NULL, 'o'},
- {"random-source", required_argument, NULL, RANDOM_SOURCE_OPTION},
- {"repeat", no_argument, NULL, 'r'},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"echo", no_argument, nullptr, 'e'},
+ {"input-range", required_argument, nullptr, 'i'},
+ {"head-count", required_argument, nullptr, 'n'},
+ {"output", required_argument, nullptr, 'o'},
+ {"random-source", required_argument, nullptr, RANDOM_SOURCE_OPTION},
+ {"repeat", no_argument, nullptr, 'r'},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{0, 0, 0, 0},
{
randint n_lines = 0;
size_t n_alloc_lines = MIN (k, RESERVOIR_LINES_INCREMENT);
- struct linebuffer *line = NULL;
+ struct linebuffer *line = nullptr;
struct linebuffer *rsrv;
rsrv = xcalloc (n_alloc_lines, sizeof (struct linebuffer));
/* Fill the first K lines, directly into the reservoir. */
while (n_lines < k
&& (line =
- readlinebuffer_delim (&rsrv[n_lines], in, eolbyte)) != NULL)
+ readlinebuffer_delim (&rsrv[n_lines], in, eolbyte)) != nullptr)
{
n_lines++;
}
}
- /* last line wasn't NULL - so there may be more lines to read. */
- if (line != NULL)
+ /* last line wasn't null - so there may be more lines to read. */
+ if (line != nullptr)
{
struct linebuffer dummy;
initbuffer (&dummy); /* space for lines not put in reservoir. */
randint j = randint_choose (s, n_lines + 1); /* 0 .. n_lines. */
line = (j < k) ? (&rsrv[j]) : (&dummy);
}
- while (readlinebuffer_delim (line, in, eolbyte) != NULL && n_lines++);
+ while (readlinebuffer_delim (line, in, eolbyte) != nullptr && n_lines++);
if (! n_lines)
die (EXIT_FAILURE, EOVERFLOW, _("too many input lines"));
read_input (FILE *in, char eolbyte, char ***pline)
{
char *p;
- char *buf = NULL;
+ char *buf = nullptr;
size_t used;
char *lim;
char **line;
size_t lo_input = SIZE_MAX;
size_t hi_input = 0;
size_t head_lines = SIZE_MAX;
- char const *outfile = NULL;
- char *random_source = NULL;
+ char const *outfile = nullptr;
+ char *random_source = nullptr;
char eolbyte = '\n';
- char **input_lines = NULL;
+ char **input_lines = nullptr;
bool use_reservoir_sampling = false;
bool repeat = false;
int n_operands;
char **operand;
size_t n_lines;
- char **line = NULL;
- struct linebuffer *reservoir = NULL;
+ char **line = nullptr;
+ struct linebuffer *reservoir = nullptr;
struct randint_source *randint_source;
- size_t *permutation = NULL;
+ size_t *permutation = nullptr;
int i;
initialize_main (&argc, &argv);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "ei:n:o:rz", long_opts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "ei:n:o:rz", long_opts, nullptr))
+ != -1)
switch (optc)
{
case 'e':
uintmax_t u;
char *lo_end;
- strtol_error err = xstrtoumax (optarg, &lo_end, 10, &u, NULL);
+ strtol_error err = xstrtoumax (optarg, &lo_end, 10, &u, nullptr);
if (err == LONGINT_OK)
{
lo_input = u;
err = LONGINT_INVALID;
else
{
- err = xstrtoumax (lo_end + 1, NULL, 10, &u, "");
+ err = xstrtoumax (lo_end + 1, nullptr, 10, &u, "");
if (err == LONGINT_OK)
{
hi_input = u;
case 'n':
{
uintmax_t argval;
- strtol_error e = xstrtoumax (optarg, NULL, 10, &argval, "");
+ strtol_error e = xstrtoumax (optarg, nullptr, 10, &argval, "");
if (e == LONGINT_OK)
head_lines = MIN (head_lines, argval);
if (head_lines == 0)
{
n_lines = 0;
- line = NULL;
+ line = nullptr;
}
else if (echo)
{
else if (input_range)
{
n_lines = hi_input - lo_input + 1;
- line = NULL;
+ line = nullptr;
}
else
{
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (argc == 1)
{
static struct option const long_options[] =
{
- {"ignore-leading-blanks", no_argument, NULL, 'b'},
- {"check", optional_argument, NULL, CHECK_OPTION},
- {"compress-program", required_argument, NULL, COMPRESS_PROGRAM_OPTION},
- {"debug", no_argument, NULL, DEBUG_PROGRAM_OPTION},
- {"dictionary-order", no_argument, NULL, 'd'},
- {"ignore-case", no_argument, NULL, 'f'},
- {"files0-from", required_argument, NULL, FILES0_FROM_OPTION},
- {"general-numeric-sort", no_argument, NULL, 'g'},
- {"ignore-nonprinting", no_argument, NULL, 'i'},
- {"key", required_argument, NULL, 'k'},
- {"merge", no_argument, NULL, 'm'},
- {"month-sort", no_argument, NULL, 'M'},
- {"numeric-sort", no_argument, NULL, 'n'},
- {"human-numeric-sort", no_argument, NULL, 'h'},
- {"version-sort", no_argument, NULL, 'V'},
- {"random-sort", no_argument, NULL, 'R'},
- {"random-source", required_argument, NULL, RANDOM_SOURCE_OPTION},
- {"sort", required_argument, NULL, SORT_OPTION},
- {"output", required_argument, NULL, 'o'},
- {"reverse", no_argument, NULL, 'r'},
- {"stable", no_argument, NULL, 's'},
- {"batch-size", required_argument, NULL, NMERGE_OPTION},
- {"buffer-size", required_argument, NULL, 'S'},
- {"field-separator", required_argument, NULL, 't'},
- {"temporary-directory", required_argument, NULL, 'T'},
- {"unique", no_argument, NULL, 'u'},
- {"zero-terminated", no_argument, NULL, 'z'},
- {"parallel", required_argument, NULL, PARALLEL_OPTION},
+ {"ignore-leading-blanks", no_argument, nullptr, 'b'},
+ {"check", optional_argument, nullptr, CHECK_OPTION},
+ {"compress-program", required_argument, nullptr, COMPRESS_PROGRAM_OPTION},
+ {"debug", no_argument, nullptr, DEBUG_PROGRAM_OPTION},
+ {"dictionary-order", no_argument, nullptr, 'd'},
+ {"ignore-case", no_argument, nullptr, 'f'},
+ {"files0-from", required_argument, nullptr, FILES0_FROM_OPTION},
+ {"general-numeric-sort", no_argument, nullptr, 'g'},
+ {"ignore-nonprinting", no_argument, nullptr, 'i'},
+ {"key", required_argument, nullptr, 'k'},
+ {"merge", no_argument, nullptr, 'm'},
+ {"month-sort", no_argument, nullptr, 'M'},
+ {"numeric-sort", no_argument, nullptr, 'n'},
+ {"human-numeric-sort", no_argument, nullptr, 'h'},
+ {"version-sort", no_argument, nullptr, 'V'},
+ {"random-sort", no_argument, nullptr, 'R'},
+ {"random-source", required_argument, nullptr, RANDOM_SOURCE_OPTION},
+ {"sort", required_argument, nullptr, SORT_OPTION},
+ {"output", required_argument, nullptr, 'o'},
+ {"reverse", no_argument, nullptr, 'r'},
+ {"stable", no_argument, nullptr, 's'},
+ {"batch-size", required_argument, nullptr, NMERGE_OPTION},
+ {"buffer-size", required_argument, nullptr, 'S'},
+ {"field-separator", required_argument, nullptr, 't'},
+ {"temporary-directory", required_argument, nullptr, 'T'},
+ {"unique", no_argument, nullptr, 'u'},
+ {"zero-terminated", no_argument, nullptr, 'z'},
+ {"parallel", required_argument, nullptr, PARALLEL_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0},
+ {nullptr, 0, nullptr, 0},
};
#define CHECK_TABLE \
static char const *const check_args[] =
{
#define _ct_(_s, _c) _s,
- CHECK_TABLE NULL
+ CHECK_TABLE nullptr
#undef _ct_
};
static char const check_types[] =
static char const *const sort_args[] =
{
#define _st_(_s, _c) _s,
- SORT_TABLE NULL
+ SORT_TABLE nullptr
#undef _st_
};
static char const sort_types[] =
if (status->valid)
{
/* Ignore failure when restoring the signal mask. */
- pthread_sigmask (SIG_SETMASK, &status->sigs, NULL);
+ pthread_sigmask (SIG_SETMASK, &status->sigs, nullptr);
}
}
{
if (! proctab)
{
- proctab = hash_initialize (INIT_PROCTAB_SIZE, NULL,
+ proctab = hash_initialize (INIT_PROCTAB_SIZE, nullptr,
proctab_hasher,
proctab_comparator,
- NULL);
+ nullptr);
if (! proctab)
xalloc_die ();
}
for (node = temphead; node; node = node->next)
unlink (node->name);
- temphead = NULL;
+ temphead = nullptr;
}
/* Cleanup actions to take when exiting. */
/* Create a new temporary file, returning its newly allocated tempnode.
Store into *PFD the file descriptor open for writing.
- If the creation fails, return NULL and store -1 into *PFD if the
+ If the creation fails, return nullptr and store -1 into *PFD if the
failure is due to file descriptor exhaustion and
SURVIVE_FD_EXHAUSTION; otherwise, die. */
memcpy (file, temp_dir, len);
memcpy (file + len, slashbase, sizeof slashbase);
- node->next = NULL;
+ node->next = nullptr;
if (++temp_dir_index == temp_dir_count)
temp_dir_index = 0;
die (SORT_FAILURE, errno, _("cannot create temporary file in %s"),
quoteaf (temp_dir));
free (node);
- node = NULL;
+ node = nullptr;
}
*pfd = fd;
return node;
}
-/* Return a pointer to stdout status, or NULL on failure. */
+/* Return a pointer to stdout status, or nullptr on failure. */
static struct stat *
get_outstatus (void)
static struct stat outstat;
if (outstat_errno == 0)
outstat_errno = fstat (STDOUT_FILENO, &outstat) == 0 ? -1 : errno;
- return outstat_errno < 0 ? &outstat : NULL;
+ return outstat_errno < 0 ? &outstat : nullptr;
}
/* Return a stream for FILE, opened with mode HOW. If HOW is "w",
truncated unless FILE is null. When opening for input, "-"
means standard input. To avoid confusion, do not return file
descriptors STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO when
- opening an ordinary FILE. Return NULL if unsuccessful.
+ opening an ordinary FILE. Return nullptr if unsuccessful.
Use fadvise to specify an access pattern for input files.
There are a few hints we could possibly provide,
else
{
int fd = open (file, O_RDONLY | O_CLOEXEC);
- fp = fd < 0 ? NULL : fdopen (fd, how);
+ fp = fd < 0 ? nullptr : fdopen (fd, how);
}
fadvise (fp, FADVISE_SEQUENTIAL);
}
if it receives a signal before exec-ing. */
cs_enter (&cs);
saved_temphead = temphead;
- temphead = NULL;
+ temphead = nullptr;
pid = fork ();
saved_errno = errno;
/* Create a temporary file and, if asked for, start a compressor
to that file. Set *PFP to the file handle and return
the address of the new temp node. If the creation
- fails, return NULL if the failure is due to file descriptor
+ fails, return nullptr if the failure is due to file descriptor
exhaustion and SURVIVE_FD_EXHAUSTION; otherwise, die. */
static struct tempnode *
int tempfd;
struct tempnode *node = create_temp_file (&tempfd, survive_fd_exhaustion);
if (! node)
- return NULL;
+ return nullptr;
node->state = UNCOMPRESSED;
move_fd (tempfd, STDOUT_FILENO);
move_fd (pipefds[0], STDIN_FILENO);
- execlp (compress_program, compress_program, (char *) NULL);
+ execlp (compress_program, compress_program, (char *) nullptr);
async_safe_die (errno, "couldn't execute compress program");
}
}
/* Open a compressed temp file and start a decompression process through
- which to filter the input. Return NULL (setting errno to
+ which to filter the input. Return nullptr (setting errno to
EMFILE) if we ran out of file descriptors, and die on any other
kind of failure. */
open_temp (struct tempnode *temp)
{
int tempfd, pipefds[2];
- FILE *fp = NULL;
+ FILE *fp = nullptr;
if (temp->state == UNREAPED)
wait_proc (temp->pid);
tempfd = open (temp->name, O_RDONLY);
if (tempfd < 0)
- return NULL;
+ return nullptr;
pid_t child = pipe_fork (pipefds, MAX_FORK_TRIES_DECOMPRESS);
move_fd (tempfd, STDIN_FILENO);
move_fd (pipefds[1], STDOUT_FILENO);
- execlp (compress_program, compress_program, "-d", (char *) NULL);
+ execlp (compress_program, compress_program, "-d", (char *) nullptr);
async_safe_die (errno, "couldn't execute compress program (with -d)");
{
uintmax_t n;
struct rlimit rlimit;
- enum strtol_error e = xstrtoumax (s, NULL, 10, &n, "");
+ enum strtol_error e = xstrtoumax (s, nullptr, 10, &n, "");
/* Try to find out how many file descriptors we'll be able
to open. We need at least nmerge + 3 (STDIN_FILENO,
specify_nthreads (int oi, char c, char const *s)
{
uintmax_t nthreads;
- enum strtol_error e = xstrtoumax (s, NULL, 10, &nthreads, "");
+ enum strtol_error e = xstrtoumax (s, nullptr, 10, &nthreads, "");
if (e == LONGINT_OVERFLOW)
return SIZE_MAX;
if (e != LONGINT_OK)
char stackbuf[4000];
char *buf = stackbuf;
size_t bufsize = sizeof stackbuf;
- void *allocated = NULL;
+ void *allocated = nullptr;
uint32_t dig[2][MD5_DIGEST_SIZE / sizeof (uint32_t)];
struct md5_ctx s[2];
s[0] = s[1] = random_md5_state;
bool a_fits = sizea <= bufsize;
size_t sizeb =
(textb < limb
- ? (xstrxfrm ((a_fits ? buf + sizea : NULL), textb,
+ ? (xstrxfrm ((a_fits ? buf + sizea : nullptr), textb,
(a_fits ? bufsize - sizea : 0))
+ 1)
: 0);
/* Flag global options not copied or specified in any key. */
if (ugkey.ignore && (ugkey.ignore == key->ignore))
- ugkey.ignore = NULL;
+ ugkey.ignore = nullptr;
if (ugkey.translate && (ugkey.translate == key->translate))
- ugkey.translate = NULL;
+ ugkey.translate = nullptr;
ugkey.skipsblanks &= !key->skipsblanks;
ugkey.skipeblanks &= !key->skipeblanks;
ugkey.month &= !key->month;
char enda = ta[tlena];
char endb = tb[tlenb];
- void *allocated = NULL;
+ void *allocated = nullptr;
char stackbuf[4000];
if (ignore || translate)
else if (key->human_numeric)
diff = human_numcompare (ta, tb);
else if (key->month)
- diff = getmonth (ta, NULL) - getmonth (tb, NULL);
+ diff = getmonth (ta, nullptr) - getmonth (tb, nullptr);
else if (key->random)
diff = compare_random (ta, tlena, tb, tlenb);
else if (key->version)
initbuf (&buf, sizeof (struct line),
MAX (merge_buffer_size, sort_size));
- temp.text = NULL;
+ temp.text = nullptr;
while (fillbuf (&buf, fp, file_name))
{
NFILES is the number of files; 0 <= NTEMPS <= NFILES <= NMERGE.
FPS is the vector of open stream corresponding to the files.
Close input and output streams before returning.
- OUTPUT_FILE gives the name of the output file. If it is NULL,
+ OUTPUT_FILE gives the name of the output file. If it is null,
the output file is standard output. */
static void
struct buffer *buffer = xnmalloc (nfiles, sizeof *buffer);
/* Input buffers for each file. */
struct line saved; /* Saved line storage for unique check. */
- struct line const *savedline = NULL;
+ struct line const *savedline = nullptr;
/* &saved if there is a saved line. */
size_t savealloc = 0; /* Size allocated for the saved line. */
struct line const **cur = xnmalloc (nfiles, sizeof *cur);
size_t j;
size_t t;
struct keyfield const *key = keylist;
- saved.text = NULL;
+ saved.text = nullptr;
/* Read initial lines from each input file. */
for (i = 0; i < nfiles; )
{
if (savedline && compare (savedline, smallest))
{
- savedline = NULL;
+ savedline = nullptr;
write_line (&saved, ofp, output_file);
}
if (!savedline)
struct merge_node *merge_tree = xmalloc (2 * sizeof *merge_tree * nthreads);
struct merge_node *root = merge_tree;
- root->lo = root->hi = root->end_lo = root->end_hi = NULL;
- root->dest = NULL;
+ root->lo = root->hi = root->end_lo = root->end_hi = nullptr;
+ root->dest = nullptr;
root->nlo = root->nhi = nlines;
- root->parent = NULL;
+ root->parent = nullptr;
root->level = MERGE_END;
root->queued = false;
- pthread_mutex_init (&root->lock, NULL);
+ pthread_mutex_init (&root->lock, nullptr);
init_node (root, root + 1, dest, nthreads, nlines, false);
return merge_tree;
node->parent = parent;
node->level = parent->level + 1;
node->queued = false;
- pthread_mutex_init (&node->lock, NULL);
+ pthread_mutex_init (&node->lock, nullptr);
if (nthreads > 1)
{
}
else
{
- node->lo_child = NULL;
- node->hi_child = NULL;
+ node->lo_child = nullptr;
+ node->hi_child = nullptr;
}
return node_pool;
}
queue_init (struct merge_node_queue *queue, size_t nthreads)
{
/* Though it's highly unlikely all nodes are in the heap at the same
- time, the heap should accommodate all of them. Counting a NULL
+ time, the heap should accommodate all of them. Counting a null
dummy head for the heap, reserve 2 * NTHREADS nodes. */
queue->priority_queue = heap_alloc (compare_nodes, 2 * nthreads);
- pthread_mutex_init (&queue->mutex, NULL);
- pthread_cond_init (&queue->cond, NULL);
+ pthread_mutex_init (&queue->mutex, nullptr);
+ pthread_cond_init (&queue->cond, nullptr);
}
/* Insert NODE into QUEUE. The caller either holds a lock on NODE, or
sortlines (args->lines, args->nthreads, args->total_lines,
args->node, args->queue, args->tfp,
args->output_temp);
- return NULL;
+ return nullptr;
}
/* Sort lines, possibly in parallel. The arguments are as in struct
node->lo_child, queue, tfp, temp_output};
if (nthreads > 1 && SUBTHREAD_LINES_HEURISTIC <= nlines
- && pthread_create (&thread, NULL, sortlines_thread, &args) == 0)
+ && pthread_create (&thread, nullptr, sortlines_thread, &args) == 0)
{
sortlines (lines - node->nlo, hi_threads, total_lines,
node->hi_child, queue, tfp, temp_output);
- pthread_join (thread, NULL);
+ pthread_join (thread, nullptr);
}
else
{
avoid_trashing_input (struct sortfile *files, size_t ntemps,
size_t nfiles, char const *outfile)
{
- struct tempnode *tempcopy = NULL;
+ struct tempnode *tempcopy = nullptr;
for (size_t i = ntemps; i < nfiles; i++)
{
break;
}
- saved_line.text = NULL;
+ saved_line.text = nullptr;
line = buffer_linelim (&buf);
if (buf.eof && !nfiles && !ntemps && !buf.left)
{
for (p = &keylist; *p; p = &(*p)->next)
continue;
*p = key;
- key->next = NULL;
+ key->next = nullptr;
}
/* Report a bad field specification SPEC, with extra info MSGID. */
/* Parse the leading integer in STRING and store the resulting value
(which must fit into size_t) into *VAL. Return the address of the
suffix after the integer. If the value is too large, silently
- substitute SIZE_MAX. If MSGID is NULL, return NULL after
+ substitute SIZE_MAX. If MSGID is null, return nullptr after
failure; otherwise, report MSGID and exit on failure. */
static char const *
if (msgid)
die (SORT_FAILURE, 0, _("%s: invalid count at start of %s"),
_(msgid), quote (string));
- return NULL;
+ return nullptr;
}
return suffix;
int c = 0;
char checkonly = 0;
bool mergeonly = false;
- char *random_source = NULL;
+ char *random_source = nullptr;
bool need_random = false;
size_t nthreads = 0;
size_t nfiles = 0;
- bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
+ bool posixly_correct = (getenv ("POSIXLY_CORRECT") != nullptr);
int posix_ver = posix2_version ();
bool traditional_usage = ! (200112 <= posix_ver && posix_ver < 200809);
char **files;
- char *files_from = NULL;
+ char *files_from = nullptr;
struct Tokens tok;
- char const *outfile = NULL;
+ char const *outfile = nullptr;
bool locale_ok;
initialize_main (&argc, &argv);
sigemptyset (&caught_signals);
for (i = 0; i < nsigs; i++)
{
- sigaction (sig[i], NULL, &act);
+ sigaction (sig[i], nullptr, &act);
if (act.sa_handler != SIG_IGN)
sigaddset (&caught_signals, sig[i]);
}
for (i = 0; i < nsigs; i++)
if (sigismember (&caught_signals, sig[i]))
- sigaction (sig[i], &act, NULL);
+ sigaction (sig[i], &act, nullptr);
#else
for (i = 0; i < nsigs; i++)
if (signal (sig[i], SIG_IGN) != SIG_IGN)
else switch (c)
{
case 1:
- key = NULL;
+ key = nullptr;
if (optarg[0] == '+')
{
bool minus_pos_usage = (optind != argc && argv[optind][0] == '-'
/* Treat +POS1 [-POS2] as a key if possible; but silently
treat an operand as a file if it is not a valid +POS1. */
key = key_init (&key_buf);
- s = parse_field_count (optarg + 1, &key->sword, NULL);
+ s = parse_field_count (optarg + 1, &key->sword, nullptr);
if (s && *s == '.')
- s = parse_field_count (s + 1, &key->schar, NULL);
+ s = parse_field_count (s + 1, &key->schar, nullptr);
if (! (key->sword || key->schar))
key->sword = SIZE_MAX;
if (! s || *set_ordering (s, key, bl_start))
- key = NULL;
+ key = nullptr;
else
{
if (minus_pos_usage)
char const *optarg1 = argv[optind++];
s = parse_field_count (optarg1 + 1, &key->eword,
N_("invalid number after '-'"));
- /* When called with a non-NULL message ID,
- parse_field_count cannot return NULL. Tell static
- analysis tools that dereferencing S is safe. */
+ /* When called with a non-null message ID,
+ parse_field_count cannot return a null pointer.
+ Tell static analysis tools that
+ dereferencing S is safe. */
assert (s);
if (*s == '.')
s = parse_field_count (s + 1, &key->echar,
error (0, 0, "%s", _("failed to set locale"));
if (hard_LC_COLLATE)
error (0, 0, _("text ordering performed using %s sorting rules"),
- quote (setlocale (LC_COLLATE, NULL)));
+ quote (setlocale (LC_COLLATE, nullptr)));
else
error (0, 0, "%s",
_("text ordering performed using simple byte comparison"));
static struct option const longopts[] =
{
- {"bytes", required_argument, NULL, 'b'},
- {"lines", required_argument, NULL, 'l'},
- {"line-bytes", required_argument, NULL, 'C'},
- {"number", required_argument, NULL, 'n'},
- {"elide-empty-files", no_argument, NULL, 'e'},
- {"unbuffered", no_argument, NULL, 'u'},
- {"suffix-length", required_argument, NULL, 'a'},
- {"additional-suffix", required_argument, NULL,
+ {"bytes", required_argument, nullptr, 'b'},
+ {"lines", required_argument, nullptr, 'l'},
+ {"line-bytes", required_argument, nullptr, 'C'},
+ {"number", required_argument, nullptr, 'n'},
+ {"elide-empty-files", no_argument, nullptr, 'e'},
+ {"unbuffered", no_argument, nullptr, 'u'},
+ {"suffix-length", required_argument, nullptr, 'a'},
+ {"additional-suffix", required_argument, nullptr,
ADDITIONAL_SUFFIX_OPTION},
- {"numeric-suffixes", optional_argument, NULL, 'd'},
- {"hex-suffixes", optional_argument, NULL, 'x'},
- {"filter", required_argument, NULL, FILTER_OPTION},
- {"verbose", no_argument, NULL, VERBOSE_OPTION},
- {"separator", required_argument, NULL, 't'},
- {"-io-blksize", required_argument, NULL,
+ {"numeric-suffixes", optional_argument, nullptr, 'd'},
+ {"hex-suffixes", optional_argument, nullptr, 'x'},
+ {"filter", required_argument, nullptr, FILTER_OPTION},
+ {"verbose", no_argument, nullptr, VERBOSE_OPTION},
+ {"separator", required_argument, nullptr, 't'},
+ {"-io-blksize", required_argument, nullptr,
IO_BLKSIZE_OPTION}, /* do not document */
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Return true if the errno value, ERR, is ignorable. */
if (numeric_suffix_start)
{
intmax_t n_start;
- strtol_error e = xstrtoimax (numeric_suffix_start, NULL, 10,
+ strtol_error e = xstrtoimax (numeric_suffix_start, nullptr, 10,
&n_start, "");
if (e == LONGINT_OK && n_start < n_units)
{
int fd_pair[2];
pid_t child_pid;
char const *shell_prog = getenv ("SHELL");
- if (shell_prog == NULL)
+ if (shell_prog == nullptr)
shell_prog = "/bin/sh";
if (setenv ("FILE", name, 1) != 0)
die (EXIT_FAILURE, errno,
if (default_SIGPIPE)
signal (SIGPIPE, SIG_DFL);
execl (shell_prog, last_component (shell_prog), "-c",
- filter_command, (char *) NULL);
+ filter_command, (char *) nullptr);
die (EXIT_FAILURE, errno, _("failed to run command: \"%s -c %s\""),
shell_prog, filter_command);
}
static void
closeout (FILE *fp, int fd, pid_t pid, char const *name)
{
- if (fp != NULL && fclose (fp) != 0 && ! ignorable (errno))
+ if (fp != nullptr && fclose (fp) != 0 && ! ignorable (errno))
die (EXIT_FAILURE, errno, "%s", quotef (name));
if (fd >= 0)
{
- if (fp == NULL && close (fd) < 0)
+ if (fp == nullptr && close (fd) < 0)
die (EXIT_FAILURE, errno, "%s", quotef (name));
int j;
for (j = 0; j < n_open_pipes; ++j)
{
if (!bp && bytes == 0 && elide_empty_files)
return true;
- closeout (NULL, output_desc, filter_pid, outfile);
+ closeout (nullptr, output_desc, filter_pid, outfile);
next_file_name ();
output_desc = create (outfile);
if (output_desc < 0)
any existing files or notifies any consumers on fifos.
FIXME: Should we do this before EXIT_FAILURE? */
while (opened++ < max_files)
- cwrite (true, NULL, 0);
+ cwrite (true, nullptr, 0);
}
/* Split into pieces of exactly N_LINES lines.
ssize_t n_read;
intmax_t n_out = 0; /* for each split. */
idx_t n_hold = 0;
- char *hold = NULL; /* for lines > bufsize. */
+ char *hold = nullptr; /* for lines > bufsize. */
idx_t hold_size = 0;
bool split_line = false; /* Whether a \n was output in a split. */
while (n_left)
{
idx_t split_rest = 0;
- char *eoc = NULL;
+ char *eoc = nullptr;
char *eol;
/* Determine End Of Chunk and/or End of Line,
if (chunk_end <= n_written)
{
if (! k)
- cwrite (true, NULL, 0);
+ cwrite (true, nullptr, 0);
}
else
next = false;
FIXME: Should we do this before EXIT_FAILURE? */
if (!k)
while (chunk_no++ <= n)
- cwrite (true, NULL, 0);
+ cwrite (true, nullptr, 0);
}
/* -n K/N: Extract Kth of N chunks. */
if (fclose (files[i_reopen].ofile) != 0)
die (EXIT_FAILURE, errno, "%s", quotef (files[i_reopen].of_name));
- files[i_reopen].ofile = NULL;
+ files[i_reopen].ofile = nullptr;
files[i_reopen].ofd = OFD_APPEND;
}
bool wrote = false;
bool file_limit;
idx_t i_file;
- of_t *files IF_LINT (= NULL);
+ of_t *files IF_LINT (= nullptr);
intmax_t line_no;
if (k)
next_file_name ();
files[i_file].of_name = xstrdup (outfile);
files[i_file].ofd = OFD_NEW;
- files[i_file].ofile = NULL;
+ files[i_file].ofile = nullptr;
files[i_file].opid = 0;
}
i_file = 0;
die (EXIT_FAILURE, errno, "%s",
quotef (files[i_file].of_name));
}
- files[i_file].ofile = NULL;
+ files[i_file].ofile = nullptr;
files[i_file].ofd = OFD_APPEND;
}
if (next && ++i_file == n)
parse_n_units (char const *arg, char const *multipliers, char const *msgid)
{
intmax_t n;
- if (OVERFLOW_OK < xstrtoimax (arg, NULL, 10, &n, multipliers) || n < 1)
+ if (OVERFLOW_OK < xstrtoimax (arg, nullptr, 10, &n, multipliers) || n < 1)
strtoint_die (msgid, arg);
return n;
}
int this_optind = optind ? optind : 1;
c = getopt_long (argc, argv, "0123456789C:a:b:del:n:t:ux",
- longopts, NULL);
+ longopts, nullptr);
if (c == -1)
break;
if (close (STDIN_FILENO) != 0)
die (EXIT_FAILURE, errno, "%s", quotef (infile));
- closeout (NULL, output_desc, filter_pid, outfile);
+ closeout (nullptr, output_desc, filter_pid, outfile);
main_exit (EXIT_SUCCESS);
}
static char const *const cached_args[] =
{
- "default", "never", "always", NULL
+ "default", "never", "always", nullptr
};
static enum cached_mode const cached_modes[] =
static struct option const long_options[] =
{
- {"dereference", no_argument, NULL, 'L'},
- {"file-system", no_argument, NULL, 'f'},
- {"format", required_argument, NULL, 'c'},
- {"printf", required_argument, NULL, PRINTF_OPTION},
- {"terse", no_argument, NULL, 't'},
- {"cached", required_argument, NULL, 0},
+ {"dereference", no_argument, nullptr, 'L'},
+ {"file-system", no_argument, nullptr, 'f'},
+ {"format", required_argument, nullptr, 'c'},
+ {"printf", required_argument, nullptr, PRINTF_OPTION},
+ {"terse", no_argument, nullptr, 't'},
+ {"cached", required_argument, nullptr, 0},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Whether to follow symbolic links; True for --dereference (-L). */
if (ISDIGIT (dot[1]))
{
- long int lprec = strtol (dot + 1, NULL, 10);
+ long int lprec = strtol (dot + 1, nullptr, 10);
precision = (lprec <= INT_MAX ? lprec : INT_MAX);
}
else
--p;
while (ISDIGIT (p[-1]));
- long int lwidth = strtol (p, NULL, 10);
+ long int lwidth = strtol (p, nullptr, 10);
width = (lwidth <= INT_MAX ? lwidth : INT_MAX);
if (1 < width)
{
{
error (0, errno, _("failed to get security context of %s"),
quoteaf (filename));
- scontext = NULL;
+ scontext = nullptr;
fail = true;
}
strcpy (pformat + prefix_len, "s");
/* Return any bind mounted source for a path.
The caller should not free the returned buffer.
- Return NULL if no bind mount found. */
+ Return nullptr if no bind mount found. */
NODISCARD
static char const *
find_bind_mount (char const * name)
{
- char const * bind_mount = NULL;
+ char const * bind_mount = nullptr;
static struct mount_entry *mount_list;
static bool tried_mount_list = false;
struct stat name_stats;
if (stat (name, &name_stats) != 0)
- return NULL;
+ return nullptr;
struct mount_entry *me;
for (me = mount_list; me; me = me->me_next)
const struct stat *statp)
{
- char const *np = "?", *bp = NULL;
- char *mp = NULL;
+ char const *np = "?", *bp = nullptr;
+ char *mp = nullptr;
bool fail = true;
/* Look for bind mounts first. Note we output the immediate alias,
{
int i = ARGMATCH (q_style, quoting_style_args, quoting_style_vals);
if (0 <= i)
- set_quoting_style (NULL, quoting_style_vals[i]);
+ set_quoting_style (nullptr, quoting_style_vals[i]);
else
{
- set_quoting_style (NULL, shell_escape_always_quoting_style);
+ set_quoting_style (nullptr, shell_escape_always_quoting_style);
error (0, 0, _("ignoring invalid value of environment "
"variable QUOTING_STYLE: %s"), quote (q_style));
}
}
else
- set_quoting_style (NULL, shell_escape_always_quoting_style);
+ set_quoting_style (nullptr, shell_escape_always_quoting_style);
}
/* Equivalent to quotearg(), but explicit to avoid syntax checks. */
-#define quoteN(x) quotearg_style (get_quoting_style (NULL), x)
+#define quoteN(x) quotearg_style (get_quoting_style (nullptr), x)
/* Output a single-character \ escape. */
if (S_ISLNK (statbuf->st_mode))
{
char *linkname = areadlink_with_size (filename, statbuf->st_size);
- if (linkname == NULL)
+ if (linkname == nullptr)
{
error (0, errno, _("cannot read symbolic link %s"),
quoteaf (filename));
int c;
bool fs = false;
bool terse = false;
- char *format = NULL;
+ char *format = nullptr;
char *format2;
bool ok = true;
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "c:fLt", long_options, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "c:fLt", long_options, nullptr)) != -1)
{
switch (c)
{
static struct option const longopts[] =
{
- {"input", required_argument, NULL, 'i'},
- {"output", required_argument, NULL, 'o'},
- {"error", required_argument, NULL, 'e'},
+ {"input", required_argument, nullptr, 'i'},
+ {"output", required_argument, nullptr, 'o'},
+ {"error", required_argument, nullptr, 'e'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Set size to the value of STR, interpreted as a decimal integer,
parse_size (char const *str, size_t *size)
{
uintmax_t tmp_size;
- enum strtol_error e = xstrtoumax (str, NULL, 10, &tmp_size, "EGkKMPQRTYZ0");
+ enum strtol_error e = xstrtoumax (str, nullptr, 10,
+ &tmp_size, "EGkKMPQRTYZ0");
if (e == LONGINT_OK && SIZE_MAX < tmp_size)
e = LONGINT_OVERFLOW;
{
char *dir;
path = xstrdup (path);
- for (dir = strtok (path, ":"); dir != NULL; dir = strtok (NULL, ":"))
+ for (dir = strtok (path, ":"); dir != nullptr;
+ dir = strtok (nullptr, ":"))
{
- char *candidate = file_name_concat (dir, arg, NULL);
+ char *candidate = file_name_concat (dir, arg, nullptr);
if (access (candidate, X_OK) == 0)
{
program_path = dir_name (candidate);
char const *const search_path[] = {
program_path,
PKGLIBEXECDIR,
- NULL
+ nullptr
};
char const *const *path = search_path;
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "+i:o:e:", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "+i:o:e:", longopts, nullptr)) != -1)
{
int opt_fileno;
stdbuf is running from. */
set_program_path (program_name);
if (!program_path)
- program_path = xstrdup (PKGLIBDIR); /* Need to init to non-NULL. */
+ program_path = xstrdup (PKGLIBDIR); /* Need to init to non-null. */
set_LD_PRELOAD ();
free (program_path);
{"crt", combination, OMIT, 0, 0},
{"dec", combination, OMIT, 0, 0},
- {NULL, control, 0, 0, 0}
+ {nullptr, control, 0, 0, 0}
};
/* Control character settings. */
/* These must be last because of the display routines. */
{"min", 1, VMIN},
{"time", 0, VTIME},
- {NULL, 0, 0}
+ {nullptr, 0, 0}
};
static char const *visible (cc_t ch);
static struct option const longopts[] =
{
- {"all", no_argument, NULL, 'a'},
- {"save", no_argument, NULL, 'g'},
- {"file", required_argument, NULL, 'F'},
- {"-debug", no_argument, NULL, DEV_DEBUG_OPTION},
+ {"all", no_argument, nullptr, 'a'},
+ {"save", no_argument, nullptr, 'g'},
+ {"file", required_argument, nullptr, 'F'},
+ {"-debug", no_argument, nullptr, DEV_DEBUG_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Print format string MESSAGE and optional args.
tcsetattr_options = reversed ? TCSANOW : TCSADRAIN;
continue;
}
- for (i = 0; mode_info[i].name != NULL; ++i)
+ for (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 != NULL; ++i)
+ for (i = 0; control_info[i].name != nullptr; ++i)
{
if (STREQ (arg, control_info[i].name))
{
bool verbose_output;
bool recoverable_output;
bool noargs = true;
- char *file_name = NULL;
+ char *file_name = nullptr;
char const *device_name;
initialize_main (&argc, &argv);
short and long options, --, POSIXLY_CORRECT, etc. */
while ((optc = getopt_long (argc - argi, argv + argi, "-agF:",
- longopts, NULL))
+ longopts, nullptr))
!= -1)
{
switch (optc)
/* Clear fully-parsed arguments, so they don't confuse the 2nd pass. */
while (opti < optind)
- argv[argi + opti++] = NULL;
+ argv[argi + opti++] = nullptr;
}
/* Specifying both -a and -g gets an error. */
bitsp = mode_type_flag (info->type, mode);
- if (bitsp == NULL)
+ if (bitsp == nullptr)
{
/* Combination mode. */
if (STREQ (info->name, "evenp") || STREQ (info->name, "parity"))
/* Use $COLUMNS if it's in [1..INT_MAX]. */
char *col_string = getenv ("COLUMNS");
long int n_columns;
- if (!(col_string != NULL
- && xstrtol (col_string, NULL, 0, &n_columns, "") == LONGINT_OK
+ if (!(col_string != nullptr
+ && xstrtol (col_string, nullptr, 0, &n_columns, "") == LONGINT_OK
&& 0 < n_columns
&& n_columns <= INT_MAX))
n_columns = 80;
return &mode->c_lflag;
case combination:
- return NULL;
+ return nullptr;
default:
abort ();
current_col = 0;
empty_line = true;
- for (i = 0; mode_info[i].name != NULL; ++i)
+ for (i = 0; mode_info[i].name != nullptr; ++i)
{
if (mode_info[i].flags & OMIT)
continue;
bitsp = mode_type_flag (mode_info[i].type, mode);
mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
- /* bitsp would be NULL only for "combination" modes, yet those
+ /* bitsp would be null only for "combination" modes, yet those
are filtered out above via the OMIT flag. Tell static analysis
tools that it's ok to dereference bitsp here. */
assert (bitsp);
putchar ('\n');
current_col = 0;
- for (i = 0; mode_info[i].name != NULL; ++i)
+ for (i = 0; mode_info[i].name != nullptr; ++i)
{
if (mode_info[i].flags & OMIT)
continue;
#ifdef B4000000
{"4000000", B4000000, 4000000},
#endif
- {NULL, 0, 0}
+ {nullptr, 0, 0}
};
ATTRIBUTE_PURE
static speed_t
string_to_baud (char const *arg)
{
- for (int i = 0; speeds[i].string != NULL; ++i)
+ for (int i = 0; speeds[i].string != nullptr; ++i)
if (STREQ (arg, speeds[i].string))
return speeds[i].speed;
return (speed_t) -1;
static unsigned long int
baud_to_value (speed_t speed)
{
- for (int i = 0; speeds[i].string != NULL; ++i)
+ for (int i = 0; speeds[i].string != nullptr; ++i)
if (speed == speeds[i].speed)
return speeds[i].value;
return 0;
mode->c_cc[control_info[i].offset] = control_info[i].saneval;
}
- for (i = 0; mode_info[i].name != NULL; ++i)
+ for (i = 0; mode_info[i].name != nullptr; ++i)
{
if (mode_info[i].flags & NO_SETATTR)
continue;
static struct option const long_options[] =
{
- {"data", no_argument, NULL, 'd'},
- {"file-system", no_argument, NULL, 'f'},
+ {"data", no_argument, nullptr, 'd'},
+ {"file-system", no_argument, nullptr, 'f'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "df", long_options, NULL))
+ while ((c = getopt_long (argc, argv, "df", long_options, nullptr))
!= -1)
{
switch (c)
while (true)
{
struct dirent const *dp = readdir (dirp);
- if (dp == NULL || ! dot_or_dotdot (dp->d_name))
+ if (dp == nullptr || ! dot_or_dotdot (dp->d_name))
return dp;
}
}
return errno;
dirp = fdopendir (fd);
- if (dirp == NULL)
+ if (dirp == nullptr)
{
saved_errno = errno;
close (fd);
};
#define GETOPT_HELP_OPTION_DECL \
- "help", no_argument, NULL, GETOPT_HELP_CHAR
+ "help", no_argument, nullptr, GETOPT_HELP_CHAR
#define GETOPT_VERSION_OPTION_DECL \
- "version", no_argument, NULL, GETOPT_VERSION_CHAR
+ "version", no_argument, nullptr, GETOPT_VERSION_CHAR
#define GETOPT_SELINUX_CONTEXT_OPTION_DECL \
- "context", optional_argument, NULL, 'Z'
+ "context", optional_argument, nullptr, 'Z'
#define case_GETOPT_HELP_CHAR \
case GETOPT_HELP_CHAR: \
#define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
case GETOPT_VERSION_CHAR: \
version_etc (stdout, Program_name, PACKAGE_NAME, Version, Authors, \
- (char *) NULL); \
+ (char *) nullptr); \
exit (EXIT_SUCCESS); \
break;
#define DECIMAL_DIGIT_ACCUMULATE(Accum, Digit_val, Type) \
( \
- (void) (&(Accum) == (Type *) NULL), /* The type matches. */ \
+ (void) (&(Accum) == (Type *) nullptr), /* The type matches. */ \
verify_expr (! TYPE_SIGNED (Type), /* The type is unsigned. */ \
(((Type) -1 / 10 < (Accum) \
|| (Type) ((Accum) * 10 + (Digit_val)) < (Accum)) \
{ "sha256sum", "sha2 utilities" },
{ "sha384sum", "sha2 utilities" },
{ "sha512sum", "sha2 utilities" },
- { NULL, NULL }
+ { nullptr, nullptr }
};
char const *node = program;
/* Don't output this redundant message for English locales.
Note we still output for 'C' so that it gets included in the man page. */
- char const *lc_messages = setlocale (LC_MESSAGES, NULL);
+ char const *lc_messages = setlocale (LC_MESSAGES, nullptr);
if (lc_messages && STRNCMP_LIT (lc_messages, "en_"))
{
/* TRANSLATORS: Replace LANG_CODE in this URL with your language code
char *buf = (char *) malloc (BUFFER_SIZE);
size_t bytes_read;
- if (buf == NULL)
+ if (buf == nullptr)
{
/* Fall back on the code that relies on a temporary file.
Write all buffers to that file and free them. */
if (!last_byte_is_eol_byte)
{
char *buf = malloc (1);
- if (buf == NULL)
+ if (buf == nullptr)
{
/* FIXME: just like above */
ok = false;
{
for (size_t i = 0; i < x->n_bufs; i++)
free (x->p[i].start);
- obstack_free (OBS, NULL);
+ obstack_free (OBS, nullptr);
}
Line_ptr
static struct option const longopts[] =
{
- {"before", no_argument, NULL, 'b'},
- {"regex", no_argument, NULL, 'r'},
- {"separator", required_argument, NULL, 's'},
+ {"before", no_argument, nullptr, 'b'},
+ {"regex", no_argument, nullptr, 'r'},
+ {"separator", required_argument, nullptr, 's'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
}
/* Print the characters from START to PAST_END - 1.
- If START is NULL, just flush the buffer. */
+ If START is null, just flush the buffer. */
static void
output (char const *start, char const *past_end)
static bool
temp_stream (FILE **fp, char **file_name)
{
- static char *tempfile = NULL;
+ static char *tempfile = nullptr;
static FILE *tmp_fp;
- if (tempfile == NULL)
+ if (tempfile == nullptr)
{
char const *t = getenv ("TMPDIR");
char const *tempdir = t ? t : DEFAULT_TMPDIR;
- tempfile = mfile_name_concat (tempdir, "tacXXXXXX", NULL);
- if (tempdir == NULL)
+ tempfile = mfile_name_concat (tempdir, "tacXXXXXX", nullptr);
+ if (tempdir == nullptr)
{
error (0, 0, _("memory exhausted"));
return false;
unlink (tempfile);
Reset:
free (tempfile);
- tempfile = NULL;
+ tempfile = nullptr;
return false;
}
/* Initializer for file_list if no file-arguments
were specified on the command line. */
- static char const *const default_file_list[] = {"-", NULL};
+ static char const *const default_file_list[] = {"-", nullptr};
char const *const *file;
initialize_main (&argc, &argv);
sentinel_length = 1;
separator_ends_record = true;
- while ((optc = getopt_long (argc, argv, "brs:", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "brs:", longopts, nullptr)) != -1)
{
switch (optc)
{
if (*separator == 0)
die (EXIT_FAILURE, 0, _("separator cannot be empty"));
- compiled_separator.buffer = NULL;
+ compiled_separator.buffer = nullptr;
compiled_separator.allocated = 0;
compiled_separator.fastmap = compiled_separator_fastmap;
- compiled_separator.translate = NULL;
+ compiled_separator.translate = nullptr;
error_message = re_compile_pattern (separator, strlen (separator),
&compiled_separator);
if (error_message)
}
/* Flush the output buffer. */
- output ((char *) NULL, (char *) NULL);
+ output ((char *) nullptr, (char *) nullptr);
if (have_read_stdin && close (STDIN_FILENO) < 0)
{
static char const *const follow_mode_string[] =
{
- "descriptor", "name", NULL
+ "descriptor", "name", nullptr
};
static enum Follow_mode const follow_mode_map[] =
static struct option const long_options[] =
{
- {"bytes", required_argument, NULL, 'c'},
- {"follow", optional_argument, NULL, LONG_FOLLOW_OPTION},
- {"lines", required_argument, NULL, 'n'},
- {"max-unchanged-stats", required_argument, NULL, MAX_UNCHANGED_STATS_OPTION},
- {"-disable-inotify", no_argument, NULL,
+ {"bytes", required_argument, nullptr, 'c'},
+ {"follow", optional_argument, nullptr, LONG_FOLLOW_OPTION},
+ {"lines", required_argument, nullptr, 'n'},
+ {"max-unchanged-stats", required_argument, nullptr,
+ MAX_UNCHANGED_STATS_OPTION},
+ {"-disable-inotify", no_argument, nullptr,
DISABLE_INOTIFY_OPTION}, /* do not document */
- {"pid", required_argument, NULL, PID_OPTION},
- {"-presume-input-pipe", no_argument, NULL,
+ {"pid", required_argument, nullptr, PID_OPTION},
+ {"-presume-input-pipe", no_argument, nullptr,
PRESUME_INPUT_PIPE_OPTION}, /* do not document */
- {"quiet", no_argument, NULL, 'q'},
- {"retry", no_argument, NULL, RETRY_OPTION},
- {"silent", no_argument, NULL, 'q'},
- {"sleep-interval", required_argument, NULL, 's'},
- {"verbose", no_argument, NULL, 'v'},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"quiet", no_argument, nullptr, 'q'},
+ {"retry", no_argument, nullptr, RETRY_OPTION},
+ {"silent", no_argument, nullptr, 'q'},
+ {"sleep-interval", required_argument, nullptr, 's'},
+ {"verbose", no_argument, nullptr, 'v'},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
{
char const *nl;
nl = memrchr (buffer, line_end, n);
- if (nl == NULL)
+ if (nl == nullptr)
break;
n = nl - buffer;
if (n_lines-- == 0)
first = last = xmalloc (sizeof (LBUFFER));
first->nbytes = first->nlines = 0;
- first->next = NULL;
+ first->next = nullptr;
tmp = xmalloc (sizeof (LBUFFER));
/* Input is always read into a fresh buffer. */
tmp->nbytes = n_read;
*read_pos += n_read;
tmp->nlines = 0;
- tmp->next = NULL;
+ tmp->next = nullptr;
/* Count the number of newlines just read. */
{
first = last = xmalloc (sizeof (CBUFFER));
first->nbytes = 0;
- first->next = NULL;
+ first->next = nullptr;
tmp = xmalloc (sizeof (CBUFFER));
/* Input is always read into a fresh buffer. */
break;
*read_pos += n_read;
tmp->nbytes = n_read;
- tmp->next = NULL;
+ tmp->next = nullptr;
total_bytes += tmp->nbytes;
/* If there is enough room in the last buffer read, just append the new
size_t evbuf_off = 0;
size_t len = 0;
- wd_to_name = hash_initialize (n_files, NULL, wd_hasher, wd_comparator, NULL);
+ wd_to_name = hash_initialize (n_files, nullptr, wd_hasher, wd_comparator,
+ nullptr);
if (! wd_to_name)
xalloc_die ();
*wd_to_namep = wd_to_name;
continue;
}
- if (hash_insert (wd_to_name, &(f[i])) == NULL)
+ if (hash_insert (wd_to_name, &(f[i])) == nullptr)
xalloc_die ();
found_watchable_file = true;
close_fd (prev->fd, pretty_name (prev));
}
- if (hash_insert (wd_to_name, fspec) == NULL)
+ if (hash_insert (wd_to_name, fspec) == nullptr)
xalloc_die ();
}
if (n_string == n_string_end)
*n_units = default_count;
- else if ((xstrtoumax (n_string, NULL, 10, n_units, "b")
+ else if ((xstrtoumax (n_string, nullptr, 10, n_units, "b")
& ~LONGINT_INVALID_SUFFIX_CHAR)
!= LONGINT_OK)
{
int c;
while ((c = getopt_long (argc, argv, "c:n:fFqs:vz0123456789",
- long_options, NULL))
+ long_options, nullptr))
!= -1)
{
switch (c)
case 'f':
case LONG_FOLLOW_OPTION:
forever = true;
- if (optarg == NULL)
+ if (optarg == nullptr)
follow_mode = DEFAULT_FOLLOW_MODE;
else
follow_mode = XARGMATCH ("--follow", optarg,
case 's':
{
double s;
- if (! (xstrtod (optarg, NULL, &s, cl_strtod) && 0 <= s))
+ if (! (xstrtod (optarg, nullptr, &s, cl_strtod) && 0 <= s))
die (EXIT_FAILURE, 0,
_("invalid number of seconds: %s"), quote (optarg));
*sleep_interval = s;
static struct option const long_options[] =
{
- {"append", no_argument, NULL, 'a'},
- {"ignore-interrupts", no_argument, NULL, 'i'},
- {"output-error", optional_argument, NULL, 'p'},
+ {"append", no_argument, nullptr, 'a'},
+ {"ignore-interrupts", no_argument, nullptr, 'i'},
+ {"output-error", optional_argument, nullptr, 'p'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static char const *const output_error_args[] =
{
- "warn", "warn-nopipe", "exit", "exit-nopipe", NULL
+ "warn", "warn-nopipe", "exit", "exit-nopipe", nullptr
};
static enum output_error const output_error_types[] =
{
ignore_interrupts = false;
int optc;
- while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "aip", long_options, nullptr)) != -1)
{
switch (optc)
{
}
-/* Return the index of the first non-NULL descriptor after idx,
- or -1 if all are NULL. */
+/* Return the index of the first non-null descriptor after idx,
+ or -1 if all are null. */
static int
get_next_out (FILE **descriptors, int nfiles, int idx)
|| output_error == output_error_exit_nopipe,
w_errno, "%s", quotef (files[i]));
}
- descriptors[i] = NULL;
+ descriptors[i] = nullptr;
return fail;
}
{
size_t n_outputs = 0;
FILE **descriptors;
- bool *out_pollable IF_LINT ( = NULL);
+ 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 */
+ int first_out = 0; /* idx of first non-null output in descriptors */
bool ok = true;
char const *mode_string =
(O_BINARY
if (pipe_check)
out_pollable[0] = iopoll_output_ok (fileno (descriptors[0]));
files[0] = bad_cast (_("standard output"));
- setvbuf (stdout, NULL, _IONBF, 0);
+ setvbuf (stdout, nullptr, _IONBF, 0);
n_outputs++;
for (i = 1; i <= nfiles; i++)
{
/* Do not treat "-" specially - as mandated by POSIX. */
descriptors[i] = fopen (files[i], mode_string);
- if (descriptors[i] == NULL)
+ if (descriptors[i] == nullptr)
{
if (pipe_check)
out_pollable[i] = false;
{
if (pipe_check)
out_pollable[i] = iopoll_output_ok (fileno (descriptors[i]));
- setvbuf (descriptors[i], NULL, _IONBF, 0);
+ setvbuf (descriptors[i], nullptr, _IONBF, 0);
n_outputs++;
}
}
unary_advance ();
arg = find_int (argv[pos - 1]);
errno = 0;
- fd = strtol (arg, NULL, 10);
+ fd = strtol (arg, nullptr, 10);
return (errno != ERANGE && 0 <= fd && fd <= INT_MAX && isatty (fd));
}
if (STREQ (margv[1], "--version"))
{
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
- (char *) NULL);
+ (char *) nullptr);
test_main_return (EXIT_SUCCESS);
}
}
static struct option const long_options[] =
{
- {"kill-after", required_argument, NULL, 'k'},
- {"signal", required_argument, NULL, 's'},
- {"verbose", no_argument, NULL, 'v'},
- {"foreground", no_argument, NULL, FOREGROUND_OPTION},
- {"preserve-status", no_argument, NULL, PRESERVE_STATUS_OPTION},
+ {"kill-after", required_argument, nullptr, 'k'},
+ {"signal", required_argument, nullptr, 's'},
+ {"verbose", no_argument, nullptr, 'v'},
+ {"foreground", no_argument, nullptr, FOREGROUND_OPTION},
+ {"preserve-status", no_argument, nullptr, PRESERVE_STATUS_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Start the timeout after which we'll receive a SIGALRM.
struct timespec ts = dtotimespec (duration);
struct itimerspec its = { {0, 0}, ts };
timer_t timerid;
- if (timer_create (CLOCK_REALTIME, NULL, &timerid) == 0)
+ if (timer_create (CLOCK_REALTIME, nullptr, &timerid) == 0)
{
- if (timer_settime (timerid, 0, &its, NULL) == 0)
+ if (timer_settime (timerid, 0, &its, nullptr) == 0)
return;
else
{
tv.tv_usec--;
}
struct itimerval it = { {0, 0}, tv };
- if (setitimer (ITIMER_REAL, &it, NULL) == 0)
+ if (setitimer (ITIMER_REAL, &it, nullptr) == 0)
return;
else
{
sigset_t unblock_set;
sigemptyset (&unblock_set);
sigaddset (&unblock_set, sig);
- if (sigprocmask (SIG_UNBLOCK, &unblock_set, NULL) != 0)
+ if (sigprocmask (SIG_UNBLOCK, &unblock_set, nullptr) != 0)
error (0, errno, _("warning: sigprocmask"));
}
sa.sa_flags = SA_RESTART; /* Restart syscalls if possible, as that's
more likely to work cleanly. */
- sigaction (SIGCHLD, &sa, NULL);
+ sigaction (SIGCHLD, &sa, nullptr);
/* We inherit the signal mask from our parent process,
so ensure SIGCHLD is not blocked. */
sa.sa_flags = SA_RESTART; /* Restart syscalls if possible, as that's
more likely to work cleanly. */
- sigaction (SIGALRM, &sa, NULL); /* our timeout. */
- sigaction (SIGINT, &sa, NULL); /* Ctrl-C at terminal for example. */
- sigaction (SIGQUIT, &sa, NULL); /* Ctrl-\ at terminal for example. */
- sigaction (SIGHUP, &sa, NULL); /* terminal closed for example. */
- sigaction (SIGTERM, &sa, NULL); /* if we're killed, stop monitored proc. */
- sigaction (sigterm, &sa, NULL); /* user specified termination signal. */
+ sigaction (SIGALRM, &sa, nullptr); /* our timeout. */
+ sigaction (SIGINT, &sa, nullptr); /* Ctrl-C at terminal for example. */
+ sigaction (SIGQUIT, &sa, nullptr); /* Ctrl-\ at terminal for example. */
+ sigaction (SIGHUP, &sa, nullptr); /* terminal closed for example. */
+ sigaction (SIGTERM, &sa, nullptr); /* if killed, stop monitored proc. */
+ sigaction (sigterm, &sa, nullptr); /* user specified termination signal. */
}
/* Block all signals which were registered with cleanup() as the signal
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "+k:s:v", long_options, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "+k:s:v", long_options, nullptr)) != -1)
{
switch (c)
{
static struct option const longopts[] =
{
- {"time", required_argument, NULL, TIME_OPTION},
- {"no-create", no_argument, NULL, 'c'},
- {"date", required_argument, NULL, 'd'},
- {"reference", required_argument, NULL, 'r'},
- {"no-dereference", no_argument, NULL, 'h'},
+ {"time", required_argument, nullptr, TIME_OPTION},
+ {"no-create", no_argument, nullptr, 'c'},
+ {"date", required_argument, nullptr, 'd'},
+ {"reference", required_argument, nullptr, 'r'},
+ {"no-dereference", no_argument, nullptr, 'h'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Valid arguments to the '--time' option. */
static char const *const time_args[] =
{
- "atime", "access", "use", "mtime", "modify", NULL
+ "atime", "access", "use", "mtime", "modify", nullptr
};
/* The bits in 'change_times' that those arguments set. */
if (amtime_now)
{
- /* Pass NULL to futimens so it will not fail if we have
+ /* Pass nullptr to futimens so it will not fail if we have
write access to the file, but don't own it. */
- t = NULL;
+ t = nullptr;
}
- char const *file_opt = fd == STDOUT_FILENO ? NULL : file;
+ char const *file_opt = fd == STDOUT_FILENO ? nullptr : file;
int atflag = no_dereference ? AT_SYMLINK_NOFOLLOW : 0;
int utime_errno = (fdutimensat (fd, AT_FDCWD, file_opt, t, atflag) == 0
? 0 : errno);
int c;
bool date_set = false;
bool ok = true;
- char const *flex_date = NULL;
+ char const *flex_date = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
change_times = 0;
no_create = use_ref = false;
- while ((c = getopt_long (argc, argv, "acd:fhmr:t:", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "acd:fhmr:t:", longopts, nullptr)) != -1)
{
switch (c)
{
struct tm const *tm = localtime (&newtime[0].tv_sec);
/* Technically, it appears that even a deliberate attempt to cause
- the above localtime to return NULL will always fail because our
+ the above localtime to return nullptr will always fail because our
posixtime implementation rejects all dates for which localtime
would fail. However, skip the warning if it ever fails. */
if (tm)
static struct option const long_options[] =
{
- {"complement", no_argument, NULL, 'c'},
- {"delete", no_argument, NULL, 'd'},
- {"squeeze-repeats", no_argument, NULL, 's'},
- {"truncate-set1", no_argument, NULL, 't'},
+ {"complement", no_argument, nullptr, 'c'},
+ {"delete", no_argument, nullptr, 'd'},
+ {"squeeze-repeats", no_argument, nullptr, 's'},
+ {"truncate-set1", no_argument, nullptr, 't'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
for (size_t i = 0; i < len; i++)
{
char buf[5];
- char const *tmp = NULL;
+ char const *tmp = nullptr;
unsigned char c = s[i];
switch (c)
append_normal_char (struct Spec_list *list, unsigned char c)
{
struct List_element *new = xmalloc (sizeof *new);
- new->next = NULL;
+ new->next = nullptr;
new->type = RE_NORMAL_CHAR;
new->u.normal_char = c;
assert (list->tail);
return false;
}
struct List_element *new = xmalloc (sizeof *new);
- new->next = NULL;
+ new->next = nullptr;
new->type = RE_RANGE;
new->u.range.first_char = first;
new->u.range.last_char = last;
if (char_class == CC_NO_CLASS)
return false;
struct List_element *new = xmalloc (sizeof *new);
- new->next = NULL;
+ new->next = nullptr;
new->type = RE_CHAR_CLASS;
new->u.char_class = char_class;
assert (list->tail);
count repeat_count)
{
struct List_element *new = xmalloc (sizeof *new);
- new->next = NULL;
+ new->next = nullptr;
new->type = RE_REPEATED_CHAR;
new->u.repeated_char.the_repeated_char = the_char;
new->u.repeated_char.repeat_count = repeat_count;
return false;
struct List_element *new = xmalloc (sizeof *new);
- new->next = NULL;
+ new->next = nullptr;
new->type = RE_EQUIV_CLASS;
new->u.equiv_code = *equiv_class_str;
assert (list->tail);
char const *digit_str = &es->s[start_idx + 2];
char *d_end;
if ((xstrtoumax (digit_str, &d_end, *digit_str == '0' ? 8 : 10,
- repeat_count, NULL)
+ repeat_count, nullptr)
!= LONGINT_OK)
|| REPEAT_COUNT_MAXIMUM < *repeat_count
|| digit_str + digit_str_len != d_end)
}
/* Advance past the current construct.
- S->tail must be non-NULL. */
+ S->tail must be non-null. */
static void
skip_construct (struct Spec_list *s)
{
}
p = s->tail;
- if (p == NULL)
+ if (p == nullptr)
return -1;
switch (p->type)
bool in_set[N_CHARS] = { 0, };
s->state = BEGIN_STATE;
- while ((c = get_next (s, NULL)) != -1)
+ while ((c = get_next (s, nullptr)) != -1)
{
cardinality -= (!in_set[c]);
in_set[c] = true;
{
struct List_element *new = xmalloc (sizeof *new);
spec_list->head = spec_list->tail = new;
- spec_list->head->next = NULL;
+ spec_list->head->next = nullptr;
}
/* This function makes two passes over the argument string S. The first
s->state = BEGIN_STATE;
- if ((b = get_next (s, NULL)) == -1)
+ if ((b = get_next (s, nullptr)) == -1)
return false;
- while ((c = get_next (s, NULL)) != -1)
+ while ((c = get_next (s, nullptr)) != -1)
if (c != b)
return false;
}
/* Read buffers of SIZE bytes via the function READER (if READER is
- NULL, read from stdin) until EOF. When non-NULL, READER is either
+ null, read from stdin) until EOF. When non-null, READER is either
read_and_delete or read_and_xlate. After each buffer is read, it is
processed and written to stdout. The buffers are processed so that
multiple consecutive occurrences of the same character in the input
int c;
s->state = BEGIN_STATE;
- while ((c = get_next (s, NULL)) != -1)
+ while ((c = get_next (s, nullptr)) != -1)
in_set[c] = true;
if (complement_this_set)
for (size_t i = 0; i < N_CHARS; i++)
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "+AcCdst", long_options, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "+AcCdst", long_options, nullptr)) != -1)
{
switch (c)
{
main_exit (EXIT_FAILURE);
}
else
- s2 = NULL;
+ s2 = nullptr;
validate (s1, s2);
{
if (!in_s1[i])
{
- int ch = get_next (s2, NULL);
+ int ch = get_next (s2, nullptr);
assert (ch != -1 || truncate_set1);
if (ch == -1)
{
if (STREQ (argv[1], "--version"))
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
- (char *) NULL);
+ (char *) nullptr);
}
return EXIT_STATUS;
static struct option const longopts[] =
{
- {"no-create", no_argument, NULL, 'c'},
- {"io-blocks", no_argument, NULL, 'o'},
- {"reference", required_argument, NULL, 'r'},
- {"size", required_argument, NULL, 's'},
+ {"no-create", no_argument, nullptr, 'c'},
+ {"io-blocks", no_argument, nullptr, 'o'},
+ {"reference", required_argument, nullptr, 'r'},
+ {"size", required_argument, nullptr, 's'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
typedef enum
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, "cor:s:", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "cor:s:", longopts, nullptr)) != -1)
{
switch (c)
{
};
/* The head of the sorted list. */
-static struct item *head = NULL;
+static struct item *head = nullptr;
/* The tail of the list of 'zeros', strings that have no predecessors. */
-static struct item *zeros = NULL;
+static struct item *zeros = nullptr;
/* Used for loop detection. */
-static struct item *loop = NULL;
+static struct item *loop = nullptr;
/* The number of strings to sort. */
static size_t n_strings = 0;
}
/* Search binary tree rooted at *ROOT for STR. Allocate a new tree if
- *ROOT is NULL. Insert a node/item for STR if not found. Return
+ *ROOT is null. Insert a node/item for STR if not found. Return
the node/item found/created for STR.
This is done according to Algorithm A (Balanced tree search and
/* Make sure the tree is not empty, since that is what the algorithm
below expects. */
- if (root->right == NULL)
+ if (root->right == nullptr)
return (root->right = new_item (str));
/* A1. Initialize. */
else
q = p->right;
- if (q == NULL)
+ if (q == nullptr)
{
/* A5. Insert. */
q = new_item (str);
/* Ignore strings that have already been printed. */
if (k->count == 0 && !k->printed)
{
- if (head == NULL)
+ if (head == nullptr)
head = k;
else
zeros->qlink = k;
are stored in the tree is not related to the specified partial
ordering, we may need to walk the tree several times before the
loop has completely been constructed. If the loop was found, the
- global variable LOOP will be NULL. */
+ global variable LOOP will be null. */
static bool
detect_loop (struct item *k)
/* K does not have to be part of a cycle. It is however part of
a graph that contains a cycle. */
- if (loop == NULL)
+ if (loop == nullptr)
/* Start traversing the graph at K. */
loop = k;
else
/* Tidy things up since we might have to
detect another loop. */
- loop->qlink = NULL;
+ loop->qlink = nullptr;
loop = tmp;
}
{
struct item *tmp = loop->qlink;
- loop->qlink = NULL;
+ loop->qlink = nullptr;
loop = tmp;
}
static bool
recurse_tree (struct item *root, bool (*action) (struct item *))
{
- if (root->left == NULL && root->right == NULL)
+ if (root->left == nullptr && root->right == nullptr)
return (*action) (root);
else
{
- if (root->left != NULL)
+ if (root->left != nullptr)
if (recurse_tree (root->left, action))
return true;
if ((*action) (root))
return true;
- if (root->right != NULL)
+ if (root->right != nullptr)
if (recurse_tree (root->right, action))
return true;
}
{
bool ok = true;
struct item *root;
- struct item *j = NULL;
- struct item *k = NULL;
+ struct item *j = nullptr;
+ struct item *k = nullptr;
token_buffer tokenbuffer;
bool is_stdin = STREQ (file, "-");
/* Intialize the head of the tree will hold the strings we're sorting. */
- root = new_item (NULL);
+ root = new_item (nullptr);
if (!is_stdin && ! freopen (file, "r", stdin))
die (EXIT_FAILURE, errno, "%s", quotef (file));
{
/* T3. Record the relation. */
record_relation (j, k);
- k = NULL;
+ k = nullptr;
}
j = k;
}
- if (k != NULL)
+ if (k != nullptr)
die (EXIT_FAILURE, 0, _("%s: input contains an odd number of tokens"),
quotef (file));
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (1 < argc - optind)
{
static struct option const longopts[] =
{
- {"silent", no_argument, NULL, 's'},
- {"quiet", no_argument, NULL, 's'},
+ {"silent", no_argument, nullptr, 's'},
+ {"quiet", no_argument, nullptr, 's'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
silent = false;
- while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "s", longopts, nullptr)) != -1)
{
switch (optc)
{
static struct option const uname_long_options[] =
{
- {"all", no_argument, NULL, 'a'},
- {"kernel-name", no_argument, NULL, 's'},
- {"sysname", no_argument, NULL, 's'}, /* Obsolescent. */
- {"nodename", no_argument, NULL, 'n'},
- {"kernel-release", no_argument, NULL, 'r'},
- {"release", no_argument, NULL, 'r'}, /* Obsolescent. */
- {"kernel-version", no_argument, NULL, 'v'},
- {"machine", no_argument, NULL, 'm'},
- {"processor", no_argument, NULL, 'p'},
- {"hardware-platform", no_argument, NULL, 'i'},
- {"operating-system", no_argument, NULL, 'o'},
+ {"all", no_argument, nullptr, 'a'},
+ {"kernel-name", no_argument, nullptr, 's'},
+ {"sysname", no_argument, nullptr, 's'}, /* Obsolescent. */
+ {"nodename", no_argument, nullptr, 'n'},
+ {"kernel-release", no_argument, nullptr, 'r'},
+ {"release", no_argument, nullptr, 'r'}, /* Obsolescent. */
+ {"kernel-version", no_argument, nullptr, 'v'},
+ {"machine", no_argument, nullptr, 'm'},
+ {"processor", no_argument, nullptr, 'p'},
+ {"hardware-platform", no_argument, nullptr, 'i'},
+ {"operating-system", no_argument, nullptr, 'o'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
static struct option const arch_long_options[] =
{
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
if (uname_mode == UNAME_ARCH)
{
while ((c = getopt_long (argc, argv, "",
- arch_long_options, NULL)) != -1)
+ arch_long_options, nullptr))
+ != -1)
{
switch (c)
{
else
{
while ((c = getopt_long (argc, argv, "asnrvmpio",
- uname_long_options, NULL)) != -1)
+ uname_long_options, nullptr))
+ != -1)
{
switch (c)
{
static struct option const longopts[] =
{
- {"tabs", required_argument, NULL, 't'},
- {"all", no_argument, NULL, 'a'},
- {"first-only", no_argument, NULL, CONVERT_FIRST_ONLY_OPTION},
+ {"tabs", required_argument, nullptr, 't'},
+ {"all", no_argument, nullptr, 'a'},
+ {"first-only", no_argument, nullptr, CONVERT_FIRST_ONLY_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
unexpand (void)
{
/* Input stream. */
- FILE *fp = next_file (NULL);
+ FILE *fp = next_file (nullptr);
/* The array of pending blanks. In non-POSIX locales, blanks can
include characters other than spaces, so the blanks must be
atexit (close_stdout);
- while ((c = getopt_long (argc, argv, ",0123456789at:", longopts, NULL))
+ while ((c = getopt_long (argc, argv, ",0123456789at:", longopts, nullptr))
!= -1)
{
switch (c)
finalize_tab_stops ();
- set_file_list ((optind < argc) ? &argv[optind] : NULL);
+ set_file_list ((optind < argc) ? &argv[optind] : nullptr);
unexpand ();
static char const *const delimit_method_string[] =
{
- "none", "prepend", "separate", NULL
+ "none", "prepend", "separate", nullptr
};
static enum delimit_method const delimit_method_map[] =
static char const *const grouping_method_string[] =
{
- "prepend", "append", "separate", "both", NULL
+ "prepend", "append", "separate", "both", nullptr
};
static enum grouping_method const grouping_method_map[] =
static struct option const longopts[] =
{
- {"count", no_argument, NULL, 'c'},
- {"repeated", no_argument, NULL, 'd'},
- {"all-repeated", optional_argument, NULL, 'D'},
- {"group", optional_argument, NULL, GROUP_OPTION},
- {"ignore-case", no_argument, NULL, 'i'},
- {"unique", no_argument, NULL, 'u'},
- {"skip-fields", required_argument, NULL, 'f'},
- {"skip-chars", required_argument, NULL, 's'},
- {"check-chars", required_argument, NULL, 'w'},
- {"zero-terminated", no_argument, NULL, 'z'},
+ {"count", no_argument, nullptr, 'c'},
+ {"repeated", no_argument, nullptr, 'd'},
+ {"all-repeated", optional_argument, nullptr, 'D'},
+ {"group", optional_argument, nullptr, GROUP_OPTION},
+ {"ignore-case", no_argument, nullptr, 'i'},
+ {"unique", no_argument, nullptr, 'u'},
+ {"skip-fields", required_argument, nullptr, 'f'},
+ {"skip-chars", required_argument, nullptr, 's'},
+ {"check-chars", required_argument, nullptr, 'w'},
+ {"zero-terminated", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
void
{
uintmax_t size;
- switch (xstrtoumax (opt, NULL, 10, &size, ""))
+ switch (xstrtoumax (opt, nullptr, 10, &size, ""))
{
case LONGINT_OK:
case LONGINT_OVERFLOW:
*/
if (output_unique && output_first_repeated && countmode == count_none)
{
- char *prevfield = NULL;
+ char *prevfield = nullptr;
size_t prevlen;
bool first_group_printed = false;
main (int argc, char **argv)
{
int optc = 0;
- bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
+ bool posixly_correct = (getenv ("POSIXLY_CORRECT") != nullptr);
enum Skip_field_option_type skip_field_option_type = SFO_NONE;
unsigned int nfiles = 0;
char const *file[2];
if (optc == -1
|| (posixly_correct && nfiles != 0)
|| ((optc = getopt_long (argc, argv,
- "-0123456789Dcdf:is:uw:z", longopts, NULL))
+ "-0123456789Dcdf:is:uw:z",
+ longopts, nullptr))
== -1))
{
if (argc <= optind)
uintmax_t size;
if (optarg[0] == '+'
&& ! strict_posix2 ()
- && xstrtoumax (optarg, NULL, 10, &size, "") == LONGINT_OK
+ && xstrtoumax (optarg, nullptr, 10, &size, "") == LONGINT_OK
&& size <= SIZE_MAX)
skip_chars = size;
else if (nfiles == 2)
case 'D':
output_unique = false;
output_later_repeated = true;
- if (optarg == NULL)
+ if (optarg == nullptr)
delimit_groups = DM_NONE;
else
delimit_groups = XARGMATCH ("--all-repeated", optarg,
break;
case GROUP_OPTION:
- if (optarg == NULL)
+ if (optarg == nullptr)
grouping = GM_SEPARATE;
else
grouping = XARGMATCH ("--group", optarg,
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (argc < optind + 1)
{
FILE *fp;
fp = fopen ("/proc/uptime", "r");
- if (fp != NULL)
+ if (fp != nullptr)
{
char buf[BUFSIZ];
char *b = fgets (buf, BUFSIZ, fp);
struct timeval result;
size_t result_len = sizeof result;
- if (sysctl (request, 2, &result, &result_len, NULL, 0) >= 0)
+ if (sysctl (request, 2, &result, &result_len, nullptr, 0) >= 0)
boot_time = result.tv_sec;
}
#endif
(void) this;
#endif
- time_now = time (NULL);
+ time_now = time (nullptr);
#if defined HAVE_PROC_UPTIME
if (uptime == 0)
#endif
uptime (char const *filename, int options)
{
size_t n_users;
- STRUCT_UTMP *utmp_buf = NULL;
+ STRUCT_UTMP *utmp_buf = nullptr;
#if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
switch (argc - optind)
{
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
switch (argc - optind)
{
static struct option const longopts[] =
{
- {"bytes", no_argument, NULL, 'c'},
- {"chars", no_argument, NULL, 'm'},
- {"lines", no_argument, NULL, 'l'},
- {"words", no_argument, NULL, 'w'},
- {"debug", no_argument, NULL, DEBUG_PROGRAM_OPTION},
- {"files0-from", required_argument, NULL, FILES0_FROM_OPTION},
- {"max-line-length", no_argument, NULL, 'L'},
- {"total", required_argument, NULL, TOTAL_OPTION},
+ {"bytes", no_argument, nullptr, 'c'},
+ {"chars", no_argument, nullptr, 'm'},
+ {"lines", no_argument, nullptr, 'l'},
+ {"words", no_argument, nullptr, 'w'},
+ {"debug", no_argument, nullptr, DEBUG_PROGRAM_OPTION},
+ {"files0-from", required_argument, nullptr, FILES0_FROM_OPTION},
+ {"max-line-length", no_argument, nullptr, 'L'},
+ {"total", required_argument, nullptr, TOTAL_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
enum total_type
};
static char const *const total_args[] =
{
- "auto", "always", "only", "never", NULL
+ "auto", "always", "only", "never", nullptr
};
static enum total_type const total_types[] =
{
return iswnbspace (btowc (c));
}
-/* FILE is the name of the file (or NULL for standard input)
+/* FILE is the name of the file (or null for standard input)
associated with the specified counters. */
static void
write_counts (uintmax_t lines,
return true;
}
-/* Count words. FILE_X is the name of the file (or NULL for standard
+/* Count words. FILE_X is the name of the file (or null for standard
input) that is open on descriptor FD. *FSTATUS is its status.
CURRENT_POS is the current file offset if known, negative if unknown.
Return true if successful. */
int optc;
size_t nfiles;
char **files;
- char *files_from = NULL;
+ char *files_from = nullptr;
struct fstatus *fstatus;
struct Tokens tok;
page_size = getpagesize ();
/* Line buffer stdout to ensure lines are written atomically and immediately
so that processes running in parallel do not intersperse their output. */
- setvbuf (stdout, NULL, _IOLBF, 0);
+ setvbuf (stdout, nullptr, _IOLBF, 0);
- posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
+ posixly_correct = (getenv ("POSIXLY_CORRECT") != nullptr);
print_lines = print_words = print_chars = print_bytes = false;
print_linelength = false;
total_lines = total_words = total_chars = total_bytes = max_line_length = 0;
- while ((optc = getopt_long (argc, argv, "clLmw", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "clLmw", longopts, nullptr)) != -1)
switch (optc)
{
case 'c':
else
{
stream = fopen (files_from, "r");
- if (stream == NULL)
+ if (stream == nullptr)
die (EXIT_FAILURE, errno, _("cannot open %s for reading"),
quoteaf (files_from));
}
}
else
{
- files = NULL;
+ files = nullptr;
nfiles = 0;
ai = argv_iter_init_stream (stream);
}
}
else
{
- static char *stdin_only[] = { NULL };
+ static char *stdin_only[] = { nullptr };
files = (optind < argc ? argv + optind : stdin_only);
nfiles = (optind < argc ? argc - optind : 1);
ai = argv_iter_init_argv (files);
among many, knowing the record number may help.
FIXME: currently print the record number only with
--files0-from=FILE. Maybe do it for argv, too? */
- if (files_from == NULL)
+ if (files_from == nullptr)
error (0, 0, "%s", _("invalid zero-length file name"));
else
{
However, no arguments on the --files0-from input stream is an error
means don't read anything. */
if (ok && !files_from && argv_iter_n_args (ai) == 0)
- ok &= wc_file (NULL, &fstatus[0]);
+ ok &= wc_file (nullptr, &fstatus[0]);
if (read_tokens)
readtokens0_free (&tok);
write_counts (total_lines, total_words, total_chars, total_bytes,
max_line_length,
- total_mode != total_only ? _("total") : NULL);
+ total_mode != total_only ? _("total") : nullptr);
}
argv_iter_free (ai);
static struct option const longopts[] =
{
- {"all", no_argument, NULL, 'a'},
- {"boot", no_argument, NULL, 'b'},
- {"count", no_argument, NULL, 'q'},
- {"dead", no_argument, NULL, 'd'},
- {"heading", no_argument, NULL, 'H'},
- {"login", no_argument, NULL, 'l'},
- {"lookup", no_argument, NULL, LOOKUP_OPTION},
- {"message", no_argument, NULL, 'T'},
- {"mesg", no_argument, NULL, 'T'},
- {"process", no_argument, NULL, 'p'},
- {"runlevel", no_argument, NULL, 'r'},
- {"short", no_argument, NULL, 's'},
- {"time", no_argument, NULL, 't'},
- {"users", no_argument, NULL, 'u'},
- {"writable", no_argument, NULL, 'T'},
+ {"all", no_argument, nullptr, 'a'},
+ {"boot", no_argument, nullptr, 'b'},
+ {"count", no_argument, nullptr, 'q'},
+ {"dead", no_argument, nullptr, 'd'},
+ {"heading", no_argument, nullptr, 'H'},
+ {"login", no_argument, nullptr, 'l'},
+ {"lookup", no_argument, nullptr, LOOKUP_OPTION},
+ {"message", no_argument, nullptr, 'T'},
+ {"mesg", no_argument, nullptr, 'T'},
+ {"process", no_argument, nullptr, 'p'},
+ {"runlevel", no_argument, nullptr, 'r'},
+ {"short", no_argument, nullptr, 's'},
+ {"time", no_argument, nullptr, 't'},
+ {"users", no_argument, nullptr, 'u'},
+ {"writable", no_argument, nullptr, 'T'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
- {NULL, 0, NULL, 0}
+ {nullptr, 0, nullptr, 0}
};
/* Return a string representing the time between WHEN and now.
if (utmp_ent->ut_host[0])
{
char ut_host[sizeof (utmp_ent->ut_host) + 1];
- char *host = NULL;
- char *display = NULL;
+ char *host = nullptr;
+ char *display = nullptr;
/* Copy the host name into UT_HOST, and ensure it's nul terminated. */
stzncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
static void
scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
{
- char *ttyname_b IF_LINT ( = NULL);
+ char *ttyname_b IF_LINT ( = nullptr);
time_t boottime = TYPE_MINIMUM (time_t);
if (include_heading)
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "abdlmpqrstuwHT", longopts, NULL))
+ while ((optc = getopt_long (argc, argv, "abdlmpqrstuwHT", longopts, nullptr))
!= -1)
{
switch (optc)
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
if (optind != argc)
{
errno = 0;
uid = geteuid ();
- pw = (uid == NO_UID && errno ? NULL : getpwuid (uid));
+ pw = uid == NO_UID && errno ? nullptr : getpwuid (uid);
if (!pw)
die (EXIT_FAILURE, errno, _("cannot find name for user ID %lu"),
(unsigned long int) uid);
parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME,
Version, true, usage, AUTHORS,
- (char const *) NULL);
+ (char const *) nullptr);
char **operands = argv + optind;
char **operand_lim = argv + argc;