Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendllmain.c
Go to the documentation of this file.
00001 /* 00002 * dllmain.c 00003 * 00004 * ReactOS CRTDLL.DLL Compatibility Library 00005 * 00006 * THIS SOFTWARE IS NOT COPYRIGHTED 00007 * 00008 * This source code is offered for use in the public domain. You may 00009 * use, modify or distribute it freely. 00010 * 00011 * This code is distributed in the hope that it will be useful but 00012 * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY 00013 * DISCLAMED. This includes but is not limited to warrenties of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00015 * 00016 */ 00017 00018 #include <precomp.h> 00019 #include <locale.h> 00020 #include <mbctype.h> 00021 #include <sys/stat.h> 00022 #include <internal/wine/msvcrt.h> 00023 #include <internal/tls.h> 00024 00025 00026 #include "wine/debug.h" 00027 WINE_DEFAULT_DEBUG_CHANNEL(crtdll); 00028 00029 /* from msvcrt */ 00030 extern void __getmainargs( int *argc, char ***argv, char ***envp, 00031 int expand_wildcards, int *new_mode ); 00032 00033 /* EXTERNAL PROTOTYPES ********************************************************/ 00034 00035 extern int BlockEnvToEnvironA(void); 00036 extern int BlockEnvToEnvironW(void); 00037 extern void FreeEnvironment(char **environment); 00038 extern void _atexit_cleanup(void); 00039 00040 extern unsigned int _osver; 00041 extern unsigned int _winminor; 00042 extern unsigned int _winmajor; 00043 extern unsigned int _winver; 00044 00045 unsigned int CRTDLL__basemajor_dll = 0; 00046 unsigned int CRTDLL__baseminor_dll = 0; 00047 unsigned int CRTDLL__baseversion_dll = 0; 00048 unsigned int CRTDLL__cpumode_dll = 0; 00049 unsigned int CRTDLL__osmajor_dll = 0; 00050 unsigned int CRTDLL__osminor_dll = 0; 00051 unsigned int CRTDLL__osmode_dll = 0; 00052 unsigned int CRTDLL__osversion_dll = 0; 00053 int _fileinfo_dll; 00054 00055 extern char* _acmdln; /* pointer to ascii command line */ 00056 extern wchar_t* _wcmdln; /* pointer to wide character command line */ 00057 #undef _environ 00058 extern char** _environ; /* pointer to environment block */ 00059 extern char** __initenv; /* pointer to initial environment block */ 00060 extern wchar_t** _wenviron; /* pointer to environment block */ 00061 extern wchar_t** __winitenv; /* pointer to initial environment block */ 00062 00063 /* dev_t is a short in crtdll but an unsigned int in msvcrt */ 00064 typedef short crtdll_dev_t; 00065 00066 struct crtdll_stat 00067 { 00068 crtdll_dev_t st_dev; 00069 _ino_t st_ino; 00070 unsigned short st_mode; 00071 short st_nlink; 00072 short st_uid; 00073 short st_gid; 00074 crtdll_dev_t st_rdev; 00075 _off_t st_size; 00076 time_t st_atime; 00077 time_t st_mtime; 00078 time_t st_ctime; 00079 }; 00080 00081 /* convert struct _stat from crtdll format to msvcrt format */ 00082 static void convert_struct_stat( struct crtdll_stat *dst, const struct _stat *src ) 00083 { 00084 dst->st_dev = src->st_dev; 00085 dst->st_ino = src->st_ino; 00086 dst->st_mode = src->st_mode; 00087 dst->st_nlink = src->st_nlink; 00088 dst->st_uid = src->st_uid; 00089 dst->st_gid = src->st_gid; 00090 dst->st_rdev = src->st_rdev; 00091 dst->st_size = src->st_size; 00092 dst->st_atime = src->st_atime; 00093 dst->st_mtime = src->st_mtime; 00094 dst->st_ctime = src->st_ctime; 00095 } 00096 00097 /* LIBRARY ENTRY POINT ********************************************************/ 00098 00099 BOOL 00100 WINAPI 00101 DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) 00102 { 00103 DWORD version; 00104 switch (dwReason) 00105 { 00106 case DLL_PROCESS_ATTACH: 00107 version = GetVersion(); 00108 00109 /* initialize version info */ 00110 CRTDLL__basemajor_dll = (version >> 24) & 0xFF; 00111 CRTDLL__baseminor_dll = (version >> 16) & 0xFF; 00112 CRTDLL__baseversion_dll = (version >> 16); 00113 CRTDLL__cpumode_dll = 1; /* FIXME */ 00114 CRTDLL__osmajor_dll = (version >>8) & 0xFF; 00115 CRTDLL__osminor_dll = (version & 0xFF); 00116 CRTDLL__osmode_dll = 1; /* FIXME */ 00117 CRTDLL__osversion_dll = (version & 0xFFFF); 00118 00119 _winmajor = (_osver >> 8) & 0xFF; 00120 _winminor = _osver & 0xFF; 00121 _winver = (_winmajor << 8) + _winminor; 00122 _osver = (_osver >> 16) & 0xFFFF; 00123 00124 /* create tls stuff */ 00125 if (!msvcrt_init_tls()) 00126 return FALSE; 00127 00128 if (BlockEnvToEnvironA() < 0) 00129 return FALSE; 00130 00131 if (BlockEnvToEnvironW() < 0) 00132 { 00133 FreeEnvironment(_environ); 00134 return FALSE; 00135 } 00136 00137 _acmdln = _strdup(GetCommandLineA()); 00138 _wcmdln = _wcsdup(GetCommandLineW()); 00139 00140 /* Initialization of the WINE code */ 00141 msvcrt_init_mt_locks(); 00142 //if(!msvcrt_init_locale()) { 00143 //msvcrt_free_mt_locks(); 00144 // msvcrt_free_tls_mem(); 00145 //return FALSE; 00146 //} 00147 //msvcrt_init_math(); 00148 msvcrt_init_io(); 00149 //msvcrt_init_console(); 00150 //msvcrt_init_args(); 00151 //msvcrt_init_signals(); 00152 _setmbcp(_MB_CP_LOCALE); 00153 TRACE("Attach done\n"); 00154 break; 00155 case DLL_THREAD_ATTACH: 00156 break; 00157 00158 case DLL_THREAD_DETACH: 00159 msvcrt_free_tls_mem(); 00160 break; 00161 00162 case DLL_PROCESS_DETACH: 00163 TRACE("Detach\n"); 00164 /* Deinit of the WINE code */ 00165 msvcrt_free_io(); 00166 msvcrt_free_mt_locks(); 00167 //msvcrt_free_console(); 00168 //msvcrt_free_args(); 00169 //msvcrt_free_signals(); 00170 msvcrt_free_tls_mem(); 00171 if (!msvcrt_free_tls()) 00172 return FALSE; 00173 //MSVCRT__free_locale(MSVCRT_locale); 00174 00175 if (__winitenv && __winitenv != _wenviron) 00176 FreeEnvironment((char**)__winitenv); 00177 if (_wenviron) 00178 FreeEnvironment((char**)_wenviron); 00179 00180 if (__initenv && __initenv != _environ) 00181 FreeEnvironment(__initenv); 00182 if (_environ) 00183 FreeEnvironment(_environ); 00184 00185 TRACE("Detach done\n"); 00186 break; 00187 } 00188 00189 return TRUE; 00190 } 00191 00192 00193 /********************************************************************* 00194 * __GetMainArgs (CRTDLL.@) 00195 */ 00196 void __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards ) 00197 { 00198 int new_mode = 0; 00199 __getmainargs( argc, argv, envp, expand_wildcards, &new_mode ); 00200 } 00201 00202 00203 /********************************************************************* 00204 * _fstat (CRTDLL.@) 00205 */ 00206 int CRTDLL__fstat(int fd, struct crtdll_stat* buf) 00207 { 00208 extern int _fstat(int,struct _stat*); 00209 struct _stat st; 00210 int ret; 00211 00212 if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st ); 00213 return ret; 00214 } 00215 00216 00217 /********************************************************************* 00218 * _stat (CRTDLL.@) 00219 */ 00220 int CRTDLL__stat(const char* path, struct crtdll_stat * buf) 00221 { 00222 extern int _stat(const char*,struct _stat*); 00223 struct _stat st; 00224 int ret; 00225 00226 if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st ); 00227 return ret; 00228 } 00229 00230 00231 /********************************************************************* 00232 * _strdec (CRTDLL.@) 00233 */ 00234 char *_strdec(const char *str1, const char *str2) 00235 { 00236 return (char *)(str2 - 1); 00237 } 00238 00239 00240 /********************************************************************* 00241 * _strinc (CRTDLL.@) 00242 */ 00243 char *_strinc(const char *str) 00244 { 00245 return (char *)(str + 1); 00246 } 00247 00248 00249 /********************************************************************* 00250 * _strncnt (CRTDLL.@) 00251 */ 00252 size_t _strncnt(const char *str, size_t maxlen) 00253 { 00254 size_t len = strlen(str); 00255 return (len > maxlen) ? maxlen : len; 00256 } 00257 00258 00259 /********************************************************************* 00260 * _strnextc (CRTDLL.@) 00261 */ 00262 unsigned int _strnextc(const char *str) 00263 { 00264 return (unsigned int)str[0]; 00265 } 00266 00267 00268 /********************************************************************* 00269 * _strninc (CRTDLL.@) 00270 */ 00271 char *_strninc(const char *str, size_t len) 00272 { 00273 return (char *)(str + len); 00274 } 00275 00276 00277 /********************************************************************* 00278 * _strspnp (CRTDLL.@) 00279 */ 00280 char *_strspnp( const char *str1, const char *str2) 00281 { 00282 str1 += strspn( str1, str2 ); 00283 return *str1 ? (char*)str1 : NULL; 00284 } 00285 00286 /* EOF */ Generated on Sun May 27 2012 04:22:39 for ReactOS by
1.7.6.1
|