crtdll_main.c 5.31 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
2
 * Old C RunTime DLL - All functionality is provided by msvcrt.
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
4
 * Copyright 2000 Jon Griffiths
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard's avatar
Alexandre Julliard committed
19
 */
20

21
#include "config.h"
22

23
#include <stdarg.h>
24 25 26
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
27

28 29
#include "windef.h"
#include "winbase.h"
30

31
#include "wine/debug.h"
32

33
WINE_DEFAULT_DEBUG_CHANNEL(crtdll);
Alexandre Julliard's avatar
Alexandre Julliard committed
34

35
/* from msvcrt */
36 37
extern void CDECL __getmainargs( int *argc, char ***argv, char ***envp,
                                 int expand_wildcards, int *new_mode );
38

39 40 41 42 43 44 45 46 47
/* 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;
48

49 50 51 52 53 54 55 56 57 58 59 60
/* 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;
61 62 63 64
  _off_t         st_size;
  time_t         st_atime;
  time_t         st_mtime;
  time_t         st_ctime;
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
};

/* 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;
}


84
/*********************************************************************
85
 *                  DllMain  (CRTDLL.init)
86
 */
87
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
88
{
89
  TRACE("(%p,%d,%p)\n",hinstDLL,fdwReason,lpvReserved);
90

91
  if (fdwReason == DLL_PROCESS_ATTACH)
92
  {
93
    DWORD version = GetVersion();
94 95 96

    DisableThreadLibraryCalls(hinstDLL);

97 98 99 100 101 102 103 104
    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);
105
  }
106
  return TRUE;
107
}
108 109 110 111 112


/*********************************************************************
 *                  __GetMainArgs  (CRTDLL.@)
 */
113
void CDECL __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards )
114
{
115
    int new_mode = 0;
116
    __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
117
}
118 119 120 121 122


/*********************************************************************
 *		_fstat (CRTDLL.@)
 */
123
int CDECL CRTDLL__fstat(int fd, struct crtdll_stat* buf)
124
{
125
    extern int _fstat(int,struct _stat*);
126 127 128 129 130 131 132 133 134 135 136
    struct _stat st;
    int ret;

    if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
    return ret;
}


/*********************************************************************
 *		_stat (CRTDLL.@)
 */
137
int CDECL CRTDLL__stat(const char* path, struct crtdll_stat * buf)
138
{
139
    extern int _stat(const char*,struct _stat*);
140 141 142 143 144 145
    struct _stat st;
    int ret;

    if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
    return ret;
}
146 147 148 149 150


/*********************************************************************
 *		_strdec (CRTDLL.@)
 */
151
char * CDECL _strdec(const char *str1, const char *str2)
152 153 154 155 156 157 158 159
{
    return (char *)(str2 - 1);
}


/*********************************************************************
 *		_strinc (CRTDLL.@)
 */
160
char * CDECL _strinc(const char *str)
161 162 163 164 165 166 167 168
{
    return (char *)(str + 1);
}


/*********************************************************************
 *		_strncnt (CRTDLL.@)
 */
169
size_t CDECL _strncnt(const char *str, size_t maxlen)
170 171 172 173 174 175 176 177 178
{
    size_t len = strlen(str);
    return (len > maxlen) ? maxlen : len;
}


/*********************************************************************
 *		_strnextc (CRTDLL.@)
 */
179
unsigned int CDECL _strnextc(const char *str)
180 181 182 183 184 185 186 187
{
    return (unsigned int)str[0];
}


/*********************************************************************
 *		_strninc (CRTDLL.@)
 */
188
char * CDECL _strninc(const char *str, size_t len)
189 190 191 192 193 194 195 196
{
    return (char *)(str + len);
}


/*********************************************************************
 *		_strspnp (CRTDLL.@)
 */
197
char * CDECL _strspnp( const char *str1, const char *str2)
198 199 200 201
{
    str1 += strspn( str1, str2 );
    return *str1 ? (char*)str1 : NULL;
}