Include the msvcrt headers, remove duplicate definitions.
Fixed the signature of a few functions.
Don't use wcs* functions, use *W (from unicode.h) instead.

diff --git a/dlls/msvcrt/Makefile.in b/dlls/msvcrt/Makefile.in
index 5eee50b..c9f57c4 100644
--- a/dlls/msvcrt/Makefile.in
+++ b/dlls/msvcrt/Makefile.in
@@ -1,3 +1,4 @@
+EXTRADEFS = -DUSE_MSVCRT_PREFIX
 TOPSRCDIR = @top_srcdir@
 TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
diff --git a/dlls/msvcrt/console.c b/dlls/msvcrt/console.c
index aa02a60..f83caaa 100644
--- a/dlls/msvcrt/console.c
+++ b/dlls/msvcrt/console.c
@@ -9,8 +9,14 @@
 #include "msvcrt.h"
 #include "wincon.h"
 
+#include "msvcrt/conio.h"
+#include "msvcrt/stdio.h"
+#include "msvcrt/stdlib.h"
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
+
+
 /* MT */
 extern CRITICAL_SECTION MSVCRT_console_cs;
 #define LOCK_CONSOLE   EnterCriticalSection(&MSVCRT_console_cs)
@@ -333,8 +339,6 @@
 }
 
 
-extern int snprintf(char *, int, const char *, ...);
-
 /*********************************************************************
  *		_cprintf (MSVCRT.@)
  */
@@ -350,7 +354,7 @@
    * Return the number of bytes that would have been written
    * The code below handles both cases
    */
-  while ((written = snprintf( mem, resize, format, valist )) == -1 ||
+  while ((written = _snprintf( mem, resize, format, valist )) == -1 ||
           written > resize)
   {
     resize = (written == -1 ? resize * 2 : written + 1);
diff --git a/dlls/msvcrt/cpp.c b/dlls/msvcrt/cpp.c
index 4d8117c..aed3a3e 100644
--- a/dlls/msvcrt/cpp.c
+++ b/dlls/msvcrt/cpp.c
@@ -5,6 +5,9 @@
  */
 #include "msvcrt.h"
 
+#include "msvcrt/stdlib.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 
diff --git a/dlls/msvcrt/ctype.c b/dlls/msvcrt/ctype.c
index 07f4b98..7d001ee 100644
--- a/dlls/msvcrt/ctype.c
+++ b/dlls/msvcrt/ctype.c
@@ -5,20 +5,11 @@
  */
 #include "msvcrt.h"
 
+#include "msvcrt/ctype.h"
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
-/* ASCII char classification table - binary compatible */
-#define _UPPER        C1_UPPER
-#define _LOWER        C1_LOWER
-#define _DIGIT        C1_DIGIT
-#define _SPACE        C1_SPACE
-#define _PUNCT        C1_PUNCT
-#define _CONTROL      C1_CNTRL
-#define _BLANK        C1_BLANK
-#define _HEX          C1_XDIGIT
-#define _LEADBYTE     0x8000
-#define _ALPHA       (C1_ALPHA|_UPPER|_LOWER)
-
+/* Some abbreviations to make the following table readable */
 #define _C_ _CONTROL
 #define _S_ _SPACE
 #define _P_ _PUNCT
diff --git a/dlls/msvcrt/data.c b/dlls/msvcrt/data.c
index f710308..71d30d0 100644
--- a/dlls/msvcrt/data.c
+++ b/dlls/msvcrt/data.c
@@ -6,6 +6,10 @@
 #include <math.h>
 #include "msvcrt.h"
 
+#include "msvcrt/stdlib.h"
+#include "msvcrt/string.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 unsigned int MSVCRT___argc;
@@ -22,7 +26,8 @@
 unsigned int MSVCRT__winmajor;
 unsigned int MSVCRT__winminor;
 unsigned int MSVCRT__winver;
-unsigned int MSVCRT__sys_nerr;
+unsigned int MSVCRT__sys_nerr; /* FIXME: not accessible from Winelib apps */
+char**       MSVCRT__sys_errlist; /* FIXME: not accessible from Winelib apps */
 unsigned int MSVCRT___setlc_active;
 unsigned int MSVCRT___unguarded_readlc_active;
 double MSVCRT__HUGE;
@@ -30,8 +35,8 @@
 WCHAR **MSVCRT___wargv;
 char *MSVCRT__acmdln;
 WCHAR *MSVCRT__wcmdln;
-char *MSVCRT__environ;
-WCHAR *MSVCRT__wenviron;
+char **MSVCRT__environ;
+WCHAR **MSVCRT__wenviron;
 char **MSVCRT___initenv;
 WCHAR **MSVCRT___winitenv;
 int MSVCRT_timezone;
@@ -42,7 +47,7 @@
 /***********************************************************************
  *		__p___argc (MSVCRT.@)
  */
-unsigned int* __p___argc(void) { return &MSVCRT___argc; }
+int* __p___argc(void) { return &MSVCRT___argc; }
 
 /***********************************************************************
  *		__p__commode (MSVCRT.@)
@@ -97,12 +102,12 @@
 /*********************************************************************
  *		__p__environ (MSVCRT.@)
  */
-char** __p__environ(void) { return &MSVCRT__environ; }
+char*** __p__environ(void) { return &MSVCRT__environ; }
 
 /*********************************************************************
  *		__p__wenviron (MSVCRT.@)
  */
-WCHAR** __p__wenviron(void) { return &MSVCRT__wenviron; }
+WCHAR*** __p__wenviron(void) { return &MSVCRT__wenviron; }
 
 /*********************************************************************
  *		__p___initenv (MSVCRT.@)
@@ -216,10 +221,16 @@
   MSVCRT_free( cmdline );
 
   TRACE("found %d arguments\n",MSVCRT___argc);
+  /* FIXME: This is plain wrong, we must convert from a '\0' separated 
+   * memory block to an array of pointers to string format.
+   */
   MSVCRT__environ = GetEnvironmentStringsA();
-  MSVCRT___initenv = &MSVCRT__environ;
+  MSVCRT___initenv = MSVCRT__environ;
+  /* FIXME: This is plain wrong, we must convert from a '\0' separated 
+   * memory block to an array of pointers to string format.
+   */
   MSVCRT__wenviron = GetEnvironmentStringsW();
-  MSVCRT___winitenv = &MSVCRT__wenviron;
+  MSVCRT___winitenv = MSVCRT__wenviron;
 }
 
 
@@ -232,26 +243,26 @@
 /*********************************************************************
  *		__getmainargs (MSVCRT.@)
  */
-void __getmainargs(int *argc, char ***argv, char **environ,
+void __getmainargs(int *argc, char** *argv, char** *envp,
                                   int expand_wildcards, int *new_mode)
 {
-  TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, environ, expand_wildcards, new_mode);
+  TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
   *argc = MSVCRT___argc;
   *argv = MSVCRT___argv;
-  *environ = MSVCRT__environ;
+  *envp = MSVCRT__environ;
   MSVCRT__set_new_mode( *new_mode );
 }
 
 /*********************************************************************
  *		__wgetmainargs (MSVCRT.@)
  */
-void __wgetmainargs(int *argc, WCHAR ***wargv, WCHAR **wenviron,
+void __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
                                    int expand_wildcards, int *new_mode)
 {
-  TRACE("(%p,%p,%p,%d,%p).\n", argc, wargv, wenviron, expand_wildcards, new_mode);
+  TRACE("(%p,%p,%p,%d,%p).\n", argc, wargv, wenvp, expand_wildcards, new_mode);
   *argc = MSVCRT___argc;
   *wargv = MSVCRT___wargv;
-  *wenviron = MSVCRT__wenviron;
+  *wenvp = MSVCRT__wenviron;
   MSVCRT__set_new_mode( *new_mode );
 }
 
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index ca95f9a..2d2d2b2 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -13,37 +13,17 @@
 #include "msvcrt.h"
 #include "ms_errno.h"
 
+#include "wine/unicode.h"
+#include "msvcrt/direct.h"
+#include "msvcrt/dos.h"
+#include "msvcrt/io.h"
+#include "msvcrt/stdlib.h"
+#include "msvcrt/string.h"
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
-typedef struct MSVCRT_finddata_t
-{
-  unsigned      attrib;
-  time_t        time_create; /* -1 when N/A */
-  time_t        time_access; /* -1 when N/A */
-  time_t        time_write;
-  unsigned long size;        /* FIXME: 64 bit ??*/
-  char          name[MAX_PATH];
-} MSVCRT_finddata_t;
-
-typedef struct MSVCRT_wfinddata_t
-{
-  unsigned      attrib;
-  time_t        time_create; /* -1 when N/A */
-  time_t        time_access; /* -1 when N/A */
-  time_t        time_write;
-  unsigned long size;        /* FIXME: 64 bit ??*/
-  WCHAR          name[MAX_PATH];
-} MSVCRT_wfinddata_t;
-
-typedef struct msvcrt_diskfree_t {
-  unsigned num_clusters;
-  unsigned available;
-  unsigned cluster_sectors;
-  unsigned sector_bytes;
-} MSVCRT_diskfree_t;
-
 /* INTERNAL: Translate finddata_t to PWIN32_FIND_DATAA */
-static void msvcrt_fttofd(LPWIN32_FIND_DATAA fd, MSVCRT_finddata_t* ft)
+static void msvcrt_fttofd(LPWIN32_FIND_DATAA fd, struct _finddata_t* ft)
 {
   DWORD dw;
 
@@ -63,7 +43,7 @@
 }
 
 /* INTERNAL: Translate wfinddata_t to PWIN32_FIND_DATAA */
-static void msvcrt_wfttofd(LPWIN32_FIND_DATAW fd, MSVCRT_wfinddata_t* ft)
+static void msvcrt_wfttofd(LPWIN32_FIND_DATAW fd, struct _wfinddata_t* ft)
 {
   DWORD dw;
 
@@ -82,17 +62,6 @@
   strcpyW(ft->name, fd->cFileName);
 }
 
-char* msvcrt_strndup(const char*, unsigned int);
-LPWSTR _wcsdup( LPCWSTR );
-LPWSTR msvcrt_wstrndup( LPCWSTR , unsigned int );
-char * MSVCRT_getenv(const char *);
-WCHAR *wcscpy(WCHAR *,const WCHAR *);
-WCHAR *wcsncpy(WCHAR *,const WCHAR *,unsigned int);
-WCHAR *wcscat(WCHAR *,const WCHAR *);
-WCHAR *wcschr(WCHAR *,WCHAR);
-WCHAR *wcsrchr(WCHAR *,WCHAR);
-void _splitpath(const char *,char *, char *,char *,char *);
-
 /*********************************************************************
  *		_chdir (MSVCRT.@)
  */
@@ -139,7 +108,7 @@
 /*********************************************************************
  *		_findclose (MSVCRT.@)
  */
-int _findclose(DWORD hand)
+int _findclose(long hand)
 {
   TRACE(":handle %ld\n",hand);
   if (!FindClose((HANDLE)hand))
@@ -153,7 +122,7 @@
 /*********************************************************************
  *		_findfirst (MSVCRT.@)
  */
-DWORD _findfirst(const char * fspec, MSVCRT_finddata_t* ft)
+long _findfirst(const char * fspec, struct _finddata_t* ft)
 {
   WIN32_FIND_DATAA find_data;
   HANDLE hfind;
@@ -172,7 +141,7 @@
 /*********************************************************************
  *		_wfindfirst (MSVCRT.@)
  */
-DWORD _wfindfirst(const WCHAR * fspec, MSVCRT_wfinddata_t* ft)
+long _wfindfirst(const WCHAR * fspec, struct _wfinddata_t* ft)
 {
   WIN32_FIND_DATAW find_data;
   HANDLE hfind;
@@ -191,7 +160,7 @@
 /*********************************************************************
  *		_findnext (MSVCRT.@)
  */
-int _findnext(DWORD hand, MSVCRT_finddata_t * ft)
+int _findnext(long hand, struct _finddata_t * ft)
 {
   WIN32_FIND_DATAA find_data;
 
@@ -208,7 +177,7 @@
 /*********************************************************************
  *		_wfindnext (MSVCRT.@)
  */
-int _wfindnext(DWORD hand, MSVCRT_wfinddata_t * ft)
+int _wfindnext(long hand, struct _wfinddata_t * ft)
 {
   WIN32_FIND_DATAW find_data;
 
@@ -367,7 +336,7 @@
 /*********************************************************************
  *		_getdiskfree (MSVCRT.@)
  */
-unsigned int _getdiskfree(unsigned int disk, MSVCRT_diskfree_t* d)
+unsigned int _getdiskfree(unsigned int disk, struct _diskfree_t* d)
 {
   char drivespec[4] = {'@', ':', '\\', 0};
   DWORD ret[4];
@@ -380,10 +349,10 @@
 
   if (GetDiskFreeSpaceA(disk==0?NULL:drivespec,ret,ret+1,ret+2,ret+3))
   {
-    d->cluster_sectors = (unsigned)ret[0];
-    d->sector_bytes = (unsigned)ret[1];
-    d->available = (unsigned)ret[2];
-    d->num_clusters = (unsigned)ret[3];
+    d->sectors_per_cluster = (unsigned)ret[0];
+    d->bytes_per_sector = (unsigned)ret[1];
+    d->avail_clusters = (unsigned)ret[2];
+    d->total_clusters = (unsigned)ret[3];
     return 0;
   }
   err = GetLastError();
@@ -446,7 +415,8 @@
   WCHAR pathbuff[MAX_PATH],*path=pathbuff;
 
   TRACE(":splitting path '%s'\n",debugstr_w(path));
-  wcscpy(pathbuff, inpath);
+  /* FIXME: Should be an strncpyW or something */
+  strcpyW(pathbuff, inpath);
 
   /* convert slashes to backslashes for searching */
   for (ptr = (WCHAR*)path; *ptr; ++ptr)
@@ -454,12 +424,12 @@
       *ptr = (WCHAR)L'\\';
 
   /* look for drive spec */
-  if ((ptr = wcschr(path, (WCHAR)L':')) != (WCHAR)L'\0')
+  if ((ptr = strchrW(path, (WCHAR)L':')) != (WCHAR)L'\0')
   {
     ++ptr;
     if (drv)
     {
-      wcsncpy(drv, path, ptr - path);
+      strncpyW(drv, path, ptr - path);
       drv[ptr - path] = (WCHAR)L'\0';
     }
     path = ptr;
@@ -468,8 +438,8 @@
     *drv = (WCHAR)L'\0';
 
   /* find rightmost backslash or leftmost colon */
-  if ((ptr = wcsrchr(path, (WCHAR)L'\\')) == NULL)
-    ptr = (wcschr(path, (WCHAR)L':'));
+  if ((ptr = strrchrW(path, (WCHAR)L'\\')) == NULL)
+    ptr = (strchrW(path, (WCHAR)L':'));
 
   if (!ptr)
   {
@@ -484,15 +454,15 @@
     {
       ch = *ptr;
       *ptr = (WCHAR)L'\0';
-      wcscpy(dir, path);
+      strcpyW(dir, path);
       *ptr = ch;
     }
   }
 
-  if ((p = wcsrchr(ptr, (WCHAR)L'.')) == NULL)
+  if ((p = strrchrW(ptr, (WCHAR)L'.')) == NULL)
   {
     if (fname)
-      wcscpy(fname, ptr);
+      strcpyW(fname, ptr);
     if (ext)
       *ext = (WCHAR)L'\0';
   }
@@ -500,10 +470,10 @@
   {
     *p = (WCHAR)L'\0';
     if (fname)
-      wcscpy(fname, ptr);
+      strcpyW(fname, ptr);
     *p = (WCHAR)L'.';
     if (ext)
-      wcscpy(ext, p);
+      strcpyW(ext, p);
   }
 
   /* Fix pathological case - Win returns ':' as part of the
@@ -516,8 +486,8 @@
     {
       pathbuff[0] = (WCHAR)L':';
       pathbuff[1] = (WCHAR)L'\0';
-      wcscat(pathbuff,dir);
-      wcscpy(dir, pathbuff);
+      strcatW(pathbuff,dir);
+      strcpyW(dir, pathbuff);
     }
   }
 }
@@ -688,7 +658,7 @@
                               const char * extension )
 {
     char ch;
-    TRACE("_makepath got %s %s %s %s\n", drive, directory,
+    TRACE("got %s %s %s %s\n", drive, directory,
           filename, extension);
 
     if ( !path )
@@ -719,7 +689,7 @@
         }
     }
 
-    TRACE("_makepath returns %s\n",path);
+    TRACE("returning %s\n",path);
 }
 
 
diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c
index c1c5e8e..8c513f5 100644
--- a/dlls/msvcrt/environ.c
+++ b/dlls/msvcrt/environ.c
@@ -9,9 +9,10 @@
 #include "wine/unicode.h"
 #include "msvcrt.h"
 
-DEFAULT_DEBUG_CHANNEL(msvcrt);
+#include "msvcrt/stdlib.h"
 
-LPWSTR wcsrchr( LPWSTR str, WCHAR ch );
+
+DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 /*********************************************************************
  *		getenv (MSVCRT.@)
@@ -51,7 +52,7 @@
 
   for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
   {
-    pos =wcsrchr(pp,'=');
+    pos = strrchrW(pp,'=');
     if (pos)
       length = pos -pp;
     else
diff --git a/dlls/msvcrt/errno.c b/dlls/msvcrt/errno.c
index 31682c6..971c9e0 100644
--- a/dlls/msvcrt/errno.c
+++ b/dlls/msvcrt/errno.c
@@ -7,6 +7,11 @@
 #include "msvcrt.h"
 #include "ms_errno.h"
 
+#include <stdio.h>
+#include <string.h>
+#include "msvcrt/conio.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 
@@ -86,8 +91,6 @@
   return GET_THREAD_VAR_PTR(doserrno);
 }
 
-char *strerror(int);
-
 /*********************************************************************
  *		strerror (MSVCRT.@)
  */
@@ -99,8 +102,6 @@
 /**********************************************************************
  *		_strerror	(MSVCRT.@)
  */
-extern int sprintf(char *str, const char *format, ...);
-
 const char* _strerror(const char* err)
 {
   static char strerrbuff[256]; /* FIXME: Per thread, nprintf */
@@ -108,12 +109,10 @@
   return strerrbuff;
 }
 
-int _cprintf( const char * format, ... );
-
 /*********************************************************************
  *		perror (MSVCRT.@)
  */
-void MSVCRT_perror(const char *str)
+void MSVCRT_perror(const char* str)
 {
   _cprintf("%s: %s\n",str,MSVCRT_strerror(GET_THREAD_VAR(errno)));
 }
diff --git a/dlls/msvcrt/exit.c b/dlls/msvcrt/exit.c
index 0311117..569fb39 100644
--- a/dlls/msvcrt/exit.c
+++ b/dlls/msvcrt/exit.c
@@ -5,6 +5,10 @@
  */
 #include "msvcrt.h"
 
+#include "msvcrt/conio.h"
+#include "msvcrt/stdlib.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 /* MT */
@@ -12,9 +16,7 @@
 #define LOCK_EXIT      EnterCriticalSection(&MSVCRT_exit_cs)
 #define UNLOCK_EXIT    LeaveCriticalSection(&MSVCRT_exit_cs)
 
-typedef void (*MSVCRT_atexit_func)(void);
-
-static MSVCRT_atexit_func *MSVCRT_atexit_table = NULL;
+static _onexit_t *MSVCRT_atexit_table = NULL;
 static int MSVCRT_atexit_table_size = 0;
 static int MSVCRT_atexit_registered = 0; /* Points to free slot */
 
@@ -40,11 +42,9 @@
 /*********************************************************************
  *		__dllonexit (MSVCRT.@)
  */
-MSVCRT_atexit_func __dllonexit(MSVCRT_atexit_func func,
-                                              MSVCRT_atexit_func **start,
-                                              MSVCRT_atexit_func **end)
+_onexit_t __dllonexit(_onexit_t func, _onexit_t **start, _onexit_t **end)
 {
-  MSVCRT_atexit_func *tmp;
+  _onexit_t *tmp;
   int len;
 
   TRACE("(%p,%p,%p)\n", func, start, end);
@@ -62,7 +62,7 @@
   if (++len <= 0)
     return NULL;
 
-  tmp = (MSVCRT_atexit_func *)MSVCRT_realloc(*start, len * sizeof(tmp));
+  tmp = (_onexit_t *)MSVCRT_realloc(*start, len * sizeof(tmp));
   if (!tmp)
     return NULL;
   *start = tmp;
@@ -145,7 +145,7 @@
 /*********************************************************************
  *		_onexit (MSVCRT.@)
  */
- MSVCRT_atexit_func _onexit(MSVCRT_atexit_func func)
+_onexit_t _onexit(_onexit_t func)
 {
   TRACE("(%p)\n",func);
 
@@ -155,7 +155,7 @@
   LOCK_EXIT;
   if (MSVCRT_atexit_registered > MSVCRT_atexit_table_size - 1)
   {
-    MSVCRT_atexit_func *newtable;
+    _onexit_t *newtable;
     TRACE("expanding table\n");
     newtable = MSVCRT_calloc(sizeof(void *),MSVCRT_atexit_table_size + 32);
     if (!newtable)
@@ -191,7 +191,7 @@
 /*********************************************************************
  *		atexit (MSVCRT.@)
  */
-int MSVCRT_atexit(MSVCRT_atexit_func func)
+int MSVCRT_atexit(_onexit_t func)
 {
   TRACE("(%p)\n", func);
   return _onexit(func) == func ? 0 : -1;
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index e00f126..bcbdfd5 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -7,99 +7,34 @@
  * Copyright 2000 Jon Griffiths
  */
 #include <time.h>
+#include <stdio.h>
+#include <unistd.h>
+
 #include "ntddk.h"
 #include "msvcrt.h"
 #include "ms_errno.h"
 
-DEFAULT_DEBUG_CHANNEL(msvcrt);
+#include "wine/unicode.h"
+#include "msvcrt/direct.h"
+#include "msvcrt/fcntl.h"
+#include "msvcrt/io.h"
+#include "msvcrt/stdio.h"
+#include "msvcrt/stdlib.h"
+#include "msvcrt/string.h"
+#include "msvcrt/sys/stat.h"
+#include "msvcrt/sys/utime.h"
+#include "msvcrt/time.h"
 
-/* stat() mode bits */
-#define _S_IFMT   0xF000
-#define _S_IFREG  0x8000
-#define _S_IFDIR  0x4000
-#define _S_IFCHR  0x2000
-#define _S_IFIFO  0x1000
-#define _S_IFBLK  0x3000
-#define _S_IREAD  0x0100
-#define _S_IWRITE 0x0080
-#define _S_IEXEC  0x0040
+DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 /* for stat mode, permissions apply to all,owner and group */
 #define MSVCRT_S_IREAD  (_S_IREAD  | (_S_IREAD  >> 3) | (_S_IREAD  >> 6))
 #define MSVCRT_S_IWRITE (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
 #define MSVCRT_S_IEXEC  (_S_IEXEC  | (_S_IEXEC  >> 3) | (_S_IEXEC  >> 6))
 
-/* _open modes */
-#define _O_RDONLY 0x0000
-#define _O_WRONLY 0x0001
-#define _O_RDWR   0x0002
-#define _O_APPEND 0x0008
-#define _O_CREAT  0x0100
-#define _O_TRUNC  0x0200
-#define _O_EXCL   0x0400
-#define _O_TEXT   0x4000
-#define _O_BINARY 0x8000
-#define _O_TEMPORARY 0x0040 /* Will be closed and deleted on exit */
-
 /* _access() bit flags FIXME: incomplete */
 #define W_OK      2
 
-typedef struct _crtfile
-{
-  char* _ptr;
-  int   _cnt;
-  char* _base;
-  int   _flag;
-  int   _file; /* fd */
-  int   _charbuf;
-  int   _bufsiz;
-  char *_tmpfname;
-} MSVCRT_FILE;
-
-/* file._flag flags */
-#define _IOREAD   0x0001
-#define _IOWRT    0x0002
-#define _IOEOF    0x0010
-#define _IOERR    0x0020
-#define _IORW     0x0080
-#define _IOAPPEND 0x0200
-
-#define SEEK_SET    0
-#define SEEK_CUR    1
-#define SEEK_END    2
-
-#define _IOFBF 0
-#define _IOLBF 1
-#define _IONBF 2
-
-#define BUFSIZ 512
-
-#define MSVCRT_stdin  (&MSVCRT__iob[0])
-#define MSVCRT_stdout (&MSVCRT__iob[1])
-#define MSVCRT_stderr (&MSVCRT__iob[2])
-
-struct _stat
-{
-    unsigned short st_dev;
-    unsigned short st_ino;
-    unsigned short st_mode;
-    short  st_nlink;
-    short  st_uid;
-    short  st_gid;
-    unsigned int   st_rdev;
-    int    st_size;
-    int    st_atime;
-    int    st_mtime;
-    int    st_ctime;
-};
-
-typedef long MSVCRT_fpos_t;
-
-struct _utimbuf
-{
-  time_t actime;
-  time_t modtime;
-};
 
 /* FIXME: Make this dynamic */
 #define MSVCRT_MAX_FILES 257
@@ -109,6 +44,9 @@
 int  MSVCRT_flags[MSVCRT_MAX_FILES];
 char *MSVCRT_tempfiles[MSVCRT_MAX_FILES];
 MSVCRT_FILE MSVCRT__iob[3];
+#define MSVCRT_stdin       (MSVCRT__iob+STDIN_FILENO)
+#define MSVCRT_stdout      (MSVCRT__iob+STDOUT_FILENO)
+#define MSVCRT_stderr      (MSVCRT__iob+STDERR_FILENO)
 
 static int MSVCRT_fdstart = 3; /* first unallocated fd */
 static int MSVCRT_fdend = 3; /* highest allocated fd */
@@ -134,14 +72,6 @@
 #define LOCK_FILES     EnterCriticalSection(&MSVCRT_file_cs)
 #define UNLOCK_FILES   LeaveCriticalSection(&MSVCRT_file_cs)
 
-time_t MSVCRT_time(time_t *);
-int _getdrive(void);
-WCHAR *_wcsdup(const WCHAR *);
-unsigned int wcslen(const WCHAR*);
-int iswalpha(WCHAR);
-int towupper(WCHAR);
-int towlower(WCHAR);
-int _vsnwprintf(WCHAR *,unsigned int,const WCHAR *,va_list);
 
 /* INTERNAL: Get the HANDLE for a fd */
 static HANDLE msvcrt_fdtoh(int fd)
@@ -656,7 +586,7 @@
 
   if (!t)
   {
-    time_t currTime;
+    MSVCRT_time_t currTime;
     MSVCRT_time(&currTime);
     RtlSecondsSince1970ToTime(currTime, &at);
     memcpy(&wt, &at, sizeof(wt));
@@ -681,7 +611,7 @@
 /*********************************************************************
  *		_get_osfhandle (MSVCRT.@)
  */
-HANDLE _get_osfhandle(int fd)
+long _get_osfhandle(int fd)
 {
   HANDLE hand = msvcrt_fdtoh(fd);
   HANDLE newhand = hand;
@@ -789,7 +719,7 @@
 /*********************************************************************
  *		_open (MSVCRT.@)
  */
-int _open(const char *path,int flags)
+int _open(const char *path,int flags,...)
 {
   DWORD access = 0, creation = 0;
   int ioflag = 0, fd;
@@ -875,9 +805,9 @@
 /*********************************************************************
  *		_wopen (MSVCRT.@)
  */
-int _wopen(const WCHAR *path,int flags)
+int _wopen(const WCHAR *path,int flags,...)
 {
-  const unsigned int len = wcslen(path);
+  const unsigned int len = strlenW(path);
   char *patha = MSVCRT_calloc(len + 1,1);
   if (patha && WideCharToMultiByte(CP_ACP,0,path,len,patha,len,NULL,NULL))
   {
@@ -919,10 +849,10 @@
 /*********************************************************************
  *		_open_osfhandle (MSVCRT.@)
  */
-int _open_osfhandle(HANDLE hand, int flags)
+int _open_osfhandle(long hand, int flags)
 {
   int fd = msvcrt_alloc_fd(hand,flags);
-  TRACE(":handle (%d) fd (%d)\n",hand,fd);
+  TRACE(":handle (%ld) fd (%d)\n",hand,fd);
   return fd;
 }
 
@@ -1057,7 +987,7 @@
   buf->st_atime = dw;
   RtlTimeToSecondsSince1970(&hfi.ftLastWriteTime, &dw);
   buf->st_mtime = buf->st_ctime = dw;
-  TRACE("\n%d %d %d %d %d %d\n", buf->st_mode,buf->st_nlink,buf->st_size,
+  TRACE("\n%d %d %d %ld %ld %ld\n", buf->st_mode,buf->st_nlink,buf->st_size,
     buf->st_atime,buf->st_mtime, buf->st_ctime);
   return 0;
 }
@@ -1083,13 +1013,13 @@
 
   memset(buf,0,sizeof(struct _stat));
 
-  /* FIXME: rdev isnt drive num,despite what the docs say-what is it? */
-  if (iswalpha(*path))
-    buf->st_dev = buf->st_rdev = towupper(*path - (WCHAR)L'A'); /* drive num */
+  /* FIXME: rdev isn't drive num, despite what the docs says-what is it? */
+  if (MSVCRT_iswalpha(*path))
+    buf->st_dev = buf->st_rdev = toupperW(*path - (WCHAR)L'A'); /* drive num */
   else
     buf->st_dev = buf->st_rdev = _getdrive() - 1;
 
-  plen = wcslen(path);
+  plen = strlenW(path);
 
   /* Dir, or regular file? */
   if ((hfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
@@ -1101,8 +1031,8 @@
     /* executable? */
     if (plen > 6 && path[plen-4] == (WCHAR)L'.')  /* shortest exe: "\x.exe" */
     {
-      ULONGLONG ext = towlower(path[plen-1]) | (towlower(path[plen-2]) << 16) |
-                               ((ULONGLONG)towlower(path[plen-3]) << 32);
+      ULONGLONG ext = tolowerW(path[plen-1]) | (tolowerW(path[plen-2]) << 16) |
+                               ((ULONGLONG)tolowerW(path[plen-3]) << 32);
       if (ext == WCEXE || ext == WCBAT || ext == WCCMD || ext == WCCOM)
         mode |= MSVCRT_S_IEXEC;
     }
@@ -1118,7 +1048,7 @@
   buf->st_atime = dw;
   RtlTimeToSecondsSince1970(&hfi.ftLastWriteTime, &dw);
   buf->st_mtime = buf->st_ctime = dw;
-  TRACE("\n%d %d %d %d %d %d\n", buf->st_mode,buf->st_nlink,buf->st_size,
+  TRACE("\n%d %d %d %ld %ld %ld\n", buf->st_mode,buf->st_nlink,buf->st_size,
         buf->st_atime,buf->st_mtime, buf->st_ctime);
   return 0;
 }
@@ -1211,7 +1141,7 @@
 /*********************************************************************
  *		_write (MSVCRT.@)
  */
-unsigned int _write(int fd, const void* buf, unsigned int count)
+int _write(int fd, const void* buf, unsigned int count)
 {
   DWORD num_written;
   HANDLE hand = msvcrt_fdtoh(fd);
@@ -1366,9 +1296,9 @@
 /*********************************************************************
  *		fgetwc (MSVCRT.@)
  */
-WCHAR MSVCRT_fgetwc(MSVCRT_FILE* file)
+MSVCRT_wint_t MSVCRT_fgetwc(MSVCRT_FILE* file)
 {
-  WCHAR wc;
+  MSVCRT_wint_t wc;
   if (_read(file->_file, &wc, sizeof(wc)) != sizeof(wc))
     return MSVCRT_WEOF;
   return wc;
@@ -1377,7 +1307,7 @@
 /*********************************************************************
  *		getwc (MSVCRT.@)
  */
-WCHAR MSVCRT_getwc(MSVCRT_FILE* file)
+MSVCRT_wint_t MSVCRT_getwc(MSVCRT_FILE* file)
 {
   return MSVCRT_fgetwc(file);
 }
@@ -1385,7 +1315,7 @@
 /*********************************************************************
  *		_fgetwchar (MSVCRT.@)
  */
-WCHAR _fgetwchar(void)
+MSVCRT_wint_t _fgetwchar(void)
 {
   return MSVCRT_fgetwc(MSVCRT_stdin);
 }
@@ -1393,7 +1323,7 @@
 /*********************************************************************
  *		getwchar (MSVCRT.@)
  */
-WCHAR MSVCRT_getwchar(void)
+MSVCRT_wint_t MSVCRT_getwchar(void)
 {
   return _fgetwchar();
 }
@@ -1401,7 +1331,7 @@
 /*********************************************************************
  *		fputwc (MSVCRT.@)
  */
-WCHAR MSVCRT_fputwc(WCHAR wc, MSVCRT_FILE* file)
+MSVCRT_wint_t MSVCRT_fputwc(MSVCRT_wint_t wc, MSVCRT_FILE* file)
 {
   if (_write(file->_file, &wc, sizeof(wc)) != sizeof(wc))
     return MSVCRT_WEOF;
@@ -1411,7 +1341,7 @@
 /*********************************************************************
  *		_fputwchar (MSVCRT.@)
  */
-WCHAR _fputwchar(WCHAR wc)
+MSVCRT_wint_t _fputwchar(MSVCRT_wint_t wc)
 {
   return MSVCRT_fputwc(wc, MSVCRT_stdout);
 }
@@ -1482,7 +1412,7 @@
  */
 MSVCRT_FILE *_wfopen(const WCHAR *path, const WCHAR *mode)
 {
-  const unsigned int plen = wcslen(path), mlen = wcslen(mode);
+  const unsigned int plen = strlenW(path), mlen = strlenW(mode);
   char *patha = MSVCRT_calloc(plen + 1, 1);
   char *modea = MSVCRT_calloc(mlen + 1, 1);
 
@@ -1548,9 +1478,9 @@
 /*********************************************************************
  *		fread (MSVCRT.@)
  */
-DWORD MSVCRT_fread(void *ptr, int size, int nmemb, MSVCRT_FILE* file)
+MSVCRT_size_t MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nmemb, MSVCRT_FILE* file)
 {
-  DWORD read = _read(file->_file,ptr, size * nmemb);
+  int read = _read(file->_file,ptr, size * nmemb);
   if (read <= 0)
     return 0;
   return read / size;
@@ -1615,7 +1545,7 @@
  */
 int MSVCRT_fscanf(MSVCRT_FILE* file, const char *format, ...)
 {
-    /* NOTE: If you extend this function, extend _cscanf in console.c too */
+    /* NOTE: If you extend this function, extend MSVCRT__cscanf in console.c too */
     int rd = 0;
     int nch;
     va_list ap;
@@ -1736,7 +1666,7 @@
 /*********************************************************************
  *		fseek (MSVCRT.@)
  */
-LONG MSVCRT_fseek(MSVCRT_FILE* file, LONG offset, int whence)
+int MSVCRT_fseek(MSVCRT_FILE* file, long offset, int whence)
 {
   return _lseek(file->_file,offset,whence);
 }
@@ -1752,9 +1682,9 @@
 /*********************************************************************
  *		fwrite (MSVCRT.@)
  */
-unsigned int MSVCRT_fwrite(const void *ptr, int size, int nmemb, MSVCRT_FILE* file)
+MSVCRT_size_t MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_size_t nmemb, MSVCRT_FILE* file)
 {
-  unsigned int written = _write(file->_file, ptr, size * nmemb);
+  int written = _write(file->_file, ptr, size * nmemb);
   if (written <= 0)
     return 0;
   return written / size;
@@ -1773,7 +1703,7 @@
  */
 int MSVCRT_fputws(const WCHAR *s, MSVCRT_FILE* file)
 {
-  return MSVCRT_fwrite(s,wcslen(s),1,file) == 1 ? 0 : MSVCRT_EOF;
+  return MSVCRT_fwrite(s,strlenW(s),1,file) == 1 ? 0 : MSVCRT_EOF;
 }
 
 /*********************************************************************
@@ -1825,9 +1755,9 @@
 /*********************************************************************
  *		putchar (MSVCRT.@)
  */
-void MSVCRT_putchar(int c)
+int MSVCRT_putchar(int c)
 {
-  MSVCRT_fputc(c, MSVCRT_stdout);
+  return MSVCRT_fputc(c, MSVCRT_stdout);
 }
 
 /*********************************************************************
@@ -1847,7 +1777,7 @@
 int _putws(const WCHAR *s)
 {
   static const WCHAR nl = (WCHAR)L'\n';
-  if (MSVCRT_fwrite(s,wcslen(s),1,MSVCRT_stdout) == 1)
+  if (MSVCRT_fwrite(s,strlenW(s),1,MSVCRT_stdout) == 1)
     return MSVCRT_fwrite(&nl,sizeof(nl),1,MSVCRT_stdout) == 1 ? 0 : MSVCRT_EOF;
   return MSVCRT_EOF;
 }
@@ -1921,9 +1851,10 @@
 /*********************************************************************
  *		setvbuf (MSVCRT.@)
  */
-void MSVCRT_setvbuf(MSVCRT_FILE* file, char *buf, int mode, unsigned int size)
+int MSVCRT_setvbuf(MSVCRT_FILE* file, char *buf, int mode, MSVCRT_size_t size)
 {
   FIXME("(%p,%p,%d,%d)stub\n",file, buf, mode, size);
+  return -1;
 }
 
 /*********************************************************************
@@ -1931,7 +1862,7 @@
  */
 void MSVCRT_setbuf(MSVCRT_FILE* file, char *buf)
 {
-  MSVCRT_setvbuf(file, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+  MSVCRT_setvbuf(file, buf, buf ? MSVCRT__IOFBF : MSVCRT__IONBF, BUFSIZ);
 }
 
 /*********************************************************************
@@ -1964,7 +1895,6 @@
     return msvcrt_alloc_fp(fd);
   return NULL;
 }
-extern int vsnprintf(void *, unsigned int, const void*, va_list);
 
 /*********************************************************************
  *		vfprintf (MSVCRT.@)
diff --git a/dlls/msvcrt/heap.c b/dlls/msvcrt/heap.c
index 50fc9cf..1759745 100644
--- a/dlls/msvcrt/heap.c
+++ b/dlls/msvcrt/heap.c
@@ -9,6 +9,9 @@
 
 #include "msvcrt.h"
 
+#include "msvcrt/stdlib.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 /* MT */
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index f710cbe..60156f3 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -111,17 +111,9 @@
   return !strncasecmp(cmp, buff, strlen(cmp));
 }
 
-
-/* INTERNAL: Callback for enumerated languages */
-#ifdef __GNUC__
-#define UNUSED __attribute__((unused))
-#else
-#define UNUSED
-#endif
-
 static BOOL CALLBACK
-find_best_locale_proc(HMODULE hModule UNUSED, LPCSTR type UNUSED,
-                      LPCSTR name UNUSED, WORD LangID, LONG lParam)
+find_best_locale_proc(HMODULE hModule WINE_UNUSED, LPCSTR type WINE_UNUSED,
+                      LPCSTR name WINE_UNUSED, WORD LangID, LONG lParam)
 {
   locale_search_t *res = (locale_search_t *)lParam;
   const LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
diff --git a/dlls/msvcrt/main.c b/dlls/msvcrt/main.c
index 859f0ac..b912f22 100644
--- a/dlls/msvcrt/main.c
+++ b/dlls/msvcrt/main.c
@@ -5,6 +5,9 @@
  */
 #include "msvcrt.h"
 
+#include "msvcrt/stdio.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 /* Index to TLS */
@@ -21,11 +24,7 @@
 static inline BOOL msvcrt_free_tls(void);
 static inline void msvcrt_init_critical_sections(void);
 static inline void msvcrt_free_critical_sections(void);
-#ifdef __GNUC__
-const char *msvcrt_get_reason(DWORD reason) __attribute__((unused));
-#else
-const char *msvcrt_get_reason(DWORD reason);
-#endif
+const char* msvcrt_get_reason(DWORD reason) WINE_UNUSED;
 
 void msvcrt_init_io(void);
 void msvcrt_init_console(void);
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index ce9e0f5..25a4aae 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -14,6 +14,8 @@
 #include <ieeefp.h>
 #endif
 
+#include "msvcrt/stdlib.h"
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 #ifndef HAVE_FINITE
@@ -674,7 +676,7 @@
  * VERSION
  *	[!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
  */
-div_t MSVCRT_div(int num, int denom)
+MSVCRT_div_t MSVCRT_div(int num, int denom)
 {
   return div(num,denom);
 }
@@ -700,7 +702,7 @@
  * VERSION
  *	[!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
  */
-ldiv_t MSVCRT_ldiv(long num, long denom)
+MSVCRT_ldiv_t MSVCRT_ldiv(long num, long denom)
 {
   return ldiv(num,denom);
 }
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index bd532f8..34517cb 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -10,6 +10,9 @@
  */
 #include "msvcrt.h"
 
+#include "msvcrt/string.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 unsigned char MSVCRT_mbctype[257];
@@ -428,7 +431,7 @@
  *
  * Find a multibyte character in a multibyte string.
  */
-char *_mbschr(const char *str, unsigned int c)
+unsigned char* _mbschr(const unsigned char* str, unsigned int c)
 {
   if(MSVCRT___mb_cur_max > 1)
   {
@@ -472,7 +475,7 @@
 /*********************************************************************
  *		_mbsncat(MSVCRT.@)
  */
-char *_mbsncat(char *dst, const unsigned char *src, unsigned int len)
+unsigned char* _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
 {
   if(MSVCRT___mb_cur_max > 1)
   {
diff --git a/dlls/msvcrt/misc.c b/dlls/msvcrt/misc.c
index 0535958..803902d 100644
--- a/dlls/msvcrt/misc.c
+++ b/dlls/msvcrt/misc.c
@@ -6,6 +6,10 @@
 
 #include "msvcrt.h"
 
+#include <stdlib.h>
+#include "msvcrt/stdlib.h"
+
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 typedef int (*MSVCRT_comp_func)(const void*, const void*);
@@ -19,8 +23,6 @@
     Beep(freq, duration);
 }
 
-extern int rand(void);
-
 /*********************************************************************
  *		rand (MSVCRT.@)
  */
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index f59a7c1..b4368da 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -11,10 +11,6 @@
 #include <ctype.h>
 #include <string.h>
 
-/* Files */
-#define MSVCRT_EOF   -1
-#define MSVCRT_WEOF (WCHAR)(0xFFFF)
-
 /* TLS data */
 extern DWORD MSVCRT_tls_index;
 
@@ -33,14 +29,13 @@
 #define SET_THREAD_VAR(x,y) \
   ((MSVCRT_thread_data*)TlsGetValue(MSVCRT_tls_index))->x = y
 
-void  MSVCRT__set_errno(int);
-int   MSVCRT__set_new_mode(int mode);
-int   _fcloseall(void);
-void* MSVCRT_malloc(unsigned int);
-void* MSVCRT_calloc(unsigned int, unsigned int);
-void  MSVCRT_free(void *);
-int   _cputs(const char *);
-int   _cprintf( const char *, ... );
-char* _strdup(const char *);
+void   MSVCRT__set_errno(int);
+char*  msvcrt_strndup(const char*,unsigned int);
+LPWSTR msvcrt_wstrndup(LPCWSTR, unsigned int);
+
+/* FIXME: This should be declared in new.h but it's not an extern "C" so 
+ * it would not be much use anyway. Even for Winelib applications.
+ */
+int    MSVCRT__set_new_mode(int mode);
 
 #endif /* __WINE_MSVCRT_H */
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 3b6ec88..4bd3e36 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -470,8 +470,8 @@
 @ cdecl _strtime(str) _strtime
 @ forward -noimport _strupr ntdll._strupr
 @ cdecl _swab(str str long) _swab
-@ stub _sys_errlist #() # FIXME: This is supposed to be a variable!
-@ stub _sys_nerr #() # FIXME: This is supposed to be a variable!
+@ extern _sys_errlist MSVCRT__sys_errlist
+@ extern _sys_nerr MSVCRT__sys_nerr
 @ cdecl _tell(long) _tell
 @ stub _telli64 #(long)
 @ cdecl _tempnam(str str) _tempnam
diff --git a/dlls/msvcrt/process.c b/dlls/msvcrt/process.c
index c2841bc..b9c805c 100644
--- a/dlls/msvcrt/process.c
+++ b/dlls/msvcrt/process.c
@@ -14,18 +14,11 @@
 #include "msvcrt.h"
 #include "ms_errno.h"
 
+#include "msvcrt/process.h"
+#include "msvcrt/stdlib.h"
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
-/* Process creation flags */
-#define _P_WAIT    0
-#define _P_NOWAIT  1
-#define _P_OVERLAY 2
-#define _P_NOWAITO 3
-#define _P_DETACH  4
-
-void MSVCRT__exit(int);
-void _searchenv(const char* file, const char* env, char *buf);
-
 /* FIXME: Check file extensions for app to run */
 static const unsigned int EXE = 'e' << 16 | 'x' << 8 | 'e';
 static const unsigned int BAT = 'b' << 16 | 'a' << 8 | 't';
@@ -83,9 +76,9 @@
 }
 
 /* INTERNAL: Convert argv list to a single 'delim'-separated string */
-static char* msvcrt_argvtos(const char* *arg, char delim)
+static char* msvcrt_argvtos(const char* const* arg, char delim)
 {
-  const char **search = arg;
+  const char* const* search = arg;
   long size = 0;
   char *ret;
 
@@ -152,8 +145,8 @@
 /*********************************************************************
  *		_spawnve (MSVCRT.@)
  */
-int _spawnve(int flags, const char* name, const char **argv,
-                            const char **envv)
+int _spawnve(int flags, const char* name, const char* const* argv,
+                            const char* const* envv)
 {
   char * args = msvcrt_argvtos(argv,' ');
   char * envs = msvcrt_argvtos(envv,0);
@@ -177,7 +170,7 @@
 /*********************************************************************
  *		_spawnv (MSVCRT.@)
  */
-int _spawnv(int flags, const char* name, const char **argv)
+int _spawnv(int flags, const char* name, const char* const* argv)
 {
   return _spawnve(flags, name, argv, NULL);
 }
@@ -185,8 +178,8 @@
 /*********************************************************************
  *		_spawnvpe (MSVCRT.@)
  */
-int _spawnvpe(int flags, const char* name, const char **argv,
-                            const char **envv)
+int _spawnvpe(int flags, const char* name, const char* const* argv,
+                            const char* const* envv)
 {
   char fullname[MAX_PATH];
   _searchenv(name, "PATH", fullname);
@@ -196,7 +189,7 @@
 /*********************************************************************
  *		_spawnvp (MSVCRT.@)
  */
-int _spawnvp(int flags, const char* name, const char **argv)
+int _spawnvp(int flags, const char* name, const char* const* argv)
 {
   return _spawnvpe(flags, name, argv, NULL);
 }
diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c
index 22d5c3e..0beb83e 100644
--- a/dlls/msvcrt/string.c
+++ b/dlls/msvcrt/string.c
@@ -8,6 +8,8 @@
  */
 #include "msvcrt.h"
 
+#include "msvcrt/stdlib.h"
+#include "msvcrt/string.h"
 
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
diff --git a/dlls/msvcrt/thread.c b/dlls/msvcrt/thread.c
index 89a5d04..138706c 100644
--- a/dlls/msvcrt/thread.c
+++ b/dlls/msvcrt/thread.c
@@ -5,6 +5,8 @@
  */
 #include "msvcrt.h"
 
+#include "msvcrt/process.h"
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 
@@ -13,7 +15,7 @@
  */
 unsigned long _beginthreadex(void* sec,
                              unsigned int stack,
-                             LPTHREAD_START_ROUTINE start,
+                             unsigned __stdcall (*start)(void*),
                              void* arg, unsigned int flag,
                              unsigned int* addr)
 {
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index fbb1eb8..514e9c7 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -10,21 +10,18 @@
 #include <sys/times.h>
 #include "msvcrt.h"
 
-DEFAULT_DEBUG_CHANNEL(msvcrt);
+#include "msvcrt/stdlib.h"
+#include "msvcrt/sys/timeb.h"
+#include "msvcrt/time.h"
 
-typedef struct __MSVCRT_timeb
-{
-  time_t  time;
-  unsigned short  millitm;
-  short   timezone;
-  short   dstflag;
-} MSVCRT_timeb;
+
+DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 
 /* INTERNAL: Return formatted current time/date */
 char* msvcrt_get_current_time(char* out, const char* format)
 {
-  static const time_t bad_time = (time_t)-1;
+  static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
   time_t t;
   struct tm *_tm = NULL;
   char *retval = NULL;
@@ -73,7 +70,7 @@
 /*********************************************************************
  *		difftime (MSVCRT.@)
  */
-double MSVCRT_difftime(time_t time1, time_t time2)
+double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
 {
     return (double)(time1 - time2);
 }
@@ -81,16 +78,16 @@
 /*********************************************************************
  *		time (MSVCRT.@)
  */
-time_t MSVCRT_time(time_t* buf)
+MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
 {
-  time_t curtime = time(NULL);
+  MSVCRT_time_t curtime = time(NULL);
   return buf ? *buf = curtime : curtime;
 }
 
 /*********************************************************************
  *		_ftime (MSVCRT.@)
  */
-void _ftime(MSVCRT_timeb* buf)
+void _ftime(struct _timeb *buf)
 {
   buf->time = MSVCRT_time(NULL);
   buf->millitm = 0; /* FIXME */
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index 4ba83cc..ec8929d 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -10,11 +10,16 @@
 #include "winnls.h"
 #include "wine/unicode.h"
 
+#include "msvcrt/stdio.h"
+#include "msvcrt/stdlib.h"
+#include "msvcrt/string.h"
+#include "msvcrt/wctype.h"
+
 DEFAULT_DEBUG_CHANNEL(msvcrt);
 
 
 /* INTERNAL: MSVCRT_malloc() based wstrndup */
-LPWSTR msvcrt_wstrndup(LPCWSTR buf, unsigned int size)
+WCHAR* msvcrt_wstrndup(LPCWSTR buf, unsigned int size)
 {
   WCHAR* ret;
   unsigned int len = strlenW(buf), max_len;
@@ -33,9 +38,9 @@
 /*********************************************************************
  *		_wcsdup (MSVCRT.@)
  */
-LPWSTR _wcsdup( LPCWSTR str )
+WCHAR* _wcsdup( const WCHAR* str )
 {
-  LPWSTR ret = NULL;
+  WCHAR* ret = NULL;
   if (str)
   {
     int size = (strlenW(str) + 1) * sizeof(WCHAR);
@@ -48,7 +53,7 @@
 /*********************************************************************
  *		_wcsicoll (MSVCRT.@)
  */
-INT _wcsicoll( LPCWSTR str1, LPCWSTR str2 )
+INT _wcsicoll( const WCHAR* str1, const WCHAR* str2 )
 {
   /* FIXME: handle collates */
   return strcmpiW( str1, str2 );
@@ -57,9 +62,9 @@
 /*********************************************************************
  *		_wcsnset (MSVCRT.@)
  */
-LPWSTR _wcsnset( LPWSTR str, WCHAR c, INT n )
+WCHAR* _wcsnset( WCHAR* str, WCHAR c, MSVCRT_size_t n )
 {
-  LPWSTR ret = str;
+  WCHAR* ret = str;
   while ((n-- > 0) && *str) *str++ = c;
   return ret;
 }
@@ -67,10 +72,10 @@
 /*********************************************************************
  *		_wcsrev (MSVCRT.@)
  */
-LPWSTR _wcsrev( LPWSTR str )
+WCHAR* _wcsrev( WCHAR* str )
 {
-  LPWSTR ret = str;
-  LPWSTR end = str + strlenW(str) - 1;
+  WCHAR* ret = str;
+  WCHAR* end = str + strlenW(str) - 1;
   while (end > str)
   {
     WCHAR t = *end;
@@ -83,9 +88,9 @@
 /*********************************************************************
  *		_wcsset (MSVCRT.@)
  */
-LPWSTR _wcsset( LPWSTR str, WCHAR c )
+WCHAR* _wcsset( WCHAR* str, WCHAR c )
 {
-  LPWSTR ret = str;
+  WCHAR* ret = str;
   while (*str) *str++ = c;
   return ret;
 }
@@ -219,7 +224,7 @@
 /*********************************************************************
  *		vswprintf (MSVCRT.@)
  */
-int MSVCRT_vswprintf( LPWSTR str, LPCWSTR format, va_list args )
+int MSVCRT_vswprintf( WCHAR* str, const WCHAR* format, va_list args )
 {
   return _vsnwprintf( str, INT_MAX, format, args );
 }
@@ -227,7 +232,7 @@
 /*********************************************************************
  *		wcscoll (MSVCRT.@)
  */
-DWORD MSVCRT_wcscoll( LPCWSTR str1, LPCWSTR str2 )
+int MSVCRT_wcscoll( const WCHAR* str1, const WCHAR* str2 )
 {
   /* FIXME: handle collates */
   return strcmpW( str1, str2 );
@@ -236,12 +241,12 @@
 /*********************************************************************
  *		wcspbrk (MSVCRT.@)
  */
-LPWSTR MSVCRT_wcspbrk( LPCWSTR str, LPCWSTR accept )
+WCHAR* MSVCRT_wcspbrk( const WCHAR* str, const WCHAR* accept )
 {
-  LPCWSTR p;
+  const WCHAR* p;
   while (*str)
   {
-    for (p = accept; *p; p++) if (*p == *str) return (LPWSTR)str;
+    for (p = accept; *p; p++) if (*p == *str) return (WCHAR*)str;
       str++;
   }
   return NULL;
@@ -343,10 +348,6 @@
   return get_char_typeW(wc) & C1_XDIGIT;
 }
 
-extern char *_itoa( long , char *, int);
-extern char *_ultoa( long , char *, int);
-extern char *_ltoa( long , char *, int);
-
 /*********************************************************************
  *		_itow (MSVCRT.@)
  */