• R/O
  • HTTP
  • SSH
  • HTTPS

mingw-org-wsl: 提交

The MinGW.org Windows System Libraries


Commit MetaInfo

修訂3130b134f2cf2a41361dd57306656191f1ee0e0f (tree)
時間2020-01-18 00:39:44
作者Keith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Support GCC-9.x gratuitous use of non-standard errno accessor API.

Change Summary

差異

--- a/mingwrt/ChangeLog
+++ b/mingwrt/ChangeLog
@@ -1,3 +1,17 @@
1+2020-01-17 Keith Marshall <keith@users.osdn.me>
2+
3+ Support GCC-9.x gratuitous use of non-standard errno accessor API.
4+
5+ * include/stdlib.h (_get_errno, _set_errno): Declare prototypes;
6+ implement them in-line, for legacy Windows versions which may lack
7+ them, since GCC-9.x gratuitously and ill-advisedly requires them.
8+ (__STDLIB_H_SOURCED__): Define, and selectively #include...
9+
10+ * include/errno.h: ...this, subject to criterion...
11+ [__STDLIB_H_SOURCED__]: ...for exposure of only...
12+ (errno): ...this public API declaration, and...
13+ (EINVAL): ...this symbolic constant.
14+
115 2019-10-26 Keith Marshall <keith@users.osdn.me>
216
317 Fix MinGW-Issue #39757; avoid multiple vsnprintf() definitions.
--- a/mingwrt/include/errno.h
+++ b/mingwrt/include/errno.h
@@ -6,7 +6,8 @@
66 * $Id$
77 *
88 * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
9- * Copyright (C) 1997-1999, 2001, 2003-2005, 2007, 2016, MinGW.org Project.
9+ * Copyright (C) 1997-1999, 2001, 2003-2005, 2007, 2016, 2020,
10+ * MinGW.org Project.
1011 *
1112 *
1213 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -30,6 +31,17 @@
3031 *
3132 */
3233 #ifndef _ERRNO_H
34+#pragma GCC system_header
35+
36+/* Although ISO-C requires inclusion of <errno.h>, for all content
37+ * provided herein, Microsoft contravenes this by assuming that the
38+ * "errno" variable is also declared in <stdlib.h>; allow partial
39+ * inclusion, to support this anomaly...
40+ */
41+#ifndef __STDLIB_H_SOURCED__
42+/* ...defining the _ERRNO_H multiple inclusion guard, only when
43+ * <errno.h> is included explicitl, other than by <stdlib.h>
44+ */
3345 #define _ERRNO_H
3446
3547 /* All MinGW headers are expected to include <_mingw.h>; however...
@@ -41,17 +53,13 @@
4153 #include <_mingw.h>
4254 #endif
4355
44-/* Error code numbers.
45- *
46- * TODO: Can't be sure of some of these assignments, I guessed from the
47- * names given by strerror and the defines in the Cygnus errno.h. A lot
48- * of the names from the Cygnus errno.h are not represented, and a few
49- * of the descriptions returned by strerror do not obviously match
50- * their error naming.
56+/* Error code numbers -- these are as documented at
57+ * https://docs.microsoft.com/en-us/cpp/c-runtime-library/
58+ * errno-doserrno-sys-errlist-and-sys-nerr?view=vs-2019
5159 */
5260 #define EPERM 1 /* Operation not permitted */
53-#define ENOFILE 2 /* No such file or directory */
54-#define ENOENT 2
61+#define ENOENT 2 /* No such file or directory */
62+#define ENOFILE 2 /* Microsoft legacy alias for ENOENT */
5563 #define ESRCH 3 /* No such process */
5664 #define EINTR 4 /* Interrupted function call */
5765 #define EIO 5 /* Input/output error */
@@ -64,18 +72,35 @@
6472 #define ENOMEM 12 /* Not enough space */
6573 #define EACCES 13 /* Permission denied */
6674 #define EFAULT 14 /* Bad address */
75+
6776 /* 15 - Unknown Error */
68-#define EBUSY 16 /* strerror reports "Resource device" */
77+
78+#define EBUSY 16 /* Device or resource busy */
6979 #define EEXIST 17 /* File exists */
70-#define EXDEV 18 /* Improper link (cross-device link?) */
80+#define EXDEV 18 /* Improper link (cross-device link) */
7181 #define ENODEV 19 /* No such device */
7282 #define ENOTDIR 20 /* Not a directory */
7383 #define EISDIR 21 /* Is a directory */
84+
85+#endif /* !__STDLIB_H_SOURCED__ */
86+/* Microsoft's non-standard _get_errno() and _set_errno(), which are
87+ * declared in <stdlib.h>, and for which we provide in-line support on
88+ * legacy Windows versions, (also in <stdlib.h>), demand exposure of
89+ * EINVAL within <stdlib.h>, (for legacy support), regardless of the
90+ * state of _ERRNO_H.
91+ */
7492 #define EINVAL 22 /* Invalid argument */
93+
94+#ifdef _ERRNO_H
95+/* The remaining error codes are to be exposed only when <errno.h> has
96+ * been included explicitly.
97+ */
7598 #define ENFILE 23 /* Too many open files in system */
7699 #define EMFILE 24 /* Too many open files */
77100 #define ENOTTY 25 /* Inappropriate I/O control operation */
101+
78102 /* 26 - Unknown Error */
103+
79104 #define EFBIG 27 /* File too large */
80105 #define ENOSPC 28 /* No space left on device */
81106 #define ESPIPE 29 /* Invalid seek (seek on a pipe?) */
@@ -84,26 +109,36 @@
84109 #define EPIPE 32 /* Broken pipe */
85110 #define EDOM 33 /* Domain error (math functions) */
86111 #define ERANGE 34 /* Result too large (possibly too small) */
112+
87113 /* 35 - Unknown Error */
88-#define EDEADLOCK 36 /* Resource deadlock avoided (non-Cyg) */
89-#define EDEADLK 36
114+
115+#define EDEADLK 36 /* Resource deadlock avoided (non-Cyg) */
116+#define EDEADLOCK 36 /* Microsoft legacy alias for EDEADLK */
117+
90118 /* 37 - Unknown Error */
119+
91120 #define ENAMETOOLONG 38 /* Filename too long (91 in Cyg?) */
92121 #define ENOLCK 39 /* No locks available (46 in Cyg?) */
93122 #define ENOSYS 40 /* Function not implemented (88 in Cyg?) */
94123 #define ENOTEMPTY 41 /* Directory not empty (90 in Cyg?) */
95124 #define EILSEQ 42 /* Illegal byte sequence */
96125
126+#endif /* _ERRNO_H */
127+#if ! (defined _ERRNO_H && defined _STDLIB_H)
128+/* ISO-C requires that the standard errno feature is defined here, in
129+ * <errno.h>, but Microsoft require it to also be defined in <stdlib.h>;
130+ * we expose it for inclusion of both <errno.h> and <stdlib.h>, but we
131+ * process it once only.
132+ */
133+#if ! defined RC_INVOKED && ! defined __ASSEMBLER__
97134 /* C language function prototype declarations are unnecessary, when
98135 * compiling resource files, and they actually represent syntactically
99136 * invalid statements, in preprocessed assembly language code.
100137 */
101-#if ! defined RC_INVOKED && ! defined __ASSEMBLER__
102-
103138 _BEGIN_C_DECLS
104139
105-/* Definitions of errno. For _doserrno, sys_nerr and * sys_errlist, see
106- * stdlib.h.
140+/* Definitions of errno. For _doserrno, sys_nerr and * sys_errlist,
141+ * see <stdlib.h>
107142 */
108143 #ifdef _UWIN
109144 #undef errno
@@ -116,8 +151,9 @@ _CRTIMP int* __cdecl __MINGW_NOTHROW _errno(void);
116151 _END_C_DECLS
117152
118153 #endif /* ! RC_INVOKED && !__ASSEMBLY__ */
154+#endif /* ! (_ERRNO_H && _STDLIB_H) */
119155
120-#if defined __PTW32_H && ! defined _PTW32_ERRNO_H
156+#if defined _ERRNO_H && defined __PTW32_H && ! defined _PTW32_ERRNO_H
121157 /* As a courtesy to users of pthreads-win32, ensure that the appropriate
122158 * additional error codes, as defined by that package, are automatically
123159 * defined when <errno.h> is included AFTER any pthreads-win32 header; a
--- a/mingwrt/include/stdlib.h
+++ b/mingwrt/include/stdlib.h
@@ -7,7 +7,7 @@
77 * $Id$
88 *
99 * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
10- * Copyright (C) 1997-2009, 2011, 2014-2016, 2018, MinGW.org Project.
10+ * Copyright (C) 1997-2009, 2011, 2014-2016, 2018, 2020, MinGW.org Project.
1111 *
1212 *
1313 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -156,16 +156,43 @@ __MINGW_IMPORT char **__argv_dll;
156156 #endif /* __DECLSPEC_SUPPORTED */
157157 #endif /* MB_CUR_MAX */
158158
159-/* FIXME: Nominally in <errno.h>, Microsoft likes to declare errno
160- * in <stdlib.h> as well; we should factor this out.
159+/* In MSVCR80.DLL, Microsoft introduced the following pair of errno
160+ * accessor functions; they subsequently became available in MSVCRT.DLL
161+ * from Vista onward. Although they are not required by ISO-C, and they
162+ * are more cumbersome to use, than referring to errno directly, the GCC
163+ * developers have gratuitously chosen to assume, in GCC-9.x, that they
164+ * are always supported on MS-Windows, regardless of Windows version.
165+ * Logically, we might expect these to be declared in <errno.h>, but
166+ * Microsoft's documentation insists that they are actually declared
167+ * here; thus, to satisfy the GCC-9.x requirement, we will declare
168+ * them unconditionally here ...
161169 */
162-#ifdef _UWIN
163-# undef errno
164- extern int errno;
165-#else
166-_CRTIMP __cdecl __MINGW_NOTHROW int *_errno(void);
167-# define errno (*_errno())
170+__cdecl __MINGW_NOTHROW int _get_errno(int *);
171+__cdecl __MINGW_NOTHROW int _set_errno(int);
172+
173+/* ... then provide in-line implementations, (depending on gratuitous
174+ * exposure of EINVAL, which strictly belongs in <errno.h> only, while
175+ * also requiring declaring the ISO-C errno feature, which Microsoft
176+ * documentation calls for both here, and in <errno.h>; we satisfy
177+ * both of these requirements by selective <errno.h> inclusion).
178+ */
179+#define __STDLIB_H_SOURCED__ 1
180+#include "errno.h"
181+
182+#if __MSVCRT_VERSION__ < __MSVCR80_DLL && _WIN32_WINNT < _WIN32_WINNT_VISTA
183+/* These in-line implementations will support universal use of this API,
184+ * even on legacy Windows versions pre-dating Vista, without requiring use
185+ * of non-free MSVCRT80.DLL or later.
186+ */
187+__CRT_ALIAS __cdecl __MINGW_NOTHROW int _get_errno( int *__val )
188+{ return (__val == NULL) ? (errno = EINVAL) : 0 & (*__val = errno); }
189+
190+__CRT_ALIAS __cdecl __MINGW_NOTHROW int _set_errno( int __val )
191+{ errno = __val; return 0; }
192+
168193 #endif
194+#undef __STDLIB_H_SOURCED__
195+
169196 _CRTIMP __cdecl __MINGW_NOTHROW int *__doserrno(void);
170197 #define _doserrno (*__doserrno())
171198
Show on old repository browser