Skip to content

Commit 6e1ca3c

Browse files
committed
[acquire/CMakeLists.txt] Ensure LIBACQUIRE_ACQUIRE_FILEUTILS_IMPL is only defined in one translation unit to fix linkage duplication error ; [*.h] Combine ifdef LIBACQUIRE_IMPLEMENTATION with IMPL condition ; [acquire/tests] Include stdbool the way I've made standard
1 parent da31a58 commit 6e1ca3c

20 files changed

+76
-65
lines changed

acquire/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ else ()
178178
elseif (src MATCHES "/gen_acquire_fileutils.c$")
179179
set_source_files_properties(
180180
${src} PROPERTIES
181-
COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;LIBACQUIRE_IMPL_ACQUIRE_FILEUTILS=1"
181+
COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;LIBACQUIRE_ACQUIRE_FILEUTILS_IMPL=1"
182182
)
183183
elseif (src MATCHES "/gen_acquire_libcurl.c$")
184184
set_source_files_properties(
@@ -223,7 +223,7 @@ else ()
223223
elseif (src MATCHES "/gen_acquire_url_utils.c$")
224224
set_source_files_properties(
225225
${src} PROPERTIES
226-
COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;LIBACQUIRE_IMPL_ACQUIRE_FILEUTILS=1"
226+
COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION"
227227
)
228228
elseif (src MATCHES "/gen_acquire_extract.c$")
229229
# For extract, could detect MINIZ or LIBARCHIVE

acquire/acquire_extract.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ extern LIBACQUIRE_EXPORT int extract_archive(enum Archive archive,
5959
*/
6060
extern LIBACQUIRE_EXPORT enum Archive extension2archive(const char *extension);
6161

62-
#ifdef LIBACQUIRE_IMPLEMENTATION
63-
#ifndef LIBACQUIRE_IMPL_ACQUIRE_EXTRACT_H
64-
#define LIBACQUIRE_IMPL_ACQUIRE_EXTRACT_H
62+
#if defined(LIBACQUIRE_IMPLEMENTATION) && defined(LIBACQUIRE_EXTRACT_IMPL)
6563
#include <acquire_string_extras.h>
6664

6765
enum Archive extension2archive(const char *const extension) {
@@ -73,8 +71,8 @@ enum Archive extension2archive(const char *const extension) {
7371
return LIBACQUIRE_INFER;
7472
}
7573

76-
#endif /* !LIBACQUIRE_IMPL_ACQUIRE_EXTRACT_H */
77-
#endif /* LIBACQUIRE_IMPLEMENTATION */
74+
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \
75+
defined(LIBACQUIRE_EXTRACT_IMPL) */
7876

7977
#ifdef __cplusplus
8078
}

acquire/acquire_fileutils.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ extern "C" {
2626

2727
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
2828

29-
#include <acquire_common_defs.h>
3029
#include <Fileapi.h>
30+
#include <acquire_common_defs.h>
3131
#include <io.h>
3232
#include <wchar.h>
3333

@@ -80,8 +80,8 @@ extern LIBACQUIRE_EXPORT bool is_relative(const char *path);
8080
*/
8181
extern LIBACQUIRE_EXPORT const char *get_extension(const char *path);
8282

83-
#ifdef LIBACQUIRE_IMPLEMENTATION
84-
#ifdef LIBACQUIRE_IMPL_ACQUIRE_FILEUTILS
83+
#if defined(LIBACQUIRE_IMPLEMENTATION) && \
84+
defined(LIBACQUIRE_ACQUIRE_FILEUTILS_IMPL)
8585

8686
bool is_directory(const char *const path) {
8787
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
@@ -160,8 +160,8 @@ const char *get_extension(const char *const filename) {
160160
return strncmp(ext0, ".tar", 4) == 0 ? ext0 : ext1;
161161
}
162162

163-
#endif /* LIBACQUIRE_IMPL_ACQUIRE_FILEUTILS */
164-
#endif /* LIBACQUIRE_IMPLEMENTATION */
163+
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \
164+
defined(LIBACQUIRE_ACQUIRE_FILEUTILS_IMPL) */
165165

166166
#ifdef __cplusplus
167167
}

acquire/acquire_libarchive.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#if !defined(LIBACQUIRE_ACQUIRE_LIBARCHIVE_H) && defined(USE_LIBARCHIVE) && \
2-
defined(LIBACQUIRE_IMPLEMENTATION) && \
3-
!defined(LIBACQUIRE_ACQUIRE_EXTRACT_IMPL)
2+
defined(LIBACQUIRE_IMPLEMENTATION) && !defined(LIBACQUIRE_EXTRACT_IMPL)
43
#define LIBACQUIRE_ACQUIRE_LIBARCHIVE_H
5-
#define LIBACQUIRE_ACQUIRE_EXTRACT_IMPL
4+
#define LIBACQUIRE_EXTRACT_IMPL
65

76
/* Note this file is mostly the
87
* https://github.com/libarchive/libarchive/wiki/Examples#a-complete-extractor
@@ -114,4 +113,4 @@ int extract_archive(enum Archive archive, const char *archive_filepath,
114113

115114
#endif /* !defined(LIBACQUIRE_ACQUIRE_LIBARCHIVE_H) && defined(USE_LIBARCHIVE) \
116115
&& defined(LIBACQUIRE_IMPLEMENTATION) && \
117-
!defined(LIBACQUIRE_ACQUIRE_EXTRACT_IMPL) */
116+
!defined(LIBACQUIRE_EXTRACT_IMPL) */

acquire/acquire_librhash.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,25 @@ int hash_file(const char *filepath, const enum rhash_ids hash_id,
4444
}
4545
}
4646

47-
#if !defined(LIBACQUIRE_IMPL_SHA256) && !defined(CRYPTO_LIB)
48-
#define LIBACQUIRE_IMPL_SHA256
47+
#if !defined(LIBACQUIRE_SHA256_IMPL) && !defined(CRYPTO_LIB)
48+
#define LIBACQUIRE_SHA256_IMPL
4949
bool sha256(const char *filename, const char *gold_hash) {
5050
char gen_hash[130], digest[64];
5151
return hash_file(filename, RHASH_SHA256, RHPR_HEX, digest, gen_hash) < 0
5252
? false
5353
: strcmp(gen_hash, gold_hash) == 0;
5454
}
55-
#endif /* !defined(LIBACQUIRE_IMPL_SHA256) && !defined(CRYPTO_LIB) */
55+
#endif /* !defined(LIBACQUIRE_SHA256_IMPL) && !defined(CRYPTO_LIB) */
5656

57-
#if !defined(LIBACQUIRE_IMPL_SHA512) && !defined(CRYPTO_LIB)
58-
#define LIBACQUIRE_IMPL_SHA512
57+
#if !defined(LIBACQUIRE_SHA512_IMPL) && !defined(CRYPTO_LIB)
58+
#define LIBACQUIRE_SHA512_IMPL
5959
bool sha512(const char *filename, const char *gold_hash) {
6060
char gen_hash[130], digest[64];
6161
return hash_file(filename, RHASH_SHA512, RHPR_HEX, digest, gen_hash) < 0
6262
? false
6363
: strcmp(gen_hash, gold_hash) == 0;
6464
}
65-
#endif /* !defined(LIBACQUIRE_IMPL_SHA512) && !defined(CRYPTO_LIB) */
65+
#endif /* !defined(LIBACQUIRE_SHA512_IMPL) && !defined(CRYPTO_LIB) */
6666

6767
/* X(sha256, RHASH_SHA256, comma) \ */
6868
/* X(sha512, RHASH_SHA512, comma) \ */

acquire/acquire_miniz.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#if !defined(LIBACQUIRE_ACQUIRE_MINIZ_H) && defined(USE_MINIZ) && \
2-
defined(LIBACQUIRE_IMPLEMENTATION) && \
3-
!defined(LIBACQUIRE_ACQUIRE_EXTRACT_IMPL)
2+
defined(LIBACQUIRE_IMPLEMENTATION) && !defined(LIBACQUIRE_EXTRACT_IMPL)
43
#define LIBACQUIRE_ACQUIRE_MINIZ_H
5-
#define LIBACQUIRE_ACQUIRE_EXTRACT_IMPL
4+
#define LIBACQUIRE_EXTRACT_IMPL
65

76
#ifdef __cplusplus
87
extern "C" {
@@ -44,4 +43,4 @@ int extract_archive(enum Archive archive, const char *archive_filepath,
4443

4544
#endif /* !defined(LIBACQUIRE_ACQUIRE_MINIZ_H) && defined(USE_MINIZ) && \
4645
defined(LIBACQUIRE_IMPLEMENTATION) && \
47-
!defined(LIBACQUIRE_ACQUIRE_EXTRACT_IMPL) */
46+
!defined(LIBACQUIRE_EXTRACT_IMPL) */

acquire/acquire_net_common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
extern "C" {
1313
#endif /* __cplusplus */
1414

15-
#include "acquire_config.h"
1615
#include "acquire_common_defs.h"
16+
#include "acquire_config.h"
1717

1818
/**
1919
* Check if a file represented by URL is already downloaded locally and matches
@@ -32,11 +32,11 @@ extern LIBACQUIRE_EXPORT bool is_downloaded(const char *url,
3232
const char *target_location);
3333

3434
#if defined(LIBACQUIRE_IMPLEMENTATION) && \
35-
!defined(LIBACQUIRE_IMPL_ACQUIRE_NET_COMMON)
36-
#include "acquire_config.h"
35+
!defined(LIBACQUIRE_ACQUIRE_NET_COMMON_IMPL)
3736
#include "acquire_common_defs.h"
37+
#include "acquire_config.h"
3838

39-
#define LIBACQUIRE_IMPL_ACQUIRE_NET_COMMON 1
39+
#define LIBACQUIRE_ACQUIRE_NET_COMMON_IMPL 1
4040

4141
#ifdef DOWNLOAD_DIR_IMPL
4242
const char *get_download_dir(void) { return ".downloads"; }
@@ -81,7 +81,7 @@ bool is_downloaded(const char *url, enum Checksum checksum, const char *hash,
8181
}
8282

8383
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \
84-
!defined(LIBACQUIRE_IMPL_ACQUIRE_NET_COMMON) */
84+
!defined(LIBACQUIRE_ACQUIRE_NET_COMMON_IMPL) */
8585

8686
#ifdef __cplusplus
8787
}

acquire/acquire_openssl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,25 +228,25 @@ int sha512_file(const char *filename,
228228
return exit_code;
229229
}
230230

231-
#ifndef LIBACQUIRE_IMPL_SHA256
232-
#define LIBACQUIRE_IMPL_SHA256
231+
#ifndef LIBACQUIRE_SHA256_IMPL
232+
#define LIBACQUIRE_SHA256_IMPL
233233
bool sha256(const char *filename, const char *hash) {
234234
unsigned char sha_output[SHA256_DIGEST_LENGTH * 2 + 1];
235235
sha256_file(filename, sha_output);
236236

237237
return strcmp((const char *)sha_output, hash) == 0;
238238
}
239-
#endif /* !LIBACQUIRE_IMPL_SHA256 */
239+
#endif /* !LIBACQUIRE_SHA256_IMPL */
240240

241-
#ifndef LIBACQUIRE_IMPL_SHA512
242-
#define LIBACQUIRE_IMPL_SHA512
241+
#ifndef LIBACQUIRE_SHA512_IMPL
242+
#define LIBACQUIRE_SHA512_IMPL
243243
bool sha512(const char *filename, const char *hash) {
244244
unsigned char sha_output[SHA512_DIGEST_LENGTH * 2 + 1];
245245
sha512_file(filename, sha_output);
246246

247247
return strcmp((const char *)sha_output, hash) == 0;
248248
}
249-
#endif /* !LIBACQUIRE_IMPL_SHA512 */
249+
#endif /* !LIBACQUIRE_SHA512_IMPL */
250250

251251
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \
252252
defined(LIBACQUIRE_CRYPTO_IMPL) */

acquire/acquire_stdbool.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !defined(_STDBOOL_H) && !defined(HAS_STDBOOL)
1+
#if !defined(_STDBOOL_H) && !defined(HAS_STDBOOL) && !defined(__cplusplus)
22
#define _STDBOOL_H
33

44
/**
@@ -27,4 +27,5 @@ typedef size_t bool;
2727
#define true 1
2828
#define false (!true)
2929

30-
#endif /* !defined(_STDBOOL_H) && !defined(HAS_STDBOOL) */
30+
#endif /* !defined(_STDBOOL_H) && !defined(HAS_STDBOOL) && \
31+
!defined(__cplusplus) */

acquire/acquire_string_extras.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,13 @@ extern LIBACQUIRE_EXPORT size_t strerrorlen_s(errno_t);
134134

135135
#if !defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_H)
136136
extern LIBACQUIRE_EXPORT int snprintf(char *buffer, size_t count,
137-
const char *format, ...);
137+
const char *format, ...);
138138
#endif /* !defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_H) */
139139

140140
#ifdef LIBACQUIRE_IMPLEMENTATION
141141

142-
#if !defined(HAVE_SNPRINTF) && !defined(SNPRINTF_IMPL) && !defined(HAVE_SNPRINTF_H)
142+
#if !defined(HAVE_SNPRINTF) && !defined(SNPRINTF_IMPL) && \
143+
!defined(HAVE_SNPRINTF_H)
143144
#define SNPRINTF_IMPL
144145

145146
/*
@@ -182,7 +183,8 @@ inline double wtf_vsnprintf(char *buffer, size_t count, const char *format,
182183
#define vsnprintf(buffer, count, format, args) \
183184
wtf_vsnprintf(buffer, count, format, args)
184185

185-
#endif /* !defined(HAVE_SNPRINTF) && !defined(SNPRINTF_IMPL) && !defined(HAVE_SNPRINTF_H) */
186+
#endif /* !defined(HAVE_SNPRINTF) && !defined(SNPRINTF_IMPL) && \
187+
!defined(HAVE_SNPRINTF_H) */
186188

187189
#if !defined(HAVE_STRNCASECMP) && !defined(STRNCASECMP_IMPL)
188190
#define STRNCASECMP_IMPL

0 commit comments

Comments
 (0)