Skip to content

Commit

Permalink
fixes warning
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 24, 2024
1 parent b0356c8 commit 07e610c
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions bee/net/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,45 +553,43 @@ namespace bee::net::socket {

#if defined(_WIN32)
static bool unnamed_unix_bind(fd_t s) noexcept {
wchar_t tmpdir[MAX_PATH];
int bind_try = 0;
wchar_t buf[MAX_PATH];
const wchar_t* tmpdir = buf;
int bind_try = 0;
for (;;) {
switch (bind_try++) {
case 0:
GetTempPathW(MAX_PATH, tmpdir);
GetTempPathW(MAX_PATH, buf);
tmpdir = buf;
break;
case 1: {
UINT n = GetWindowsDirectoryW(tmpdir, MAX_PATH);
# if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
# endif
_snwprintf(tmpdir + n, MAX_PATH - n, L"\\Temp\\");
# if defined(_MSC_VER)
# pragma warning(pop)
# endif
constexpr size_t sz = std::size(L"\\Temp\\");
UINT n = GetWindowsDirectoryW(buf, MAX_PATH);
if (n + sz >= MAX_PATH) {
tmpdir = nullptr;
break;
}
for (size_t i = 0; i < sz; ++i) {
buf[n + i] = L"\\Temp\\"[i];
}
tmpdir = buf;
break;
}
case 2:
# if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
# endif
_snwprintf(tmpdir, MAX_PATH, L"C:\\Temp\\");
# if defined(_MSC_VER)
# pragma warning(pop)
# endif
tmpdir = L"C:\\Temp\\";
break;
case 3:
tmpdir[0] = L'.';
tmpdir[1] = L'\0';
tmpdir = L".";
break;
case 4:
::WSASetLastError(WSAEFAULT);
return false;
default:
std::unreachable();
}
if (!tmpdir) {
continue;
}
wchar_t tmpname[MAX_PATH];
if (0 == GetTempFileNameW(tmpdir, L"bee", 1, tmpname)) {
continue;
Expand Down

0 comments on commit 07e610c

Please sign in to comment.