Index: trunk/src/msvcrt/dir.c
===================================================================
--- trunk/src/msvcrt/dir.c	(revision 21395)
+++ trunk/src/msvcrt/dir.c	(revision 21398)
@@ -31,4 +31,6 @@
 #endif
 
+#ifndef __MINIVCRT__
+
 #include "wine/port.h"
 
@@ -49,4 +51,19 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
+
+#else /* !__MINIVCRT__ */
+
+#include "minivcrt.h"
+#include "minivcrt_internal.h"
+
+#include "winternl.h"
+#include "wine/unicode.h"
+
+#include <errno.h>
+#include <stdlib.h>
+
+#endif /* !__MINIVCRT__ */
+
+#ifndef __MINIVCRT__
 
 /* INTERNAL: Translate finddata_t to PWIN32_FIND_DATAA */
@@ -70,4 +87,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /* INTERNAL: Translate wfinddata_t to PWIN32_FIND_DATAA */
 static void msvcrt_wfttofd(LPWIN32_FIND_DATAW fd, struct _wfinddata_t* ft)
@@ -90,4 +109,6 @@
 }
 
+#ifndef __MINIVCRT__
+
 /*********************************************************************
  *		_chdir (MSVCRT.@)
@@ -103,4 +124,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wchdir (MSVCRT.@)
@@ -115,4 +138,6 @@
   return 0;
 }
+
+#ifndef __MINIVCRT__
 
 /*********************************************************************
@@ -166,4 +191,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wfindfirst (MSVCRT.@)
@@ -185,4 +212,6 @@
 }
 
+#ifndef __MINIVCRT__
+
 /*********************************************************************
  *		_findnext (MSVCRT.@)
@@ -194,5 +223,5 @@
   if (!FindNextFileA((HANDLE)hand, &find_data))
   {
-    *MSVCRT__errno() = MSVCRT_ENOENT;
+    *MSVCRT__errno() = MSVCRT(ENOENT);
     return -1;
   }
@@ -202,4 +231,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wfindnext (MSVCRT.@)
@@ -211,5 +242,5 @@
   if (!FindNextFileW((HANDLE)hand, &find_data))
   {
-    *MSVCRT__errno() = MSVCRT_ENOENT;
+    *MSVCRT__errno() = MSVCRT(ENOENT);
     return -1;
   }
@@ -218,4 +249,6 @@
   return 0;
 }
+
+#ifndef __MINIVCRT__
 
 /*********************************************************************
@@ -245,4 +278,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wgetcwd (MSVCRT.@)
@@ -264,5 +299,5 @@
   if (dir_len >= size)
   {
-    *MSVCRT__errno() = MSVCRT_ERANGE;
+    *MSVCRT__errno() = MSVCRT(ERANGE);
     return NULL; /* buf too small */
   }
@@ -270,4 +305,6 @@
   return buf;
 }
+
+#ifndef __MINIVCRT__
 
 /*********************************************************************
@@ -322,4 +359,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wgetdcwd (MSVCRT.@)
@@ -342,5 +381,5 @@
     if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE)
     {
-      *MSVCRT__errno() = MSVCRT_EACCES;
+      *MSVCRT__errno() = MSVCRT(EACCES);
       return NULL;
     }
@@ -349,5 +388,5 @@
     if (dir_len >= size || dir_len < 1)
     {
-      *MSVCRT__errno() = MSVCRT_ERANGE;
+      *MSVCRT__errno() = MSVCRT(ERANGE);
       return NULL; /* buf too small */
     }
@@ -360,4 +399,6 @@
   return buf;
 }
+
+#ifndef __MINIVCRT__
 
 /*********************************************************************
@@ -399,4 +440,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wmkdir (MSVCRT.@)
@@ -410,4 +453,6 @@
 }
 
+#ifndef __MINIVCRT__
+
 /*********************************************************************
  *		_rmdir (MSVCRT.@)
@@ -420,4 +465,6 @@
   return -1;
 }
+
+#endif /* !__MINIVCRT__ */
 
 /*********************************************************************
@@ -519,4 +566,6 @@
   }
 }
+
+#ifndef __MINIVCRT__
 
 /* INTERNAL: Helper for _fullpath. Modified PD code from 'snippets'. */
@@ -720,4 +769,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wmakepath (MSVCRT.@)
@@ -767,4 +818,6 @@
 }
 
+#ifndef __MINIVCRT__
+
 /*********************************************************************
  *		_searchenv (MSVCRT.@)
@@ -828,4 +881,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 MSVCRT_wchar_t* _wfullpath(MSVCRT_wchar_t* absPath,const MSVCRT_wchar_t* relPath,MSVCRT(size_t) size)
 {
@@ -836,9 +891,9 @@
 
    WideCharToMultiByte(CP_ACP, 0, relPath, -1, (LPSTR)asciirelPath, 280, NULL, NULL);
-   
+
    MSVCRT__fullpath(asciiabsPath, asciirelPath, size);
-   
+
    MultiByteToWideChar(CP_ACP, 0, asciiabsPath, -1, absPath, size);
 
-   return absPath;  
-}
+   return absPath;
+}
Index: trunk/src/msvcrt/environ.c
===================================================================
--- trunk/src/msvcrt/environ.c	(revision 21395)
+++ trunk/src/msvcrt/environ.c	(revision 21398)
@@ -26,4 +26,6 @@
 #endif
 
+#ifndef __MINIVCRT__
+
 #include "wine/unicode.h"
 #include "msvcrt.h"
@@ -32,8 +34,19 @@
 #include "msvcrt/stdlib.h"
 
-
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
+
+#else /* !__MINIVCRT__ */
+
+#include "minivcrt.h"
+#include "minivcrt_internal.h"
+
+#include "winternl.h"
+#include "wine/unicode.h"
+
+#endif /* !__MINIVCRT__ */
+
+#ifndef __MINIVCRT__
 
 /*********************************************************************
@@ -67,4 +80,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wgetenv (MSVCRT.@)
@@ -97,4 +112,6 @@
   return NULL;
 }
+
+#ifndef __MINIVCRT__
 
 /*********************************************************************
@@ -130,4 +147,6 @@
 }
 
+#endif /* !__MINIVCRT__ */
+
 /*********************************************************************
  *		_wputenv (MSVCRT.@)
@@ -154,4 +173,5 @@
 
  ret = !SetEnvironmentVariableW(name, value[0] ? value : NULL);
+#ifndef __MINIVCRT__
  /* Update the __p__environ array only when already initialized */
  if (MSVCRT__environ)
@@ -159,4 +179,5 @@
  if (MSVCRT__wenviron)
    MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(MSVCRT__wenviron);
+#endif /* !__MINIVCRT__ */
  return ret;
 }
Index: trunk/src/msvcrt/errno.c
===================================================================
--- trunk/src/msvcrt/errno.c	(revision 21395)
+++ trunk/src/msvcrt/errno.c	(revision 21398)
@@ -19,4 +19,6 @@
  */
 
+#ifndef __MINIVCRT__
+
 #include "msvcrt.h"
 #include "msvcrt/errno.h"
@@ -29,22 +31,44 @@
 #include "msvcrt/string.h"
 
-
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 
+#else /* !__MINIVCRT__ */
+
+#include <winbase.h>
+#include <winerror.h>
+
+#include "minivcrt.h"
+#include "minivcrt_internal.h"
+
+#include <errno.h>
+
+#endif /* !__MINIVCRT__ */
 
 /* INTERNAL: Set the crt and dos errno's from the OS error given. */
 void MSVCRT__set_errno(int err)
 {
-  int *msv_errno = MSVCRT__errno();
+#ifndef __MINIVCRT__
+
+  int *__errno = MSVCRT__errno();
   unsigned long *doserrno = MSVCRT_doserrno();
- 
+
   *doserrno = err;
+
+#define ERR_CASE(oserr) case oserr:
+#define ERR_MAPS(oserr,crterr) case oserr:*__errno = MSVCRT_##crterr;break;
+
+#else /* !__MINIVCRT__ */
+
+  int *__errno = _errno();
+
+#define ERR_CASE(oserr) case oserr:
+#define ERR_MAPS(oserr,crterr) case oserr:*__errno = crterr;break;
+
+#endif /* !__MINIVCRT__ */
 
   switch(err)
   {
-#define ERR_CASE(oserr) case oserr:
-#define ERR_MAPS(oserr,crterr) case oserr:*msv_errno = crterr;break;
     ERR_CASE(ERROR_ACCESS_DENIED)
     ERR_CASE(ERROR_NETWORK_ACCESS_DENIED)
@@ -57,5 +81,5 @@
     ERR_CASE(ERROR_NOT_LOCKED)
     ERR_CASE(ERROR_INVALID_ACCESS)
-    ERR_MAPS(ERROR_LOCK_VIOLATION,       MSVCRT_EACCES);
+    ERR_MAPS(ERROR_LOCK_VIOLATION,       EACCES);
     ERR_CASE(ERROR_FILE_NOT_FOUND)
     ERR_CASE(ERROR_NO_MORE_FILES)
@@ -65,33 +89,35 @@
     ERR_CASE(ERROR_BAD_NET_NAME)
     ERR_CASE(ERROR_FILENAME_EXCED_RANGE)
-    ERR_MAPS(ERROR_PATH_NOT_FOUND,       MSVCRT_ENOENT);
-    ERR_MAPS(ERROR_IO_DEVICE,            MSVCRT_EIO);
-    ERR_MAPS(ERROR_BAD_FORMAT,           MSVCRT_ENOEXEC);
-    ERR_MAPS(ERROR_INVALID_HANDLE,       MSVCRT_EBADF);
+    ERR_MAPS(ERROR_PATH_NOT_FOUND,       ENOENT);
+    ERR_MAPS(ERROR_IO_DEVICE,            EIO);
+    ERR_MAPS(ERROR_BAD_FORMAT,           ENOEXEC);
+    ERR_MAPS(ERROR_INVALID_HANDLE,       EBADF);
     ERR_CASE(ERROR_OUTOFMEMORY)
     ERR_CASE(ERROR_INVALID_BLOCK)
     ERR_CASE(ERROR_NOT_ENOUGH_QUOTA);
-    ERR_MAPS(ERROR_ARENA_TRASHED,        MSVCRT_ENOMEM);
-    ERR_MAPS(ERROR_BUSY,                 MSVCRT_EBUSY);
+    ERR_MAPS(ERROR_ARENA_TRASHED,        ENOMEM);
+    ERR_MAPS(ERROR_BUSY,                 EBUSY);
     ERR_CASE(ERROR_ALREADY_EXISTS)
-    ERR_MAPS(ERROR_FILE_EXISTS,          MSVCRT_EEXIST);
-    ERR_MAPS(ERROR_BAD_DEVICE,           MSVCRT_ENODEV);
-    ERR_MAPS(ERROR_TOO_MANY_OPEN_FILES,  MSVCRT_EMFILE);
-    ERR_MAPS(ERROR_DISK_FULL,            MSVCRT_ENOSPC);
-    ERR_MAPS(ERROR_BROKEN_PIPE,          MSVCRT_EPIPE);
-    ERR_MAPS(ERROR_POSSIBLE_DEADLOCK,    MSVCRT_EDEADLK);
-    ERR_MAPS(ERROR_DIR_NOT_EMPTY,        MSVCRT_ENOTEMPTY);
-    ERR_MAPS(ERROR_BAD_ENVIRONMENT,      MSVCRT_E2BIG);
+    ERR_MAPS(ERROR_FILE_EXISTS,          EEXIST);
+    ERR_MAPS(ERROR_BAD_DEVICE,           ENODEV);
+    ERR_MAPS(ERROR_TOO_MANY_OPEN_FILES,  EMFILE);
+    ERR_MAPS(ERROR_DISK_FULL,            ENOSPC);
+    ERR_MAPS(ERROR_BROKEN_PIPE,          EPIPE);
+    ERR_MAPS(ERROR_POSSIBLE_DEADLOCK,    EDEADLK);
+    ERR_MAPS(ERROR_DIR_NOT_EMPTY,        ENOTEMPTY);
+    ERR_MAPS(ERROR_BAD_ENVIRONMENT,      E2BIG);
     ERR_CASE(ERROR_WAIT_NO_CHILDREN)
-    ERR_MAPS(ERROR_CHILD_NOT_COMPLETE,   MSVCRT_ECHILD);
+    ERR_MAPS(ERROR_CHILD_NOT_COMPLETE,   ECHILD);
     ERR_CASE(ERROR_NO_PROC_SLOTS)
     ERR_CASE(ERROR_MAX_THRDS_REACHED)
-    ERR_MAPS(ERROR_NESTING_NOT_ALLOWED,  MSVCRT_EAGAIN);
+    ERR_MAPS(ERROR_NESTING_NOT_ALLOWED,  EAGAIN);
   default:
     /*  Remaining cases map to EINVAL */
     /* FIXME: may be missing some errors above */
-    *msv_errno = MSVCRT_EINVAL;
+    *__errno = MSVCRT(EINVAL);
   }
 }
+
+#ifndef __MINIVCRT__
 
 /*********************************************************************
@@ -100,5 +126,5 @@
 int* MSVCRT__errno(void)
 {
-    dprintf(("MSVCRT: __errno %d",msvcrt_get_thread_data()->msv_errno));  
+    dprintf(("MSVCRT: __errno %d",msvcrt_get_thread_data()->msv_errno));
     return &msvcrt_get_thread_data()->msv_errno;
 }
@@ -109,5 +135,5 @@
 unsigned long* MSVCRT_doserrno(void)
 {
-    dprintf(("MSVCRT: _doserrno %d",msvcrt_get_thread_data()->doserrno));  
+    dprintf(("MSVCRT: _doserrno %d",msvcrt_get_thread_data()->doserrno));
     return &msvcrt_get_thread_data()->doserrno;
 }
@@ -138,2 +164,4 @@
   MSVCRT__cprintf("%s: %s\n",str,MSVCRT_strerror(msvcrt_get_thread_data()->msv_errno));
 }
+
+#endif /* !__MINIVCRT__ */
Index: trunk/src/msvcrt/makefile
===================================================================
--- trunk/src/msvcrt/makefile	(revision 21395)
+++ trunk/src/msvcrt/makefile	(revision 21398)
@@ -23,7 +23,10 @@
 
 all clean lib:  # add all common rules here
+!ifdef BUILD_MSVCRT    
     $(MAKE_CMD) -f msvcrt.mak $@
     $(MAKE_CMD) -f msvcrt20.mak $@
     $(MAKE_CMD) -f msvcrt40.mak $@
+!endif
+    $(MAKE_CMD) -f minivcrt.mak $@
 
 # don't have to make deps more than once.
Index: trunk/src/msvcrt/minivcrt.mak
===================================================================
--- trunk/src/msvcrt/minivcrt.mak	(revision 21398)
+++ trunk/src/msvcrt/minivcrt.mak	(revision 21398)
@@ -0,0 +1,51 @@
+#
+# Odin32 API
+#
+#       minivcrt.lib makefile
+#
+
+
+#
+# Tell buildenvironment that we have a non-default makefilename.
+#
+MAKEFILE = minivcrt.mak
+
+CCENV = EMX
+LIBTARGET = 1
+PUBLICLIB = 1
+
+DIREXT2 = .minivcrt
+
+#
+# Compiler, tools, and interference rules.
+#
+!include ../../makefile.inc
+
+
+CDEFINES = -D__MINIVCRT__ $(CDEFINES)
+
+
+#
+# Object files. Prefix with OBJDIR and one space before the '\'.
+#
+OBJS = \
+$(OBJDIR)\dir.obj \
+$(OBJDIR)\environ.obj \
+$(OBJDIR)\errno.obj \
+$(OBJDIR)\wcs.obj
+
+LIBS = \
+$(ODIN32_LIB)\kernel32.lib \
+$(ODIN32_LIB)\ntdll.lib \
+$(ODIN32_LIB)\user32.lib
+
+
+#
+# Target name - name of the dll without extention and path.
+#
+TARGET = minivcrt
+
+
+# Includes the common rules.
+#
+!include $(ODIN32_POST_INC)
Index: trunk/src/msvcrt/minivcrt_internal.h
===================================================================
--- trunk/src/msvcrt/minivcrt_internal.h	(revision 21398)
+++ trunk/src/msvcrt/minivcrt_internal.h	(revision 21398)
@@ -0,0 +1,38 @@
+/*
+ * Header file for the stripped down version of MSVCRT that only
+ * contains functions specific to the MS VC Runtime (internal definitions).
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#ifndef _minivcrt_internal_h_
+#define _minivcrt_internal_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void MSVCRT__set_errno(int err);
+
+/*char*  msvcrt_strndup(const char*,unsigned int);*/
+LPWSTR msvcrt_wstrndup(LPCWSTR, unsigned int);
+
+#define MSVCRT_wchar_t  WCHAR
+#define MSVCRT_size_t   size_t
+
+#define MSVCRT__errno       _errno
+#define MSVCRT__getdrive    _getdrive
+#define MSVCRT__fullpath    _fullpath
+#define MSVCRT_malloc       malloc
+
+#define TRACE 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
+#define FIXME 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
+#define debugstr_w(a) ""
+#define dprintf(a) do {} while(0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _minivcrt_internal_h_ */
Index: trunk/src/msvcrt/wcs.c
===================================================================
--- trunk/src/msvcrt/wcs.c	(revision 21395)
+++ trunk/src/msvcrt/wcs.c	(revision 21398)
@@ -19,4 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+#ifndef __MINIVCRT__
+
 #include <limits.h>
 #include <stdlib.h>
@@ -38,4 +41,18 @@
 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 
+#else /* !__MINIVCRT__ */
+
+#include <string.h>
+#include <sys/limits.h>
+
+#include <winbase.h>
+
+#include "minivcrt.h"
+#include "minivcrt_internal.h"
+
+#include "winternl.h"
+#include "wine/unicode.h"
+
+#endif /* !__MINIVCRT__ */
 
 /* INTERNAL: MSVCRT_malloc() based wstrndup */
