Add num_done counter to the pg_stat_checkpointer view.
[pgsql.git] / src / port / win32common.c
blobdc83396236d7deba8d186fe45d1830a4c898f435
1 /*-------------------------------------------------------------------------
3 * win32common.c
4 * Common routines shared among the win32*.c ports.
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * src/port/win32common.c
13 *-------------------------------------------------------------------------
16 #ifdef FRONTEND
17 #include "postgres_fe.h"
18 #else
19 #include "postgres.h"
20 #endif
23 * pgwin32_get_file_type
25 * Convenience wrapper for GetFileType() with specific error handling for all the
26 * port implementations. Returns the file type associated with a HANDLE.
28 * On error, sets errno with FILE_TYPE_UNKNOWN as file type.
30 DWORD
31 pgwin32_get_file_type(HANDLE hFile)
33 DWORD fileType = FILE_TYPE_UNKNOWN;
34 DWORD lastError;
36 errno = 0;
39 * When stdin, stdout, and stderr aren't associated with a stream the
40 * special value -2 is returned:
41 * https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle
43 if (hFile == INVALID_HANDLE_VALUE || hFile == (HANDLE) -2)
45 errno = EINVAL;
46 return FILE_TYPE_UNKNOWN;
49 fileType = GetFileType(hFile);
50 lastError = GetLastError();
53 * Invoke GetLastError in order to distinguish between a "valid" return of
54 * FILE_TYPE_UNKNOWN and its return due to a calling error. In case of
55 * success, GetLastError() returns NO_ERROR.
57 if (fileType == FILE_TYPE_UNKNOWN && lastError != NO_ERROR)
59 _dosmaperr(lastError);
60 return FILE_TYPE_UNKNOWN;
63 return fileType;