Skip to content

Commit 0b15fe9

Browse files
committed
[acquire/tests] Get all tests to pass on macOS (Linux half pass) ; [*.h] Improve checks by using defined A && A approach
1 parent 10c5b12 commit 0b15fe9

23 files changed

+102
-90
lines changed

acquire/acquire_checksums.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ extern LIBACQUIRE_EXPORT bool (*get_checksum_function(enum Checksum checksum))(
8787
defined(LIBACQUIRE_ACQUIRE_CHECKSUMS_IMPL)
8888

8989
enum Checksum string2checksum(const char *const s) {
90-
if (strncasecmp(s, "CRC32C", 6) == 0)
90+
if (s == NULL)
91+
return LIBACQUIRE_UNSUPPORTED_CHECKSUM;
92+
else if (strncasecmp(s, "CRC32C", 6) == 0)
9193
return LIBACQUIRE_CRC32C;
9294
else if (strncasecmp(s, "SHA256", 6) == 0)
9395
return LIBACQUIRE_SHA256;

acquire/acquire_crc32c.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern "C" {
1818
#endif /* __cplusplus */
1919

2020
#include <stdio.h>
21+
#include <string.h>
2122

2223
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
2324
#else
@@ -133,11 +134,13 @@ unsigned int crc32_file(FILE *file) {
133134
* Reads the file and computes its CRC32C checksum, then compares with
134135
* the hash string ignoring character cases.
135136
*/
136-
bool crc32c(const char *filename, const char *hash) {
137+
bool crc32c(const char *const filename, const char *const hash) {
137138
unsigned int crc32_res;
138139
FILE *fh;
139140
char computed[9];
140141

142+
fprintf(stderr, "fopen %s\n", filename);
143+
141144
#if defined(_MSC_VER) || (defined(__STDC_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__)
142145
fopen_s(&fh, filename, "rb");
143146
#else
@@ -151,23 +154,8 @@ bool crc32c(const char *filename, const char *hash) {
151154
fclose(fh);
152155

153156
snprintf(computed, sizeof(computed), "%08x", crc32_res);
154-
155-
{
156-
int i;
157-
for (i = 0; computed[i] && hash[i]; i++) {
158-
char c1 = computed[i];
159-
char c2 = hash[i];
160-
if (c1 >= 'A' && c1 <= 'F')
161-
c1 += 'a' - 'A';
162-
if (c2 >= 'A' && c2 <= 'F')
163-
c2 += 'a' - 'A';
164-
if (c1 != c2)
165-
return false;
166-
}
167-
if (computed[i] != '\0' || hash[i] != '\0')
168-
return false;
169-
}
170-
return true;
157+
fprintf(stderr, "computed: \"%s\"\n", computed);
158+
return strcmp(computed, hash) == 0;
171159
}
172160

173161
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \

acquire/acquire_download.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ extern "C" {
2828
#include "acquire_checksums.h"
2929
#include "libacquire_export.h"
3030

31-
#if (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO==1) || (defined(USE_OPENSSL) && USE_OPENSSL==1)
31+
#if (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO) || \
32+
(defined(USE_OPENSSL) && USE_OPENSSL)
3233
#include "acquire_openssl.h"
33-
#elif defined(USE_WINCRYPT) && USE_WINCRYPT==1
34+
#elif defined(USE_WINCRYPT) && USE_WINCRYPT
3435
#include "acquire_wincrypt.h"
35-
#endif /* (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO==1) || (defined(USE_OPENSSL) && USE_OPENSSL==1) */
36+
#endif /* (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO) || \
37+
(defined(USE_OPENSSL) && USE_OPENSSL) */
3638

3739
extern LIBACQUIRE_EXPORT const char *get_download_dir(void);
3840

acquire/acquire_libarchive.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#if !defined(LIBACQUIRE_ACQUIRE_LIBARCHIVE_H) && defined(USE_LIBARCHIVE) && \
2-
USE_LIBARCHIVE==1 && defined(LIBACQUIRE_IMPLEMENTATION) && !defined(LIBACQUIRE_EXTRACT_IMPL)
1+
#if !defined(LIBACQUIRE_ACQUIRE_LIBARCHIVE_H) && defined(USE_LIBARCHIVE) && \
2+
USE_LIBARCHIVE && defined(LIBACQUIRE_IMPLEMENTATION) && \
3+
!defined(LIBACQUIRE_EXTRACT_IMPL)
34
#define LIBACQUIRE_ACQUIRE_LIBARCHIVE_H
45
#define LIBACQUIRE_EXTRACT_IMPL
56

@@ -111,5 +112,6 @@ int extract_archive(enum Archive archive, const char *archive_filepath,
111112
}
112113
#endif /* __cplusplus */
113114

114-
#endif /* !defined(LIBACQUIRE_ACQUIRE_LIBARCHIVE_H) && defined(USE_LIBARCHIVE) && \
115-
USE_LIBARCHIVE==1 && defined(LIBACQUIRE_IMPLEMENTATION) && !defined(LIBACQUIRE_EXTRACT_IMPL) */
115+
#endif /* !defined(LIBACQUIRE_ACQUIRE_LIBARCHIVE_H) && defined(USE_LIBARCHIVE) \
116+
&& USE_LIBARCHIVE && defined(LIBACQUIRE_IMPLEMENTATION) && \
117+
!defined(LIBACQUIRE_EXTRACT_IMPL) */

acquire/acquire_libcurl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef LIBACQUIRE_LIBCURL_H
22
#define LIBACQUIRE_LIBCURL_H
33

4-
#if defined(USE_LIBCURL) && USE_LIBCURL==1 && defined(LIBACQUIRE_IMPLEMENTATION)
4+
#if defined(USE_LIBCURL) && USE_LIBCURL && defined(LIBACQUIRE_IMPLEMENTATION)
55

66
/*
77
* libcurl implementation of libacquire's download API

acquire/acquire_libfetch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ __FBSDID("$FreeBSD$");
7474
#include <termios.h>
7575
#include <unistd.h>
7676

77-
#if defined(USE_MY_LIBFETCH) && USE_MY_LIBFETCH==1
77+
#if defined(USE_MY_LIBFETCH) && USE_MY_LIBFETCH
7878
#include "freebsd_libfetch/fetch.h"
7979
#else
8080
#include <fetch.h>
81-
#endif /* defined(USE_MY_LIBFETCH) && USE_MY_LIBFETCH==1 */
81+
#endif /* defined(USE_MY_LIBFETCH) && USE_MY_LIBFETCH */
8282

8383
#define TIMEOUT 120
8484

acquire/acquire_librhash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef LIBACQUIRE_ACQUIRE_LIBRHASH_H
66
#define LIBACQUIRE_ACQUIRE_LIBRHASH_H
77

8-
#if defined(LIBACQUIRE_IMPLEMENTATION) && defined(USE_LIBRHASH) && USE_LIBRHASH==1
8+
#if defined(LIBACQUIRE_IMPLEMENTATION) && defined(USE_LIBRHASH) && USE_LIBRHASH
99

1010
#ifdef __cplusplus
1111
extern "C" {

acquire/acquire_miniz.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !defined(LIBACQUIRE_ACQUIRE_MINIZ_H) && defined(USE_MINIZ) && USE_MINIZ==1 \
1+
#if !defined(LIBACQUIRE_ACQUIRE_MINIZ_H) && defined(USE_MINIZ) && USE_MINIZ && \
22
defined(LIBACQUIRE_IMPLEMENTATION) && !defined(LIBACQUIRE_EXTRACT_IMPL)
33
#define LIBACQUIRE_ACQUIRE_MINIZ_H
44
#define LIBACQUIRE_EXTRACT_IMPL
@@ -41,5 +41,6 @@ int extract_archive(enum Archive archive, const char *archive_filepath,
4141
}
4242
#endif /* __cplusplus */
4343

44-
#endif /* !defined(LIBACQUIRE_ACQUIRE_MINIZ_H) && defined(USE_MINIZ) && USE_MINIZ==1 \
45-
defined(LIBACQUIRE_IMPLEMENTATION) && !defined(LIBACQUIRE_EXTRACT_IMPL) */
44+
#endif /* !defined(LIBACQUIRE_ACQUIRE_MINIZ_H) && defined(USE_MINIZ) && \
45+
USE_MINIZ && defined(LIBACQUIRE_IMPLEMENTATION) && \
46+
!defined(LIBACQUIRE_EXTRACT_IMPL) */

acquire/acquire_openssl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern "C" {
1717

1818
#include "acquire_config.h"
1919

20-
#if (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO==1) || (defined(USE_OPENSSL) && USE_OPENSSL==1)
20+
#if (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO) || \
21+
(defined(USE_OPENSSL) && USE_OPENSSL)
2122

2223
#include "acquire_checksums.h"
2324

@@ -37,7 +38,7 @@ extern "C" {
3738
#define SHA512_Final CC_SHA512_Final
3839
#define SHA512_BLOCK_BYTES CC_SHA512_BLOCK_BYTES
3940

40-
#elif defined(USE_OPENSSL) && USE_OPENSSL==1
41+
#elif defined(USE_OPENSSL) && USE_OPENSSL
4142

4243
#include <openssl/macros.h>
4344
#include <openssl/sha.h>
@@ -50,7 +51,8 @@ extern "C" {
5051
#define SHA256_BLOCK_BYTES 64 /* block size in bytes */
5152
#define SHA512_BLOCK_BYTES (SHA256_BLOCK_BYTES * 2)
5253

53-
#endif /* (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO==1) || (defined(USE_OPENSSL) && USE_OPENSSL==1) */
54+
#endif /* (defined(USE_COMMON_CRYPTO) && USE_COMMON_CRYPTO) || \
55+
(defined(USE_OPENSSL) && USE_OPENSSL) */
5456

5557
#include <errno.h>
5658
#include <stdio.h>

acquire/acquire_wincrypt.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* This should also work on Windows, ReactOS, and derivatives.
55
* */
66

7-
#if !defined(LIBACQUIRE_WINCRYPT_H) && defined(USE_WINCRYPT) && USE_WINCRYPT==1 \
8-
defined(LIBACQUIRE_IMPLEMENTATION) && defined(LIBACQUIRE_CRYPTO_IMPL)
7+
#if !defined(LIBACQUIRE_WINCRYPT_H) && defined(USE_WINCRYPT) && \
8+
USE_WINCRYPT && defined(LIBACQUIRE_IMPLEMENTATION) && \
9+
defined(LIBACQUIRE_CRYPTO_IMPL)
910
#define LIBACQUIRE_WINCRYPT_H
1011

1112
#include <stdio.h>
@@ -145,5 +146,6 @@ bool sha512(const char *filename, const char *hash) {
145146
}
146147
#endif /* __cplusplus */
147148

148-
#endif /* !defined(LIBACQUIRE_WINCRYPT_H) && defined(USE_WINCRYPT) && USE_WINCRYPT==1 \
149-
defined(LIBACQUIRE_IMPLEMENTATION) && defined(LIBACQUIRE_CRYPTO_IMPL) */
149+
#endif /* !defined(LIBACQUIRE_WINCRYPT_H) && defined(USE_WINCRYPT) && \
150+
USE_WINCRYPT && defined(LIBACQUIRE_IMPLEMENTATION) && \
151+
defined(LIBACQUIRE_CRYPTO_IMPL) */

0 commit comments

Comments
 (0)