From: Eric Engestrom Date: Thu, 4 Jul 2019 15:13:34 +0000 (+0100) Subject: util: drop strncat(), strcmp(), strncmp(), snprintf() & vsnprintf() MSVC fallbacks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6f8b5872ab9238a3b3965c43edb6a5c9192d470d;p=mesa.git util: drop strncat(), strcmp(), strncmp(), snprintf() & vsnprintf() MSVC fallbacks It would seem MSVC>=2015 is now C99-compliant wrt these functions: strncat: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strncat-strncat-l-wcsncat-wcsncat-l-mbsncat-mbsncat-l?view=vs-2017 strcmp: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strcmp-wcscmp-mbscmp?view=vs-2017 strncmp: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strncmp-wcsncmp-mbsncmp-mbsncmp-l?view=vs-2017 snprintf: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l?view=vs-2017 vsnprintf: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/vsnprintf-vsnprintf-vsnprintf-l-vsnwprintf-vsnwprintf-l?view=vs-2017 Suggested-by: Emil Velikov Signed-off-by: Eric Engestrom Reviewed-by: Eric Anholt --- diff --git a/src/util/u_string.h b/src/util/u_string.h index 055d769fe13..499894b9f94 100644 --- a/src/util/u_string.h +++ b/src/util/u_string.h @@ -65,37 +65,6 @@ util_strchrnul(const char *s, char c) #ifdef _WIN32 -#define vsnprintf util_vsnprintf -static inline int -util_vsnprintf(char *str, size_t size, const char *format, va_list ap) -{ - /* We need to use _vscprintf to calculate the length as vsnprintf returns -1 - * if the number of characters to write is greater than count. - */ - va_list ap_copy; - int ret; - va_copy(ap_copy, ap); - ret = _vsnprintf(str, size, format, ap); - if (ret < 0) { - ret = _vscprintf(format, ap_copy); - } - va_end(ap_copy); - return ret; -} - -#define snprintf util_snprintf -static inline int - PRINTFLIKE(3, 4) -util_snprintf(char *str, size_t size, const char *format, ...) -{ - va_list ap; - int ret; - va_start(ap, format); - ret = vsnprintf(str, size, format, ap); - va_end(ap); - return ret; -} - #define sprintf util_sprintf static inline void PRINTFLIKE(2, 3) @@ -129,56 +98,6 @@ util_vasprintf(char **ret, const char *format, va_list ap) return vsnprintf(*ret, r + 1, format, ap); } -#define strncat util_strncat -static inline char* -util_strncat(char *dst, const char *src, size_t n) -{ - char *p = dst + strlen(dst); - const char *q = src; - size_t i; - - for (i = 0; i < n && *q != '\0'; ++i) - *p++ = *q++; - *p = '\0'; - - return dst; -} - -#define strcmp util_strcmp -static inline int -util_strcmp(const char *s1, const char *s2) -{ - unsigned char u1, u2; - - while (1) { - u1 = (unsigned char) *s1++; - u2 = (unsigned char) *s2++; - if (u1 != u2) - return u1 - u2; - if (u1 == '\0') - return 0; - } - return 0; -} - -#define strncmp util_strncmp -static inline int -util_strncmp(const char *s1, const char *s2, size_t n) -{ - unsigned char u1, u2; - - while (n-- > 0) { - u1 = (unsigned char) *s1++; - u2 = (unsigned char) *s2++; - if (u1 != u2) - return u1 - u2; - if (u1 == '\0') - return 0; - } - return 0; -} - - #define strcasecmp stricmp #define strdup _strdup