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
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-
5644static 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
8471int 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
263256extern 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 );
0 commit comments