Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c94cfb3

Browse files
committed
Minor cleanup for win32stat.c.
Ensure that CloseHandle() can't clobber the errno we set for failure exits, and make a couple of tweaks for pgindent. Juan José Santamaría Flecha Discussion: https://postgr.es/m/CAC+AXB0g44SbvSpC86o_1HWh8TAU2pZrMRW6tJT-dkijotx5Qg@mail.gmail.com
1 parent fe27009 commit c94cfb3

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/port/win32stat.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ typedef struct _FILE_STANDARD_INFORMATION
4040
#endif /* !defined(__MINGW32__) &&
4141
* !defined(__MINGW64__) */
4242

43-
typedef NTSTATUS(NTAPI * PFN_NTQUERYINFORMATIONFILE)
44-
(
45-
IN HANDLE FileHandle,
46-
OUT PIO_STATUS_BLOCK IoStatusBlock,
47-
OUT PVOID FileInformation,
48-
IN ULONG Length,
49-
IN FILE_INFORMATION_CLASS FileInformationClass
50-
);
43+
typedef NTSTATUS (NTAPI * PFN_NTQUERYINFORMATIONFILE)
44+
(IN HANDLE FileHandle,
45+
OUT PIO_STATUS_BLOCK IoStatusBlock,
46+
OUT PVOID FileInformation,
47+
IN ULONG Length,
48+
IN FILE_INFORMATION_CLASS FileInformationClass);
5149

5250
static PFN_NTQUERYINFORMATIONFILE _NtQueryInformationFile = NULL;
5351

@@ -101,8 +99,8 @@ fileattr_to_unixmode(int attr)
10199
uxmode |= (unsigned short) ((attr & FILE_ATTRIBUTE_DIRECTORY) ?
102100
(_S_IFDIR) : (_S_IFREG));
103101

104-
uxmode |= (unsigned short) (attr & FILE_ATTRIBUTE_READONLY) ?
105-
(_S_IREAD) : (_S_IREAD | _S_IWRITE);
102+
uxmode |= (unsigned short) ((attr & FILE_ATTRIBUTE_READONLY) ?
103+
(_S_IREAD) : (_S_IREAD | _S_IWRITE));
106104

107105
/* there is no need to simulate _S_IEXEC using CMD's PATHEXT extensions */
108106
uxmode |= _S_IEXEC;
@@ -149,8 +147,8 @@ fileinfo_to_stat(HANDLE hFile, struct stat *buf)
149147
buf->st_mode = fileattr_to_unixmode(fiData.dwFileAttributes);
150148
buf->st_nlink = fiData.nNumberOfLinks;
151149

152-
buf->st_size = (((uint64) fiData.nFileSizeHigh) << 32) |
153-
(uint64) fiData.nFileSizeLow;
150+
buf->st_size = ((((uint64) fiData.nFileSizeHigh) << 32) |
151+
fiData.nFileSizeLowi);
154152

155153
return 0;
156154
}
@@ -220,17 +218,21 @@ _pgstat64(const char *name, struct stat *buf)
220218
LoadNtdll();
221219
if (ntdll == NULL)
222220
{
223-
_dosmaperr(GetLastError());
221+
DWORD err = GetLastError();
222+
224223
CloseHandle(hFile);
224+
_dosmaperr(err);
225225
return -1;
226226
}
227227

228228
_NtQueryInformationFile = (PFN_NTQUERYINFORMATIONFILE)
229229
GetProcAddress(ntdll, "NtQueryInformationFile");
230230
if (_NtQueryInformationFile == NULL)
231231
{
232-
_dosmaperr(GetLastError());
232+
DWORD err = GetLastError();
233+
233234
CloseHandle(hFile);
235+
_dosmaperr(err);
234236
return -1;
235237
}
236238
}
@@ -239,16 +241,20 @@ _pgstat64(const char *name, struct stat *buf)
239241
sizeof(standardInfo),
240242
FileStandardInformation)))
241243
{
242-
_dosmaperr(GetLastError());
244+
DWORD err = GetLastError();
245+
243246
CloseHandle(hFile);
247+
_dosmaperr(err);
244248
return -1;
245249
}
246250
#else
247251
if (!GetFileInformationByHandleEx(hFile, FileStandardInfo, &standardInfo,
248252
sizeof(standardInfo)))
249253
{
250-
_dosmaperr(GetLastError());
254+
DWORD err = GetLastError();
255+
251256
CloseHandle(hFile);
257+
_dosmaperr(err);
252258
return -1;
253259
}
254260
#endif /* _WIN32_WINNT < 0x0600 */

0 commit comments

Comments
 (0)