* lib/linebuffer.h (struct linebuffer):
* lib/readtokens.c (readtoken, readtokens):
* lib/readutmp.c (read_utmp):
+ * lib/savedir.c (streamsavedir):
Prefer idx_t to size_t for indexes, and use idx_t-related allocators.
* lib/basename.c: Do not include xstrndup.h.
(basename): Simplify by always using memcpy.
char *name_space = NULL;
idx_t allocated = 0;
direntry_t *entries = NULL;
- size_t entries_allocated = 0;
+ idx_t entries_allocated = 0;
idx_t entries_used = 0;
idx_t used = 0;
comparison_function cmp = comparison_function_table[option];
if (cmp)
{
if (entries_allocated == entries_used)
- entries = x2nrealloc (entries, &entries_allocated,
- sizeof *entries);
+ entries = xpalloc (entries, &entries_allocated, 1, -1,
+ sizeof *entries);
entries[entries_used].name = xstrdup (entry);
#if D_INO_IN_DIRENT
entries[entries_used].ino = dp->d_ino;
if (cmp)
{
- size_t i;
-
if (entries_used)
qsort (entries, entries_used, sizeof *entries, cmp);
- name_space = xmalloc (used + 1);
+ name_space = ximalloc (used + 1);
used = 0;
- for (i = 0; i < entries_used; i++)
+ for (idx_t i = 0; i < entries_used; i++)
{
char *dest = name_space + used;
used += stpcpy (dest, entries[i].name) - dest + 1;
free (entries);
}
else if (used == allocated)
- name_space = xrealloc (name_space, used + 1);
+ name_space = xirealloc (name_space, used + 1);
name_space[used] = '\0';
return name_space;