Skip to content

Commit 1862358

Browse files
committed
macOS improvements
1 parent 3dd0431 commit 1862358

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

c89stringutils/c89stringutils_string_extras.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ C89STRINGUTILS_EXPORT size_t c89stringutils_strerrorlen_s(errno_t errnum) {
884884
return res ? strlen(res) : 0;
885885
#endif
886886
#else
887+
int rc;
887888
errbuf[0] = '\0';
888889
rc = strerror_r(errnum, errbuf, sizeof(errbuf));
889890
errbuf[sizeof(errbuf) - 1] = '\0';

c89stringutils/c89stringutils_string_extras.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,17 @@ c89stringutils_vsnprintf(char *s, size_t n, const char *format, va_list arg)
490490
* respectively, to be less than, to match, or be greater than s2.
491491
*/
492492
#if defined(C89STRINGUTILS_HAVE__STRNICMP)
493-
#define c89stringutils_strncasecmp _strnicmp
493+
#define c89stringutils_strncasecmp(s1, s2, n) \
494+
(((s1) == NULL && (s2) == NULL) ? 0 \
495+
: ((s1) == NULL) ? -1 \
496+
: ((s2) == NULL) ? 1 \
497+
: _strnicmp((s1), (s2), (n)))
494498
#elif defined(C89STRINGUTILS_HAVE_STRNCASECMP)
495-
#define c89stringutils_strncasecmp strncasecmp
499+
#define c89stringutils_strncasecmp(s1, s2, n) \
500+
(((s1) == NULL && (s2) == NULL) ? 0 \
501+
: ((s1) == NULL) ? -1 \
502+
: ((s2) == NULL) ? 1 \
503+
: strncasecmp((s1), (s2), (n)))
496504
#else
497505
extern C89STRINGUTILS_EXPORT int
498506
c89stringutils_strncasecmp(const char *s1, const char *s2, size_t n);
@@ -506,9 +514,17 @@ c89stringutils_strncasecmp(const char *s1, const char *s2, size_t n);
506514
* respectively, to be less than, to match, or be greater than s2.
507515
*/
508516
#if defined(C89STRINGUTILS_HAVE__STRICMP)
509-
#define c89stringutils_strcasecmp _stricmp
517+
#define c89stringutils_strcasecmp(s1, s2) \
518+
(((s1) == NULL && (s2) == NULL) ? 0 \
519+
: ((s1) == NULL) ? -1 \
520+
: ((s2) == NULL) ? 1 \
521+
: _stricmp((s1), (s2)))
510522
#elif defined(C89STRINGUTILS_HAVE_STRCASECMP)
511-
#define c89stringutils_strcasecmp strcasecmp
523+
#define c89stringutils_strcasecmp(s1, s2) \
524+
(((s1) == NULL && (s2) == NULL) ? 0 \
525+
: ((s1) == NULL) ? -1 \
526+
: ((s2) == NULL) ? 1 \
527+
: strcasecmp((s1), (s2)))
512528
#else
513529
extern C89STRINGUTILS_EXPORT int c89stringutils_strcasecmp(const char *s1,
514530
const char *s2);
@@ -524,7 +540,8 @@ extern C89STRINGUTILS_EXPORT int c89stringutils_strcasecmp(const char *s1,
524540
* found.
525541
*/
526542
#if defined(C89STRINGUTILS_HAVE_STRNSTR)
527-
#define c89stringutils_strnstr strnstr
543+
#define c89stringutils_strnstr(b, t, l) \
544+
(((b) == NULL || (t) == NULL) ? NULL : strnstr((b), (t), (l)))
528545
#else
529546
extern C89STRINGUTILS_EXPORT char *c89stringutils_strnstr(const char *buffer,
530547
const char *target,
@@ -539,7 +556,8 @@ extern C89STRINGUTILS_EXPORT char *c89stringutils_strnstr(const char *buffer,
539556
* found.
540557
*/
541558
#if defined(C89STRINGUTILS_HAVE_STRCASESTR)
542-
#define c89stringutils_strcasestr strcasestr
559+
#define c89stringutils_strcasestr(h, n) \
560+
(((h) == NULL || (n) == NULL) ? NULL : strcasestr((h), (n)))
543561
#else
544562
extern C89STRINGUTILS_EXPORT char *c89stringutils_strcasestr(const char *h,
545563
const char *n);

0 commit comments

Comments
 (0)