Skip to content

Commit 359d601

Browse files
committed
Fix symlink() errno on Windows.
Ancient bug noticed while working on a test suite for these functions. https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.com
1 parent f186c7c commit 359d601

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/port/dirmod.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ pgsymlink(const char *oldpath, const char *newpath)
197197
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0);
198198

199199
if (dirhandle == INVALID_HANDLE_VALUE)
200+
{
201+
_dosmaperr(GetLastError());
200202
return -1;
203+
}
201204

202205
/* make sure we have an unparsed native win32 path */
203206
if (memcmp("\\??\\", oldpath, 4) != 0)
@@ -230,8 +233,11 @@ pgsymlink(const char *oldpath, const char *newpath)
230233
0, 0, &len, 0))
231234
{
232235
LPSTR msg;
236+
int save_errno;
237+
238+
_dosmaperr(GetLastError());
239+
save_errno = errno;
233240

234-
errno = 0;
235241
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
236242
FORMAT_MESSAGE_IGNORE_INSERTS |
237243
FORMAT_MESSAGE_FROM_SYSTEM,
@@ -251,6 +257,9 @@ pgsymlink(const char *oldpath, const char *newpath)
251257

252258
CloseHandle(dirhandle);
253259
RemoveDirectory(newpath);
260+
261+
errno = save_errno;
262+
254263
return -1;
255264
}
256265

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy