Skip to content

Commit 704ff0b

Browse files
committed
>>> I understand your disliking of non-posix stuff. OTOH,
>>GetLastError will >>> give much more details than errno. >> >>How much more, really? That mapping table gave me the impression that >>the win32 error codes aren't all that much more detailed than errno... > >The mapping table is not complete. My winerror.h from the SDK >lists 2209 >error codes, whereas errno.h lists 42... > >I still don't think we'll get that much more stuff. Right now, >the Win32 >code paths that actually use the more advanced functions already write >out the error number in case something happens. We can keep doing that >for the other paths (ereport the error *number* when the mapping does >not have a match). The map to errno will catch almost all cases, I >think. And in the corner cases we can do with just the number, and use >"net helpmsg" to get the actual message when checking... Here's an attempt on this. new file goes in backend/port/win32. Magnus Hagander
1 parent fe90fb4 commit 704ff0b

File tree

5 files changed

+104
-6
lines changed

5 files changed

+104
-6
lines changed

src/backend/port/win32/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Makefile for port/win32
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.5 2004/06/24 21:02:42 tgl Exp $
7+
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.6 2004/08/29 00:38:03 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/port/win32
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = sema.o shmem.o timer.o socket.o signal.o security.o
15+
OBJS = sema.o shmem.o timer.o socket.o signal.o security.o error.o
1616

1717
all: SUBSYS.o
1818

src/backend/port/win32/error.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* error.c
4+
* Map win32 error codes to errno values
5+
*
6+
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7+
*
8+
* IDENTIFICATION
9+
* $PostgreSQL: pgsql/src/backend/port/win32/error.c,v 1.1 2004/08/29 00:38:03 momjian Exp $
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#include "postgres.h"
15+
16+
static struct { DWORD winerr; int doserr;} doserrors[] =
17+
{
18+
{ ERROR_INVALID_FUNCTION, EINVAL },
19+
{ ERROR_FILE_NOT_FOUND, ENOENT },
20+
{ ERROR_PATH_NOT_FOUND, ENOENT },
21+
{ ERROR_TOO_MANY_OPEN_FILES, EMFILE },
22+
{ ERROR_ACCESS_DENIED, EACCES },
23+
{ ERROR_INVALID_HANDLE, EBADF },
24+
{ ERROR_ARENA_TRASHED, ENOMEM },
25+
{ ERROR_NOT_ENOUGH_MEMORY, ENOMEM },
26+
{ ERROR_INVALID_BLOCK, ENOMEM },
27+
{ ERROR_BAD_ENVIRONMENT, E2BIG },
28+
{ ERROR_BAD_FORMAT, ENOEXEC },
29+
{ ERROR_INVALID_ACCESS, EINVAL },
30+
{ ERROR_INVALID_DATA, EINVAL },
31+
{ ERROR_INVALID_DRIVE, ENOENT },
32+
{ ERROR_CURRENT_DIRECTORY, EACCES },
33+
{ ERROR_NOT_SAME_DEVICE, EXDEV },
34+
{ ERROR_NO_MORE_FILES, ENOENT },
35+
{ ERROR_LOCK_VIOLATION, EACCES },
36+
{ ERROR_BAD_NETPATH, ENOENT },
37+
{ ERROR_NETWORK_ACCESS_DENIED, EACCES },
38+
{ ERROR_BAD_NET_NAME, ENOENT },
39+
{ ERROR_FILE_EXISTS, EEXIST },
40+
{ ERROR_CANNOT_MAKE, EACCES },
41+
{ ERROR_FAIL_I24, EACCES },
42+
{ ERROR_INVALID_PARAMETER, EINVAL },
43+
{ ERROR_NO_PROC_SLOTS, EAGAIN },
44+
{ ERROR_DRIVE_LOCKED, EACCES },
45+
{ ERROR_BROKEN_PIPE, EPIPE },
46+
{ ERROR_DISK_FULL, ENOSPC },
47+
{ ERROR_INVALID_TARGET_HANDLE, EBADF },
48+
{ ERROR_INVALID_HANDLE, EINVAL },
49+
{ ERROR_WAIT_NO_CHILDREN, ECHILD },
50+
{ ERROR_CHILD_NOT_COMPLETE, ECHILD },
51+
{ ERROR_DIRECT_ACCESS_HANDLE, EBADF },
52+
{ ERROR_NEGATIVE_SEEK, EINVAL },
53+
{ ERROR_SEEK_ON_DEVICE, EACCES },
54+
{ ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
55+
{ ERROR_NOT_LOCKED, EACCES },
56+
{ ERROR_BAD_PATHNAME, ENOENT },
57+
{ ERROR_MAX_THRDS_REACHED, EAGAIN },
58+
{ ERROR_LOCK_FAILED, EACCES },
59+
{ ERROR_ALREADY_EXISTS, EEXIST },
60+
{ ERROR_FILENAME_EXCED_RANGE, ENOENT },
61+
{ ERROR_NESTING_NOT_ALLOWED, EAGAIN },
62+
{ ERROR_NOT_ENOUGH_QUOTA, ENOMEM }
63+
};
64+
65+
void _dosmaperr(unsigned long e)
66+
{
67+
int i;
68+
69+
if (e == 0)
70+
{
71+
errno = 0;
72+
return;
73+
}
74+
75+
for (i=0; i<sizeof(doserrors)/sizeof(doserrors[0]); i++)
76+
{
77+
if (doserrors[i].winerr == e)
78+
{
79+
errno = doserrors[i].doserr;
80+
ereport(DEBUG5,
81+
(errmsg_internal("Mapped win32 error code %i to %i",
82+
(int)e, errno)));
83+
return;
84+
}
85+
}
86+
87+
ereport(DEBUG4,
88+
(errmsg_internal("Unknown win32 error code: %i",
89+
(int)e)));
90+
errno = EINVAL;
91+
return;
92+
}

src/backend/port/win32/shmem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/port/win32/shmem.c,v 1.5 2004/04/19 17:42:58 momjian Exp $
9+
* $PostgreSQL: pgsql/src/backend/port/win32/shmem.c,v 1.6 2004/08/29 00:38:03 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -40,7 +40,7 @@ shmat(int memId, void *shmaddr, int flag)
4040
if (lpmem == NULL)
4141
{
4242
lpmem = (void *) -1;
43-
errno = GetLastError();
43+
_dosmaperr(GetLastError());
4444
}
4545

4646
return lpmem;
@@ -123,6 +123,7 @@ shmget(int memKey, int size, int flag)
123123
else if (!hmap)
124124
{
125125
/* Unable to get shared memory */
126+
_dosmaperr(GetLastError());
126127
return -1;
127128
}
128129

src/backend/postmaster/syslogger.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.5 2004/08/09 20:28:48 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.6 2004/08/29 00:38:03 momjian Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -706,6 +706,7 @@ pipeThread(void *arg)
706706
if (error == ERROR_HANDLE_EOF ||
707707
error == ERROR_BROKEN_PIPE)
708708
break;
709+
_dosmaperr(error);
709710
ereport(LOG,
710711
(errcode_for_file_access(),
711712
errmsg("could not read from logger pipe: %m")));

src/include/port/win32.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.27 2004/07/23 01:58:36 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.28 2004/08/29 00:38:03 momjian Exp $ */
22

33
/* undefine and redefine after #include */
44
#undef mkdir
@@ -147,6 +147,9 @@ extern int pgwin32_is_admin(void);
147147
extern int pgwin32_is_service(void);
148148
#endif
149149

150+
/* in backend/port/win32/error.c */
151+
void _dosmaperr(unsigned long);
152+
150153

151154
#define WEXITSTATUS(w) (((w) >> 8) & 0xff)
152155
#define WIFEXITED(w) (((w) & 0xff) == 0)
@@ -222,3 +225,4 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue
222225
#define ECONNREFUSED WSAECONNREFUSED
223226
#define EBADFD WSAENOTSOCK
224227
#define EOPNOTSUPP WSAEOPNOTSUPP
228+

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