To avoid using a deprecated function on Windows.
Also: de-dupe `SNPRINTF` definition in curlx.
Closes #19681
curlx/inet_pton.h \
curlx/multibyte.h \
curlx/nonblock.h \
+ curlx/snprintf.h \
curlx/strerr.h \
curlx/strparse.h \
curlx/timediff.h \
unlink(), etc. */
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_WARNINGS /* for getenv(), gmtime(), sprintf(),
- strcpy(),
+#define _CRT_SECURE_NO_WARNINGS /* for getenv(), gmtime(), strcpy(),
in tests: localtime(), sscanf() */
#endif
#endif /* _MSC_VER */
#endif
#include "inet_ntop.h"
+#include "snprintf.h"
#define IN6ADDRSZ 16
/* #define INADDRSZ 4 */
DEBUGASSERT(size >= 16);
- /* this sprintf() does not overflow the buffer. Avoids snprintf to work more
- widely. Avoids the msnprintf family to work as a curlx function. */
- (void)(sprintf)(tmp, "%d.%d.%d.%d",
- ((int)((unsigned char)src[0])) & 0xff,
- ((int)((unsigned char)src[1])) & 0xff,
- ((int)((unsigned char)src[2])) & 0xff,
- ((int)((unsigned char)src[3])) & 0xff);
+ /* this snprintf() does not overflow the buffer. */
+ SNPRINTF(tmp, sizeof(tmp), "%d.%d.%d.%d",
+ ((int)((unsigned char)src[0])) & 0xff,
+ ((int)((unsigned char)src[1])) & 0xff,
+ ((int)((unsigned char)src[2])) & 0xff,
+ ((int)((unsigned char)src[3])) & 0xff);
len = strlen(tmp);
if(len == 0 || len >= size) {
--- /dev/null
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+
+/* Raw snprintf() for curlx */
+
+#ifdef WITHOUT_LIBCURL /* when built for the test servers */
+#if defined(_MSC_VER) && (_MSC_VER < 1900) /* adjust for old MSVC */
+#define SNPRINTF _snprintf
+#else
+#define SNPRINTF snprintf
+#endif
+#else /* !WITHOUT_LIBCURL */
+#include <curl/mprintf.h>
+#define SNPRINTF curl_msnprintf
+#endif /* WITHOUT_LIBCURL */
#include <curl/curl.h>
-#ifndef WITHOUT_LIBCURL
-#include <curl/mprintf.h>
-#define SNPRINTF curl_msnprintf
-#else
-/* when built for the test servers */
-
-/* adjust for old MSVC */
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-#define SNPRINTF _snprintf
-#else
-#define SNPRINTF snprintf
-#endif
-#endif /* !WITHOUT_LIBCURL */
-
#include "winapi.h"
+#include "snprintf.h"
#include "strerr.h"
/* The last 2 #include files should be in this order */
#include "../curl_memory.h"
*/
#ifdef _WIN32
#include "winapi.h"
-
-#ifndef WITHOUT_LIBCURL
-#include <curl/mprintf.h>
-#define SNPRINTF curl_msnprintf
-#else
-/* when built for the test servers */
-
-/* adjust for old MSVC */
-#if defined(_MSC_VER) && (_MSC_VER < 1900)
-#define SNPRINTF _snprintf
-#else
-#define SNPRINTF snprintf
-#endif
-#endif /* !WITHOUT_LIBCURL */
+#include "snprintf.h"
/* This is a helper function for curlx_strerror that converts Windows API error
* codes (GetLastError) to error messages.
../lib/curlx/fopen.h \
../lib/curlx/multibyte.h \
../lib/curlx/nonblock.h \
+ ../lib/curlx/snprintf.h \
../lib/curlx/strerr.h \
../lib/curlx/strparse.h \
../lib/curlx/timediff.h \