From: Paul Eggert Date: Sun, 9 Nov 2025 00:01:14 +0000 (-0800) Subject: Prefer streq/memeq when they will do X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=238250f19e3a65248193d08f3e80ef8f52f9a4a0;p=thirdparty%2Ftar.git Prefer streq/memeq when they will do Gnulib’s new streq and memeq functions make code a bit more readable and, we hope, a bit more reliable and easy to maintain. * gnulib.modules: Add stringeq. * lib/wordsplit.c (wordsplit_find_env): * src/buffer.c (check_compressed_archive, check_tty) (_open_archive, new_volume, try_new_volume) (drop_volume_label_suffix): * src/checkpoint.c (checkpoint_compile_action): * src/compare.c (process_rawdata, diff_symlink): * src/create.c (cachedir_file_p): * src/delete.c (delete_archive_members): * src/exclist.c (hg_addfn, get_vcs_ignore_file): * src/extract.c (ds_compare, remove_delayed_set_stat) (fixup_delayed_set_stat, apply_nonancestor_delayed_set_stat) (extract_link): * src/incremen.c (nfs_file_stat, compare_directory_canonical_names) (procdir): * src/list.c (read_header, decode_header): * src/misc.c (replace_prefix): * src/names.c (uname_to_uid, gname_to_gid, read_next_name) (name_compare): * src/sparse.c (check_data_region): * src/suffix.c (find_compression_suffix): * src/system.c (sys_detect_dev_null_output) (sys_child_open_for_compress, sys_child_open_for_uncompress): * src/tar.c (set_archive_format, tar_set_quoting_style) (optloc_eq, set_use_compress_program_option, decode_signal) (report_textual_dates, decode_options): * src/update.c (update_archive): * src/warning.c (set_warning_option): * src/xattrs.c (xattrs_xattrs_set): * src/xheader.c (xheader_keyword_override_p) (xheader_set_keyword_equal, locate_handler) (xheader_protected_keyword_p): Prefer memeq/streq to memcmp/strcmp when either will do. --- diff --git a/gnulib.modules b/gnulib.modules index 2526cce8..4044ce97 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -107,6 +107,7 @@ stpcpy stdopen strdup-posix strerror +stringeq strnlen symlinkat sys_stat-h diff --git a/lib/wordsplit.c b/lib/wordsplit.c index 289f7c10..22057209 100644 --- a/lib/wordsplit.c +++ b/lib/wordsplit.c @@ -1020,7 +1020,7 @@ wordsplit_find_env (struct wordsplit *wsp, char const *name, idx_t len, for (i = 0; wsp->ws_env[i]; i++) { idx_t elen = strlen (wsp->ws_env[i]); - if (elen == len && memcmp (wsp->ws_env[i], name, elen) == 0) + if (elen == len && memeq (wsp->ws_env[i], name, elen)) { *ret = wsp->ws_env[i + 1]; return WRDSE_OK; diff --git a/src/buffer.c b/src/buffer.c index e0d415c3..a32c43b1 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -419,17 +419,16 @@ check_compressed_archive (bool *pshort) read_full_records = sfr; if (record_start != record_end /* no files smaller than BLOCKSIZE */ - && (memcmp (record_start->header.magic, TMAGIC, sizeof TMAGIC) == 0 - || (memcmp (record_start->buffer + offsetof (struct posix_header, - magic), - OLDGNU_MAGIC, sizeof OLDGNU_MAGIC) - == 0)) + && (memeq (record_start->header.magic, TMAGIC, sizeof TMAGIC) + || memeq (record_start->buffer + offsetof (struct posix_header, + magic), + OLDGNU_MAGIC, sizeof OLDGNU_MAGIC)) && tar_checksum (record_start, true) == HEADER_SUCCESS) /* Probably a valid header */ return ct_tar; for (p = magic + 2; p < magic + n_zip_magic; p++) - if (memcmp (record_start->buffer, p->magic, p->length) == 0) + if (memeq (record_start->buffer, p->magic, p->length)) return p->type; return ct_none; @@ -679,7 +678,7 @@ static void check_tty (enum access_mode mode) { /* Refuse to read archive from and write it to a tty. */ - if (strcmp (archive_name_array[0], "-") == 0 + if (streq (archive_name_array[0], "-") && isatty (mode == ACCESS_READ ? STDIN_FILENO : STDOUT_FILENO)) { paxfatal (0, (mode == ACCESS_READ @@ -777,10 +776,10 @@ _open_archive (enum access_mode wanted_access) if (!index_file_name && wanted_access == ACCESS_WRITE - && strcmp (archive_name_array[0], "-") == 0) + && streq (archive_name_array[0], "-")) stdlis = stderr; } - else if (strcmp (archive_name_array[0], "-") == 0) + else if (streq (archive_name_array[0], "-")) { read_full_records = true; /* could be a pipe, be safe */ if (verify_option) @@ -1366,7 +1365,7 @@ new_volume (enum access_mode mode) change_tape_menu (read_file); } - if (strcmp (archive_name_cursor[0], "-") == 0) + if (streq (archive_name_cursor[0], "-")) { read_full_records = true; archive = STDIN_FILENO; @@ -1540,7 +1539,7 @@ try_new_volume (void) return false; } - if (strcmp (continued_file_name, bufmap_head->file_name) != 0) + if (!streq (continued_file_name, bufmap_head->file_name)) { if ((archive_format == GNU_FORMAT || archive_format == OLDGNU_FORMAT) && strlen (bufmap_head->file_name) >= NAME_FIELD_SIZE @@ -1598,7 +1597,7 @@ drop_volume_label_suffix (const char *label) prefix_len = i + 1; ptrdiff_t len = prefix_len - VOLUME_TEXT_LEN; - return (0 <= len && memcmp (label + len, VOLUME_TEXT, VOLUME_TEXT_LEN) == 0 + return (0 <= len && memeq (label + len, VOLUME_TEXT, VOLUME_TEXT_LEN) ? ximemdup0 (label, len) : NULL); } diff --git a/src/checkpoint.c b/src/checkpoint.c index 02621d67..903b8ce3 100644 --- a/src/checkpoint.c +++ b/src/checkpoint.c @@ -97,11 +97,11 @@ checkpoint_compile_action (const char *str) checkpoint_state = CHKP_COMPILE; } - if (strcmp (str, ".") == 0 || strcmp (str, "dot") == 0) + if (streq (str, ".") || streq (str, "dot")) alloc_action (cop_dot, NULL); - else if (strcmp (str, "bell") == 0) + else if (streq (str, "bell")) alloc_action (cop_bell, NULL); - else if (strcmp (str, "echo") == 0) + else if (streq (str, "echo")) alloc_action (cop_echo, NULL)->v.command = NULL; else if (strncmp (str, "echo=", 5) == 0) alloc_action (cop_echo, str + 5); @@ -118,7 +118,7 @@ checkpoint_compile_action (const char *str) if ((p == arg) | *p) paxfatal (0, _("%s: not a valid timeout"), str); } - else if (strcmp (str, "totals") == 0) + else if (streq (str, "totals")) alloc_action (cop_totals, NULL); else if (strncmp (str, "wait=", 5) == 0) { diff --git a/src/compare.c b/src/compare.c index c2d0d157..71d51cc8 100644 --- a/src/compare.c +++ b/src/compare.c @@ -106,7 +106,7 @@ process_rawdata (idx_t bytes, char *buffer) return false; } - if (memcmp (buffer, diff_buffer, bytes) != 0) + if (!memeq (buffer, diff_buffer, bytes)) { report_difference (¤t_stat_info, _("Contents differ")); return false; @@ -278,7 +278,7 @@ diff_symlink (void) report_difference (¤t_stat_info, NULL); } else if (status != len - || memcmp (current_stat_info.link_name, linkbuf, len) != 0) + || !memeq (current_stat_info.link_name, linkbuf, len)) report_difference (¤t_stat_info, _("Symlink differs")); if (linkbuf != buf) diff --git a/src/create.c b/src/create.c index 078c77e1..274d760a 100644 --- a/src/create.c +++ b/src/create.c @@ -115,7 +115,7 @@ cachedir_file_p (int fd) = "Signature: 8a477f597d28d172789f06886806bc55"; char tagbuf[sizeof sig]; return (read (fd, tagbuf, sizeof sig) == sizeof sig - && memcmp (tagbuf, sig, sizeof sig) == 0); + && memeq (tagbuf, sig, sizeof sig)); } diff --git a/src/delete.c b/src/delete.c index c158fb5a..fba56416 100644 --- a/src/delete.c +++ b/src/delete.c @@ -157,7 +157,7 @@ delete_archive_members (void) name_gather (); open_archive (ACCESS_UPDATE); - acting_as_filter = strcmp (archive_name_array[0], "-") == 0; + acting_as_filter = streq (archive_name_array[0], "-"); /* Skip to the first member that matches the name list. */ do diff --git a/src/exclist.c b/src/exclist.c index 2d03b110..106b206c 100644 --- a/src/exclist.c +++ b/src/exclist.c @@ -263,10 +263,10 @@ hg_addfn (struct exclude *ex, char const *pattern, int options, void *data) { for (pattern += 7; c_isspace (*pattern); ++pattern) ; - if (strcmp (pattern, "regexp") == 0) + if (streq (pattern, "regexp")) /* FIXME: Regexps must be perl-style */ *hgopt = EXCLUDE_REGEX; - else if (strcmp (pattern, "glob") == 0) + else if (streq (pattern, "glob")) *hgopt = EXCLUDE_WILDCARDS; /* Ignore unknown syntax */ return; @@ -306,7 +306,7 @@ get_vcs_ignore_file (const char *name) struct vcs_ignore_file *p; for (p = vcs_ignore_files; p->filename; p++) - if (strcmp (p->filename, name) == 0) + if (streq (p->filename, name)) break; return p; diff --git a/src/extract.c b/src/extract.c index 92c34b2a..54386629 100644 --- a/src/extract.c +++ b/src/extract.c @@ -230,7 +230,7 @@ static bool ds_compare (void const *a, void const *b) { struct delayed_set_stat const *dsa = a, *dsb = b; - return strcmp (dsa->file_name, dsb->file_name) == 0; + return streq (dsa->file_name, dsb->file_name); } /* Set up to extract files. */ @@ -704,7 +704,7 @@ remove_delayed_set_stat (const char *fname) { next = data->next; if (chdir_current == data->change_dir - && strcmp (data->file_name, fname) == 0) + && streq (data->file_name, fname)) { hash_remove (delayed_set_stat_table, data); free_delayed_set_stat (data); @@ -726,7 +726,7 @@ fixup_delayed_set_stat (char const *src, char const *dst) for (data = delayed_set_stat_head; data; data = data->next) { if (chdir_current == data->change_dir - && strcmp (data->file_name, src) == 0) + && streq (data->file_name, src)) { free (data->file_name); data->file_name = xstrdup (dst); @@ -1009,7 +1009,7 @@ apply_nonancestor_delayed_set_stat (char const *file_name, bool after_links) && file_name[data->file_name_len] && (ISSLASH (file_name[data->file_name_len]) || ISSLASH (file_name[data->file_name_len - 1])) - && memcmp (file_name, data->file_name, data->file_name_len) == 0)) + && memeq (file_name, data->file_name, data->file_name_len))) break; chdir_do (data->change_dir); @@ -1567,7 +1567,7 @@ extract_link (char *file_name, MAYBE_UNUSED char typeflag) return true; } - else if ((e == EEXIST && strcmp (link_name, file_name) == 0) + else if ((e == EEXIST && streq (link_name, file_name)) || ((fstatat (chdir_fd, link_name, &st1, AT_SYMLINK_NOFOLLOW) == 0) && (fstatat (chdir_fd, file_name, &st2, AT_SYMLINK_NOFOLLOW) diff --git a/src/incremen.c b/src/incremen.c index c4c9dd45..859f3bbe 100644 --- a/src/incremen.c +++ b/src/incremen.c @@ -257,7 +257,7 @@ static bool nfs_file_stat (struct stat const *st) { #if HAVE_ST_FSTYPE_STRING - return strcmp (st->st_fstype, "nfs") == 0; + return streq (st->st_fstype, "nfs"); #else return (st->st_dev >> (TYPE_WIDTH (st->st_dev) - 1)) & 1; #endif @@ -277,7 +277,7 @@ compare_directory_canonical_names (void const *entry1, void const *entry2) { struct directory const *directory1 = entry1; struct directory const *directory2 = entry2; - return strcmp (directory1->caname, directory2->caname) == 0; + return streq (directory1->caname, directory2->caname); } static size_t @@ -515,7 +515,7 @@ procdir (const char *name_buffer, struct tar_stat_info *st, } } - if (strcmp (directory->name, name_buffer)) + if (!streq (directory->name, name_buffer)) { *entry = 'N'; return directory; @@ -537,7 +537,7 @@ procdir (const char *name_buffer, struct tar_stat_info *st, stat_data->st_ino); if (d) { - if (strcmp (d->name, name_buffer)) + if (!streq (d->name, name_buffer)) { warnopt (WARN_RENAME_DIRECTORY, 0, _("%s: Directory has been renamed from %s"), @@ -580,7 +580,7 @@ procdir (const char *name_buffer, struct tar_stat_info *st, if (d) { - if (strcmp (d->name, name_buffer)) + if (!streq (d->name, name_buffer)) { warnopt (WARN_RENAME_DIRECTORY, 0, _("%s: Directory has been renamed from %s"), diff --git a/src/list.c b/src/list.c index 822c12dd..d7cf2644 100644 --- a/src/list.c +++ b/src/list.c @@ -542,7 +542,7 @@ read_header (union block **return_block, struct tar_stat_info *info, section 10.1.1. */ char *np = namebuf; - if (h->prefix[0] && memcmp (h->magic, TMAGIC, sizeof TMAGIC) == 0) + if (h->prefix[0] && memeq (h->magic, TMAGIC, sizeof TMAGIC)) { memcpy (np, h->prefix, sizeof h->prefix); np[sizeof h->prefix] = '\0'; @@ -613,7 +613,7 @@ decode_header (union block *header, struct tar_stat_info *stat_info, bool hbits; mode_t mode = MODE_FROM_HEADER (header->header.mode, &hbits); - if (memcmp (header->header.magic, TMAGIC, sizeof TMAGIC) == 0) + if (memeq (header->header.magic, TMAGIC, sizeof TMAGIC)) { if (header->star_header.prefix[130] == 0 && is_octal_digit (header->star_header.atime[0]) @@ -626,9 +626,8 @@ decode_header (union block *header, struct tar_stat_info *stat_info, else format = USTAR_FORMAT; } - else if (memcmp (header->buffer + offsetof (struct posix_header, magic), - OLDGNU_MAGIC, sizeof OLDGNU_MAGIC) - == 0) + else if (memeq (header->buffer + offsetof (struct posix_header, magic), + OLDGNU_MAGIC, sizeof OLDGNU_MAGIC)) format = hbits ? OLDGNU_FORMAT : GNU_FORMAT; else format = V7_FORMAT; diff --git a/src/misc.c b/src/misc.c index 607f5daf..77981412 100644 --- a/src/misc.c +++ b/src/misc.c @@ -377,7 +377,7 @@ replace_prefix (char **pname, const char *samp, idx_t slen, { char *name = *pname; idx_t nlen = strlen (name); - if (nlen > slen && memcmp (name, samp, slen) == 0 && ISSLASH (name[slen])) + if (slen < nlen && memeq (name, samp, slen) && ISSLASH (name[slen])) { if (rlen > slen) { diff --git a/src/names.c b/src/names.c index e1927ba4..c29d3aa3 100644 --- a/src/names.c +++ b/src/names.c @@ -541,12 +541,12 @@ uname_to_uid (char const *uname, uid_t *uidp) struct passwd *passwd; if (cached_no_such_uname - && strcmp (uname, cached_no_such_uname) == 0) + && streq (uname, cached_no_such_uname)) return false; - if (!cached_uname - || uname[0] != cached_uname[0] - || strcmp (uname, cached_uname) != 0) + if (! (cached_uname + && uname[0] == cached_uname[0] + && streq (uname, cached_uname))) { passwd = getpwnam (uname); if (passwd) @@ -572,12 +572,12 @@ gname_to_gid (char const *gname, gid_t *gidp) struct group *group; if (cached_no_such_gname - && strcmp (gname, cached_no_such_gname) == 0) + && streq (gname, cached_no_such_gname)) return false; - if (!cached_gname - || gname[0] != cached_gname[0] - || strcmp (gname, cached_gname) != 0) + if (! (cached_gname + && gname[0] == cached_gname[0] + && streq (gname, cached_gname))) { group = getgrnam (gname); if (group) @@ -1016,7 +1016,7 @@ read_next_name (struct name_elt *ent, struct name_elt *ret) { if (!ent->v.file.fp) { - if (strcmp (ent->v.file.name, "-") == 0) + if (streq (ent->v.file.name, "-")) { request_stdin ("-T"); ent->v.file.fp = stdin; @@ -1067,7 +1067,7 @@ read_next_name (struct name_elt *ent, struct name_elt *ret) return true; case file_list_end: - if (strcmp (ent->v.file.name, "-")) + if (!streq (ent->v.file.name, "-")) fclose (ent->v.file.fp); ent->v.file.fp = NULL; name_list_advance (); @@ -1707,7 +1707,7 @@ name_compare (void const *entry1, void const *entry2) { struct name const *name1 = entry1; struct name const *name2 = entry2; - return strcmp (name1->caname, name2->caname) == 0; + return streq (name1->caname, name2->caname); } diff --git a/src/sparse.c b/src/sparse.c index 327a9069..1e05ab71 100644 --- a/src/sparse.c +++ b/src/sparse.c @@ -659,7 +659,7 @@ check_data_region (struct tar_sparse_file *file, idx_t i) idx_t bytes_read = full_read (file->fd, diff_buffer, rdsize); size_left -= bytes_read; mv_size_left (file->stat_info->archive_file_size - file->dumped_size); - if (memcmp (blk->buffer, diff_buffer, bytes_read) != 0) + if (!memeq (blk->buffer, diff_buffer, bytes_read)) { report_difference (file->stat_info, _("Contents differ")); return false; diff --git a/src/suffix.c b/src/suffix.c index 3fd81b11..b1118f15 100644 --- a/src/suffix.c +++ b/src/suffix.c @@ -75,7 +75,7 @@ find_compression_suffix (char const *name, idx_t *ret_len) p < (compression_suffixes + sizeof compression_suffixes / sizeof *compression_suffixes); p++) - if (strcmp (p->suffix, suf) == 0) + if (streq (p->suffix, suf)) return p; } else if (ret_len) diff --git a/src/system.c b/src/system.c index 7538b6b2..f7a2b866 100644 --- a/src/system.c +++ b/src/system.c @@ -95,7 +95,7 @@ sys_detect_dev_null_output (void) { static char const dev_null[] = "nul"; - dev_null_output = (strcmp (archive_name_array[0], dev_null) == 0 + dev_null_output = (streq (archive_name_array[0], dev_null) || (! _isrmt (archive))); } @@ -200,7 +200,7 @@ sys_detect_dev_null_output (void) { static struct stat dev_null_stat; - dev_null_output = (strcmp (archive_name_array[0], dev_null) == 0 + dev_null_output = (streq (archive_name_array[0], dev_null) || (! _isrmt (archive) && S_ISCHR (archive_stat.st_mode) && (dev_null_stat.st_ino != 0 @@ -383,7 +383,7 @@ sys_child_open_for_compress (void) /* We don't need a grandchild tar. Open the archive and launch the compressor. */ - if (strcmp (archive_name_array[0], "-")) + if (!streq (archive_name_array[0], "-")) { archive = creat (archive_name_array[0], MODE_RW); if (archive < 0) @@ -425,7 +425,7 @@ sys_child_open_for_compress (void) xdup2 (child_pipe[PREAD], STDIN_FILENO); xclose (child_pipe[PWRITE]); - if (strcmp (archive_name_array[0], "-") == 0) + if (streq (archive_name_array[0], "-")) archive = STDOUT_FILENO; else { @@ -553,7 +553,7 @@ sys_child_open_for_uncompress (void) b) the file is to be accessed by rmt: compressor doesn't know how; c) the file is not a plain file. */ - if (strcmp (archive_name_array[0], "-") != 0 + if (!streq (archive_name_array[0], "-") && !_remdev (archive_name_array[0]) && is_regular_file (archive_name_array[0])) { @@ -593,7 +593,7 @@ sys_child_open_for_uncompress (void) xdup2 (child_pipe[PWRITE], STDOUT_FILENO); xclose (child_pipe[PREAD]); - if (strcmp (archive_name_array[0], "-") == 0) + if (streq (archive_name_array[0], "-")) archive = STDIN_FILENO; else archive = rmtopen (archive_name_array[0], O_RDONLY | O_BINARY, diff --git a/src/tar.c b/src/tar.c index c58a19fa..9be0d7f0 100644 --- a/src/tar.c +++ b/src/tar.c @@ -240,7 +240,7 @@ set_archive_format (char const *name) { struct fmttab const *p; - for (p = fmttab; strcmp (p->name, name) != 0; ) + for (p = fmttab; !streq (p->name, name); ) if (! (++p)->name) paxusage (_("%s: Invalid archive format"), quotearg_colon (name)); @@ -336,7 +336,7 @@ static void tar_set_quoting_style (char *arg) { for (idx_t i = 0; quoting_style_args[i]; i++) - if (strcmp (arg, quoting_style_args[i]) == 0) + if (streq (arg, quoting_style_args[i])) { set_quoting_style (NULL, i); return; @@ -1039,7 +1039,7 @@ optloc_eq (struct option_locus *a, struct option_locus *b) if (a->source == OPTS_COMMAND_LINE) return true; assume (a->name); - return strcmp (a->name, b->name) == 0; + return streq (a->name, b->name); } static void @@ -1058,7 +1058,7 @@ set_use_compress_program_option (const char *string, struct option_locus *loc) { struct option_locus *p = optloc_save (OC_COMPRESS, loc); if (use_compress_program_option - && strcmp (use_compress_program_option, string) != 0 + && !streq (use_compress_program_option, string) && p->source == OPTS_COMMAND_LINE) paxusage (_("Conflicting compression options")); @@ -1112,7 +1112,7 @@ decode_signal (const char *name) if (strncmp (s, "SIG", 3) == 0) s += 3; for (struct sigtab const *p = sigtab; p < sigtab + nsigtab; p++) - if (strcmp (p->name, s) == 0) + if (streq (p->name, s)) return p->signo; paxfatal (0, _("Unknown signal name: %s"), name); } @@ -1180,7 +1180,7 @@ report_textual_dates (struct tar_args *args) if (verbose_option) { char const *treated_as = tartime (p->ts, true); - if (strcmp (p->date, treated_as) != 0) + if (!streq (p->date, treated_as)) paxwarn (0, _("Option %s: Treating date '%s' as %s"), p->option, p->date, treated_as); } @@ -2741,7 +2741,7 @@ decode_options (int argc, char **argv) if (!name_more_files ()) paxusage (_("Cowardly refusing to create an empty archive")); if (args.compress_autodetect && archive_names - && strcmp (archive_name_array[0], "-")) + && !streq (archive_name_array[0], "-")) set_compression_program_by_suffix (archive_name_array[0], use_compress_program_option, true); @@ -2754,7 +2754,7 @@ decode_options (int argc, char **argv) for (archive_name_cursor = archive_name_array; archive_name_cursor < archive_name_array + archive_names; archive_name_cursor++) - if (strcmp (*archive_name_cursor, "-") == 0) + if (streq (*archive_name_cursor, "-")) request_stdin ("-f"); break; @@ -2764,7 +2764,7 @@ decode_options (int argc, char **argv) for (archive_name_cursor = archive_name_array; archive_name_cursor < archive_name_array + archive_names; archive_name_cursor++) - if (strcmp (*archive_name_cursor, "-") == 0) + if (streq (*archive_name_cursor, "-")) paxusage (_("Options '-Aru' are incompatible with '-f -'")); default: diff --git a/src/update.c b/src/update.c index c74d3baa..b693b838 100644 --- a/src/update.c +++ b/src/update.c @@ -102,7 +102,7 @@ update_archive (void) name_gather (); open_archive (ACCESS_UPDATE); - acting_as_filter = strcmp (archive_name_array[0], "-") == 0; + acting_as_filter = streq (archive_name_array[0], "-"); xheader_forbid_global (); while (!found_end) diff --git a/src/warning.c b/src/warning.c index 161ac877..395fec63 100644 --- a/src/warning.c +++ b/src/warning.c @@ -95,12 +95,12 @@ set_warning_option (const char *arg) bool negate = false; int option; - if (strcmp (arg, "none") == 0) + if (streq (arg, "none")) { warning_option = 0; return; } - if (strlen (arg) > 2 && memcmp (arg, "no-", 3) == 0) + if (strncmp (arg, "no-", 3) == 0) { negate = true; arg += 3; diff --git a/src/xattrs.c b/src/xattrs.c index 8c2d5062..399eb7fb 100644 --- a/src/xattrs.c +++ b/src/xattrs.c @@ -751,7 +751,7 @@ xattrs_xattrs_set (MAYBE_UNUSED struct tar_stat_info const *st, the first run except 'security.capability' which is restored in 'later_run == 1'. */ if (typeflag == REGTYPE - && later_run == (strcmp (keyword, "security.capability") != 0)) + && streq (keyword, "security.capability") != later_run) continue; if (xattrs_masked_out (keyword, false /* extracting */ )) diff --git a/src/xheader.c b/src/xheader.c index 6d2f4d47..7d081b3f 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -124,7 +124,7 @@ xheader_keyword_override_p (const char *keyword) struct keyword_list *kp; for (kp = keyword_override_list; kp; kp = kp->next) - if (strcmp (kp->pattern, keyword) == 0) + if (streq (kp->pattern, keyword)) return true; return false; } @@ -201,19 +201,19 @@ xheader_set_keyword_equal (char *kw, char *eq) for (p = eq + 1; *p && c_isspace (*p); p++) ; - if (strcmp (kw, "delete") == 0) + if (streq (kw, "delete")) { if (xheader_protected_pattern_p (p)) paxusage (_("Pattern %s cannot be used"), quote (p)); xheader_list_append (&keyword_pattern_list, p, NULL); } - else if (strcmp (kw, "exthdr.name") == 0) + else if (streq (kw, "exthdr.name")) assign_string (&exthdr_name, p); - else if (strcmp (kw, "globexthdr.name") == 0) + else if (streq (kw, "globexthdr.name")) assign_string (&globexthdr_name, p); - else if (strcmp (kw, "exthdr.mtime") == 0) + else if (streq (kw, "exthdr.mtime")) assign_time_option (&exthdr_mtime_option, &exthdr_mtime, p); - else if (strcmp (kw, "globexthdr.mtime") == 0) + else if (streq (kw, "globexthdr.mtime")) assign_time_option (&globexthdr_mtime_option, &globexthdr_mtime, p); else { @@ -561,7 +561,7 @@ locate_handler (char const *keyword) } else { - if (strcmp (p->keyword, keyword) == 0) + if (streq (p->keyword, keyword)) return p; } @@ -587,7 +587,7 @@ xheader_protected_keyword_p (const char *keyword) for (p = xhdr_tab; p->keyword; p++) if (!p->prefix && (p->flags & XHDR_PROTECTED) - && strcmp (p->keyword, keyword) == 0) + && streq (p->keyword, keyword)) return true; return false; }