Release 20030408.
[wine/gsoc-2012-control.git] / dlls / crtdll / crtdll_main.c
blobf4614595bcafe812810940261d4719bd3b0f5973
1 /*
2 * Old C RunTime DLL - All functionality is provided by msvcrt.
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <sys/stat.h>
25 #include "windef.h"
26 #include "winbase.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(crtdll);
32 /* from msvcrt */
33 extern void __getmainargs( int *argc, char ***argv, char ***envp,
34 int expand_wildcards, int *new_mode );
36 /* The following data items are not exported from msvcrt */
37 unsigned int CRTDLL__basemajor_dll;
38 unsigned int CRTDLL__baseminor_dll;
39 unsigned int CRTDLL__baseversion_dll;
40 unsigned int CRTDLL__cpumode_dll;
41 unsigned int CRTDLL__osmajor_dll;
42 unsigned int CRTDLL__osminor_dll;
43 unsigned int CRTDLL__osmode_dll;
44 unsigned int CRTDLL__osversion_dll;
46 /* dev_t is a short in crtdll but an unsigned int in msvcrt */
47 typedef short crtdll_dev_t;
49 struct crtdll_stat
51 crtdll_dev_t st_dev;
52 _ino_t st_ino;
53 unsigned short st_mode;
54 short st_nlink;
55 short st_uid;
56 short st_gid;
57 crtdll_dev_t st_rdev;
58 _off_t st_size;
59 time_t st_atime;
60 time_t st_mtime;
61 time_t st_ctime;
64 /* convert struct _stat from crtdll format to msvcrt format */
65 static void convert_struct_stat( struct crtdll_stat *dst, const struct _stat *src )
67 dst->st_dev = src->st_dev;
68 dst->st_ino = src->st_ino;
69 dst->st_mode = src->st_mode;
70 dst->st_nlink = src->st_nlink;
71 dst->st_uid = src->st_uid;
72 dst->st_gid = src->st_gid;
73 dst->st_rdev = src->st_rdev;
74 dst->st_size = src->st_size;
75 dst->st_atime = src->st_atime;
76 dst->st_mtime = src->st_mtime;
77 dst->st_ctime = src->st_ctime;
81 /*********************************************************************
82 * DllMain (CRTDLL.init)
84 BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
86 TRACE("(%p,%ld,%p)\n",hinstDLL,fdwReason,lpvReserved);
88 if (fdwReason == DLL_PROCESS_ATTACH)
90 DWORD version = GetVersion();
91 CRTDLL__basemajor_dll = (version >> 24) & 0xFF;
92 CRTDLL__baseminor_dll = (version >> 16) & 0xFF;
93 CRTDLL__baseversion_dll = (version >> 16);
94 CRTDLL__cpumode_dll = 1; /* FIXME */
95 CRTDLL__osmajor_dll = (version>>8) & 0xFF;
96 CRTDLL__osminor_dll = (version & 0xFF);
97 CRTDLL__osmode_dll = 1; /* FIXME */
98 CRTDLL__osversion_dll = (version & 0xFFFF);
100 return TRUE;
104 /*********************************************************************
105 * __GetMainArgs (CRTDLL.@)
107 void __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards )
109 int new_mode = 0;
110 __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
114 /*********************************************************************
115 * _fstat (CRTDLL.@)
117 int CRTDLL__fstat(int fd, struct crtdll_stat* buf)
119 extern int _fstat(int,struct _stat*);
120 struct _stat st;
121 int ret;
123 if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
124 return ret;
128 /*********************************************************************
129 * _stat (CRTDLL.@)
131 int CRTDLL__stat(const char* path, struct crtdll_stat * buf)
133 extern int _stat(const char*,struct _stat*);
134 struct _stat st;
135 int ret;
137 if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
138 return ret;
142 /*********************************************************************
143 * _strdec (CRTDLL.@)
145 char *_strdec(const char *str1, const char *str2)
147 return (char *)(str2 - 1);
151 /*********************************************************************
152 * _strinc (CRTDLL.@)
154 char *_strinc(const char *str)
156 return (char *)(str + 1);
160 /*********************************************************************
161 * _strncnt (CRTDLL.@)
163 size_t _strncnt(const char *str, size_t maxlen)
165 size_t len = strlen(str);
166 return (len > maxlen) ? maxlen : len;
170 /*********************************************************************
171 * _strnextc (CRTDLL.@)
173 unsigned int _strnextc(const char *str)
175 return (unsigned int)str[0];
179 /*********************************************************************
180 * _strninc (CRTDLL.@)
182 char *_strninc(const char *str, size_t len)
184 return (char *)(str + len);
188 /*********************************************************************
189 * _strspnp (CRTDLL.@)
191 char *_strspnp( const char *str1, const char *str2)
193 str1 += strspn( str1, str2 );
194 return *str1 ? (char*)str1 : NULL;