common,w32: Set a proper error code when creating an output file.

* common/iobuf.c (direct_open) [W32]: Set errno.
(fd_cache_open): Ditto.
--
This commit is contained in:
Werner Koch 2023-05-23 14:50:22 +02:00
parent 7e681da1b2
commit 42bea7de16
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 10 additions and 2 deletions

View File

@ -311,6 +311,13 @@ direct_open (const char *fname, const char *mode, int mode700)
{ {
hfile = CreateFileW (wfname, da, sm, NULL, cd, hfile = CreateFileW (wfname, da, sm, NULL, cd,
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
if (hfile == INVALID_HANDLE_VALUE)
{
gnupg_w32_set_errno (-1);
if (DBG_IOBUF)
log_debug ("iobuf:direct_open '%s' CreateFile failed: %s\n",
fname, gpg_strerror (gpg_error_from_syserror()));
}
xfree (wfname); xfree (wfname);
} }
else else
@ -426,8 +433,9 @@ fd_cache_open (const char *fname, const char *mode)
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff) if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff)
{ {
log_error ("rewind file failed on handle %p: ec=%d\n", int ec = (int) GetLastError ();
fp, (int) GetLastError ()); log_error ("rewind file failed on handle %p: ec=%d\n", fp, ec);
gnupg_w32_set_errno (ec);
fp = GNUPG_INVALID_FD; fp = GNUPG_INVALID_FD;
} }
#else #else