Skip to content

Commit 8688441

Browse files
committed
CI fixes
1 parent b17aa29 commit 8688441

5 files changed

Lines changed: 54 additions & 60 deletions

File tree

c89stringutils/c89stringutils_log.h

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,26 @@ extern "C" {
66
#endif /* __cplusplus */
77

88
/* clang-format off */
9-
#include <stdio.h>
9+
#include "c89stringutils_export.h"
1010
/* clang-format on */
1111

1212
#ifndef LOG_DEBUG
1313
#ifdef DEBUG
14-
#if defined(_MSC_VER) && _MSC_VER < 1400
15-
/* MSVC older than 2005 doesn't support variadic macros well */
16-
#define LOG_DEBUG(fmt, ...)
14+
/**
15+
* @brief Log debug message
16+
* @param fmt The format string.
17+
* @param ... The arguments.
18+
*/
19+
C89STRINGUTILS_EXPORT void c89stringutils_log_debug(const char *fmt, ...);
20+
#define LOG_DEBUG c89stringutils_log_debug
1721
#else
18-
#if defined(__GNUC__) || defined(__clang__)
19-
#pragma GCC diagnostic push
20-
#pragma GCC diagnostic ignored "-Wvariadic-macros"
21-
#endif /* defined(__GNUC__) || defined(__clang__) */
22-
#define LOG_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " fmt, ##__VA_ARGS__)
23-
#if defined(__GNUC__) || defined(__clang__)
24-
#pragma GCC diagnostic pop
25-
#endif /* defined(__GNUC__) || defined(__clang__) */
26-
#endif
27-
#else
28-
#if defined(__GNUC__) || defined(__clang__)
29-
#pragma GCC diagnostic push
30-
#pragma GCC diagnostic ignored "-Wvariadic-macros"
31-
#endif /* defined(__GNUC__) || defined(__clang__) */
32-
#define LOG_DEBUG(fmt, ...)
33-
#if defined(__GNUC__) || defined(__clang__)
34-
#pragma GCC diagnostic pop
35-
#endif /* defined(__GNUC__) || defined(__clang__) */
22+
/**
23+
* @brief Log debug message
24+
* @param fmt The format string.
25+
* @param ... The arguments.
26+
*/
27+
C89STRINGUTILS_EXPORT void c89stringutils_log_debug(const char *fmt, ...);
28+
#define LOG_DEBUG 1 ? (void)0 : c89stringutils_log_debug
3629
#endif /* DEBUG */
3730
#endif /* !LOG_DEBUG */
3831

c89stringutils/c89stringutils_string_extras.c

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
#include <limits.h> /* for INT_MAX */
1616
/* clang-format on */
1717

18+
void c89stringutils_log_debug(const char *fmt, ...) {
19+
va_list args;
20+
va_start(args, fmt);
21+
vfprintf(stderr, fmt, args);
22+
fprintf(stderr, "\n");
23+
va_end(args);
24+
}
25+
1826
#ifndef HAVE_SNPRINTF_H
1927
#define HAVE_SNPRINTF_H
2028

@@ -33,26 +41,6 @@
3341
#define _vsnprintf vsnprintf
3442
#endif /* ANY_BSD */
3543

36-
static int wtf_snprintf(char *buffer, size_t count, const char *format, ...) {
37-
int rc;
38-
va_list args;
39-
va_start(args, format);
40-
#if defined(_MSC_VER)
41-
rc = _vsnprintf_s(buffer, count, _TRUNCATE, format, args);
42-
if (rc < 0) {
43-
rc = _vscprintf(format, args);
44-
}
45-
#else
46-
rc = _vsnprintf(buffer, count, format, args);
47-
#endif
48-
va_end(args);
49-
/* In the case where the string entirely filled the buffer, _vsnprintf will
50-
not null-terminate it, but snprintf must. */
51-
if (count > 0)
52-
buffer[count - 1] = '\0';
53-
return rc;
54-
}
55-
5644
static int wtf_vsnprintf(char *buffer, size_t count, const char *format,
5745
va_list args) {
5846
int rc;
@@ -73,7 +61,6 @@ static int wtf_vsnprintf(char *buffer, size_t count, const char *format,
7361

7462
#define vsnprintf(buffer, count, format, args) \
7563
wtf_vsnprintf(buffer, count, format, args)
76-
#define snprintf wtf_snprintf
7764

7865
#endif /* !HAVE_SNPRINTF_H */
7966

@@ -82,10 +69,16 @@ static int wtf_vsnprintf(char *buffer, size_t count, const char *format,
8269
#define HAVE_STRNCASECMP_H
8370

8471
int strncasecmp(const char *s1, const char *s2, size_t n) {
85-
return _strnicmp(s1, s2, n);
72+
int rc;
73+
rc = _strnicmp(s1, s2, n);
74+
return rc;
8675
}
8776

88-
int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1, s2); }
77+
int strcasecmp(const char *s1, const char *s2) {
78+
int rc;
79+
rc = _stricmp(s1, s2);
80+
return rc;
81+
}
8982

9083
#endif /* !HAVE_STRNCASECMP_H */
9184

@@ -98,15 +91,15 @@ char *strnstr(const char *buffer, const char *target, size_t bufferLength) {
9891
first slen characters of s.
9992
10093
DESCRIPTION
101-
The strnstr() function locates the first occurrence of the
94+
The strnstr() function locates the first occurrence of the
10295
null-termi-
103-
nated string little in the string big, where not more than len
104-
characters are searched. Characters that appear after a `\0' character are
96+
nated string little in the string big, where not more than len
97+
characters are searched. Characters that appear after a `\0' character are
10598
not searched.
10699
107100
RETURN VALUES
108-
If little is an empty string, big is returned; if little occurs
109-
nowhere in big, NULL is returned; otherwise a pointer to the first
101+
If little is an empty string, big is returned; if little occurs
102+
nowhere in big, NULL is returned; otherwise a pointer to the first
110103
character of the first occurrence of little is returned.
111104
112105
[this doc (c) FreeBSD <3 clause BSD license> from their manpage] */
@@ -250,9 +243,9 @@ extern int vasprintf(char **str, const char *fmt, va_list ap) {
250243
#ifdef _MSC_VER
251244
char errbuf[256];
252245
strerror_s(errbuf, sizeof(errbuf), errno);
253-
LOG_DEBUG("vasprintf failed with rc=%d, error=%s\n", rc, errbuf);
246+
LOG_DEBUG("vasprintf failed with rc=%d, error=%s", rc, errbuf);
254247
#else
255-
LOG_DEBUG("vasprintf failed with rc=%d, error=%s\n", rc, strerror(errno));
248+
LOG_DEBUG("vasprintf failed with rc=%d, error=%s", rc, strerror(errno));
256249
#endif
257250
}
258251
*str = NULL;
@@ -261,8 +254,8 @@ extern int vasprintf(char **str, const char *fmt, va_list ap) {
261254
}
262255

263256
extern int asprintf(char **str, const char *fmt, ...) {
264-
va_list ap;
265257
int rc;
258+
va_list ap;
266259

267260
*str = NULL;
268261
va_start(ap, fmt);
@@ -273,9 +266,9 @@ extern int asprintf(char **str, const char *fmt, ...) {
273266
#ifdef _MSC_VER
274267
char errbuf[256];
275268
strerror_s(errbuf, sizeof(errbuf), errno);
276-
LOG_DEBUG("asprintf failed with rc=%d, error=%s\n", rc, errbuf);
269+
LOG_DEBUG("asprintf failed with rc=%d, error=%s", rc, errbuf);
277270
#else
278-
LOG_DEBUG("asprintf failed with rc=%d, error=%s\n", rc, strerror(errno));
271+
LOG_DEBUG("asprintf failed with rc=%d, error=%s", rc, strerror(errno));
279272
#endif
280273
}
281274

@@ -320,12 +313,12 @@ char *jasprintf(char **unto, const char *fmt, ...) {
320313
rc = vsprintf_s(result + base_length, (size_t)length + 1, fmt, args);
321314
if (rc < 0) {
322315
/* handle error, printing the nonzero exit code for debug purposes */
323-
LOG_DEBUG("vsprintf_s failed with rc=%d\n", rc);
316+
LOG_DEBUG("vsprintf_s failed with rc=%d", rc);
324317
}
325318
#else
326319
rc = vsprintf(result + base_length, fmt, args);
327320
if (rc < 0) {
328-
LOG_DEBUG("vsprintf failed with rc=%d\n", rc);
321+
LOG_DEBUG("vsprintf failed with rc=%d", rc);
329322
}
330323
#endif
331324
va_end(args);

c89stringutils/c89stringutils_string_extras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,4 @@ extern C89STRINGUTILS_EXPORT char *jasprintf(char **unto, const char *fmt, ...);
227227
}
228228
#endif /* __cplusplus */
229229

230-
#endif /* !C89STRINGUTILS_STRING_EXTRAS_H */
230+
#endif /* !C89STRINGUTILS_STRING_EXTRAS_H */

c89stringutils/tests/test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* clang-format off */
22
#include <greatest.h>
3+
#include <c89stringutils_log.h>
34

45
#include "test_string_extras.h"
56
/* clang-format on */
@@ -11,4 +12,4 @@ int main(int argc, char **argv) {
1112
GREATEST_MAIN_BEGIN();
1213
RUN_SUITE(strnstr_suite);
1314
GREATEST_MAIN_END();
14-
}
15+
}

c89stringutils/tests/test_string_extras.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern "C" {
99
#include <greatest.h>
1010

1111
#include <c89stringutils_string_extras.h>
12+
#include <c89stringutils_log.h>
1213
#include <stdlib.h>
1314
#include <errno.h>
1415
/* clang-format on */
@@ -90,6 +91,11 @@ TEST x_vasprintf_should_succeed(void) {
9091
PASS();
9192
}
9293

94+
TEST x_log_debug_should_succeed(void) {
95+
LOG_DEBUG("test log debug: %d", 1);
96+
PASS();
97+
}
98+
9399
/* Suites can group multiple tests with common setup. */
94100
SUITE(strnstr_suite) {
95101
RUN_TEST(x_strnstr_should_succeed);
@@ -101,10 +107,11 @@ SUITE(strnstr_suite) {
101107
RUN_TEST(x_strcasestr_should_succeed);
102108
RUN_TEST(x_strerrorlen_s_should_succeed);
103109
RUN_TEST(x_vasprintf_should_succeed);
110+
RUN_TEST(x_log_debug_should_succeed);
104111
}
105112

106113
#ifdef __cplusplus
107114
}
108115
#endif /* __cplusplus */
109116

110-
#endif /* !TEST_STRING_EXTRAS_H */
117+
#endif /* !TEST_STRING_EXTRAS_H */

0 commit comments

Comments
 (0)