2021-12-10 Paul Eggert <eggert@cs.ucla.edu>
+ backupfile: assume C99 decls
+ * lib/backupfile.c: Use C99-style decls after statements.
+
backupfile: prefer signed integers
* lib/backupfile.c: Include ialloc.h instead of idx.h.
Prefer idx_t to size_t where either will do.
Use imalloc and irealloc instead of malloc and realloc.
+
* modules/backupfile, modules/backup-rename (Depends-on):
Depend on ialloc not idx.
{
enum numbered_backup_result result = BACKUP_IS_NEW;
DIR *dirp = *dirpp;
- struct dirent *dp;
char *buf = *buffer;
idx_t versionlenmax = 1;
- char *base = buf + base_offset;
idx_t baselen = filelen - base_offset;
if (dirp)
/* Temporarily modify the buffer into its parent directory name,
open the directory, and then restore the buffer. */
char tmp[sizeof "."];
+ char *base = buf + base_offset;
memcpy (tmp, base, sizeof ".");
strcpy (base, ".");
dirp = opendirat (dir_fd, buf, 0, pnew_fd);
*dirpp = dirp;
}
- while ((dp = readdir (dirp)) != NULL)
+ for (struct dirent *dp; (dp = readdir (dirp)) != NULL; )
{
- char const *p;
- char *q;
- bool all_9s;
- idx_t versionlen;
-
if (_D_EXACT_NAMLEN (dp) < baselen + 4)
continue;
if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0)
continue;
- p = dp->d_name + baselen + 2;
+ char const *p = dp->d_name + baselen + 2;
/* Check whether this file has a version number and if so,
whether it is larger. Use string operations rather than
if (! ('1' <= *p && *p <= '9'))
continue;
- all_9s = (*p == '9');
+ bool all_9s = (*p == '9');
+ idx_t versionlen;
for (versionlen = 1; ISDIGIT (p[versionlen]); versionlen++)
all_9s &= (p[versionlen] == '9');
buf = new_buf;
buffer_size = new_buffer_size;
}
- q = buf + filelen;
+ char *q = buf + filelen;
*q++ = '.';
*q++ = '~';
*q = '0';