1996-08-11 17:49:51 +02:00
|
|
|
/*
|
2001-01-12 21:42:06 +01:00
|
|
|
* Old C RunTime DLL - All functionality is provided by msvcrt.
|
1996-08-11 17:49:51 +02:00
|
|
|
*
|
2000-11-08 23:42:53 +01:00
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1996-08-11 17:49:51 +02:00
|
|
|
*/
|
2002-06-13 23:42:01 +02:00
|
|
|
|
2000-12-02 00:53:46 +01:00
|
|
|
#include "config.h"
|
2003-01-02 20:28:09 +01:00
|
|
|
|
2003-08-22 07:05:56 +02:00
|
|
|
#include <stdarg.h>
|
2005-05-06 18:22:54 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
2003-01-02 20:28:09 +01:00
|
|
|
|
2001-01-12 21:42:06 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2003-01-02 20:28:09 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-04-03 18:22:01 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(crtdll);
|
1996-08-11 17:49:51 +02:00
|
|
|
|
2001-02-20 02:56:46 +01:00
|
|
|
/* from msvcrt */
|
2006-06-12 21:35:20 +02:00
|
|
|
extern void CDECL __getmainargs( int *argc, char ***argv, char ***envp,
|
|
|
|
int expand_wildcards, int *new_mode );
|
2001-02-20 02:56:46 +01:00
|
|
|
|
2001-01-12 21:42:06 +01:00
|
|
|
/* The following data items are not exported from msvcrt */
|
|
|
|
unsigned int CRTDLL__basemajor_dll;
|
|
|
|
unsigned int CRTDLL__baseminor_dll;
|
|
|
|
unsigned int CRTDLL__baseversion_dll;
|
|
|
|
unsigned int CRTDLL__cpumode_dll;
|
|
|
|
unsigned int CRTDLL__osmajor_dll;
|
|
|
|
unsigned int CRTDLL__osminor_dll;
|
|
|
|
unsigned int CRTDLL__osmode_dll;
|
|
|
|
unsigned int CRTDLL__osversion_dll;
|
2000-12-12 01:37:27 +01:00
|
|
|
|
2002-06-13 23:42:01 +02:00
|
|
|
/* dev_t is a short in crtdll but an unsigned int in msvcrt */
|
|
|
|
typedef short crtdll_dev_t;
|
|
|
|
|
|
|
|
struct crtdll_stat
|
|
|
|
{
|
|
|
|
crtdll_dev_t st_dev;
|
|
|
|
_ino_t st_ino;
|
|
|
|
unsigned short st_mode;
|
|
|
|
short st_nlink;
|
|
|
|
short st_uid;
|
|
|
|
short st_gid;
|
|
|
|
crtdll_dev_t st_rdev;
|
2002-12-18 21:17:51 +01:00
|
|
|
_off_t st_size;
|
|
|
|
time_t st_atime;
|
|
|
|
time_t st_mtime;
|
|
|
|
time_t st_ctime;
|
2002-06-13 23:42:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* convert struct _stat from crtdll format to msvcrt format */
|
|
|
|
static void convert_struct_stat( struct crtdll_stat *dst, const struct _stat *src )
|
|
|
|
{
|
|
|
|
dst->st_dev = src->st_dev;
|
|
|
|
dst->st_ino = src->st_ino;
|
|
|
|
dst->st_mode = src->st_mode;
|
|
|
|
dst->st_nlink = src->st_nlink;
|
|
|
|
dst->st_uid = src->st_uid;
|
|
|
|
dst->st_gid = src->st_gid;
|
|
|
|
dst->st_rdev = src->st_rdev;
|
|
|
|
dst->st_size = src->st_size;
|
|
|
|
dst->st_atime = src->st_atime;
|
|
|
|
dst->st_mtime = src->st_mtime;
|
|
|
|
dst->st_ctime = src->st_ctime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-22 12:37:57 +02:00
|
|
|
/*********************************************************************
|
2002-11-05 00:53:41 +01:00
|
|
|
* DllMain (CRTDLL.init)
|
1999-05-22 12:37:57 +02:00
|
|
|
*/
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
|
1999-05-22 12:37:57 +02:00
|
|
|
{
|
2002-10-19 01:48:57 +02:00
|
|
|
TRACE("(%p,%ld,%p)\n",hinstDLL,fdwReason,lpvReserved);
|
2000-12-16 22:53:56 +01:00
|
|
|
|
2001-01-12 21:42:06 +01:00
|
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
2000-12-16 22:53:56 +01:00
|
|
|
{
|
2001-01-12 21:42:06 +01:00
|
|
|
DWORD version = GetVersion();
|
2003-06-30 22:53:48 +02:00
|
|
|
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
|
2001-01-12 21:42:06 +01:00
|
|
|
CRTDLL__basemajor_dll = (version >> 24) & 0xFF;
|
|
|
|
CRTDLL__baseminor_dll = (version >> 16) & 0xFF;
|
|
|
|
CRTDLL__baseversion_dll = (version >> 16);
|
|
|
|
CRTDLL__cpumode_dll = 1; /* FIXME */
|
|
|
|
CRTDLL__osmajor_dll = (version>>8) & 0xFF;
|
|
|
|
CRTDLL__osminor_dll = (version & 0xFF);
|
|
|
|
CRTDLL__osmode_dll = 1; /* FIXME */
|
|
|
|
CRTDLL__osversion_dll = (version & 0xFFFF);
|
2000-12-16 22:53:56 +01:00
|
|
|
}
|
2001-01-12 21:42:06 +01:00
|
|
|
return TRUE;
|
2000-12-16 22:53:56 +01:00
|
|
|
}
|
2001-02-20 02:56:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __GetMainArgs (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
void CDECL __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards )
|
2001-02-20 02:56:46 +01:00
|
|
|
{
|
2001-02-21 03:20:08 +01:00
|
|
|
int new_mode = 0;
|
2001-04-11 01:25:40 +02:00
|
|
|
__getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
|
2001-02-20 02:56:46 +01:00
|
|
|
}
|
2002-06-13 23:42:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fstat (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
int CDECL CRTDLL__fstat(int fd, struct crtdll_stat* buf)
|
2002-06-13 23:42:01 +02:00
|
|
|
{
|
2002-07-31 22:04:57 +02:00
|
|
|
extern int _fstat(int,struct _stat*);
|
2002-06-13 23:42:01 +02:00
|
|
|
struct _stat st;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _stat (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
int CDECL CRTDLL__stat(const char* path, struct crtdll_stat * buf)
|
2002-06-13 23:42:01 +02:00
|
|
|
{
|
2002-07-31 22:04:57 +02:00
|
|
|
extern int _stat(const char*,struct _stat*);
|
2002-06-13 23:42:01 +02:00
|
|
|
struct _stat st;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
|
|
|
|
return ret;
|
|
|
|
}
|
2002-07-23 04:08:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strdec (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
char * CDECL _strdec(const char *str1, const char *str2)
|
2002-07-23 04:08:12 +02:00
|
|
|
{
|
|
|
|
return (char *)(str2 - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strinc (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
char * CDECL _strinc(const char *str)
|
2002-07-23 04:08:12 +02:00
|
|
|
{
|
|
|
|
return (char *)(str + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strncnt (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
size_t CDECL _strncnt(const char *str, size_t maxlen)
|
2002-07-23 04:08:12 +02:00
|
|
|
{
|
|
|
|
size_t len = strlen(str);
|
|
|
|
return (len > maxlen) ? maxlen : len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strnextc (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
unsigned int CDECL _strnextc(const char *str)
|
2002-07-23 04:08:12 +02:00
|
|
|
{
|
|
|
|
return (unsigned int)str[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strninc (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
char * CDECL _strninc(const char *str, size_t len)
|
2002-07-23 04:08:12 +02:00
|
|
|
{
|
|
|
|
return (char *)(str + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strspnp (CRTDLL.@)
|
|
|
|
*/
|
2006-06-12 21:35:20 +02:00
|
|
|
char * CDECL _strspnp( const char *str1, const char *str2)
|
2002-07-23 04:08:12 +02:00
|
|
|
{
|
|
|
|
str1 += strspn( str1, str2 );
|
|
|
|
return *str1 ? (char*)str1 : NULL;
|
|
|
|
}
|