]> git.cameronkatri.com Git - trustcache.git/commitdiff
Fix some portability issues
authorCameron Katri <me@cameronkatri.com>
Wed, 25 May 2022 22:20:38 +0000 (18:20 -0400)
committerCameron Katri <me@cameronkatri.com>
Wed, 25 May 2022 22:20:38 +0000 (18:20 -0400)
append.c
cache_from_tree.c
compat_strtonum.c
create.c
info.c
machoparse/cdhash.c
uuid/unparse.c
uuid/uuid.h

index 184c1ff63ee6c90bf2fea4084db42e5c8dabeebd..cf8dc83d3c30ed8fe49bbc13363a2f4484ca4329 100644 (file)
--- 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:
index 92a221029b46b95f7740337ef727d196d85360ae..90cafda39a65614479641f4b8222de8ea80aba12 100644 (file)
@@ -25,6 +25,7 @@
  * SUCH DAMAGE.
  */
 
+#define _XOPEN_SOURCE 500
 #include <ftw.h>
 #include <stdio.h>
 #include <string.h>
@@ -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))
index aa433d835b36ac117fad53ff2eb9380818260612..356153daa181ff0e41dab8bd126ebd109d6f700b 100644 (file)
  *     $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
 
+#include "compat.h"
+
 #define        INVALID         1
 #define        TOOSMALL        2
 #define        TOOLARGE        3
index 955c833972d29ddc4729a397ec6953684d61a82c..02ab9e456c0426ea957df80aa56c38165c7ce279 100644 (file)
--- 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 86aa78b4799e64f81c39ce5ca3b70a06331939ee..4f74d62d9f0b94286789538531610cd06c60a548 100644 (file)
--- 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);
index 8f7796e8d2174735ea27fd23255afb248530c409..5ccd3aa315888959edeb001139bcac0745c8bd71 100644 (file)
@@ -69,6 +69,7 @@
 #      define be32toh(x) OSSwapBigToHostInt32(x)
 #elif __has_include(<endian.h>)
 #      include <endian.h>
+#      define bswap32(x) __builtin_bswap32(x)
 #else
 #      include <sys/endian.h>
 #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)
index 3beca9169d72d2a8f039e404d31cd81fe02303ce..3f0e66f6cca5d7e1ead689d67f46109191c4f7b8 100644 (file)
@@ -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 ) {
index a4be9a573d8aa984658a723d6da157a756027294..2ffbee730d3d69e4e2c390cc2a3b98af45856ad6 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _UUID_H_
 #define _UUID_H_
 
-#include <sys/types.h>
+#include <stdint.h>
 
 typedef unsigned char uuid_t[16];