+2016-03-28 Keith Marshall <keithmarshall@users.sourceforge.net>
+
+ Factor out <wchar.h> vs. <direct.h> duplicate declarations.
+
+ * include/direct.h: Conditionally partition it, such that...
+ [__WCHAR_H_SOURCED__] (_DIRECT_H): Do not define it; declare only...
+ (_wchdir, wchar_t, wchar_t, _wmkdir, _wrmdir): ...these, otherwise...
+ [!__WCHAR_H_SOURCED__] (_DIRECT_H): Define it; expose all content.
+ (_WDIRECT_DEFINED): Never define it; delete all references.
+
+ * include/wchar.h (_WDIRECT_DEFINED): Delete all references.
+ (_wchdir, wchar_t, wchar_t, _wmkdir, _wrmdir): Delete prototypes;
+ selectively #include <direct.h> to reproduce them.
+
2016-03-26 Keith Marshall <keithmarshall@users.sourceforge.net>
Factor out <direct.h> vs. <dos.h> duplicate declarations.
*/
#ifndef _DIRECT_H
#pragma GCC system_header
+
+/* In addition to inclusion in its own right, this header supports
+ * selective inclusion by <wchar.h>; thus...
+ */
+#ifndef __WCHAR_H_SOURCED__
+ /* ...we defer definition of the normal multiple inclusion guard,
+ * until we know that this is NOT a selective inclusion request.
+ */
#define _DIRECT_H
#define __DIRECT_H_SOURCED__
#include <dos.h>
#undef __DIRECT_H_SOURCED__
+#endif /* !__WCHAR_H_SOURCED__ */
+
#ifndef RC_INVOKED
_BEGIN_C_DECLS
-/* Functions for manipulating disk drive selection.
+#ifdef _DIRECT_H
+/* Functions for manipulating disk drive selection; these are declared
+ * only when <direct.h> is included in its own right.
*/
_CRTIMP __cdecl __MINGW_NOTHROW int _getdrive (void);
_CRTIMP __cdecl __MINGW_NOTHROW unsigned long _getdrives(void);
_CRTIMP __cdecl __MINGW_NOTHROW int _chdrive (int);
_CRTIMP __cdecl __MINGW_NOTHROW char *_getdcwd (int, char*, int);
-/* The following group of functions are available only within
- * MSVCRT.DLL, (i.e. they are NOT provided by CRTDLL.DLL); they
- * are also declared in <wchar.h>, hence avoid declaring them a
- * second time.
- */
-#if defined __MSVCRT__ && ! defined _WDIRECT_DEFINED
+#endif /* _DIRECT_H */
+/* The following group of function prototypes are to be declared
+ * either when including <dirent.h> in its own right, or when it
+ * is included selectively by <wchar.h>; however...
+ */
+#if defined __MSVCRT__ && ! (defined _DIRENT_H && defined _WCHAR_H)
+ /*
+ * ...they are available only within MSVCRT.DLL, (i.e. they are
+ * NOT provided by CRTDLL.DLL), and if both _DIRENT_H and _WCHAR_H
+ * are already defined, by the time we get to here, then this must
+ * be an inclusion of <dirent.h> in its own right, AFTER they have
+ * already been declared on behalf of <wchar.h>; there is no need
+ * to declare them again.
+ */
_CRTIMP __cdecl __MINGW_NOTHROW int _wchdir (const wchar_t *);
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_wgetcwd (wchar_t *, int);
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_wgetdcwd (int, wchar_t *, int);
_CRTIMP __cdecl __MINGW_NOTHROW int _wmkdir (const wchar_t *);
_CRTIMP __cdecl __MINGW_NOTHROW int _wrmdir (const wchar_t *);
-#define _WDIRECT_DEFINED
-#endif /* __MSVCRT__ && !_WDIRECT_DEFINED */
+#endif /* __MSVCRT__ && ! (defined _DIRENT_H && defined _WCHAR_H) */
_END_C_DECLS
* long double wcstold (const wchar_t *restrict, wchar_t **restrict);
*
*
+ * while from...
+ */
+#include <direct.h>
+/* ...we obtain prototypes for each of the following functions,
+ * (none of which are available when using CRTDLL.DLL):
+ *
+ * int _wchdir (const wchar_t *);
+ * wchar_t *_wgetcwd (wchar_t *, int);
+ * wchar_t *_wgetdcwd (int, wchar_t *, int);
+ * int _wmkdir (const wchar_t *);
+ * int _wrmdir (const wchar_t *);
+ *
+ *
* Again, in similar fashion, from...
*/
#include <time.h>
#define _WIO_DEFINED
#endif /* _WIO_DEFINED */
-#ifndef _WDIRECT_DEFINED
-/* Also in direct.h */
-#ifdef __MSVCRT__
-_CRTIMP int __cdecl __MINGW_NOTHROW _wchdir (const wchar_t*);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wgetcwd (wchar_t*, int);
-_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wgetdcwd (int, wchar_t*, int);
-_CRTIMP int __cdecl __MINGW_NOTHROW _wmkdir (const wchar_t*);
-_CRTIMP int __cdecl __MINGW_NOTHROW _wrmdir (const wchar_t*);
-#endif /* __MSVCRT__ */
-#define _WDIRECT_DEFINED
-#endif /* _WDIRECT_DEFINED */
-
#ifndef _STAT_DEFINED
/*
* The structure manipulated and returned by stat and fstat.