From cf5afa870546c415afdc5e1a21c23f106bae5fa6 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Fri, 1 Sep 2023 16:24:34 +0200 Subject: [PATCH] add streq and strneq macros --- include/macro.h | 3 +++ lib/package_alternatives.c | 22 ++++++++-------- lib/package_config_files.c | 36 +++++++++++++------------- lib/package_msg.c | 2 +- lib/package_script.c | 2 +- lib/package_state.c | 2 +- lib/package_unpack.c | 8 +++--- lib/pkgdb_conversion.c | 2 +- lib/plist.c | 6 ++--- lib/plist_fetch.c | 8 +++--- lib/plist_find.c | 10 +++---- lib/plist_match.c | 4 +-- lib/plist_remove.c | 6 ++--- lib/repo.c | 4 +-- lib/rpool.c | 8 +++--- lib/transaction_check_conflicts.c | 6 ++--- lib/transaction_check_replaces.c | 2 +- lib/transaction_check_revdeps.c | 6 ++--- lib/transaction_commit.c | 2 +- lib/transaction_files.c | 12 ++++----- lib/transaction_internalize.c | 10 +++---- lib/transaction_ops.c | 4 +-- lib/transaction_pkg_deps.c | 8 +++--- lib/util.c | 43 ++++++++++--------------------- lib/util_hash.c | 4 +-- 25 files changed, 103 insertions(+), 117 deletions(-) diff --git a/include/macro.h b/include/macro.h index cbf91ea9..c6e21ebd 100644 --- a/include/macro.h +++ b/include/macro.h @@ -39,4 +39,7 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +#define streq(a,b) (strcmp((a),(b)) == 0) +#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0) + #endif /*!XBPS_MACRO_H*/ diff --git a/lib/package_alternatives.c b/lib/package_alternatives.c index 8f3a8f04..fc46b973 100644 --- a/lib/package_alternatives.c +++ b/lib/package_alternatives.c @@ -66,12 +66,12 @@ normpath(char *path) char *seg, *p; for (p = path, seg = NULL; *p; p++) { - if (strncmp(p, "/../", 4) == 0 || strncmp(p, "/..", 4) == 0) { + if (strneq(p, "/../", 4) || strneq(p, "/..", 4)) { memmove(seg ? seg : p, p+3, strlen(p+3) + 1); return normpath(path); - } else if (strncmp(p, "/./", 3) == 0 || strncmp(p, "/.", 3) == 0) { + } else if (strneq(p, "/./", 3) || strneq(p, "/.", 3)) { memmove(p, p+2, strlen(p+2) + 1); - } else if (strncmp(p, "//", 2) == 0 || strncmp(p, "/", 2) == 0) { + } else if (strneq(p, "//", 2)|| strneq(p, "/", 2)) { memmove(p, p+1, strlen(p+1) + 1); } if (*p == '/') @@ -179,7 +179,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) /* create target directory, necessary for dangling symlinks */ dir = xbps_xasprintf("%s/%s", xhp->rootdir, dir); - if (strcmp(dir, ".") && xbps_mkpath(dir, 0755) && errno != EEXIST) { + if (!streq(dir, ".") && xbps_mkpath(dir, 0755) && errno != EEXIST) { rv = errno; xbps_dbg_printf( "failed to create target dir '%s' for group '%s': %s\n", @@ -192,7 +192,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) /* create link directory, necessary for dangling symlinks */ p = strdup(linkpath); dir = dirname(p); - if (strcmp(dir, ".") && xbps_mkpath(dir, 0755) && errno != EEXIST) { + if (!streq(dir, ".") && xbps_mkpath(dir, 0755) && errno != EEXIST) { rv = errno; xbps_dbg_printf( "failed to create symlink dir '%s' for group '%s': %s\n", @@ -273,7 +273,7 @@ xbps_alternatives_set(struct xbps_handle *xhp, const char *pkgname, keysym = xbps_array_get(allkeys, i); keyname = xbps_dictionary_keysym_cstring_nocopy(keysym); - if (group && strcmp(keyname, group)) + if (group && !streq(keyname, group)) continue; array = xbps_dictionary_get(alternatives, keyname); @@ -282,7 +282,7 @@ xbps_alternatives_set(struct xbps_handle *xhp, const char *pkgname, /* remove symlinks from previous alternative */ xbps_array_get_cstring_nocopy(array, 0, &prevpkgname); - if (prevpkgname && strcmp(pkgname, prevpkgname) != 0) { + if (prevpkgname && !streq(pkgname, prevpkgname)) { if ((prevpkgd = xbps_pkgdb_get_pkg(xhp, prevpkgname)) && (prevpkg_alts = xbps_dictionary_get(prevpkgd, "alternatives")) && xbps_dictionary_count(prevpkg_alts)) { @@ -366,7 +366,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd) continue; xbps_array_get_cstring_nocopy(array, 0, &first); - if (strcmp(pkgname, first) == 0) { + if (streq(pkgname, first)) { /* this pkg is the current alternative for this group */ current = true; rv = remove_symlinks(xhp, @@ -427,7 +427,7 @@ prune_altgroup(struct xbps_handle *xhp, xbps_dictionary_t repod, /* if using alt group from another package, we won't switch anything */ xbps_array_get_cstring_nocopy(array, 0, &curpkg); - current = (strcmp(pkgname, curpkg) == 0); + current = streq(pkgname, curpkg); /* actually prune the alt group for the current package */ xbps_remove_string_from_array(array, pkgname); @@ -508,7 +508,7 @@ remove_obsoletes(struct xbps_handle *xhp, const char *pkgname, const char *pkgve array2 = xbps_dictionary_get(pkgdb_alts, keyname); if (array2) { xbps_array_get_cstring_nocopy(array2, 0, &first); - if (strcmp(pkgname, first) == 0) { + if (streq(pkgname, first)) { remove_symlinks(xhp, array_repo, keyname); } } @@ -576,7 +576,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod) } else { if (xbps_match_string_in_array(array, pkgname)) { xbps_array_get_cstring_nocopy(array, 0, &first); - if (strcmp(pkgname, first)) { + if (!streq(pkgname, first)) { /* current alternative does not match */ continue; } diff --git a/lib/package_config_files.c b/lib/package_config_files.c index 7f852a6d..df9cd7ab 100644 --- a/lib/package_config_files.c +++ b/lib/package_config_files.c @@ -50,7 +50,7 @@ xbps_entry_is_a_conf_file(xbps_dictionary_t filesd, for (unsigned int i = 0; i < xbps_array_count(array); i++) { d = xbps_array_get(array, i); xbps_dictionary_get_cstring_nocopy(d, "file", &cffile); - if (strcmp(cffile, entry_pname) == 0) + if (streq(cffile, entry_pname)) return true; } return false; @@ -116,7 +116,7 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp, xbps_dictionary_get_cstring_nocopy(obj2, "file", &cffile); snprintf(buf, sizeof(buf), ".%s", cffile); - if (strcmp(entry_pname, buf) == 0) { + if (streq(entry_pname, buf)) { xbps_dictionary_get_cstring_nocopy(obj2, "sha256", &sha256_orig); break; } @@ -139,7 +139,7 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp, while ((obj = xbps_object_iterator_next(iter))) { xbps_dictionary_get_cstring_nocopy(obj, "file", &cffile); snprintf(buf, sizeof(buf), ".%s", cffile); - if (strcmp(entry_pname, buf)) { + if (!streq(entry_pname, buf)) { continue; } if (!xbps_file_sha256(sha256_cur, sizeof sha256_cur, buf)) { @@ -162,9 +162,9 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp, * * Keep file as is (no changes). */ - if ((strcmp(sha256_orig, sha256_cur) == 0) && - (strcmp(sha256_orig, sha256_new) == 0) && - (strcmp(sha256_cur, sha256_new) == 0)) { + if (streq(sha256_orig, sha256_cur) && + streq(sha256_orig, sha256_new) && + streq(sha256_cur, sha256_new)) { xbps_dbg_printf("%s: conf_file %s orig = X, " "cur = X, new = X\n", pkgver, entry_pname); rv = 0; @@ -175,9 +175,9 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp, * Install new file (installed file hasn't been modified) if * configuration option keepconfig is NOT set. */ - } else if ((strcmp(sha256_orig, sha256_cur) == 0) && - (strcmp(sha256_orig, sha256_new)) && - (strcmp(sha256_cur, sha256_new)) && + } else if (streq(sha256_orig, sha256_cur) && + !streq(sha256_orig, sha256_new) && + !streq(sha256_cur, sha256_new) && (!(xhp->flags & XBPS_FLAG_KEEP_CONFIG))) { xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE, 0, pkgver, @@ -192,9 +192,9 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp, * but new package doesn't contain new changes compared * to the original version. */ - } else if ((strcmp(sha256_orig, sha256_new) == 0) && - (strcmp(sha256_cur, sha256_new)) && - (strcmp(sha256_orig, sha256_cur))) { + } else if (streq(sha256_orig, sha256_new) && + !streq(sha256_cur, sha256_new) && + !streq(sha256_orig, sha256_cur)) { xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE, 0, pkgver, "Keeping modified configuration file `%s'.", @@ -207,9 +207,9 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp, * Keep file as is because changes made are compatible * with new version. */ - } else if ((strcmp(sha256_cur, sha256_new) == 0) && - (strcmp(sha256_orig, sha256_new)) && - (strcmp(sha256_orig, sha256_cur))) { + } else if (streq(sha256_cur, sha256_new) && + !streq(sha256_orig, sha256_new) && + !streq(sha256_orig, sha256_cur)) { xbps_dbg_printf("%s: conf_file %s orig = X, " "cur = Y, new = Y\n", pkgver, entry_pname); rv = 0; @@ -221,9 +221,9 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp, * * Install new file as .new- */ - } else if (((strcmp(sha256_orig, sha256_cur)) && - (strcmp(sha256_cur, sha256_new)) && - (strcmp(sha256_orig, sha256_new))) || + } else if ((!streq(sha256_orig, sha256_cur) && + !streq(sha256_cur, sha256_new) && + !streq(sha256_orig, sha256_new)) || (xhp->flags & XBPS_FLAG_KEEP_CONFIG)) { version = xbps_pkg_version(pkgver); assert(version); diff --git a/lib/package_msg.c b/lib/package_msg.c index e8227f0a..fad9cc62 100644 --- a/lib/package_msg.c +++ b/lib/package_msg.c @@ -61,7 +61,7 @@ xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key buf[len] = '\0'; /* notify client to show the post-install message */ - if (strcmp(key, "install-msg") == 0) + if (streq(key, "install-msg")) xbps_set_cb_state(xhp, XBPS_STATE_SHOW_INSTALL_MSG, 0, pkgver, "%s", buf); else xbps_set_cb_state(xhp, XBPS_STATE_SHOW_REMOVE_MSG, 0, pkgver, "%s", buf); diff --git a/lib/package_script.c b/lib/package_script.c index 29843aa3..ecf1103f 100644 --- a/lib/package_script.c +++ b/lib/package_script.c @@ -62,7 +62,7 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, return 0; } - if (strcmp(xhp->rootdir, "/") == 0) { + if (streq(xhp->rootdir, "/")) { tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) tmpdir = P_tmpdir; diff --git a/lib/package_state.c b/lib/package_state.c index bd099128..efefa1cf 100644 --- a/lib/package_state.c +++ b/lib/package_state.c @@ -85,7 +85,7 @@ get_state(xbps_dictionary_t dict) return 0; for (stp = states; stp->string != NULL; stp++) - if (strcmp(state_str, stp->string) == 0) + if (streq(state_str, stp->string)) break; return stp->number; diff --git a/lib/package_unpack.c b/lib/package_unpack.c index dc6cbd1e..c069367a 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -160,11 +160,11 @@ unpack_archive(struct xbps_handle *xhp, entry_pname = archive_entry_pathname(entry); entry_size = archive_entry_size(entry); - if (strcmp("./INSTALL", entry_pname) == 0 || - strcmp("./REMOVE", entry_pname) == 0 || - strcmp("./props.plist", entry_pname) == 0) { + if (streq("./INSTALL", entry_pname) || + streq("./REMOVE", entry_pname) || + streq("./props.plist", entry_pname)) { archive_read_data_skip(ar); - } else if (strcmp("./files.plist", entry_pname) == 0) { + } else if (streq("./files.plist", entry_pname)) { binpkg_filesd = xbps_archive_get_dictionary(ar, entry); if (binpkg_filesd == NULL) { rv = EINVAL; diff --git a/lib/pkgdb_conversion.c b/lib/pkgdb_conversion.c index 079e7a1b..b519bba3 100644 --- a/lib/pkgdb_conversion.c +++ b/lib/pkgdb_conversion.c @@ -118,7 +118,7 @@ pkgdb038(struct xbps_handle *xhp, const char *opkgdb_plist) key = xbps_dictionary_keysym_cstring_nocopy(obj2); curobj = xbps_dictionary_get_keysym(pkgmetad, obj2); for (uint8_t i = 0; i < ARRAY_SIZE(excluded); i++) { - if (strcmp(excluded[i], key) == 0) { + if (streq(excluded[i], key)) { skip = true; break; } diff --git a/lib/plist.c b/lib/plist.c index 67587331..3b4dee30 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -73,7 +73,7 @@ array_foreach_thread(void *arg) pkgd = xbps_dictionary_get_keysym(thd->dict, obj); key = xbps_dictionary_keysym_cstring_nocopy(obj); /* ignore internal objs */ - if (strncmp(key, "_XBPS_", 6) == 0) + if (strneq(key, "_XBPS_", 6)) continue; } else { pkgd = obj; @@ -185,7 +185,7 @@ xbps_array_foreach_cb(struct xbps_handle *xhp, pkgd = xbps_dictionary_get_keysym(dict, obj); key = xbps_dictionary_keysym_cstring_nocopy(obj); /* ignore internal objs */ - if (strncmp(key, "_XBPS_", 6) == 0) + if (strneq(key, "_XBPS_", 6)) continue; } else { pkgd = obj; @@ -247,7 +247,7 @@ array_replace_dict(xbps_array_t array, } else { /* pkgname match */ xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); - if (strcmp(pkgname, str) == 0) { + if (streq(pkgname, str)) { if (!xbps_array_set(array, i, dict)) { return EINVAL; } diff --git a/lib/plist_fetch.c b/lib/plist_fetch.c index 764fa521..a95b09da 100644 --- a/lib/plist_fetch.c +++ b/lib/plist_fetch.c @@ -167,7 +167,7 @@ xbps_archive_fetch_file(const char *url, const char *fname) if (bfile[0] == '.') bfile++; /* skip first dot */ - if (strcmp(bfile, fname) == 0) { + if (streq(bfile, fname)) { buf = xbps_archive_get_file(a, entry); break; } @@ -199,12 +199,12 @@ xbps_repo_fetch_remote(struct xbps_repo *repo, const char *url) if (bfile[0] == '.') bfile++; /* skip first dot */ - if (strcmp(bfile, XBPS_REPOIDX_META) == 0) { + if (streq(bfile, XBPS_REPOIDX_META)) { buf = xbps_archive_get_file(a, entry); repo->idxmeta = xbps_dictionary_internalize(buf); free(buf); i++; - } else if (strcmp(bfile, XBPS_REPOIDX) == 0) { + } else if (streq(bfile, XBPS_REPOIDX)) { buf = xbps_archive_get_file(a, entry); repo->idx = xbps_dictionary_internalize(buf); free(buf); @@ -265,7 +265,7 @@ xbps_archive_fetch_file_into_fd(const char *url, const char *fname, int fd) if (bfile[0] == '.') bfile++; /* skip first dot */ - if (strcmp(bfile, fname) == 0) { + if (streq(bfile, fname)) { rv = archive_read_data_into_fd(a, fd); if (rv != ARCHIVE_OK) rv = archive_errno(a); diff --git a/lib/plist_find.c b/lib/plist_find.c index 57128005..e04e3f43 100644 --- a/lib/plist_find.c +++ b/lib/plist_find.c @@ -69,7 +69,7 @@ get_pkg_in_array(xbps_array_t array, const char *str, xbps_trans_type_t tt, bool } } else if (xbps_pkg_version(str)) { /* match by exact pkgver */ - if (strcmp(str, pkgver) == 0) { + if (streq(str, pkgver)) { found = true; break; } @@ -78,7 +78,7 @@ get_pkg_in_array(xbps_array_t array, const char *str, xbps_trans_type_t tt, bool abort(); } /* match by pkgname */ - if (strcmp(pkgname, str) == 0) { + if (streq(pkgname, str)) { found = true; break; } @@ -144,7 +144,7 @@ match_pkg_by_pkgver(xbps_dictionary_t repod, const char *p) d = xbps_dictionary_get(repod, pkgname); if (d) { xbps_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver); - if (strcmp(pkgver, p)) { + if (!streq(pkgver, p)) { d = NULL; errno = ENOENT; } @@ -256,12 +256,12 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf) if (!xbps_pkg_name(buf, sizeof(buf), vpkg)) { abort(); } - if (strcmp(buf, vpkgname)) { + if (!streq(buf, vpkgname)) { free(vpkgname); continue; } } else { - if (strcmp(vpkg, vpkgname)) { + if (!streq(vpkg, vpkgname)) { free(vpkgname); continue; } diff --git a/lib/plist_match.c b/lib/plist_match.c index 7e9355d6..1842fab6 100644 --- a/lib/plist_match.c +++ b/lib/plist_match.c @@ -125,7 +125,7 @@ match_string_in_array(xbps_array_t array, const char *str, int mode) pkgdep = xbps_string_cstring_nocopy(obj); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgdep)) break; - if (strcmp(pkgname, str) == 0) { + if (streq(pkgname, str)) { found = true; break; } @@ -134,7 +134,7 @@ match_string_in_array(xbps_array_t array, const char *str, int mode) pkgdep = xbps_string_cstring_nocopy(obj); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, str)) break; - if (strcmp(pkgname, pkgdep) == 0) { + if (streq(pkgname, pkgdep)) { found = true; break; } diff --git a/lib/plist_remove.c b/lib/plist_remove.c index 3b812e56..1099ec41 100644 --- a/lib/plist_remove.c +++ b/lib/plist_remove.c @@ -60,7 +60,7 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode) if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep)) break; - if (strcmp(curpkgname, str) == 0) { + if (streq(curpkgname, str)) { found = true; break; } @@ -68,7 +68,7 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode) /* match by pkgname, obj is a dictionary */ xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &curname); - if (strcmp(curname, str) == 0) { + if (streq(curname, str)) { found = true; break; } @@ -76,7 +76,7 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode) /* match by pkgver, obj is a dictionary */ xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &curname); - if (strcmp(curname, str) == 0) { + if (streq(curname, str)) { found = true; break; } diff --git a/lib/repo.c b/lib/repo.c index ee872dc7..65629dcf 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -56,7 +56,7 @@ xbps_repo_path_with_name(struct xbps_handle *xhp, const char *url, const char *n /* XXX: rewrite ... */ assert(xhp); assert(url); - assert(strcmp(name, "repodata") == 0 || strcmp(name, "stagedata") == 0); + assert(streq(name, "repodata") || streq(name, "stagedata")); return xbps_xasprintf("%s/%s-%s", url, xhp->target_arch ? xhp->target_arch : xhp->native_arch, name); @@ -606,7 +606,7 @@ xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg) if (!xbps_pkg_name(vpkgn, XBPS_NAME_SIZE, vpkg)) { abort(); } - if (strcmp(vpkgn, pkg) == 0) { + if (streq(vpkgn, pkg)) { match = true; break; } diff --git a/lib/rpool.c b/lib/rpool.c index 600c42f0..98978a4c 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -65,7 +65,7 @@ xbps_rpool_sync(struct xbps_handle *xhp, const char *uri) for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); /* If argument was set just process that repository */ - if (uri && strcmp(repouri, uri)) + if (uri && !streq(repouri, uri)) continue; if (xbps_repo_sync(xhp, repouri) == -1) { @@ -89,7 +89,7 @@ xbps_regget_repo(struct xbps_handle *xhp, const char *url) /* iterate until we have a match */ for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); - if (strcmp(repouri, url)) + if (!streq(repouri, url)) continue; repo = xbps_repo_open(xhp, repouri); @@ -101,7 +101,7 @@ xbps_regget_repo(struct xbps_handle *xhp, const char *url) } } SIMPLEQ_FOREACH(repo, &rpool_queue, entries) - if (strcmp(url, repo->uri) == 0) + if (streq(url, repo->uri)) return repo; return NULL; @@ -113,7 +113,7 @@ xbps_rpool_get_repo(const char *url) struct xbps_repo *repo; SIMPLEQ_FOREACH(repo, &rpool_queue, entries) - if (strcmp(url, repo->uri) == 0) + if (streq(url, repo->uri)) return repo; return NULL; diff --git a/lib/transaction_check_conflicts.c b/lib/transaction_check_conflicts.c index d5055104..bff6d6f8 100644 --- a/lib/transaction_check_conflicts.c +++ b/lib/transaction_check_conflicts.c @@ -90,7 +90,7 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array, if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) { break; } - if (strcmp(pkgname, repopkgname) == 0) { + if (streq(pkgname, repopkgname)) { continue; } if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) { @@ -135,7 +135,7 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array, if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) { break; } - if (strcmp(pkgname, repopkgname) == 0) { + if (streq(pkgname, repopkgname)) { continue; } if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) { @@ -207,7 +207,7 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj, rv = EINVAL; break; } - if (strcmp(pkgname, repopkgname) == 0) { + if (streq(pkgname, repopkgname)) { continue; } if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) { diff --git a/lib/transaction_check_replaces.c b/lib/transaction_check_replaces.c index cde11fc5..97d2c8d8 100644 --- a/lib/transaction_check_replaces.c +++ b/lib/transaction_check_replaces.c @@ -101,7 +101,7 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs) * Check that we are not replacing the same package, * due to virtual packages. */ - if (strcmp(pkgname, curpkgname) == 0) { + if (streq(pkgname, curpkgname)) { continue; } /* diff --git a/lib/transaction_check_revdeps.c b/lib/transaction_check_revdeps.c index ad6304c1..a94bc7ce 100644 --- a/lib/transaction_check_revdeps.c +++ b/lib/transaction_check_revdeps.c @@ -72,10 +72,10 @@ check_virtual_pkgs(xbps_array_t mdeps, (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgpattern))) continue; - if (strcmp(vpkgname, pkgname)) { + if (!streq(vpkgname, pkgname)) { continue; } - if (!strcmp(vpkgver, pkgpattern) || + if (streq(vpkgver, pkgpattern) || xbps_pkgpattern_match(vpkgver, pkgpattern)) { continue; } @@ -222,7 +222,7 @@ xbps_transaction_check_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs) (!xbps_pkg_name(curdepname, sizeof(curdepname), curdep))) { return false; } - if (strcmp(curdepname, curpkgname) == 0) { + if (streq(curdepname, curpkgname)) { found = true; break; } diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index a15777c6..fa9eb23b 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -368,7 +368,7 @@ xbps_transaction_commit(struct xbps_handle *xhp) !xbps_dictionary_get(xhp->transd, "total-install-pkgs")) goto out; - if (xhp->target_arch && strcmp(xhp->native_arch, xhp->target_arch)) { + if (xhp->target_arch && !streq(xhp->native_arch, xhp->target_arch)) { /* if installing packages for target_arch, don't configure anything */ goto out; /* do not configure packages if only unpacking is desired */ diff --git a/lib/transaction_files.c b/lib/transaction_files.c index c98411cb..8730f2d3 100644 --- a/lib/transaction_files.c +++ b/lib/transaction_files.c @@ -165,7 +165,7 @@ can_delete_directory(const char *file, size_t len, size_t max) */ for (size_t i = 0; i < max; i++) { item = items[i]; - if (strncmp(item->file, file, len) == 0) { + if (strneq(item->file, file, len)) { if (!item->deleted) { closedir(dp); return false; @@ -298,7 +298,7 @@ collect_obsoletes(struct xbps_handle *xhp) * Make sure to not remove any symlink of root directory. */ for (uint8_t x = 0; x < ARRAY_SIZE(basesymlinks); x++) { - if (strcmp(item->file+1, basesymlinks[x]) == 0) { + if (streq(item->file+1, basesymlinks[x])) { found = true; break; } @@ -354,7 +354,7 @@ collect_obsoletes(struct xbps_handle *xhp) (xhp->flags & XBPS_FLAG_FORCE_REMOVE_FILES) == 0) { char path[PATH_MAX], *lnk; const char *file = item->file+1; - if (strcmp(xhp->rootdir, "/") != 0) { + if (!streq(xhp->rootdir, "/")) { snprintf(path, sizeof(path), "%s%s", xhp->rootdir, item->file+1); file = path; @@ -365,7 +365,7 @@ collect_obsoletes(struct xbps_handle *xhp) "symlink_target: %s\n", item->file+1, strerror(errno)); continue; } - if (strcmp(lnk, item->old.target) != 0) { + if (!streq(lnk, item->old.target)) { xbps_dbg_printf("[obsoletes] %s: skipping modified" " symlink (stored `%s' current `%s'): %s\n", item->old.pkgname, item->old.target, lnk, item->file+1); @@ -545,7 +545,7 @@ collect_file(struct xbps_handle *xhp, const char *file, size_t size, * The file was removed by one package * and installed by another package. */ - if (strcmp(item->new.pkgname, item->old.pkgname) != 0) { + if (!streq(item->new.pkgname, item->old.pkgname)) { if (removefile) { xbps_dbg_printf("[files] %s: %s moved to" " package `%s': %s\n", pkgver, typestr(item->old.type), @@ -728,7 +728,7 @@ collect_binpkg_files(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod, continue; entry_pname = archive_entry_pathname(entry); - if ((strcmp("./files.plist", entry_pname)) == 0) { + if (streq("./files.plist", entry_pname)) { filesd = xbps_archive_get_dictionary(ar, entry); if (filesd == NULL) { rv = EINVAL; diff --git a/lib/transaction_internalize.c b/lib/transaction_internalize.c index 2a2df12d..626cfea9 100644 --- a/lib/transaction_internalize.c +++ b/lib/transaction_internalize.c @@ -140,21 +140,21 @@ internalize_binpkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod) entry_pname = archive_entry_pathname(entry); - if (strcmp("./INSTALL", entry_pname) == 0) { + if (streq("./INSTALL", entry_pname)) { rv = internalize_script(pkg_repod, "install-script", ar, entry); if (rv < 0) goto out; - } else if (strcmp("./REMOVE", entry_pname) == 0) { + } else if (streq("./REMOVE", entry_pname)) { rv = internalize_script(pkg_repod, "remove-script", ar, entry); if (rv < 0) goto out; - } else if ((strcmp("./files.plist", entry_pname)) == 0) { + } else if (streq("./files.plist", entry_pname)) { filesd = xbps_archive_get_dictionary(ar, entry); if (filesd == NULL) { rv = -EINVAL; goto out; } - } else if (strcmp("./props.plist", entry_pname) == 0) { + } else if (streq("./props.plist", entry_pname)) { propsd = xbps_archive_get_dictionary(ar, entry); if (propsd == NULL) { rv = -EINVAL; @@ -180,7 +180,7 @@ internalize_binpkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod) * by advertising a old signed package with a new version. */ xbps_dictionary_get_cstring_nocopy(propsd, "pkgver", &binpkg_pkgver); - if (strcmp(pkgver, binpkg_pkgver) != 0) { + if (!streq(pkgver, binpkg_pkgver)) { rv = -EINVAL; xbps_set_cb_state(xhp, XBPS_STATE_FILES_FAIL, -rv, pkgver, "%s: [files] pkgver mismatch repodata: `%s' binpkg: `%s'.", diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index c987796b..ac401420 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -361,7 +361,7 @@ xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg, bool force switch (rv) { case 1: /* xbps needs to be updated, only allow xbps to be updated */ - if (strcmp(pkg, "xbps")) + if (!streq(pkg, "xbps")) return EBUSY; return 0; case -1: @@ -411,7 +411,7 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg, bool forc switch (rv) { case 1: /* xbps needs to be updated, only allow xbps to be updated */ - if (strcmp(pkg, "xbps")) + if (!streq(pkg, "xbps")) return EBUSY; return 0; case -1: diff --git a/lib/transaction_pkg_deps.c b/lib/transaction_pkg_deps.c index 5c7ab658..953ea175 100644 --- a/lib/transaction_pkg_deps.c +++ b/lib/transaction_pkg_deps.c @@ -66,9 +66,9 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg) if (!xbps_pkgpattern_name(pkgnamedep, XBPS_NAME_SIZE, reqpkg)) { goto out; } - if (strcmp(pkgnamedep, curpkgnamedep) == 0) { + if (streq(pkgnamedep, curpkgnamedep)) { pkgfound = true; - if (strcmp(curver, pkgver) == 0) { + if (streq(curver, pkgver)) { rv = EEXIST; goto out; } @@ -257,7 +257,7 @@ repo_deps(struct xbps_handle *xhp, abort(); } - if (strcmp(pkgname, curpkgname)) { + if (!streq(pkgname, curpkgname)) { xbps_dbg_printf_append("not installed `%s (vpkg)'", pkgver_q); if (xbps_dictionary_get(curpkgd, "hold")) { ttype = XBPS_TRANS_HOLD; @@ -376,7 +376,7 @@ repo_deps(struct xbps_handle *xhp, rv = EINVAL; break; } - if (strcmp(pkgname, reqpkgname) == 0) { + if (streq(pkgname, reqpkgname)) { xbps_dbg_printf_append("[ignoring wrong dependency %s (depends on itself)]\n", reqpkg); xbps_remove_string_from_array(pkg_rdeps, reqpkg); continue; diff --git a/lib/util.c b/lib/util.c index 15b27b2c..04d71515 100644 --- a/lib/util.c +++ b/lib/util.c @@ -74,12 +74,9 @@ xbps_repository_is_remote(const char *uri) { assert(uri != NULL); - if ((strncmp(uri, "http://", 7) == 0) || - (strncmp(uri, "https://", 8) == 0) || - (strncmp(uri, "ftp://", 6) == 0)) - return true; - - return false; + return strneq(uri, "http://", 7) || + strneq(uri, "https://", 8) || + strneq(uri, "ftp://", 6); } int @@ -449,26 +446,12 @@ bool xbps_pkg_arch_match(struct xbps_handle *xhp, const char *orig, const char *target) { - const char *arch; - - assert(xhp); - assert(orig); - - if (xhp->target_arch) - arch = xhp->target_arch; - else - arch = xhp->native_arch; - - if (target == NULL) { - if ((strcmp(orig, "noarch") == 0) || - (strcmp(orig, arch) == 0)) - return true; - } else { - if ((strcmp(orig, "noarch") == 0) || - (strcmp(orig, target) == 0)) - return true; - } - return false; + assert(xhp && orig); + if (streq(orig, "noarch")) + return true; + if (target && streq(orig, target)) + return true; + return streq(orig, xhp->target_arch ? xhp->target_arch : xhp->native_arch); } char * @@ -499,7 +482,7 @@ xbps_pkgpattern_match(const char *pkg, const char *pattern) assert(pattern); /* simple match on "pkg" against "pattern" */ - if (strcmp(pattern, pkg) == 0) + if (streq(pattern, pkg)) return 1; /* perform relational dewey match on version number */ @@ -565,7 +548,7 @@ xbps_pkg_reverts(xbps_dictionary_t pkg, const char *pkgver) for (i = 0; i < xbps_array_count(reverts); i++) { xbps_array_get_cstring_nocopy(reverts, i, &revertver); - if (strcmp(version, revertver) == 0) { + if (streq(version, revertver)) { return true; } } @@ -650,7 +633,7 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt) free(lnk); return strdup(tgt); } - if (strcmp(rootdir, "/") == 0) { + if (streq(rootdir, "/")) { res = strdup(p); } else { p1 = strdup(p + strlen(rootdir)); @@ -666,7 +649,7 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt) assert(p); dname = dirname(p); assert(dname); - if (strcmp(rootdir, "/") == 0) { + if (streq(rootdir, "/")) { p1 = xbps_xasprintf("%s/%s", dname, lnk); assert(p1); res = xbps_sanitize_path(p1); diff --git a/lib/util_hash.c b/lib/util_hash.c index acea80e3..b6b67974 100644 --- a/lib/util_hash.c +++ b/lib/util_hash.c @@ -230,7 +230,7 @@ file_hash_dictionary(xbps_dictionary_t d, const char *key, const char *file) while ((obj = xbps_object_iterator_next(iter)) != NULL) { xbps_dictionary_get_cstring_nocopy(obj, "file", &curfile); - if (strcmp(file, curfile) == 0) { + if (streq(file, curfile)) { /* file matched */ xbps_dictionary_get_cstring_nocopy(obj, "sha256", &sha256); @@ -265,7 +265,7 @@ xbps_file_hash_check_dictionary(struct xbps_handle *xhp, return -1; /* error */ } - if (strcmp(xhp->rootdir, "/") == 0) { + if (streq(xhp->rootdir, "/")) { rv = xbps_file_sha256_check(file, sha256d); } else { buf = xbps_xasprintf("%s/%s", xhp->rootdir, file);