From 3b23fb20e267e128e90707c2d84203e6598817b4 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Mon, 20 Feb 2023 02:37:29 +0100 Subject: [PATCH 1/6] lib: include assert per file, remove side effects from asserts --- bin/xbps-install/transaction.c | 1 + include/xbps_api_impl.h | 1 - lib/archive.c | 2 +- lib/conf.c | 3 ++- lib/download.c | 12 +++-------- lib/external/dewey.c | 1 + lib/initend.c | 2 ++ lib/package_alternatives.c | 6 +++--- lib/package_config_files.c | 1 + lib/package_configure.c | 5 +++-- lib/package_fulldeptree.c | 5 +++-- lib/package_msg.c | 4 ++-- lib/package_orphans.c | 5 +++-- lib/package_register.c | 3 ++- lib/package_remove.c | 4 +--- lib/package_script.c | 2 +- lib/package_state.c | 4 ++-- lib/package_unpack.c | 11 +++++++---- lib/pkgdb.c | 20 ++++++++++--------- lib/plist.c | 9 +++++---- lib/plist_fetch.c | 4 ++-- lib/plist_find.c | 33 ++++++++++++++++++------------- lib/plist_match.c | 5 +++-- lib/plist_remove.c | 4 ++-- lib/repo.c | 9 +++++---- lib/repo_sync.c | 4 ++-- lib/rpool.c | 6 ++---- lib/transaction_check_conflicts.c | 12 +++++++---- lib/transaction_check_replaces.c | 11 ++++++----- lib/transaction_check_revdeps.c | 2 +- lib/transaction_check_shlibs.c | 9 ++++++--- lib/transaction_commit.c | 10 ++++------ lib/transaction_files.c | 4 ++-- lib/transaction_internalize.c | 2 ++ lib/transaction_ops.c | 9 +++++---- lib/transaction_pkg_deps.c | 9 ++++++--- lib/transaction_prepare.c | 18 +++++++++-------- lib/transaction_store.c | 4 ++-- lib/util.c | 24 ++++++++++++++++++---- lib/util_hash.c | 9 +++++---- lib/verifysig.c | 20 +++++++++++-------- 41 files changed, 178 insertions(+), 131 deletions(-) diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 1e207741d..5d0f3eb41 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -400,6 +400,7 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d trans->d = xhp->transd; trans->iter = xbps_array_iter_from_dict(xhp->transd, "packages"); assert(trans->iter); + /* XXX: assert with side effect */ /* * dry-run mode, show what would be done but don't run anything. diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 66ffc3c1a..f05601382 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -27,7 +27,6 @@ #ifndef _XBPS_API_IMPL_H_ #define _XBPS_API_IMPL_H_ -#include #include "xbps.h" /* diff --git a/lib/archive.c b/lib/archive.c index 94cba292d..19b41bf86 100644 --- a/lib/archive.c +++ b/lib/archive.c @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ #include #include #include diff --git a/lib/conf.c b/lib/conf.c index f9724db81..24a2131cd 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -29,6 +29,8 @@ #ifdef __FreeBSD__ #define _WITH_GETLINE /* getline() */ #endif + +#include #include #include #include @@ -36,7 +38,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/download.c b/lib/download.c index 9005efc25..21d5a8933 100644 --- a/lib/download.c +++ b/lib/download.c @@ -30,17 +30,11 @@ * $FreeBSD: src/usr.bin/fetch/fetch.c,v 1.84.2.1 2009/08/03 08:13:06 kensmith Exp $ */ -#include -#include -#include -#include -#include -#include -#include +#include /* safe */ #include #include -#include -#include +#include +#include #include diff --git a/lib/external/dewey.c b/lib/external/dewey.c index 9ee9901b8..585314724 100644 --- a/lib/external/dewey.c +++ b/lib/external/dewey.c @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #define _BSD_SOURCE diff --git a/lib/initend.c b/lib/initend.c index 70ee26cb3..3e73a1fcb 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -25,6 +25,8 @@ */ #include + +#include /* safe */ #include #include #include diff --git a/lib/package_alternatives.c b/lib/package_alternatives.c index 7d3cddb61..8f3a8f046 100644 --- a/lib/package_alternatives.c +++ b/lib/package_alternatives.c @@ -24,12 +24,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include +#include #include #include #include -#include -#include #include "xbps_api_impl.h" diff --git a/lib/package_config_files.c b/lib/package_config_files.c index bc7f7995a..7f852a6d4 100644 --- a/lib/package_config_files.c +++ b/lib/package_config_files.c @@ -23,6 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/lib/package_configure.c b/lib/package_configure.c index 709ed1287..83937ce7e 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -23,10 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include /* safe */ +#include #include #include #include -#include #include "xbps_api_impl.h" /** @@ -96,7 +97,7 @@ xbps_configure_pkg(struct xbps_handle *xhp, pkg_state_t state = 0; mode_t myumask; - assert(pkgver != NULL); + assert(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) { p = pkgver; diff --git a/lib/package_fulldeptree.c b/lib/package_fulldeptree.c index 869fbd16a..b833fac56 100644 --- a/lib/package_fulldeptree.c +++ b/lib/package_fulldeptree.c @@ -23,13 +23,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include #include #include #include -#include #include "xbps_api_impl.h" + #include "uthash.h" struct item; diff --git a/lib/package_msg.c b/lib/package_msg.c index b7bdfe4be..e8227f0a4 100644 --- a/lib/package_msg.c +++ b/lib/package_msg.c @@ -23,10 +23,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include #include #include -#include #include "xbps_api_impl.h" diff --git a/lib/package_orphans.c b/lib/package_orphans.c index 49632d5b3..e49fa8278 100644 --- a/lib/package_orphans.c +++ b/lib/package_orphans.c @@ -23,11 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include #include +#include #include #include -#include #include "xbps_api_impl.h" diff --git a/lib/package_register.c b/lib/package_register.c index 5ea2f6f9f..588a94112 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -23,10 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include /* safe */ +#include #include #include #include -#include #include #include "xbps_api_impl.h" diff --git a/lib/package_remove.c b/lib/package_remove.c index 686a844f1..b952e135e 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -23,13 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ #include -#include #include #include #include -#include #include #include #include diff --git a/lib/package_script.c b/lib/package_script.c index f34ba32fc..29843aa36 100644 --- a/lib/package_script.c +++ b/lib/package_script.c @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include diff --git a/lib/package_state.c b/lib/package_state.c index caa8f79d5..bd099128c 100644 --- a/lib/package_state.c +++ b/lib/package_state.c @@ -23,11 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include #include #include #include -#include #include "xbps_api_impl.h" diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 1d446a8fb..dc6cbd1ef 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -24,14 +24,15 @@ */ #include -#include + +#include +#include +#include +#include #include #include #include -#include -#include #include -#include #include "xbps_api_impl.h" @@ -57,6 +58,7 @@ match_preserved_file(struct xbps_handle *xhp, const char *entry) return false; if (entry[0] == '.' && entry[1] != '\0') { + /* XXX: this is stupid */ file = strchr(entry, '.') + 1; assert(file); } else { @@ -283,6 +285,7 @@ unpack_archive(struct xbps_handle *xhp, * that should be kept. */ if (!force && (entry_type == AE_IFREG)) { + /* XXX: this is stupid */ buf = strchr(entry_pname, '.') + 1; assert(buf != NULL); keep_conf_file = xbps_entry_is_a_conf_file(binpkg_filesd, buf); diff --git a/lib/pkgdb.c b/lib/pkgdb.c index dae1acbe3..71f355940 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -23,14 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include - +#include #include #include #include #include -#include #include #include @@ -151,13 +148,15 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp) if (xhp->vpkgd == NULL) { xhp->vpkgd = xbps_dictionary_create(); - assert(xhp->vpkgd); + if (!xhp->vpkgd) + return errno; } /* * This maps all pkgs that have virtualpkgs in pkgdb. */ iter = xbps_dictionary_iterator(xhp->pkgdb); - assert(iter); + if (!iter) + return ENOMEM; while ((obj = xbps_object_iterator_next(iter))) { xbps_array_t provides; @@ -210,7 +209,8 @@ pkgdb_map_names(struct xbps_handle *xhp) * This way we do it once and not multiple times. */ iter = xbps_dictionary_iterator(xhp->pkgdb); - assert(iter); + if (!iter) + return ENOMEM; while ((obj = xbps_object_iterator_next(iter))) { xbps_dictionary_t pkgd; @@ -350,7 +350,8 @@ xbps_pkgdb_foreach_cb(struct xbps_handle *xhp, return rv; allkeys = xbps_dictionary_all_keys(xhp->pkgdb); - assert(allkeys); + if (!allkeys) + return ENOMEM; rv = xbps_array_foreach_cb(xhp, allkeys, xhp->pkgdb, fn, arg); xbps_object_release(allkeys); return rv; @@ -368,7 +369,8 @@ xbps_pkgdb_foreach_cb_multi(struct xbps_handle *xhp, return rv; allkeys = xbps_dictionary_all_keys(xhp->pkgdb); - assert(allkeys); + if (!allkeys) + return ENOMEM; rv = xbps_array_foreach_cb_multi(xhp, allkeys, xhp->pkgdb, fn, arg); xbps_object_release(allkeys); return rv; diff --git a/lib/plist.c b/lib/plist.c index 5a06dd810..675873312 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -23,12 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include +#include #include #include #include -#include -#include #include "xbps_api_impl.h" @@ -120,7 +120,8 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp, return xbps_array_foreach_cb(xhp, array, dict, fn, arg); thd = calloc(maxthreads, sizeof(*thd)); - assert(thd); + if (!thd) + return errno; // maxthread is boundchecked to be > 1 if((unsigned int)maxthreads >= arraycount) { diff --git a/lib/plist_fetch.c b/lib/plist_fetch.c index efeb0de73..8034b4206 100644 --- a/lib/plist_fetch.c +++ b/lib/plist_fetch.c @@ -26,10 +26,10 @@ * From: $NetBSD: pkg_io.c,v 1.9 2009/08/16 21:10:15 joerg Exp $ */ -#include +#include /* safe */ +#include #include #include -#include #include "xbps_api_impl.h" #include "fetch.h" diff --git a/lib/plist_find.c b/lib/plist_find.c index 4d51d1c0e..57128005a 100644 --- a/lib/plist_find.c +++ b/lib/plist_find.c @@ -23,14 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ #include #include #include #include -#include -#include -#include #include "xbps_api_impl.h" @@ -163,6 +160,8 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p) const char *pkgver = NULL; char pkgname[XBPS_NAME_SIZE] = {0}; + /* XXX: stupid functions, how to handle errors? */ + assert(repod); assert(p); @@ -175,13 +174,15 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p) } d = xbps_dictionary_get(repod, pkgname); - if (d) { - xbps_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver); - assert(pkgver); - if (!xbps_pkgpattern_match(pkgver, p)) { - d = NULL; - errno = ENOENT; - } + if (!d) + return NULL; + if (!xbps_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver)) { + errno = EINVAL; + return NULL; + } + if (!xbps_pkgpattern_match(pkgver, p)) { + errno = ENOENT; + return NULL; } return d; @@ -196,6 +197,8 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf) const char *pkg = NULL; bool found = false; + /* XXX: extremely stupid api, no errors, generally stupid */ + assert(xhp); assert(vpkg); @@ -207,11 +210,12 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf) (void)xbps_pkgdb_init(xhp); } - if (d == NULL) + if (!d) return NULL; iter = xbps_dictionary_iterator(d); - assert(iter); + if (!iter) + return NULL; while ((obj = xbps_object_iterator_next(iter))) { xbps_string_t rpkg; @@ -322,7 +326,8 @@ xbps_find_virtualpkg_in_dict(struct xbps_handle *xhp, } /* ... otherwise match the first one in dictionary */ iter = xbps_dictionary_iterator(d); - assert(iter); + if (!iter) + return NULL; while ((obj = xbps_object_iterator_next(iter))) { pkgd = xbps_dictionary_get_keysym(d, obj); diff --git a/lib/plist_match.c b/lib/plist_match.c index 37146e7ff..7e9355d66 100644 --- a/lib/plist_match.c +++ b/lib/plist_match.c @@ -23,11 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include #include +#include #include #include -#include #include "xbps_api_impl.h" diff --git a/lib/plist_remove.c b/lib/plist_remove.c index e5924950f..3b812e560 100644 --- a/lib/plist_remove.c +++ b/lib/plist_remove.c @@ -23,11 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include #include #include #include -#include #include "xbps_api_impl.h" diff --git a/lib/repo.c b/lib/repo.c index 95acd906c..ee872dc78 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -23,13 +23,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include +#include +#include #include #include #include -#include -#include -#include #include #include @@ -53,6 +53,7 @@ xbps_repo_path(struct xbps_handle *xhp, const char *url) char * xbps_repo_path_with_name(struct xbps_handle *xhp, const char *url, const char *name) { + /* XXX: rewrite ... */ assert(xhp); assert(url); assert(strcmp(name, "repodata") == 0 || strcmp(name, "stagedata") == 0); diff --git a/lib/repo_sync.c b/lib/repo_sync.c index dc1612390..836ced6c1 100644 --- a/lib/repo_sync.c +++ b/lib/repo_sync.c @@ -23,10 +23,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include #include #include -#include #include "xbps_api_impl.h" #include "fetch.h" diff --git a/lib/rpool.c b/lib/rpool.c index d9936575b..cf5099456 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -23,13 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include /* safe */ +#include #include #include -#include #include -#include #include "xbps_api_impl.h" #include "fetch.h" diff --git a/lib/transaction_check_conflicts.c b/lib/transaction_check_conflicts.c index c83d0ae59..e850be84c 100644 --- a/lib/transaction_check_conflicts.c +++ b/lib/transaction_check_conflicts.c @@ -23,11 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include #include #include #include -#include #include "xbps_api_impl.h" @@ -57,6 +57,8 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array, return; } + /* XXX: propagate errors */ + trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts"); if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver)) { return; @@ -66,7 +68,8 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array, } iter = xbps_array_iterator(pkg_cflicts); - assert(iter); + if (!iter) + return; while ((obj = xbps_object_iterator_next(iter))) { const char *pkgver = NULL, *pkgname = NULL; @@ -184,7 +187,8 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj, trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts"); iter = xbps_array_iterator(pkg_cflicts); - assert(iter); + if (!iter) + return EINVAL; while ((obj2 = xbps_object_iterator_next(iter))) { const char *pkgver = NULL, *pkgname = NULL; diff --git a/lib/transaction_check_replaces.c b/lib/transaction_check_replaces.c index b691666fa..cde11fc53 100644 --- a/lib/transaction_check_replaces.c +++ b/lib/transaction_check_replaces.c @@ -23,13 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include #include -#include #include -#include #include -#include #include "xbps_api_impl.h" @@ -59,6 +57,7 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs) if (replaces == NULL || xbps_array_count(replaces) == 0) continue; + /* XXX: propagate errors, wtf */ if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver)) { return false; } @@ -67,7 +66,9 @@ xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs) } iter = xbps_array_iterator(replaces); - assert(iter); + if (!iter) { + return false; + } while ((obj2 = xbps_object_iterator_next(iter)) != NULL) { const char *curpkgver = NULL, *pattern = NULL; diff --git a/lib/transaction_check_revdeps.c b/lib/transaction_check_revdeps.c index 3af3d86dc..ad6304c1f 100644 --- a/lib/transaction_check_revdeps.c +++ b/lib/transaction_check_revdeps.c @@ -180,7 +180,7 @@ xbps_transaction_check_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs) if (revpkgd == NULL) revpkgd = xbps_pkgdb_get_pkg(xhp, curpkgver); - + /* XXX: check revpkgd */ xbps_dictionary_get_cstring_nocopy(revpkgd, "pkgver", &revpkgver); /* * If target pkg is being removed, all its revdeps diff --git a/lib/transaction_check_shlibs.c b/lib/transaction_check_shlibs.c index d13655f48..27c8a347d 100644 --- a/lib/transaction_check_shlibs.c +++ b/lib/transaction_check_shlibs.c @@ -22,11 +22,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include + +#include +#include +#include #include #include -#include -#include #include "xbps_api_impl.h" @@ -68,6 +69,8 @@ collect_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, bool req) xbps_dictionary_t d, pd; const char *pkgname, *pkgver; + /* XXX: errors ????? */ + d = xbps_dictionary_create(); assert(d); diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 2a0dbd85b..a15777c6f 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -23,15 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include #include "xbps_api_impl.h" @@ -114,6 +111,7 @@ xbps_transaction_commit(struct xbps_handle *xhp) int rv = 0; bool update; + /* XXX: is this the right place? */ setlocale(LC_ALL, ""); /* diff --git a/lib/transaction_files.c b/lib/transaction_files.c index 693e3c98a..970dfac3a 100644 --- a/lib/transaction_files.c +++ b/lib/transaction_files.c @@ -24,6 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include /* safeish */ #include #include #include @@ -210,8 +211,7 @@ collect_obsoletes(struct xbps_handle *xhp) struct item *item; int rv = 0; - if (xhp->transd == NULL) - return ENOTSUP; + assert(xhp->transd); if (!xbps_dictionary_get_dict(xhp->transd, "obsolete_files", &obsd)) return ENOENT; diff --git a/lib/transaction_internalize.c b/lib/transaction_internalize.c index 7b37ea6be..2a2df12da 100644 --- a/lib/transaction_internalize.c +++ b/lib/transaction_internalize.c @@ -22,6 +22,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include /* safe */ #include #include #include diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index d4fef601e..c987796b7 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -23,12 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include +#include #include #include #include -#include -#include #include "xbps_api_impl.h" @@ -102,7 +102,8 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force) struct xbps_repo *repo; /* find update from repo */ xbps_dictionary_get_cstring_nocopy(pkg_pkgdb, "repository", &repoloc); - assert(repoloc); + if (!repoloc) + return EINVAL; if ((repo = xbps_regget_repo(xhp, repoloc)) == NULL) { /* not found */ return ENOENT; diff --git a/lib/transaction_pkg_deps.c b/lib/transaction_pkg_deps.c index ae0602ece..5c7ab658c 100644 --- a/lib/transaction_pkg_deps.c +++ b/lib/transaction_pkg_deps.c @@ -23,10 +23,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safeish */ +#include #include #include -#include #include "xbps_api_impl.h" @@ -142,7 +142,10 @@ repo_deps(struct xbps_handle *xhp, goto out; iter = xbps_array_iterator(pkg_rdeps); - assert(iter); + if (!iter) { + rv = ENOMEM; + goto out; + } while ((obj = xbps_object_iterator_next(iter))) { bool error = false, foundvpkg = false; diff --git a/lib/transaction_prepare.c b/lib/transaction_prepare.c index 76db67e8d..d82373999 100644 --- a/lib/transaction_prepare.c +++ b/lib/transaction_prepare.c @@ -23,12 +23,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include + +#include /* safe */ +#include #include #include #include -#include -#include #include "xbps_api_impl.h" @@ -281,7 +282,7 @@ xbps_transaction_prepare(struct xbps_handle *xhp) xbps_array_t pkgs, edges; xbps_dictionary_t tpkgd; xbps_trans_type_t ttype; - unsigned int i, cnt; + unsigned cnt; int rv = 0; bool all_on_hold = true; @@ -303,9 +304,9 @@ xbps_transaction_prepare(struct xbps_handle *xhp) * collected; the edges at the original array are removed later. */ pkgs = xbps_dictionary_get(xhp->transd, "packages"); - assert(xbps_object_type(pkgs) == XBPS_TYPE_ARRAY); cnt = xbps_array_count(pkgs); - for (i = 0; i < cnt; i++) { + /* XXX: this is broken, iteratoes over an array and adds more elements???? */ + for (unsigned i = 0; i < cnt; i++) { xbps_dictionary_t pkgd; xbps_string_t str; @@ -322,6 +323,7 @@ xbps_transaction_prepare(struct xbps_handle *xhp) xbps_object_release(edges); return ENOMEM; } + /* XXX: xbps_transaction_pkg_deps return code */ if ((rv = xbps_transaction_pkg_deps(xhp, pkgs, pkgd)) != 0) { xbps_object_release(edges); return rv; @@ -332,7 +334,7 @@ xbps_transaction_prepare(struct xbps_handle *xhp) } } /* ... remove dup edges at head */ - for (i = 0; i < xbps_array_count(edges); i++) { + for (unsigned i = 0; i < xbps_array_count(edges); i++) { const char *pkgver = NULL; xbps_array_get_cstring_nocopy(edges, i, &pkgver); xbps_remove_pkg_from_array_by_pkgver(pkgs, pkgver); @@ -351,7 +353,7 @@ xbps_transaction_prepare(struct xbps_handle *xhp) * for anything else. */ xbps_dbg_printf("%s: checking on hold pkgs\n", __func__); - for (i = 0; i < cnt; i++) { + for (unsigned i = 0; i < xbps_array_count(pkgs); i++) { tpkgd = xbps_array_get(pkgs, i); if (xbps_transaction_pkg_type(tpkgd) != XBPS_TRANS_HOLD) { all_on_hold = false; diff --git a/lib/transaction_store.c b/lib/transaction_store.c index 89d7c1fc5..6d446ad4e 100644 --- a/lib/transaction_store.c +++ b/lib/transaction_store.c @@ -23,10 +23,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* safe */ +#include #include #include -#include #include "xbps_api_impl.h" diff --git a/lib/util.c b/lib/util.c index 54847dbaa..15b27b2c3 100644 --- a/lib/util.c +++ b/lib/util.c @@ -35,6 +35,7 @@ #include +#include #include #include #include @@ -159,6 +160,8 @@ xbps_binpkg_pkgver(const char *pkg) char *p, *p1, *res; unsigned int len; + /* XXX: rewrite less stupid */ + assert(pkg); /* skip path if found, only interested in filename */ @@ -173,7 +176,8 @@ xbps_binpkg_pkgver(const char *pkg) len -= 5; p = malloc(len+1); - assert(p); + if (!p) + return NULL; (void)memcpy(p, fname, len); p[len] = '\0'; if (!(p1 = strrchr(p, '.'))) { @@ -188,7 +192,8 @@ xbps_binpkg_pkgver(const char *pkg) return NULL; } res = strdup(p); - assert(res); + if (!res) + return NULL; free(p); return res; @@ -201,6 +206,8 @@ xbps_binpkg_arch(const char *pkg) char *p, *p1, *res; unsigned int len; + /* XXX: rewrite less stupid */ + assert(pkg); /* skip path if found, only interested in filename */ @@ -215,7 +222,8 @@ xbps_binpkg_arch(const char *pkg) len -= 5; p = malloc(len+1); - assert(p); + if (!p) + return NULL; (void)memcpy(p, fname, len); p[len] = '\0'; if (!(p1 = strrchr(p, '.'))) { @@ -223,7 +231,10 @@ xbps_binpkg_arch(const char *pkg) return NULL; } res = strdup(p1 + 1); - assert(res); + if (!res) { + free(p); + return NULL; + } free(p); return res; @@ -350,6 +361,7 @@ xbps_repository_pkg_path(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod) /* * First check if binpkg is available in cachedir. */ + /* XXX: replace with sane buffer */ lbinpkg = xbps_xasprintf("%s/%s.%s.xbps", xhp->cachedir, pkgver, arch); if (access(lbinpkg, R_OK) == 0) @@ -360,6 +372,7 @@ xbps_repository_pkg_path(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod) /* * Local and remote repositories use the same path. */ + /* XXX: replace with sane buffer */ return xbps_xasprintf("%s/%s.%s.xbps", repoloc, pkgver, arch); } @@ -468,6 +481,7 @@ xbps_xasprintf(const char *fmt, ...) if (vasprintf(&buf, fmt, ap) == -1) { va_end(ap); assert(buf); + abort(); } va_end(ap); assert(buf); @@ -594,6 +608,8 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt) char *rootdir = NULL; ssize_t r; + /* XXX: rewrite wth... */ + assert(xhp); assert(path); assert(tgt); diff --git a/lib/util_hash.c b/lib/util_hash.c index 4b1de715b..acea80e30 100644 --- a/lib/util_hash.c +++ b/lib/util_hash.c @@ -23,13 +23,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include -#include -#include -#include + +#include #include #include #include +#include +#include +#include #include diff --git a/lib/verifysig.c b/lib/verifysig.c index b8b8f4c2d..78ea1bd26 100644 --- a/lib/verifysig.c +++ b/lib/verifysig.c @@ -23,14 +23,15 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include + +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include #include #include @@ -52,9 +53,12 @@ rsa_verify_hash(struct xbps_repo *repo, xbps_data_t pubkey, ERR_load_crypto_strings(); SSL_load_error_strings(); - bio = BIO_new_mem_buf(xbps_data_data_nocopy(pubkey), - xbps_data_size(pubkey)); - assert(bio); + bio = BIO_new_mem_buf(xbps_data_data_nocopy(pubkey), xbps_data_size(pubkey)); + if (!bio) { + xbps_error_printf("failed to load public key: %s\n", + ERR_error_string(ERR_get_error(), NULL)); + return false; + } rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL); if (rsa == NULL) { From 349f1534881d5e2bc8cf51f8cb40ae0eea15f953 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Fri, 1 Sep 2023 16:02:39 +0200 Subject: [PATCH 2/6] add macro.h header --- bin/xbps-alternatives/main.c | 2 ++ bin/xbps-checkvers/main.c | 17 +++++++----- bin/xbps-create/main.c | 27 ++++++++++--------- bin/xbps-fbulk/main.c | 24 +++++++++-------- bin/xbps-install/main.c | 2 ++ bin/xbps-install/state_cb.c | 7 +++-- bin/xbps-pkgdb/check.c | 9 ++++--- bin/xbps-pkgdb/check_pkg_unneeded.c | 9 ++----- bin/xbps-pkgdb/main.c | 7 ++--- bin/xbps-query/list.c | 10 +++++--- bin/xbps-query/main.c | 5 ++-- bin/xbps-query/ownedby.c | 14 +++++----- bin/xbps-query/search.c | 16 +++++++----- bin/xbps-reconfigure/main.c | 8 +++--- bin/xbps-remove/clean-cache.c | 12 +++++---- bin/xbps-remove/main.c | 14 +++++----- bin/xbps-rindex/index-clean.c | 17 +++++++----- bin/xbps-rindex/remove-obsoletes.c | 13 ++++++---- configure | 1 - include/compat.h | 9 +++---- include/macro.h | 40 +++++++++++++++++++++++++++++ include/xbps_api_impl.h | 17 +----------- lib/pkgdb.c | 1 + lib/plist_fetch.c | 1 + lib/rpool.c | 1 + lib/transaction_check_conflicts.c | 1 + lib/util_path.c | 3 +++ 27 files changed, 176 insertions(+), 111 deletions(-) create mode 100644 include/macro.h diff --git a/bin/xbps-alternatives/main.c b/bin/xbps-alternatives/main.c index 6bfbae6c4..853640135 100644 --- a/bin/xbps-alternatives/main.c +++ b/bin/xbps-alternatives/main.c @@ -35,6 +35,8 @@ #include +#include "macro.h" + static void __attribute__((noreturn)) usage(bool fail) { diff --git a/bin/xbps-checkvers/main.c b/bin/xbps-checkvers/main.c index ab1f56f34..c63c4df0d 100644 --- a/bin/xbps-checkvers/main.c +++ b/bin/xbps-checkvers/main.c @@ -26,21 +26,24 @@ * */ +#include + +#include +#include +#include +#include #include +#include #include -#include #include +#include #include #include -#include -#include -#include -#include -#include -#include #include +#include "macro.h" + #define GOT_PKGNAME_VAR 0x1 #define GOT_VERSION_VAR 0x2 #define GOT_REVISION_VAR 0x4 diff --git a/bin/xbps-create/main.c b/bin/xbps-create/main.c index a9a902ba0..37e78a3db 100644 --- a/bin/xbps-create/main.c +++ b/bin/xbps-create/main.c @@ -22,27 +22,30 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include #include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include #include + +#include "macro.h" #include "queue.h" #ifdef __clang__ diff --git a/bin/xbps-fbulk/main.c b/bin/xbps-fbulk/main.c index ea298e392..4bd10b055 100644 --- a/bin/xbps-fbulk/main.c +++ b/bin/xbps-fbulk/main.c @@ -49,22 +49,26 @@ */ #define _DEFAULT_SOURCE #define _BSD_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #include #include #include + +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include #include + +#include "macro.h" #include "uthash.h" #ifndef __arraycount diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index 639847a6f..c7eb56595 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -35,7 +35,9 @@ #include #include + #include "defs.h" +#include "macro.h" static void __attribute__((noreturn)) usage(bool fail) diff --git a/bin/xbps-install/state_cb.c b/bin/xbps-install/state_cb.c index a13ebbaf8..28e06fbd5 100644 --- a/bin/xbps-install/state_cb.c +++ b/bin/xbps-install/state_cb.c @@ -23,13 +23,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include -#include #include -#include + #include + #include "defs.h" +#include "macro.h" int state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED) diff --git a/bin/xbps-pkgdb/check.c b/bin/xbps-pkgdb/check.c index f5dcf9dac..12b6dfac3 100644 --- a/bin/xbps-pkgdb/check.c +++ b/bin/xbps-pkgdb/check.c @@ -24,16 +24,19 @@ */ #include -#include + +#include +#include #include +#include #include #include -#include #include -#include #include + #include "defs.h" +#include "macro.h" static int pkgdb_cb(struct xbps_handle *xhp UNUSED, diff --git a/bin/xbps-pkgdb/check_pkg_unneeded.c b/bin/xbps-pkgdb/check_pkg_unneeded.c index 2b137b3fb..90702cb71 100644 --- a/bin/xbps-pkgdb/check_pkg_unneeded.c +++ b/bin/xbps-pkgdb/check_pkg_unneeded.c @@ -23,17 +23,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include #include -#include -#include -#include -#include -#include #include + #include "defs.h" +#include "macro.h" /* * Checks package integrity of an installed package. diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-pkgdb/main.c index 48751e98c..e0b7091c7 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-pkgdb/main.c @@ -23,15 +23,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include #include +#include #include #include #include -#include -#include #include + #include "defs.h" static void __attribute__((noreturn)) diff --git a/bin/xbps-query/list.c b/bin/xbps-query/list.c index c22ae00de..e3f3bbbbc 100644 --- a/bin/xbps-query/list.c +++ b/bin/xbps-query/list.c @@ -24,14 +24,18 @@ */ #include -#include + +#include +#include #include +#include #include -#include #include -#include + +#include #include "defs.h" +#include "macro.h" struct list_pkgver_cb { unsigned int pkgver_len; diff --git a/bin/xbps-query/main.c b/bin/xbps-query/main.c index 44316c1ad..73cc84060 100644 --- a/bin/xbps-query/main.c +++ b/bin/xbps-query/main.c @@ -23,13 +23,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include #include -#include -#include #include + #include "defs.h" static void __attribute__((noreturn)) diff --git a/bin/xbps-query/ownedby.c b/bin/xbps-query/ownedby.c index 356224ec4..9edc6be41 100644 --- a/bin/xbps-query/ownedby.c +++ b/bin/xbps-query/ownedby.c @@ -23,18 +23,20 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include -#include +#include +#include #include #include -#include -#include #include +#include +#include +#include +#include #include + #include "defs.h" +#include "macro.h" struct ffdata { bool rematch; diff --git a/bin/xbps-query/search.c b/bin/xbps-query/search.c index 6724e3ef2..bf1bac27f 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -29,19 +29,21 @@ #include "compat.h" -#include -#include -#include -#include +#include #include -#include -#include #include -#include +#include +#include #include +#include +#include +#include +#include #include + #include "defs.h" +#include "macro.h" struct search_data { bool regex, repo_mode; diff --git a/bin/xbps-reconfigure/main.c b/bin/xbps-reconfigure/main.c index c1f4e2fc5..ea0f2afcb 100644 --- a/bin/xbps-reconfigure/main.c +++ b/bin/xbps-reconfigure/main.c @@ -23,16 +23,18 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include +#include #include #include -#include -#include #include +#include #include + #include "defs.h" +#include "macro.h" static void __attribute__((noreturn)) usage(bool fail) diff --git a/bin/xbps-remove/clean-cache.c b/bin/xbps-remove/clean-cache.c index ea9caccb5..fb993820d 100644 --- a/bin/xbps-remove/clean-cache.c +++ b/bin/xbps-remove/clean-cache.c @@ -23,19 +23,21 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include +#include +#include #include +#include #include #include #include -#include -#include #include -#include -#include #include + #include "defs.h" +#include "macro.h" static int binpkg_parse(char *buf, size_t bufsz, const char *path, const char **pkgver, const char **arch) diff --git a/bin/xbps-remove/main.c b/bin/xbps-remove/main.c index 7c24d614d..4b2b8d6bf 100644 --- a/bin/xbps-remove/main.c +++ b/bin/xbps-remove/main.c @@ -23,21 +23,23 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include +#include +#include +#include #include +#include #include #include #include -#include -#include -#include -#include -#include #include +#include #include + #include "../xbps-install/defs.h" #include "defs.h" +#include "macro.h" static void __attribute__((noreturn)) usage(bool fail) diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index 9e33e4095..ba3693577 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -24,19 +24,22 @@ */ #include -#include -#include -#include -#include -#include + +#include #include +#include +#include #include -#include #include -#include +#include +#include +#include +#include #include + #include "defs.h" +#include "macro.h" static xbps_dictionary_t dest; diff --git a/bin/xbps-rindex/remove-obsoletes.c b/bin/xbps-rindex/remove-obsoletes.c index 913c04292..00ad000c6 100644 --- a/bin/xbps-rindex/remove-obsoletes.c +++ b/bin/xbps-rindex/remove-obsoletes.c @@ -24,17 +24,20 @@ */ #include -#include + +#include +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include #include + #include "defs.h" +#include "macro.h" static int remove_pkg(const char *repodir, const char *file) diff --git a/configure b/configure index c7d78bf16..ba8c44578 100755 --- a/configure +++ b/configure @@ -200,7 +200,6 @@ echo "CPPFLAGS += -DXBPS_SYSCONF_PATH=\\\"${ETCDIR}\\\"" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_SYSDEFCONF_PATH=\\\"${SHAREDIR}/xbps.d\\\"" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_VERSION=\\\"${VERSION}\\\"" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_META_PATH=\\\"${DBDIR}\\\"" >>$CONFIG_MK -echo "CPPFLAGS += -DUNUSED=\"__attribute__((__unused__))\"" >>$CONFIG_MK if [ -d .git ] && command -v git >/dev/null; then _gitrev=$(git rev-parse --short HEAD) diff --git a/include/compat.h b/include/compat.h index cedd1be29..80528d595 100644 --- a/include/compat.h +++ b/include/compat.h @@ -1,15 +1,12 @@ #ifndef COMPAT_H #define COMPAT_H -#include #include + #include +#include -#if HAVE_VISIBILITY -#define HIDDEN __attribute__ ((visibility("hidden"))) -#else -#define HIDDEN -#endif +#include "macro.h" #ifndef HAVE_STRLCAT size_t HIDDEN strlcat(char *, const char *, size_t); diff --git a/include/macro.h b/include/macro.h new file mode 100644 index 000000000..1316f7582 --- /dev/null +++ b/include/macro.h @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2012-2020 Juan Romero Pardines. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef XBPS_MACRO_H +#define XBPS_MACRO_H + +#define UNUSED __attribute__((__unused__)) + +#ifndef __UNCONST +# define __UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) +#endif + +#if HAVE_VISIBILITY +# define HIDDEN __attribute__ ((visibility("hidden"))) +#else +# define HIDDEN +#endif + +#endif /*!XBPS_MACRO_H*/ diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index f05601382..02ba9bb02 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -29,19 +29,8 @@ #include "xbps.h" -/* - * By default all public functions have default visibility, unless - * visibility has been detected by configure and the HIDDEN definition - * is used. - */ -#if HAVE_VISIBILITY -#define HIDDEN __attribute__ ((visibility("hidden"))) -#else -#define HIDDEN -#endif - #include "queue.h" -#include "compat.h" +#include "macro.h" #define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \ ARCHIVE_EXTRACT_SECURE_SYMLINKS | \ @@ -50,10 +39,6 @@ ARCHIVE_EXTRACT_UNLINK #define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | EXTRACT_FLAGS -#ifndef __UNCONST -#define __UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) -#endif - #ifndef __arraycount #define __arraycount(x) (sizeof(x) / sizeof(*x)) #endif diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 71f355940..8ba7496fd 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -31,6 +31,7 @@ #include #include +#include "macro.h" #include "xbps_api_impl.h" /** diff --git a/lib/plist_fetch.c b/lib/plist_fetch.c index 8034b4206..764fa5213 100644 --- a/lib/plist_fetch.c +++ b/lib/plist_fetch.c @@ -31,6 +31,7 @@ #include #include +#include "macro.h" #include "xbps_api_impl.h" #include "fetch.h" diff --git a/lib/rpool.c b/lib/rpool.c index cf5099456..600c42f03 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -29,6 +29,7 @@ #include #include +#include "macro.h" #include "xbps_api_impl.h" #include "fetch.h" diff --git a/lib/transaction_check_conflicts.c b/lib/transaction_check_conflicts.c index e850be84c..d50551049 100644 --- a/lib/transaction_check_conflicts.c +++ b/lib/transaction_check_conflicts.c @@ -29,6 +29,7 @@ #include #include +#include "macro.h" #include "xbps_api_impl.h" static void diff --git a/lib/util_path.c b/lib/util_path.c index e6e8c97b5..2f0e05864 100644 --- a/lib/util_path.c +++ b/lib/util_path.c @@ -58,9 +58,12 @@ #include #include +#include +#include #include #include +/* XXX: this shouldn't need xbps_api_impl.h */ #include "xbps_api_impl.h" ssize_t From 5bd8d352506201835b103514fbeffcc8d6958b73 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Fri, 1 Sep 2023 16:15:13 +0200 Subject: [PATCH 3/6] replace __arraycount with ARRAY_SIZE --- include/macro.h | 2 ++ include/xbps_api_impl.h | 4 ---- lib/conf.c | 3 ++- lib/pkgdb_conversion.c | 12 +++++++----- lib/transaction_files.c | 5 +++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/macro.h b/include/macro.h index 1316f7582..cbf91ea9e 100644 --- a/include/macro.h +++ b/include/macro.h @@ -37,4 +37,6 @@ # define HIDDEN #endif +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + #endif /*!XBPS_MACRO_H*/ diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 02ba9bb02..42e99b0cd 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -39,10 +39,6 @@ ARCHIVE_EXTRACT_UNLINK #define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | EXTRACT_FLAGS -#ifndef __arraycount -#define __arraycount(x) (sizeof(x) / sizeof(*x)) -#endif - /** * @private */ diff --git a/lib/conf.c b/lib/conf.c index 24a2131cd..62adfddf4 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -42,6 +42,7 @@ #include #include +#include "macro.h" #include "xbps_api_impl.h" /** @@ -212,7 +213,7 @@ parse_option(char *line, size_t linelen, char **valp, size_t *vallen) if (*p != '=') return KEY_ERROR; - result = bsearch(&needle, keys, __arraycount(keys), sizeof(struct key), cmpkey); + result = bsearch(&needle, keys, ARRAY_SIZE(keys), sizeof(struct key), cmpkey); if (result == NULL) return KEY_ERROR; diff --git a/lib/pkgdb_conversion.c b/lib/pkgdb_conversion.c index c9be47d6c..079e7a1b9 100644 --- a/lib/pkgdb_conversion.c +++ b/lib/pkgdb_conversion.c @@ -23,14 +23,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include + +#include +#include #include +#include #include #include -#include -#include -#include +#include "macro.h" #include "xbps_api_impl.h" static int @@ -115,7 +117,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 < __arraycount(excluded); i++) { + for (uint8_t i = 0; i < ARRAY_SIZE(excluded); i++) { if (strcmp(excluded[i], key) == 0) { skip = true; break; diff --git a/lib/transaction_files.c b/lib/transaction_files.c index 970dfac3a..c98411cb0 100644 --- a/lib/transaction_files.c +++ b/lib/transaction_files.c @@ -32,8 +32,9 @@ #include #include -#include "xbps_api_impl.h" +#include "macro.h" #include "uthash.h" +#include "xbps_api_impl.h" enum type { TYPE_LINK = 1, @@ -296,7 +297,7 @@ collect_obsoletes(struct xbps_handle *xhp) /* * Make sure to not remove any symlink of root directory. */ - for (uint8_t x = 0; x < __arraycount(basesymlinks); x++) { + for (uint8_t x = 0; x < ARRAY_SIZE(basesymlinks); x++) { if (strcmp(item->file+1, basesymlinks[x]) == 0) { found = true; break; From cf5afa870546c415afdc5e1a21c23f106bae5fa6 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Fri, 1 Sep 2023 16:24:34 +0200 Subject: [PATCH 4/6] 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 cbf91ea9e..c6e21ebd5 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 8f3a8f046..fc46b973a 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 7f852a6d4..df9cd7ab9 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 e8227f0a4..fad9cc62c 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 29843aa36..ecf1103fd 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 bd099128c..efefa1cfe 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 dc6cbd1ef..c069367a4 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 079e7a1b9..b519bba39 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 675873312..3b4dee30a 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 764fa5213..a95b09da4 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 57128005a..e04e3f433 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 7e9355d66..1842fab69 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 3b812e560..1099ec415 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 ee872dc78..65629dcfd 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 600c42f03..98978a4cc 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 d50551049..bff6d6f89 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 cde11fc53..97d2c8d82 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 ad6304c1f..a94bc7ce8 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 a15777c6f..fa9eb23bd 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 c98411cb0..8730f2d3c 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 2a2df12da..626cfea96 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 c987796b7..ac401420f 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 5c7ab658c..953ea1755 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 15b27b2c3..04d715157 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 acea80e30..b6b67974f 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); From 6341168f4f70593aa1fcb60df164c9287bb8a85a Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Fri, 1 Sep 2023 21:05:32 +0200 Subject: [PATCH 5/6] remove xbps_strl{cat,cpy} and use strl{cat,cpy} directly --- bin/xbps-alternatives/main.c | 4 +- bin/xbps-checkvers/main.c | 8 +-- bin/xbps-dgraph/main.c | 4 +- bin/xbps-install/main.c | 6 +- bin/xbps-pkgdb/main.c | 4 +- bin/xbps-query/main.c | 6 +- bin/xbps-reconfigure/main.c | 4 +- bin/xbps-remove/clean-cache.c | 2 +- bin/xbps-remove/main.c | 6 +- bin/xbps-uhelper/main.c | 4 +- configure | 2 +- include/compat.h | 15 ----- lib/compat/stdio.h | 10 ++++ lib/compat/string.h | 18 ++++++ lib/compat/strlcat.c | 52 +++++++++--------- lib/compat/strlcpy.c | 41 +++++++------- lib/conf.c | 2 +- lib/download.c | 4 +- lib/external/dewey.c | 2 +- lib/fetch/common.c | 2 - lib/fetch/fetch.c | 2 - lib/fetch/file.c | 2 - lib/initend.c | 4 +- lib/portableproplib/prop_object.c | 2 - lib/util.c | 18 ------ lib/util_path.c | 14 ++--- tests/xbps/libxbps/config/main.c | 28 +++++----- tests/xbps/libxbps/find_pkg_orphans/main.c | 8 +-- tests/xbps/libxbps/pkgdb/main.c | 16 +++--- tests/xbps/libxbps/util_path/main.c | 64 +++++++++++----------- 30 files changed, 168 insertions(+), 186 deletions(-) create mode 100644 lib/compat/stdio.h create mode 100644 lib/compat/string.h diff --git a/bin/xbps-alternatives/main.c b/bin/xbps-alternatives/main.c index 853640135..92b8afe72 100644 --- a/bin/xbps-alternatives/main.c +++ b/bin/xbps-alternatives/main.c @@ -230,9 +230,9 @@ main(int argc, char **argv) memset(&xh, 0, sizeof(xh)); xh.state_cb = state_cb; if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); xh.flags = flags; diff --git a/bin/xbps-checkvers/main.c b/bin/xbps-checkvers/main.c index c63c4df0d..b8c378c34 100644 --- a/bin/xbps-checkvers/main.c +++ b/bin/xbps-checkvers/main.c @@ -113,10 +113,10 @@ rcv_init(rcv_t *rcv, const char *prog) assert(rcv->cache); if (rcv->xbps_conf != NULL) { - xbps_strlcpy(rcv->xhp.confdir, rcv->xbps_conf, sizeof(rcv->xhp.confdir)); + strlcpy(rcv->xhp.confdir, rcv->xbps_conf, sizeof(rcv->xhp.confdir)); } if (rcv->rootdir != NULL) { - xbps_strlcpy(rcv->xhp.rootdir, rcv->rootdir, sizeof(rcv->xhp.rootdir)); + strlcpy(rcv->xhp.rootdir, rcv->rootdir, sizeof(rcv->xhp.rootdir)); } if (xbps_init(&rcv->xhp) != 0) abort(); @@ -820,8 +820,8 @@ main(int argc, char **argv) if ((p = strrchr(argv[i], '/')) && (strcmp(p, "/template")) == 0) { tmpl = argv[i]; } else { - xbps_strlcat(tmp, argv[i], sizeof tmp); - xbps_strlcat(tmp, "/template", sizeof tmp); + strlcat(tmp, argv[i], sizeof tmp); + strlcat(tmp, "/template", sizeof tmp); tmpl = tmp; } rcv_process_file(&rcv, tmpl, rcv_check_version); diff --git a/bin/xbps-dgraph/main.c b/bin/xbps-dgraph/main.c index 5f6eee08e..59b5dbbb0 100644 --- a/bin/xbps-dgraph/main.c +++ b/bin/xbps-dgraph/main.c @@ -598,9 +598,9 @@ main(int argc, char **argv) /* Initialize libxbps */ memset(&xh, 0, sizeof(xh)); if (rootdir != NULL) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); xh.flags = flags; if ((rv = xbps_init(&xh)) != 0) diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index c7eb56595..a6f8e3039 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -216,11 +216,11 @@ main(int argc, char **argv) xh.fetch_cb = fetch_file_progress_cb; xh.fetch_cb_data = &xfer; if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (cachedir) - xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir)); + strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); xh.flags = flags; if (flags & XBPS_FLAG_VERBOSE) xh.unpack_cb = unpack_progress_cb; diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-pkgdb/main.c index e0b7091c7..a33e06f8f 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-pkgdb/main.c @@ -144,9 +144,9 @@ main(int argc, char **argv) memset(&xh, 0, sizeof(xh)); if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); xh.flags = flags; if ((rv = xbps_init(&xh)) != 0) { diff --git a/bin/xbps-query/main.c b/bin/xbps-query/main.c index 73cc84060..103ef7838 100644 --- a/bin/xbps-query/main.c +++ b/bin/xbps-query/main.c @@ -241,11 +241,11 @@ main(int argc, char **argv) * Initialize libxbps. */ if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (cachedir) - xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir)); + strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); xh.flags = flags; diff --git a/bin/xbps-reconfigure/main.c b/bin/xbps-reconfigure/main.c index ea0f2afcb..8b50c0b76 100644 --- a/bin/xbps-reconfigure/main.c +++ b/bin/xbps-reconfigure/main.c @@ -168,9 +168,9 @@ main(int argc, char **argv) memset(&xh, 0, sizeof(xh)); xh.state_cb = state_cb; if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); xh.flags = flags; diff --git a/bin/xbps-remove/clean-cache.c b/bin/xbps-remove/clean-cache.c index fb993820d..7606122a7 100644 --- a/bin/xbps-remove/clean-cache.c +++ b/bin/xbps-remove/clean-cache.c @@ -43,7 +43,7 @@ static int binpkg_parse(char *buf, size_t bufsz, const char *path, const char **pkgver, const char **arch) { char *p; - size_t n = xbps_strlcpy(buf, path, bufsz); + size_t n = strlcpy(buf, path, bufsz); if (n >= bufsz) return -ENOBUFS; diff --git a/bin/xbps-remove/main.c b/bin/xbps-remove/main.c index 4b2b8d6bf..6470cc36f 100644 --- a/bin/xbps-remove/main.c +++ b/bin/xbps-remove/main.c @@ -251,11 +251,11 @@ main(int argc, char **argv) memset(&xh, 0, sizeof(xh)); xh.state_cb = state_cb_rm; if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (cachedir) - xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir)); + strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); xh.flags = flags; diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 84eca5bf7..edc1fb850 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -146,9 +146,9 @@ main(int argc, char **argv) xh.fetch_cb_data = &xfer; xh.flags = flags; if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); + strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); + strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); if ((rv = xbps_init(&xh)) != 0) { xbps_error_printf("xbps-uhelper: failed to " "initialize libxbps: %s.\n", strerror(rv)); diff --git a/configure b/configure index ba8c44578..516a32ba0 100755 --- a/configure +++ b/configure @@ -195,7 +195,7 @@ echo "CC = $CC" >>$CONFIG_MK echo "CFLAGS = -O2" >>$CONFIG_MK echo "LDFLAGS = -L\$(TOPDIR)/lib" >>$CONFIG_MK -echo "CPPFLAGS = -I. -I\$(TOPDIR) -I\$(TOPDIR)/include" >>$CONFIG_MK +echo "CPPFLAGS = -I\$(TOPDIR)/lib/compat -I. -I\$(TOPDIR) -I\$(TOPDIR)/include" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_SYSCONF_PATH=\\\"${ETCDIR}\\\"" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_SYSDEFCONF_PATH=\\\"${SHAREDIR}/xbps.d\\\"" >>$CONFIG_MK echo "CPPFLAGS += -DXBPS_VERSION=\\\"${VERSION}\\\"" >>$CONFIG_MK diff --git a/include/compat.h b/include/compat.h index 80528d595..f030cc70a 100644 --- a/include/compat.h +++ b/include/compat.h @@ -8,21 +8,6 @@ #include "macro.h" -#ifndef HAVE_STRLCAT -size_t HIDDEN strlcat(char *, const char *, size_t); -#endif - -#ifndef HAVE_STRLCPY -size_t HIDDEN strlcpy(char *, const char *, size_t); -#endif - -#ifndef HAVE_STRCASESTR -char HIDDEN *strcasestr(const char *, const char *); -#endif - -#ifndef HAVE_VASPRINTF -int HIDDEN vasprintf(char **, const char *, va_list); -#endif #ifndef HAVE_HUMANIZE_NUMBER #define HN_DECIMAL 0x01 diff --git a/lib/compat/stdio.h b/lib/compat/stdio.h new file mode 100644 index 000000000..ca951d91d --- /dev/null +++ b/lib/compat/stdio.h @@ -0,0 +1,10 @@ +#ifndef XBPS_COMPAT_STDIO_H +#define XBPS_COMPAT_STDIO_H + +#include_next + +#ifndef HAVE_VASPRINTF +int vasprintf(char **, const char *, va_list); +#endif + +#endif /*!XBPS_COMPAT_STDIO_H*/ diff --git a/lib/compat/string.h b/lib/compat/string.h new file mode 100644 index 000000000..7bb18eeab --- /dev/null +++ b/lib/compat/string.h @@ -0,0 +1,18 @@ +#ifndef XBPS_COMPAT_STRING_H +#define XBPS_COMPAT_STRING_H + +#include_next + +#ifndef HAVE_STRLCAT +size_t strlcat(char *, const char *, size_t); +#endif + +#ifndef HAVE_STRLCPY +size_t strlcpy(char *, const char *, size_t); +#endif + +#ifndef HAVE_STRCASESTR +char *strcasestr(const char *, const char *); +#endif + +#endif /*!XBPS_COMPAT_STRING_H*/ diff --git a/lib/compat/strlcat.c b/lib/compat/strlcat.c index ff2731146..c94e90dee 100644 --- a/lib/compat/strlcat.c +++ b/lib/compat/strlcat.c @@ -1,7 +1,7 @@ -/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ /* - * Copyright (c) 1998 Todd C. Miller + * Copyright (c) 1998, 2015 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,39 +19,37 @@ #include #include -#include "compat.h" - /* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. */ -size_t HIDDEN -strlcat(char *dst, const char *src, size_t siz) +size_t +strlcat(char *dst, const char *src, size_t dsize) { - char *d = dst; - const char *s = src; - size_t n = siz; + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; size_t dlen; - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; n--; } - s++; + src++; } - *d = '\0'; + *dst = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + return(dlen + (src - osrc)); /* count does not include NUL */ } diff --git a/lib/compat/strlcpy.c b/lib/compat/strlcpy.c index 0915199a0..2fa498c39 100644 --- a/lib/compat/strlcpy.c +++ b/lib/compat/strlcpy.c @@ -1,7 +1,7 @@ -/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ +/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ /* - * Copyright (c) 1998 Todd C. Miller + * Copyright (c) 1998, 2015 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,35 +19,32 @@ #include #include -#include "compat.h" - /* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. */ -size_t HIDDEN -strlcpy(char *dst, const char *src, size_t siz) +size_t +strlcpy(char *dst, const char *src, size_t dsize) { - char *d = dst; - const char *s = src; - size_t n = siz; + const char *osrc = src; + size_t nleft = dsize; - /* Copy as many bytes as will fit */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') break; } } - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) ; } - return(s - src - 1); /* count does not include NUL */ + return(src - osrc - 1); /* count does not include NUL */ } diff --git a/lib/conf.c b/lib/conf.c index 62adfddf4..49bd9af5d 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -109,7 +109,7 @@ store_preserved_file(struct xbps_handle *xhp, const char *file) len = strlen(globbuf.gl_pathv[i]) - strlen(xhp->rootdir) + 1; p = malloc(len); assert(p); - xbps_strlcpy(p, globbuf.gl_pathv[i] + strlen(xhp->rootdir), len); + strlcpy(p, globbuf.gl_pathv[i] + strlen(xhp->rootdir), len); xbps_array_add_cstring(xhp->preserved_files, p); xbps_dbg_printf("Added preserved file: %s (expanded from %s)\n", p, file); free(p); diff --git a/lib/download.c b/lib/download.c index 21d5a8933..3e3fc7e20 100644 --- a/lib/download.c +++ b/lib/download.c @@ -122,7 +122,7 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char memset(&fetch_flags, 0, sizeof(fetch_flags)); if (flags != NULL) - xbps_strlcpy(fetch_flags, flags, 7); + strlcpy(fetch_flags, flags, 7); tempfile = xbps_xasprintf("%s.part", filename); /* @@ -145,7 +145,7 @@ xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char if (stat(filename, &st) == 0) { refetch = true; url->last_modified = st.st_mtime; - xbps_strlcat(fetch_flags, "i", sizeof(fetch_flags)); + strlcat(fetch_flags, "i", sizeof(fetch_flags)); } else { if (errno != ENOENT) { rv = -1; diff --git a/lib/external/dewey.c b/lib/external/dewey.c index 585314724..80977d9ce 100644 --- a/lib/external/dewey.c +++ b/lib/external/dewey.c @@ -331,7 +331,7 @@ dewey_match(const char *pattern, const char *pkg) if (sep2) { char ver[PKG_PATTERN_MAX]; - xbps_strlcpy(ver, sep, MIN((ssize_t)sizeof(ver), sep2-sep+1)); + strlcpy(ver, sep, MIN((ssize_t)sizeof(ver), sep2-sep+1)); if (dewey_cmp(version, op, ver)) return 1; } else { diff --git a/lib/fetch/common.c b/lib/fetch/common.c index b5d1a4e62..f7f019e03 100644 --- a/lib/fetch/common.c +++ b/lib/fetch/common.c @@ -31,8 +31,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "compat.h" - #include #include #include diff --git a/lib/fetch/fetch.c b/lib/fetch/fetch.c index fbf6c6fd7..1e00ee946 100644 --- a/lib/fetch/fetch.c +++ b/lib/fetch/fetch.c @@ -29,8 +29,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "compat.h" - #include #include #include diff --git a/lib/fetch/file.c b/lib/fetch/file.c index 2089b86a7..6aaf2c3ac 100644 --- a/lib/fetch/file.c +++ b/lib/fetch/file.c @@ -30,8 +30,6 @@ * $FreeBSD: file.c,v 1.18 2007/12/14 10:26:58 des Exp $ */ -#include "compat.h" - #include #include diff --git a/lib/initend.c b/lib/initend.c index 3e73a1fcb..d191a2e6f 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -114,7 +114,7 @@ xbps_init(struct xbps_handle *xhp) /* allow to overwrite uname(3) and conf file with env variable */ if ((native_arch = getenv("XBPS_ARCH")) && *native_arch != '\0') { - if (xbps_strlcpy(xhp->native_arch, native_arch, + if (strlcpy(xhp->native_arch, native_arch, sizeof xhp->native_arch) >= sizeof xhp->native_arch) return ENOBUFS; } @@ -123,7 +123,7 @@ xbps_init(struct xbps_handle *xhp) struct utsname un; if (uname(&un) == -1) return ENOTSUP; - if (xbps_strlcpy(xhp->native_arch, un.machine, + if (strlcpy(xhp->native_arch, un.machine, sizeof xhp->native_arch) >= sizeof xhp->native_arch) return ENOBUFS; } diff --git a/lib/portableproplib/prop_object.c b/lib/portableproplib/prop_object.c index 58dc7da3b..2e2a7c9d7 100644 --- a/lib/portableproplib/prop_object.c +++ b/lib/portableproplib/prop_object.c @@ -29,8 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "compat.h" - #include "prop_object_impl.h" #include diff --git a/lib/util.c b/lib/util.c index 04d715157..2e29d4d5e 100644 --- a/lib/util.c +++ b/lib/util.c @@ -511,24 +511,6 @@ xbps_humanize_number(char *buf, int64_t bytes) HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE); } -size_t -xbps_strlcat(char *dest, const char *src, size_t siz) -{ - assert(dest); - assert(src); - - return strlcat(dest, src, siz); -} - -size_t -xbps_strlcpy(char *dest, const char *src, size_t siz) -{ - assert(dest); - assert(src); - - return strlcpy(dest, src, siz); -} - /* * Check if pkg is explicitly marked to replace a specific installed version. */ diff --git a/lib/util_path.c b/lib/util_path.c index 2f0e05864..f8704b2fa 100644 --- a/lib/util_path.c +++ b/lib/util_path.c @@ -75,7 +75,7 @@ xbps_path_clean(char *dst) char *d = dst; bool rooted = *dst == '/'; - if (xbps_strlcpy(buf, dst, sizeof buf) >= sizeof buf) + if (strlcpy(buf, dst, sizeof buf) >= sizeof buf) return -1; if (rooted) { @@ -140,8 +140,8 @@ xbps_path_rel(char *dst, size_t dstlen, const char *from, const char *to) *dst = '\0'; - if (xbps_strlcpy(frombuf, from, sizeof frombuf) >= sizeof frombuf || - xbps_strlcpy(tobuf, to, sizeof tobuf) >= sizeof tobuf) + if (strlcpy(frombuf, from, sizeof frombuf) >= sizeof frombuf || + strlcpy(tobuf, to, sizeof tobuf) >= sizeof tobuf) return -1; if (xbps_path_clean(frombuf) == -1 || xbps_path_clean(tobuf) == -1) @@ -185,7 +185,7 @@ xbps_path_vjoin(char *dst, size_t dstlen, va_list ap) for (;;) { size_t n; - if ((n = xbps_strlcat(dst+len, val, dstlen-len)) >= dstlen-len) + if ((n = strlcat(dst+len, val, dstlen-len)) >= dstlen-len) goto err; len += n; if ((val = va_arg(ap, const char *)) == NULL) @@ -227,7 +227,7 @@ xbps_path_append(char *dst, size_t dstlen, const char *suffix) goto out; if (*dst == '\0') { - if ((len = xbps_strlcpy(dst, suffix, dstlen)) >= dstlen) + if ((len = strlcpy(dst, suffix, dstlen)) >= dstlen) goto err; goto out; } @@ -239,7 +239,7 @@ xbps_path_append(char *dst, size_t dstlen, const char *suffix) if (*suffix == '/') suffix++; - if ((len = xbps_strlcat(dst, suffix, dstlen)) >= dstlen) + if ((len = strlcat(dst, suffix, dstlen)) >= dstlen) goto err; out: return (ssize_t)len < 0 ? -1 : (ssize_t)len; @@ -260,7 +260,7 @@ xbps_path_prepend(char *dst, size_t dstlen, const char *prefix) goto out; if (*dst == '\0') { - if ((len = xbps_strlcpy(dst, prefix, dstlen)) >= dstlen) + if ((len = strlcpy(dst, prefix, dstlen)) >= dstlen) goto err; goto out; } diff --git a/tests/xbps/libxbps/config/main.c b/tests/xbps/libxbps/config/main.c index 4b45ddc6f..10304dde7 100644 --- a/tests/xbps/libxbps/config/main.c +++ b/tests/xbps/libxbps/config/main.c @@ -47,8 +47,8 @@ ATF_TC_BODY(config_include_test, tc) memset(&xh, 0, sizeof(xh)); buf = getcwd(pwd, sizeof(pwd)); - xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); + strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); + strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); ATF_REQUIRE_EQ((ret >= 0), 1); ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); @@ -99,8 +99,8 @@ ATF_TC_BODY(config_include_nomatch_test, tc) memset(&xh, 0, sizeof(xh)); buf = getcwd(pwd, sizeof(pwd)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); ATF_REQUIRE_EQ((ret >= 0), 1); ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); @@ -139,8 +139,8 @@ ATF_TC_BODY(config_include_absolute, tc) memset(&xh, 0, sizeof(xh)); buf = getcwd(pwd, sizeof(pwd)); - xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); + strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); + strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); ATF_REQUIRE_EQ((ret >= 0), 1); ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); @@ -187,8 +187,8 @@ ATF_TC_BODY(config_include_absolute_glob, tc) memset(&xh, 0, sizeof(xh)); buf = getcwd(pwd, sizeof(pwd)); - xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); + strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); + strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); ATF_REQUIRE_EQ((ret >= 0), 1); ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); @@ -241,8 +241,8 @@ ATF_TC_BODY(config_masking, tc) memset(&xh, 0, sizeof(xh)); buf = getcwd(pwd, sizeof(pwd)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); ATF_REQUIRE_EQ((ret >= 0), 1); ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); @@ -295,8 +295,8 @@ ATF_TC_BODY(config_trim_values, tc) memset(&xh, 0, sizeof(xh)); buf = getcwd(pwd, sizeof(pwd)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); ATF_REQUIRE_EQ((ret >= 0), 1); ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); @@ -346,8 +346,8 @@ ATF_TC_BODY(config_no_trailing_newline, tc) memset(&xh, 0, sizeof(xh)); buf = getcwd(pwd, sizeof(pwd)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); ATF_REQUIRE_EQ((ret >= 0), 1); ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); diff --git a/tests/xbps/libxbps/find_pkg_orphans/main.c b/tests/xbps/libxbps/find_pkg_orphans/main.c index 8ec47eecb..ad082b5dc 100644 --- a/tests/xbps/libxbps/find_pkg_orphans/main.c +++ b/tests/xbps/libxbps/find_pkg_orphans/main.c @@ -67,8 +67,8 @@ ATF_TC_BODY(find_pkg_orphans_test, tc) tcsdir = atf_tc_get_config_var(tc, "srcdir"); memset(&xh, 0, sizeof(xh)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ATF_REQUIRE_EQ(xbps_init(&xh), 0); a = xbps_array_create(); @@ -104,8 +104,8 @@ ATF_TC_BODY(find_all_orphans_test, tc) tcsdir = atf_tc_get_config_var(tc, "srcdir"); memset(&xh, 0, sizeof(xh)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ATF_REQUIRE_EQ(xbps_init(&xh), 0); pstr = xbps_string_create(); diff --git a/tests/xbps/libxbps/pkgdb/main.c b/tests/xbps/libxbps/pkgdb/main.c index 6e12dca94..df17d009f 100644 --- a/tests/xbps/libxbps/pkgdb/main.c +++ b/tests/xbps/libxbps/pkgdb/main.c @@ -42,8 +42,8 @@ ATF_TC_BODY(pkgdb_get_pkg_test, tc) tcsdir = atf_tc_get_config_var(tc, "srcdir"); memset(&xh, 0, sizeof(xh)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); @@ -84,8 +84,8 @@ ATF_TC_BODY(pkgdb_get_virtualpkg_test, tc) tcsdir = atf_tc_get_config_var(tc, "srcdir"); memset(&xh, 0, sizeof(xh)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); @@ -129,8 +129,8 @@ ATF_TC_BODY(pkgdb_get_pkg_revdeps_test, tc) tcsdir = atf_tc_get_config_var(tc, "srcdir"); memset(&xh, 0, sizeof(xh)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); @@ -162,8 +162,8 @@ ATF_TC_BODY(pkgdb_pkg_reverts_test, tc) tcsdir = atf_tc_get_config_var(tc, "srcdir"); memset(&xh, 0, sizeof(xh)); - xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); - xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); + strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); + strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); diff --git a/tests/xbps/libxbps/util_path/main.c b/tests/xbps/libxbps/util_path/main.c index fbd14b9a6..ee4f0f828 100644 --- a/tests/xbps/libxbps/util_path/main.c +++ b/tests/xbps/libxbps/util_path/main.c @@ -41,7 +41,7 @@ ATF_TC_BODY(xbps_path_clean, tc) char buf[PATH_MAX]; ssize_t len; #define CLEAN(a, b) \ - xbps_strlcpy(buf, a, sizeof (buf)); \ + strlcpy(buf, a, sizeof (buf)); \ len = xbps_path_clean(buf); \ ATF_CHECK_EQ(len, sizeof (b)-1); \ ATF_CHECK_STREQ(buf, b) @@ -207,7 +207,7 @@ ATF_TC_BODY(xbps_path_append, tc) ssize_t len; /* empty prefix */ - xbps_strlcpy(buf, "fizz", sizeof buf); + strlcpy(buf, "fizz", sizeof buf); len = xbps_path_append(buf, sizeof buf, ""); ATF_CHECK_EQ(len, sizeof ("fizz") - 1); ATF_CHECK_STREQ(buf, "fizz"); @@ -219,69 +219,69 @@ ATF_TC_BODY(xbps_path_append, tc) ATF_CHECK_STREQ(buf, "buzz"); /* add slash */ - xbps_strlcpy(buf, "fizz", sizeof buf); + strlcpy(buf, "fizz", sizeof buf); len = xbps_path_append(buf, sizeof buf, "buzz"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); /* already has slash in dst */ - xbps_strlcpy(buf, "fizz/", sizeof buf); + strlcpy(buf, "fizz/", sizeof buf); len = xbps_path_append(buf, sizeof buf, "buzz"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); /* already has slash in suffix */ - xbps_strlcpy(buf, "fizz", sizeof buf); + strlcpy(buf, "fizz", sizeof buf); len = xbps_path_append(buf, sizeof buf, "/buzz"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); /* slash in dst and suffix */ - xbps_strlcpy(buf, "fizz/", sizeof buf); + strlcpy(buf, "fizz/", sizeof buf); len = xbps_path_append(buf, sizeof buf, "/buzz"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); - xbps_strlcpy(buf, "abcdefghijklmno", sizeof buf); + strlcpy(buf, "abcdefghijklmno", sizeof buf); len = xbps_path_append(buf, sizeof buf, "pqrstuvwxyz"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "abcdefghijklmn", sizeof buf); + strlcpy(buf, "abcdefghijklmn", sizeof buf); len = xbps_path_append(buf, sizeof buf, "opqrstuvwxyz"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "abcdefghijklm", sizeof buf); + strlcpy(buf, "abcdefghijklm", sizeof buf); len = xbps_path_append(buf, sizeof buf, "nopqrstuvwxyz"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "abcdefghijklmno/", sizeof buf); + strlcpy(buf, "abcdefghijklmno/", sizeof buf); len = xbps_path_append(buf, sizeof buf, "pqrstuvwxyz"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "abcdefghijklmn/", sizeof buf); + strlcpy(buf, "abcdefghijklmn/", sizeof buf); len = xbps_path_append(buf, sizeof buf, "opqrstuvwxyz"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "abcdefghijklm/", sizeof buf); + strlcpy(buf, "abcdefghijklm/", sizeof buf); len = xbps_path_append(buf, sizeof buf, "nopqrstuvwxyz"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "abcdefghijklmno", sizeof buf); + strlcpy(buf, "abcdefghijklmno", sizeof buf); len = xbps_path_append(buf, sizeof buf, ""); ATF_CHECK_EQ(len, sizeof ("abcdefghijklmno") - 1); ATF_CHECK_STREQ(buf, "abcdefghijklmno"); - xbps_strlcpy(buf, "abcdefghijklmn/", sizeof buf); + strlcpy(buf, "abcdefghijklmn/", sizeof buf); len = xbps_path_append(buf, sizeof buf, ""); ATF_CHECK_EQ(len, sizeof ("abcdefghijklmn/") - 1); ATF_CHECK_STREQ(buf, "abcdefghijklmn/"); - xbps_strlcpy(buf, "", sizeof buf); + strlcpy(buf, "", sizeof buf); len = xbps_path_append(buf, sizeof buf, "abcdefghijklmno"); ATF_CHECK_EQ(len, sizeof ("abcdefghijklmno") - 1); ATF_CHECK_STREQ(buf, "abcdefghijklmno"); - xbps_strlcpy(buf, "", sizeof buf); + strlcpy(buf, "", sizeof buf); len = xbps_path_append(buf, sizeof buf, "abcdefghijklmn/"); ATF_CHECK_EQ(len, sizeof ("abcdefghijklmn/") - 1); ATF_CHECK_STREQ(buf, "abcdefghijklmn/"); @@ -300,7 +300,7 @@ ATF_TC_BODY(xbps_path_prepend, tc) ssize_t len; /* empty prefix */ - xbps_strlcpy(buf, "buzz", sizeof buf); + strlcpy(buf, "buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, ""); ATF_CHECK_EQ(len, sizeof ("buzz") - 1); ATF_CHECK_STREQ(buf, "buzz"); @@ -312,76 +312,76 @@ ATF_TC_BODY(xbps_path_prepend, tc) ATF_CHECK_STREQ(buf, "buzz"); /* add slash */ - xbps_strlcpy(buf, "buzz", sizeof buf); + strlcpy(buf, "buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); /* already has slash in dst */ - xbps_strlcpy(buf, "/buzz", sizeof buf); + strlcpy(buf, "/buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); /* already has slash in prefix */ - xbps_strlcpy(buf, "buzz", sizeof buf); + strlcpy(buf, "buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz/"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); /* slash in dst and prefix */ - xbps_strlcpy(buf, "/buzz", sizeof buf); + strlcpy(buf, "/buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz/"); ATF_CHECK_EQ(len, sizeof ("fizz/buzz") - 1); ATF_CHECK_STREQ(buf, "fizz/buzz"); /* check truncation no slashes */ - xbps_strlcpy(buf, "bar/buzz", sizeof buf); + strlcpy(buf, "bar/buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz/foo"); ATF_CHECK_EQ(len, -1); /* check truncation slash in dst*/ - xbps_strlcpy(buf, "/bar/buzz", sizeof buf); + strlcpy(buf, "/bar/buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz/foo"); ATF_CHECK_EQ(len, -1); /* check truncation slash in prefix */ - xbps_strlcpy(buf, "bar/buzz", sizeof buf); + strlcpy(buf, "bar/buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz/foo/"); ATF_CHECK_EQ(len, -1); /* check truncation slash in both */ - xbps_strlcpy(buf, "/bar/buzz", sizeof buf); + strlcpy(buf, "/bar/buzz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "fizz/foo/"); ATF_CHECK_EQ(len, -1); /* check truncation */ - xbps_strlcpy(buf, "pqrstuvwxyz", sizeof buf); + strlcpy(buf, "pqrstuvwxyz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "abcdefghijklmno"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "/opqrstuvwxyz", sizeof buf); + strlcpy(buf, "/opqrstuvwxyz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "abcdefghijklmn/"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "/nopqrstuvwxyz", sizeof buf); + strlcpy(buf, "/nopqrstuvwxyz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "abcdefghijklm/"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "opqrstuvwxyz", sizeof buf); + strlcpy(buf, "opqrstuvwxyz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "abcdefghijklmn"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "nopqrstuvwxyz", sizeof buf); + strlcpy(buf, "nopqrstuvwxyz", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "abcdefghijklm"); ATF_CHECK_EQ(len, -1); - xbps_strlcpy(buf, "", sizeof buf); + strlcpy(buf, "", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "abcdefghijklmno"); ATF_CHECK_EQ(len, sizeof ("abcdefghijklmno") - 1); ATF_CHECK_STREQ(buf, "abcdefghijklmno"); - xbps_strlcpy(buf, "", sizeof buf); + strlcpy(buf, "", sizeof buf); len = xbps_path_prepend(buf, sizeof buf, "abcdefghijklm/"); ATF_CHECK_EQ(len, sizeof ("abcdefghijklm/") - 1); ATF_CHECK_STREQ(buf, "abcdefghijklm/"); From 2631cb6dd1dab8275752bdf3ecd076cf60765faf Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Fri, 1 Sep 2023 22:56:53 +0200 Subject: [PATCH 6/6] always define _GNU_SOURCE and _DEFAULT_SOURCE --- bin/xbps-fbulk/main.c | 2 -- bin/xbps-query/search.c | 6 ------ bin/xbps-uchroot/main.c | 30 +++++++++++++++--------------- bin/xbps-uunshare/main.c | 25 +++++++++++++------------ configure | 3 ++- lib/cb_util.c | 4 ---- lib/external/dewey.c | 2 -- lib/external/fexec.c | 8 ++------ lib/fetch/ftp.c | 5 ----- lib/fetch/http.c | 4 ---- lib/portableproplib/prop_object.c | 4 +--- lib/util.c | 12 +----------- 12 files changed, 34 insertions(+), 71 deletions(-) diff --git a/bin/xbps-fbulk/main.c b/bin/xbps-fbulk/main.c index 4bd10b055..e54bea177 100644 --- a/bin/xbps-fbulk/main.c +++ b/bin/xbps-fbulk/main.c @@ -47,8 +47,6 @@ * Only one attempt is made to build any given package, no matter how many * other packages depend on it. */ -#define _DEFAULT_SOURCE -#define _BSD_SOURCE #include #include diff --git a/bin/xbps-query/search.c b/bin/xbps-query/search.c index bf1bac27f..98bd4c1d9 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -23,12 +23,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_STRCASESTR -# define _GNU_SOURCE /* for strcasestr(3) */ -#endif - -#include "compat.h" - #include #include #include diff --git a/bin/xbps-uchroot/main.c b/bin/xbps-uchroot/main.c index 410afe3b7..fefa65a02 100644 --- a/bin/xbps-uchroot/main.c +++ b/bin/xbps-uchroot/main.c @@ -32,28 +32,28 @@ * - Supports overlayfs on a temporary directory or a tmpfs mount. * - Supports read-only bind mounts. */ -#define _GNU_SOURCE -#define _XOPEN_SOURCE 700 -#include -#include + #include #include +#include #include +#include #include -#include -#include -#include -#include -#include -#include + #include -#include -#include -#include /* PATH_MAX */ +#include +#include +#include #include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include "queue.h" diff --git a/bin/xbps-uunshare/main.c b/bin/xbps-uunshare/main.c index ac257d383..8e0f5a270 100644 --- a/bin/xbps-uunshare/main.c +++ b/bin/xbps-uunshare/main.c @@ -22,25 +22,26 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define _GNU_SOURCE -#include -#include + #include +#include +#include #include + +#include +#include +#include +#include +#include +#include #include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include +#include #include #include "queue.h" diff --git a/configure b/configure index 516a32ba0..b5fce521d 100755 --- a/configure +++ b/configure @@ -219,9 +219,10 @@ if [ -n "$FULL_DEBUG" ]; then echo "CPPFLAGS+= -DFULL_DEBUG" >>$CONFIG_MK fi +echo "CPPFLAGS += -D_DEFAULT_SOURCE" >>$CONFIG_MK +echo "CPPFLAGS += -D_GNU_SOURCE" >>$CONFIG_MK case "$OS" in linux) - echo "CPPFLAGS += -D_XOPEN_SOURCE=700" >>$CONFIG_MK echo "CPPFLAGS += -D_FILE_OFFSET_BITS=64" >> $CONFIG_MK ;; *) diff --git a/lib/cb_util.c b/lib/cb_util.c index 1aa0f073e..35fbaa77e 100644 --- a/lib/cb_util.c +++ b/lib/cb_util.c @@ -23,10 +23,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_VASPRINTF -# define _GNU_SOURCE /* for vasprintf(3) */ -#endif - #include #include #include diff --git a/lib/external/dewey.c b/lib/external/dewey.c index 80977d9ce..033d2c158 100644 --- a/lib/external/dewey.c +++ b/lib/external/dewey.c @@ -31,9 +31,7 @@ #include #include #include -#define _BSD_SOURCE #include -#undef _BSD_SOURCE #include #include diff --git a/lib/external/fexec.c b/lib/external/fexec.c index 11c40120a..8de8ad039 100644 --- a/lib/external/fexec.c +++ b/lib/external/fexec.c @@ -27,19 +27,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#define _BSD_SOURCE /* for vfork and chroot */ -#define _DEFAULT_SOURCE /* glibc>=2.20 */ #include -#include - #include + #include #include #include #include +#include -#undef _DEFAULT_SOURCE -#undef _BSD_SOURCE #include "xbps_api_impl.h" static int diff --git a/lib/fetch/ftp.c b/lib/fetch/ftp.c index 28296a009..9986a57e2 100644 --- a/lib/fetch/ftp.c +++ b/lib/fetch/ftp.c @@ -57,11 +57,6 @@ * */ -#ifdef __linux__ -/* Keep this down to Linux, it can create surprises else where. */ -#define _GNU_SOURCE -#endif - #include #include diff --git a/lib/fetch/http.c b/lib/fetch/http.c index 0165de32c..e0832865c 100644 --- a/lib/fetch/http.c +++ b/lib/fetch/http.c @@ -62,10 +62,6 @@ * SUCH DAMAGE. */ -#if defined(__linux__) -#define _GNU_SOURCE -#endif - #include #include diff --git a/lib/portableproplib/prop_object.c b/lib/portableproplib/prop_object.c index 2e2a7c9d7..daac88cf6 100644 --- a/lib/portableproplib/prop_object.c +++ b/lib/portableproplib/prop_object.c @@ -36,9 +36,7 @@ static pthread_mutex_t _prop_refcnt_mtx = PTHREAD_MUTEX_INITIALIZER; #endif /* _PROP_NEED_REFCNT_MTX */ -#define __USE_MISC /* MAP_ANON on glibc */ -# include -#undef __USE_MISC +#include #include #include #include diff --git a/lib/util.c b/lib/util.c index 2e29d4d5e..d5722ef42 100644 --- a/lib/util.c +++ b/lib/util.c @@ -22,17 +22,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#ifdef HAVE_VASPRINTF -# define _GNU_SOURCE /* for vasprintf(3) */ -#endif - -#if defined(HAVE_STRLCAT) || defined(HAVE_STRLCPY) -# define _BSD_SOURCE -#endif - -#include "compat.h" - #include #include @@ -47,6 +36,7 @@ #include #include +#include "compat.h" #include "xbps_api_impl.h" #ifdef __clang__