Msvcrt headers part 2

Francois Gouget fgouget at free.fr
Mon Apr 9 22:08:36 CDT 2001


   Part 2 actually adds the meat of things. It's composed of three
patches that can only be applied together after diff20010408-msvcrt1.txt.

   Once they have been applied you can use the msvcrt headers in Winelib
applications by adding '-isystem $(WINE_INCLUDE_ROOT)/msvcrt' to
ALLCFLAGS and ALLCXXFLAGS in Make.rules.in.
   You will also need to patch windows.h to not include winsock2.h as
the later one is broken and includes unix headers that conflict with the
msvcrt headers (it should be rewritten to be standalone).

--- cut here ---
Index: include/windows.h
===================================================================
RCS file: /home/cvs/wine/wine/include/windows.h,v
retrieving revision 1.50
diff -u -r1.50 windows.h
--- include/windows.h	2000/12/19 04:51:43	1.50
+++ include/windows.h	2001/04/08 23:44:07
@@ -31,7 +31,9 @@
 #include "shellapi.h"
 /* #include "winperf.h" */
 
+#ifndef __WINE_CTYPE_H
 #include "winsock2.h"
+#endif
 /* #include "mswsock.h" */
 
 #ifndef NOCRYPT
--- cut here ---

   What else? The winsock.h problem is the next hot target as it
currently prevents normal use of the msvcrt headers. There's more
headers to write. I'm not entirely satisfied with the handling of WCHAR.
Some msvcrt variables cannot be accessed from Winelib, e.g. _sys_nerr
and _sys_errlist but there's more. For _sys_errlist, even windows
applications trying to access it are likely to crash as it's not
implemented. I found a bug in the handling of environ which needs
fixing.
   Then these new headers need a more thorough testing: with the MFC,
with the vxcl samples, ... (find bugs, fix bugs, repeat)

   If anyone is interested in tackling one of the above, please tell the
world (i.e. wine-dev) and go ahead.


Now the changelogs:

diff20010408-msvcrt2.txt
------------------------

   This patch adds the header files in include/msvcrt

Changelog:

 * include/msvcrt/ctype.h,
   include/msvcrt/direct.h,
   include/msvcrt/dos.h,
   include/msvcrt/fcntl.h,
   include/msvcrt/io.h,
   include/msvcrt/process.h,
   include/msvcrt/stdio.h,
   include/msvcrt/stdlib.h,
   include/msvcrt/string.h,
   include/msvcrt/sys/stat.h,
   include/msvcrt/sys/types.h,
   include/msvcrt/sys/timeb.h,
   include/msvcrt/sys/utime.h,
   include/msvcrt/time.h,
   include/msvcrt/wchar.h,
   include/msvcrt/conio.h,
   include/msvcrt/stddef.h,
   include/msvcrt/wctype.h

   Headers for the msvcrt library


diff20010408-msvcrt3.txt
------------------------

   This patch must be applied on top of diff20010408-msvcrt1.txt. It
further modifies the msvcrt sources so that they include the msvcrt
headers, and fixes the sources where they do not match
the headers.

Changelog:

 * dlls/msvcrt/Makefile.in
   Define USE_MSVCRT_PREFIX when compiling the msvcrt

 * dlls/msvcrt/msvcrt.spec
   _sys_nerr and _sys_errlist are variables, not functions

 * dlls/msvcrt/console.c,
   dlls/msvcrt/cpp.c,
   dlls/msvcrt/errno.c,
   dlls/msvcrt/locale.c,
   dlls/msvcrt/main.c,
   dlls/msvcrt/math.c,
   dlls/msvcrt/misc.c,
   dlls/msvcrt/msvcrt.h,
   dlls/msvcrt/string.c,
   dlls/msvcrt/time.c
   Include the msvcrt headers, remove duplicate definitions

 * dlls/msvcrt/data.c
   Include the msvcrt headers, remove duplicate definitions
   Fix the type/signature of _environ, _wenviron, __p___argc,
__p__environ, __p__wenviron, __getmainargs and __wgetmainargs

 * dlls/msvcrt/dir.c
   Include the msvcrt headers, remove duplicate definitions
   Fix the signature of _findclose, _findfirst, _wfindfirst, _findnext,
_wfindnext (windows types like DWORD are never used in the msvcrt)
   _getdiskfree: The names of the _diskfree_t fields were incorrect
   Don't use wcs*. Use *W (from unicode.h) instead

 * dlls/msvcrt/environ.c
   Include the msvcrt headers, remove duplicate definitions
   Don't use wcs*. Use *W (from unicode.h) instead

 * dlls/msvcrt/exit.c
   Include the msvcrt headers, remove duplicate definitions
   Replaced MSVCRT_atexit_func by _onexit_t (same type but defined in
the headers)

 * dlls/msvcrt/file.c
   Include the msvcrt headers, remove duplicate definitions
   Fix the signature of _get_osfhandle, _open_osfhandle, _write, fread,
fseek (windows types like HANDLE are never used in the msvcrt)
   Fix the signature of _open and _wopen
   Don't use wcs*. Use *W (from unicode.h) instead
   Fix the return type of _write, fgetwc, getwc, _fgetwchar, getwchar,
fputwc, _fputwchar, fwrite
   setvbuf and _putws are not voids
   _IONBF and _IOLBF are not binary compatible with Unix!

 * dlls/msvcrt/mbcs.c
   Include the msvcrt headers, remove duplicate definitions
   Fix the return type of _mbschr and _mbsncat

 * dlls/msvcrt/process.c
   Include the msvcrt headers, remove duplicate definitions
   Fix the signature of _spawnve, _spawnv, _spawnvpe and _spawnvp

 * dlls/msvcrt/thread.c,
   Include the msvcrt headers, remove duplicate definitions
   Fix the signature of _beginthreadex (windows types like
LPTHREAD_START_ROUTINE are never used in the msvcrt)

 * dlls/msvcrt/wcs.c
   Include the msvcrt headers, remove duplicate definitions
   Fix the signature of _beginthreadex (windows types like LPWSTR are
never used in the msvcrt)


diff20010408-msvcrt4.txt
------------------------

   Changes elsewhere in the tree related to the msvcrt headers

 * dlls/Makedll.rules.in
   Allow the Makefile.in to define EXTRADEFS and add it to DEFS

 * include/Makefile.in
   Install the msvcrt headers

 * include/tchar.h
   Remove all the definitions that are now part of the msvcrt headers

 * include/windef.h
   _MAX_PATH & co are now also defined in stdlib.h. Prevent multiple
definitions

 * include/winnt.h
   Include string.h
   WCHAR is now also defined in wctype.h. Prevent multiple definitions


--
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
   Nouvelle version : les anciens bogues ont été remplacés par de nouveaux.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: diff20010408-msvcrt2.txt.gz
Type: application/octet-stream
Size: 7926 bytes
Desc: diff20010408-msvcrt2.txt.gz
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20010409/0d9bb56d/diff20010408-msvcrt2.txt.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diff20010408-msvcrt3.txt.gz
Type: application/octet-stream
Size: 10760 bytes
Desc: diff20010408-msvcrt3.txt.gz
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20010409/0d9bb56d/diff20010408-msvcrt3.txt.obj
-------------- next part --------------
Index: dlls/Makedll.rules.in
===================================================================
RCS file: /home/cvs/wine/wine/dlls/Makedll.rules.in,v
retrieving revision 1.13
diff -u -r1.13 Makedll.rules.in
--- dlls/Makedll.rules.in	2000/12/22 22:28:00	1.13
+++ dlls/Makedll.rules.in	2001/04/08 23:43:59
@@ -9,7 +9,7 @@
 # plus all variables required by the global Make.rules.in
 #
 
-DEFS       = @DLLFLAGS@ -D__WINE__
+DEFS       = @DLLFLAGS@ -D__WINE__ $(EXTRADEFS)
 LIBEXT     = @LIBEXT@
 SONAME     = lib$(MODULE).so
 IMPORTLIBS = $(IMPORTS:%=$(DLLDIR)/lib%.$(LIBEXT))
Index: include/Makefile.in
===================================================================
RCS file: /home/cvs/wine/wine/include/Makefile.in,v
retrieving revision 1.21
diff -u -r1.21 Makefile.in
--- include/Makefile.in	2001/02/23 01:12:27	1.21
+++ include/Makefile.in	2001/04/08 23:44:06
@@ -43,6 +43,23 @@
 	mmsystem.h \
 	msacm.h \
 	msacmdlg.h \
+	msvcrt/conio.h \
+	msvcrt/ctype.h \
+	msvcrt/direct.h \
+	msvcrt/dos.h \
+	msvcrt/fcntl.h \
+	msvcrt/io.h \
+	msvcrt/process.h \
+	msvcrt/stddef.h \
+	msvcrt/stdio.h \
+	msvcrt/stdlib.h \
+	msvcrt/string.h \
+	msvcrt/sys/stat.h \
+	msvcrt/sys/timeb.h \
+	msvcrt/sys/types.h \
+	msvcrt/sys/utime.h \
+	msvcrt/time.h \
+	msvcrt/wchar.h \
 	nspapi.h \
 	ntsecapi.h \
 	oaidl.h \
@@ -152,19 +169,22 @@
 	wtypes.h \
 	zmouse.h
 
-EXTRASUBDIRS = bitmaps wine
+EXTRASUBDIRS = bitmaps msvcrt msvcrt/sys wine
 
 @MAKE_RULES@
 
 install::
 	[ -d $(includedir) ] || $(MKDIR) $(includedir)
 	[ -d $(includedir)/wine ] || $(MKDIR) $(includedir)/wine
+	[ -d $(includedir)/msvcrt ] || $(MKDIR) $(includedir)/msvcrt
+	[ -d $(includedir)/msvcrt/sys ] || $(MKDIR) $(includedir)/msvcrt/sys
 	for f in $(INSTALLED_INCLUDES); do $(INSTALL_DATA) $(SRCDIR)/$$f $(includedir)/$$f; done
 
 # Don't just do a rm -rf on $(includedir) -- don't want to wipe out 
 # anything extra the user may have put there.
 uninstall::
 	cd $(includedir) && $(RM) $(INSTALLED_INCLUDES)
+	-rmdir $(includedir)/wine/msvcrt/sys $(includedir)/wine/msvcrt
 	-rmdir $(includedir)/wine $(includedir)
 
 ### Dependencies:
Index: include/tchar.h
===================================================================
RCS file: /home/cvs/wine/wine/include/tchar.h,v
retrieving revision 1.13
diff -u -r1.13 tchar.h
--- include/tchar.h	2000/12/19 04:50:49	1.13
+++ include/tchar.h	2001/04/08 23:44:07
@@ -7,68 +7,7 @@
 extern "C" {
 #endif
 
-/* FIXME: this should be in direct.h but since it's a standard C library include (on some systems)... */
-#define _chdir chdir
-#define _rmdir rmdir
-
-/* FIXME: this should be in io.h but I believe it's a standard include on some systems... */
-/* would need unistd.h */
-#define _access access
-/* would need sys/stat.h */
-#define _chmod chmod
-/* would need fcntl.h */
-#define _creat creat
-#define _open open
-/* FIXME: we need _S_IWRITE, _O_CREAT ... */
-/* FIXME: _fsopen is not implemented */
-#define sopen _sopen
-/* FIXME: _sopen is not implemented */
-
-/* FIXME: this should be in stdio.h but since it's a standard C library include... */
-#define fgetchar getchar
-#define fputchar putchar
-#define _popen popen
-#define _tempnam tempnam
-#define _vsnprintf vsnprintf
-
-/* FIXME: this should be in stdlib.h but since it's a standard C library include... */
-/* FIXME: itoa and ltoa are missing */
-/* FIXME: _makepath is not implemented */
-/* FIXME: _searchenv is not implemented */
-/* FIXME: _splitpath is not implemented */
-
-/* FIXME: this should be in string.h but since it's a standard C library include... */
-#define _stricmp strcasecmp
-#define _strcmpi strcasecmp
-#define strcmpi strcasecmp
-#define _strnicmp strncasecmp
-#define strnicmp strncasecmp
-#define _strdup strdup
-/* FIXME: stricoll is not implemented but strcasecmp is probably close enough in most cases */
-#define _stricoll strcasecmp
-#define stricoll _stricoll
-#define strlwr _strlwr
-#define strnset _strnset
-/* FIXME: _strnset is not implemented */
-#define strrev CRTDLL__strrev
-char *CRTDLL__strrev(char *string);
-#define strset _strset
-/* FIXME: _strset is not implemented */
-#define strupr _strupr
-#define ultoa _ultoa
-/* FIXME: _ultoa is not implemented */
-
-/* FIXME: this should be in sys/stat.h but since it's a standard C library include... */
-#define _stat stat
-
-/* FIXME: this should be in time.h but since it's a standard C library include... */
-/* FIXME: _strdate is not implemented */
-/* FIXME: _strtime is not implemented */
-
-/* FIXME: this should be in utime.h but since it's a standard C library include... */
-#define _utime utime
-
-
+xb
 /*****************************************************************************
  * tchar routines
  */
Index: include/windef.h
===================================================================
RCS file: /home/cvs/wine/wine/include/windef.h,v
retrieving revision 1.55
diff -u -r1.55 windef.h
--- include/windef.h	2001/01/09 20:56:07	1.55
+++ include/windef.h	2001/04/08 23:44:07
@@ -151,12 +151,16 @@
 #define min(a,b)   (((a) < (b)) ? (a) : (b))
 #endif
 
-#define _MAX_PATH  260
-#define MAX_PATH   260
-#define _MAX_DRIVE 3
-#define _MAX_DIR   256
-#define _MAX_FNAME 255
-#define _MAX_EXT   256
+#ifndef _MAX_PATH
+/* FIXME: These are supposed to be in stdlib.h only */
+#define _MAX_DRIVE          3
+#define _MAX_FNAME          256
+#define _MAX_DIR            _MAX_FNAME
+#define _MAX_EXT            _MAX_FNAME
+#define _MAX_PATH           260
+#endif
+#define MAX_PATH            _MAX_PATH
+
 
 #define HFILE_ERROR     ((HFILE)-1)
 
Index: include/winnt.h
===================================================================
RCS file: /home/cvs/wine/wine/include/winnt.h,v
retrieving revision 1.87
diff -u -r1.87 winnt.h
--- include/winnt.h	2001/03/13 23:33:26	1.87
+++ include/winnt.h	2001/04/08 23:44:09
@@ -12,6 +12,7 @@
 #ifndef RC_INVOKED
 #include <ctype.h>
 #include <stddef.h>
+#include <string.h>
 #endif
 
 
@@ -250,10 +251,13 @@
 typedef long            LONG,       *PLONG,    *LPLONG;
 
 /* Some systems might have wchar_t, but we really need 16 bit characters */
+#ifndef WINE_WCHAR_DEFINED
 #ifdef WINE_UNICODE_NATIVE
 typedef wchar_t         WCHAR,      *PWCHAR;
 #else
 typedef unsigned short  WCHAR,      *PWCHAR;
+#endif
+#define WINE_WCHAR_DEFINED
 #endif
 
 /* 'Extended/Wide' numerical types */


More information about the wine-patches mailing list