aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2022-05-25 18:20:38 -0400
committerCameron Katri <me@cameronkatri.com>2022-05-25 18:20:38 -0400
commit3dbb2ce2ea8b12867db0e24d4bd6c7c6501f5d5d (patch)
tree34b4c2f32dca91660db151412cd94ce5a4d58ece
parenta902c812e98dd53cf9f16b5175f7c1f87e780b53 (diff)
downloadtrustcache-3dbb2ce2ea8b12867db0e24d4bd6c7c6501f5d5d.tar.gz
trustcache-3dbb2ce2ea8b12867db0e24d4bd6c7c6501f5d5d.tar.zst
trustcache-3dbb2ce2ea8b12867db0e24d4bd6c7c6501f5d5d.zip
Fix some portability issues
-rw-r--r--append.c4
-rw-r--r--cache_from_tree.c3
-rw-r--r--compat_strtonum.c5
-rw-r--r--create.c4
-rw-r--r--info.c6
-rw-r--r--machoparse/cdhash.c5
-rw-r--r--uuid/unparse.c2
-rw-r--r--uuid/uuid.h2
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 <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))
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 <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
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(<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)
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 <sys/types.h>
+#include <stdint.h>
typedef unsigned char uuid_t[16];