mirror of
https://git.savannah.gnu.org/git/tar.git
synced 2026-04-25 19:10:46 +00:00
Prefer countof to sizeof / sizeof
C2y plans to introduce a new countof operator that will be convenient for GNU tar, so start using it now via Gnulib. * gnulib.modules: Add stdcountof-h. * lib/wordsplit.c, src/buffer.c, src/suffix.c, src/tar.c: Include stdcountof.h, and prefer countof (X) to sizeof X / sizeof *X.
This commit is contained in:
@@ -102,6 +102,7 @@ selinux-at
|
||||
setenv
|
||||
stat-time
|
||||
std-gnu23
|
||||
stdcountof-h
|
||||
stddef-h
|
||||
stdint-h
|
||||
stpcpy
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <pwd.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdckdint.h>
|
||||
#include <stdcountof.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -2590,14 +2591,13 @@ static char const *const wordsplit_errstr[] = {
|
||||
N_("unbalanced parenthesis"),
|
||||
N_("globbing error")
|
||||
};
|
||||
enum { wordsplit_nerrs = sizeof wordsplit_errstr / sizeof *wordsplit_errstr };
|
||||
|
||||
const char *
|
||||
wordsplit_strerror (struct wordsplit const *ws)
|
||||
{
|
||||
if (ws->ws_errno == WRDSE_USERERR)
|
||||
return ws->ws_usererr;
|
||||
if (ws->ws_errno < wordsplit_nerrs)
|
||||
if (ws->ws_errno < countof (wordsplit_errstr))
|
||||
return wordsplit_errstr[ws->ws_errno];
|
||||
return N_("unknown error");
|
||||
}
|
||||
|
||||
10
src/buffer.c
10
src/buffer.c
@@ -33,6 +33,8 @@
|
||||
#include "common.h"
|
||||
#include <rmt.h>
|
||||
|
||||
#include <stdcountof.h>
|
||||
|
||||
/* Work around GCC bug 117236. */
|
||||
# if 13 <= __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wnull-dereference"
|
||||
@@ -328,7 +330,6 @@ static struct zip_magic const magic[] = {
|
||||
{ ct_xz, 6, "\xFD" "7zXZ" },
|
||||
{ ct_zstd, 4, "\x28\xB5\x2F\xFD" },
|
||||
};
|
||||
enum { n_zip_magic = sizeof magic / sizeof *magic };
|
||||
|
||||
static struct zip_program zip_program[] = {
|
||||
{ ct_compress, COMPRESS_PROGRAM, "-Z" },
|
||||
@@ -343,14 +344,13 @@ static struct zip_program zip_program[] = {
|
||||
{ ct_xz, XZ_PROGRAM, "-J" },
|
||||
{ ct_zstd, ZSTD_PROGRAM, "--zstd" },
|
||||
};
|
||||
enum { n_zip_programs = sizeof zip_program / sizeof *zip_program };
|
||||
|
||||
static struct zip_program const *
|
||||
find_zip_program (enum compress_type type, int *pstate)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = *pstate; i < n_zip_programs; i++)
|
||||
for (i = *pstate; i < countof (zip_program); i++)
|
||||
{
|
||||
if (zip_program[i].type == type)
|
||||
{
|
||||
@@ -367,7 +367,7 @@ first_decompress_program (int *pstate)
|
||||
{
|
||||
struct zip_program const *zp;
|
||||
|
||||
*pstate = n_zip_programs;
|
||||
*pstate = countof (zip_program);
|
||||
|
||||
if (use_compress_program_option)
|
||||
return use_compress_program_option;
|
||||
@@ -427,7 +427,7 @@ check_compressed_archive (bool *pshort)
|
||||
/* Probably a valid header */
|
||||
return ct_tar;
|
||||
|
||||
for (p = magic + 2; p < magic + n_zip_magic; p++)
|
||||
for (p = magic + 2; p < magic + countof (magic); p++)
|
||||
if (memeq (record_start->buffer, p->magic, p->length))
|
||||
return p->type;
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <system.h>
|
||||
#include "common.h"
|
||||
|
||||
#include <stdcountof.h>
|
||||
|
||||
struct compression_suffix
|
||||
{
|
||||
char suffix[sizeof "tbz2"]; /* "tbz2" is tied for longest. */
|
||||
@@ -72,8 +74,7 @@ find_compression_suffix (char const *name, idx_t *ret_len)
|
||||
suf++;
|
||||
|
||||
for (struct compression_suffix const *p = compression_suffixes;
|
||||
p < (compression_suffixes
|
||||
+ sizeof compression_suffixes / sizeof *compression_suffixes);
|
||||
p < compression_suffixes + countof (compression_suffixes);
|
||||
p++)
|
||||
if (streq (p->suffix, suf))
|
||||
return p;
|
||||
|
||||
@@ -136,6 +136,8 @@ bool delay_directory_restore_option;
|
||||
#include <priv-set.h>
|
||||
#include <savedir.h>
|
||||
|
||||
#include <stdcountof.h>
|
||||
|
||||
/* Local declarations. */
|
||||
|
||||
#ifndef DEFAULT_ARCHIVE_FORMAT
|
||||
@@ -1106,12 +1108,11 @@ decode_signal (const char *name)
|
||||
{ "INT", SIGINT },
|
||||
{ "QUIT", SIGQUIT }
|
||||
};
|
||||
enum { nsigtab = sizeof sigtab / sizeof *sigtab };
|
||||
char const *s = name;
|
||||
|
||||
if (strncmp (s, "SIG", 3) == 0)
|
||||
s += 3;
|
||||
for (struct sigtab const *p = sigtab; p < sigtab + nsigtab; p++)
|
||||
for (struct sigtab const *p = sigtab; p < sigtab + countof (sigtab); p++)
|
||||
if (streq (p->name, s))
|
||||
return p->signo;
|
||||
paxfatal (0, _("Unknown signal name: %s"), name);
|
||||
|
||||
Reference in New Issue
Block a user