# define __STDC_FORMAT_MACROS 1
#endif
-// For example for vasprintf under i686-w64-mingw32-g++-posix. The later
-// definition of _XOPEN_SOURCE disables certain features on Linux, so we need
-// _GNU_SOURCE to re-enable them (makedev, tm_zone).
+// The later definition of _XOPEN_SOURCE disables certain features on Linux, so
+// we need _GNU_SOURCE to re-enable them.
#define _GNU_SOURCE 1
// The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables certain
-// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
return p;
}
-
-// From: https://stackoverflow.com/a/40160038/262458
-#ifdef _MSC_VER
-int
-vasprintf(char** strp, const char* fmt, va_list ap)
-{
- // _vscprintf tells you how big the buffer needs to be
- int len = _vscprintf(fmt, ap);
- if (len == -1) {
- return -1;
- }
- size_t size = (size_t)len + 1;
- char* str = static_cast<char*>(malloc(size));
- if (!str) {
- return -1;
- }
- // vsprintf_s is the "secure" version of vsprintf
- int r = vsprintf_s(str, len + 1, fmt, ap);
- if (r == -1) {
- free(str);
- return -1;
- }
- *strp = str;
- return r;
-}
-#endif
-
-// Also from: https://stackoverflow.com/a/40160038/262458
-#ifdef _MSC_VER
-int
-asprintf(char** strp, const char* fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- int r = vasprintf(strp, fmt, ap);
- va_end(ap);
- return r;
-}
-#endif
-// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
struct tm* localtime_r(time_t* _clock, struct tm* _result);
-# ifdef _MSC_VER
-int asprintf(char** strp, const char* fmt, ...);
-# endif
-
namespace Win32Util {
// Add ".exe" suffix to `program` if it doesn't already end with ".exe", ".bat"
#include "environment.hpp"
-#include <Win32Util.hpp> // for asprintf
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#include <fmtmacros.hpp>
#ifdef HAVE_SETENV
::setenv(name.c_str(), value.c_str(), true);
#else
- char* string;
- asprintf(&string, "%s=%s", name.c_str(), value.c_str());
- putenv(string); // Leak to environment.
+ auto string = FMT("{}={}", name, value);
+ putenv(strdup(string.c_str())); // Leak to environment.
#endif
}