Skip to content

Commit eb8d96d

Browse files
committed
Fix amalgamation
1 parent b92e6a7 commit eb8d96d

7 files changed

Lines changed: 35 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ include(FetchContent)
6666
FetchContent_Declare(
6767
c89stringutils
6868
GIT_REPOSITORY https://github.com/offscale/c89stringutils.git
69-
GIT_TAG main # Or specify a particular commit/tag
69+
GIT_TAG master
7070
)
7171
FetchContent_MakeAvailable(c89stringutils)
7272

c89stringutils/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,40 @@ if (C89STRINGUTILS_BUILD_AMALGAMATION)
6666
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
6767
"c89stringutils_export_pregen.h"
6868
"c89stringutils_log.h"
69+
"c89stringutils_safecrt.h"
6970
"c89stringutils_string_extras.h"
71+
"c89stringutils_safecrt.c"
7072
"c89stringutils_string_extras.c")
7173

7274
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/c89stringutils_export_pregen.h" amalg_export)
7375
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/c89stringutils_log.h" amalg_log)
76+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/c89stringutils_safecrt.h" amalg_safecrt_header)
7477
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/c89stringutils_string_extras.h" amalg_header)
78+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/c89stringutils_safecrt.c" amalg_safecrt_source)
7579
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/c89stringutils_string_extras.c" amalg_source)
7680
file(READ "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.h" amalg_config)
7781

7882
string(REPLACE "#include \"c89stringutils_export.h\"" "" amalg_header "${amalg_header}")
7983
string(REPLACE "#include \"c89stringutilsConfig.h\"" "" amalg_header "${amalg_header}")
8084
string(REPLACE "#include \"c89stringutils_export.h\"" "" amalg_log "${amalg_log}")
85+
string(REPLACE "#include \"c89stringutilsConfig.h\"" "" amalg_log "${amalg_log}")
86+
string(REPLACE "#include \"c89stringutils_safecrt.h\"" "" amalg_safecrt_source "${amalg_safecrt_source}")
87+
string(REPLACE "#include \"c89stringutils_export.h\"" "" amalg_safecrt_header "${amalg_safecrt_header}")
88+
string(REPLACE "#include \"c89stringutils_string_extras.h\"" "" amalg_safecrt_header "${amalg_safecrt_header}")
89+
string(REPLACE "#include \"c89stringutils_log.h\"" "" amalg_safecrt_source "${amalg_safecrt_source}")
8190
string(REPLACE "#include \"c89stringutils_string_extras.h\"" "" amalg_source "${amalg_source}")
91+
string(REPLACE "#include \"c89stringutils_safecrt.h\"" "" amalg_source "${amalg_source}")
8292
string(REPLACE "#include \"c89stringutils_log.h\"" "" amalg_source "${amalg_source}")
8393

8494
set(amalgamation "/* c89stringutils Amalgamation STB-style */\n\n")
8595
string(APPEND amalgamation "#ifndef C89STRINGUTILS_AMALGAMATION_H\n#define C89STRINGUTILS_AMALGAMATION_H\n\n")
8696
string(APPEND amalgamation "${amalg_export}\n\n")
8797
string(APPEND amalgamation "${amalg_config}\n\n")
8898
string(APPEND amalgamation "${amalg_log}\n\n")
99+
string(APPEND amalgamation "${amalg_safecrt_header}\n\n")
89100
string(APPEND amalgamation "${amalg_header}\n\n")
90101
string(APPEND amalgamation "#ifdef C89STRINGUTILS_IMPLEMENTATION\n\n")
102+
string(APPEND amalgamation "${amalg_safecrt_source}\n\n")
91103
string(APPEND amalgamation "${amalg_source}\n\n")
92104
string(APPEND amalgamation "#endif /* C89STRINGUTILS_IMPLEMENTATION */\n\n")
93105
string(APPEND amalgamation "#endif /* C89STRINGUTILS_AMALGAMATION_H */\n")

c89stringutils/c89stringutils_safecrt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
* @brief Implementations of safe CRT functions.
44
*/
55

6+
/* clang-format off */
67
#include "c89stringutils_safecrt.h"
78
#include <stdarg.h>
89
#include <stdlib.h>
910
#include <string.h>
11+
/* clang-format on */
1012

1113
#if defined(_MSC_VER)
1214
#pragma warning(push)
@@ -241,8 +243,8 @@ static int minimal_vfscanf(FILE *stream, const char *format, va_list args) {
241243
#endif
242244

243245
#if !defined(C89STRINGUTILS_HAVE_SET_CONSTRAINT_HANDLER_S)
244-
C89STRINGUTILS_EXPORT c89stringutils_constraint_handler_t
245-
c89stringutils_set_constraint_handler_s(
246+
C89STRINGUTILS_EXPORT
247+
c89stringutils_constraint_handler_t c89stringutils_set_constraint_handler_s(
246248
c89stringutils_constraint_handler_t handler) {
247249
c89stringutils_constraint_handler_t old = current_handler;
248250
current_handler =

c89stringutils/c89stringutils_safecrt.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@
77
* handlers.
88
*/
99

10+
/* clang-format off */
1011
#include "c89stringutils_string_extras.h"
1112
#include <stddef.h>
1213
#include <stdio.h>
1314
#include <wchar.h>
1415

16+
#if defined(C89STRINGUTILS_HAVE_SET_CONSTRAINT_HANDLER_S)
17+
#include <stdlib.h>
18+
#endif
19+
/* clang-format on */
20+
1521
#ifdef __cplusplus
1622
extern "C" {
1723
#endif
1824

1925
#if defined(C89STRINGUTILS_HAVE_SET_CONSTRAINT_HANDLER_S)
20-
#include <stdlib.h>
2126
#define c89stringutils_constraint_handler_t constraint_handler_t
2227
#define c89stringutils_set_constraint_handler_s set_constraint_handler_s
2328
#define c89stringutils_abort_handler_s abort_handler_s

c89stringutils/tests/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
2323
# Tests #
2424
#########
2525

26-
set(Header_Files "test_string_extras.h")
26+
set(Header_Files "test_string_extras.h" "test_safecrt.h")
2727
source_group("Header Files" FILES "${Header_Files}")
2828

2929
set(Source_Files "test.c" "${CMAKE_CURRENT_SOURCE_DIR}/../c89stringutils_string_extras.c" "${CMAKE_CURRENT_SOURCE_DIR}/../c89stringutils_safecrt.c")
@@ -46,3 +46,9 @@ target_include_directories(
4646
)
4747

4848
add_test(NAME "${EXEC_NAME}" COMMAND "${EXEC_NAME}")
49+
50+
if (C89STRINGUTILS_BUILD_AMALGAMATION)
51+
add_executable("test_amalg" "${CMAKE_CURRENT_SOURCE_DIR}/../../test_amalg.c")
52+
target_include_directories("test_amalg" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../..")
53+
add_test(NAME "test_amalg" COMMAND "test_amalg")
54+
endif()

c89stringutils/tests/test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include <string.h>
2020
#include <stdio.h>
2121
#include <stdarg.h>
22+
#if defined(_MSC_VER)
23+
#include <crtdbg.h>
24+
#endif
2225
#include "test_string_extras.h"
2326
#include "test_safecrt.h"
2427
/* clang-format on */
@@ -284,7 +287,6 @@ FILE *mock_tmpfile(void) {
284287
}
285288

286289
#if defined(_MSC_VER)
287-
#include <crtdbg.h>
288290
#if defined(C89STRINGUTILS_HAVE_WCHAR_H) || defined(_MSC_VER)
289291
/**
290292
* @brief Invalid parameter handler that does nothing.

c89stringutils/tests/test_safecrt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#ifndef TEST_SAFECRT_H
22
#define TEST_SAFECRT_H
33

4+
/* clang-format off */
45
#include <c89stringutils_safecrt.h>
56
#include <errno.h>
67
#include <greatest.h>
78
#include <wchar.h>
8-
99
#include <setjmp.h>
10+
/* clang-format on */
1011

1112
static int g_constraint_hit = 0;
1213
jmp_buf g_abort_env;

0 commit comments

Comments
 (0)