From 3dbb2ce2ea8b12867db0e24d4bd6c7c6501f5d5d Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Wed, 25 May 2022 18:20:38 -0400 Subject: Fix some portability issues --- append.c | 4 ++-- cache_from_tree.c | 3 ++- compat_strtonum.c | 5 ++--- create.c | 4 ++-- info.c | 6 +++--- machoparse/cdhash.c | 5 +++-- uuid/unparse.c | 2 +- uuid/uuid.h | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/append.c b/append.c index 184c1ff..cf8dc83 100644 --- a/append.c +++ b/append.c @@ -106,9 +106,9 @@ tcappend(int argc, char **argv) } if (cache.version == 1) - mergesort(cache.entries, cache.num_entries, sizeof(*cache.entries), ent_cmp); + qsort(cache.entries, cache.num_entries, sizeof(*cache.entries), ent_cmp); else if (cache.version == 0) - mergesort(cache.hashes, cache.num_entries, sizeof(*cache.hashes), hash_cmp); + qsort(cache.hashes, cache.num_entries, sizeof(*cache.hashes), hash_cmp); switch (keepuuid) { case 0: diff --git a/cache_from_tree.c b/cache_from_tree.c index 92a2210..90cafda 100644 --- a/cache_from_tree.c +++ b/cache_from_tree.c @@ -25,6 +25,7 @@ * SUCH DAMAGE. */ +#define _XOPEN_SOURCE 500 #include #include #include @@ -34,7 +35,7 @@ static struct trust_cache cache = {}; -int +static int tccallback(const char *path, const struct stat *sb, int typeflag, struct FTW *ftw) { if (!S_ISREG(sb->st_mode)) diff --git a/compat_strtonum.c b/compat_strtonum.c index aa433d8..356153d 100644 --- a/compat_strtonum.c +++ b/compat_strtonum.c @@ -17,13 +17,12 @@ * $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */ -#include -__FBSDID("$FreeBSD$"); - #include #include #include +#include "compat.h" + #define INVALID 1 #define TOOSMALL 2 #define TOOLARGE 3 diff --git a/create.c b/create.c index 955c833..02ab9e4 100644 --- a/create.c +++ b/create.c @@ -98,9 +98,9 @@ tccreate(int argc, char **argv) } if (cache.version == 1) - mergesort(cache.entries, cache.num_entries, sizeof(*cache.entries), ent_cmp); + qsort(cache.entries, cache.num_entries, sizeof(*cache.entries), ent_cmp); else if (cache.version == 0) - mergesort(cache.hashes, cache.num_entries, sizeof(*cache.hashes), hash_cmp); + qsort(cache.hashes, cache.num_entries, sizeof(*cache.hashes), hash_cmp); FILE *f = NULL; if ((f = fopen(argv[0], "wb")) == NULL) { diff --git a/info.c b/info.c index 86aa78b..4f74d62 100644 --- a/info.c +++ b/info.c @@ -40,7 +40,7 @@ tcinfo(int argc, char **argv) { struct trust_cache cache; bool headeronly = false, onlyhash = false; - uint32_t entrynum = -1; + uint32_t entrynum = 0; const char *errstr = NULL; int ch; @@ -70,7 +70,7 @@ tcinfo(int argc, char **argv) cache = opentrustcache(argv[0]); - if (entrynum == -1 && !onlyhash) + if (entrynum == 0 && !onlyhash) print_header(cache); if (!headeronly) { if (onlyhash) { @@ -82,7 +82,7 @@ tcinfo(int argc, char **argv) } goto done; } - if (entrynum != -1) { + if (entrynum != 0) { if (entrynum > cache.num_entries) { fprintf(stderr, "no entry %i\n", entrynum); exit(1); diff --git a/machoparse/cdhash.c b/machoparse/cdhash.c index 8f7796e..5ccd3aa 100644 --- a/machoparse/cdhash.c +++ b/machoparse/cdhash.c @@ -69,6 +69,7 @@ # define be32toh(x) OSSwapBigToHostInt32(x) #elif __has_include() # include +# define bswap32(x) __builtin_bswap32(x) #else # include #endif @@ -374,7 +375,7 @@ compute_cdhash_macho(const struct mach_header_64 *mh, const struct mach_header * return csblob_cdhash((CS_GenericBlob *)cs_data, cs_end - cs_data, cdhash); } -bool +static bool compute_cdhash(const void *file, size_t size, struct hashes *cdhash) { // Try to compute the cdhash for a Mach-O file. const struct mach_header_64 *mh = file; @@ -397,7 +398,7 @@ compute_cdhash(const void *file, size_t size, struct hashes *cdhash) { return false; } -void +static void compute_cdhashes(const void *file, size_t size, struct cdhashes *h) { const struct fat_header *fh = NULL; if (*((uint32_t*)file) == FAT_MAGIC || *((uint32_t*)file) == FAT_CIGAM) diff --git a/uuid/unparse.c b/uuid/unparse.c index 3beca91..3f0e66f 100644 --- a/uuid/unparse.c +++ b/uuid/unparse.c @@ -39,7 +39,7 @@ void uuid_unparse(const uuid_t uu, char *out) { const uint8_t *uuid_array = (const uint8_t *)uu; - int uuid_index; + unsigned int uuid_index; static const char *fmt = "0123456789ABCDEF"; for ( uuid_index = 0; uuid_index < sizeof(uuid_t); ++uuid_index ) { diff --git a/uuid/uuid.h b/uuid/uuid.h index a4be9a5..2ffbee7 100644 --- a/uuid/uuid.h +++ b/uuid/uuid.h @@ -1,7 +1,7 @@ #ifndef _UUID_H_ #define _UUID_H_ -#include +#include typedef unsigned char uuid_t[16]; -- cgit v1.2.3-56-ge451