/* * The C RunTime DLL * * Implements C run-time functionality as known from UNIX. * * Copyright 1996 Marcus Meissner * Copyright 1996 Jukka Iivonen */ #include #include #include #include #include #include #include #include #include "win.h" #include "windows.h" #include "stddebug.h" #include "debug.h" #include "module.h" #include "xmalloc.h" #include "heap.h" #include "crtdll.h" #include "drive.h" extern INT32 WIN32_wsprintf32W( DWORD *args ); UINT32 CRTDLL_argc_dll; /* CRTDLL.23 */ LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */ LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */ UINT32 CRTDLL_basemajor_dll; /* CRTDLL.42 */ UINT32 CRTDLL_baseminor_dll; /* CRTDLL.43 */ UINT32 CRTDLL_baseversion_dll; /* CRTDLL.44 */ LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */ UINT32 CRTDLL_osmajor_dll; /* CRTDLL.241 */ UINT32 CRTDLL_osminor_dll; /* CRTDLL.242 */ UINT32 CRTDLL_osver_dll; /* CRTDLL.244 */ UINT32 CRTDLL_osversion_dll; /* CRTDLL.245 */ UINT32 CRTDLL_winmajor_dll; /* CRTDLL.329 */ UINT32 CRTDLL_winminor_dll; /* CRTDLL.330 */ UINT32 CRTDLL_winver_dll; /* CRTDLL.331 */ typedef VOID (*new_handler_type)(VOID); static new_handler_type new_handler; /********************************************************************* * _GetMainArgs (CRTDLL.022) */ DWORD CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,LPSTR *environ,DWORD flag) { char *cmdline; char **xargv; int xargc,i,afterlastspace; DWORD version; dprintf_crtdll(stderr,"__GetMainArgs(%p,%p,%p,%ld).\n", argc,argv,environ,flag ); CRTDLL_acmdln_dll = cmdline = xstrdup( GetCommandLine32A() ); version = GetVersion32(); CRTDLL_osver_dll = version >> 16; CRTDLL_winminor_dll = version & 0xFF; CRTDLL_winmajor_dll = (version>>8) & 0xFF; CRTDLL_baseversion_dll = version >> 16; CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8); CRTDLL_baseminor_dll = (version >> 16) & 0xFF; CRTDLL_basemajor_dll = (version >> 24) & 0xFF; CRTDLL_osversion_dll = version & 0xFFFF; CRTDLL_osminor_dll = version & 0xFF; CRTDLL_osmajor_dll = (version>>8) & 0xFF; /* missing threading init */ i=0;xargv=NULL;xargc=0;afterlastspace=0; while (cmdline[i]) { if (cmdline[i]==' ') { xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc)); cmdline[i]='\0'; xargv[xargc-1] = xstrdup(cmdline+afterlastspace); i++; while (cmdline[i]==' ') i++; if (cmdline[i]) afterlastspace=i; } else i++; } xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc)); cmdline[i]='\0'; xargv[xargc-1] = xstrdup(cmdline+afterlastspace); CRTDLL_argc_dll = xargc; *argc = xargc; CRTDLL_argv_dll = xargv; *argv = xargv; /* FIXME ... use real environment */ *environ = xmalloc(sizeof(LPSTR)); CRTDLL_environ_dll = *environ; (*environ)[0] = NULL; return 0; } typedef void (*_INITTERMFUN)(); /********************************************************************* * _initterm (CRTDLL.135) */ DWORD CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end) { _INITTERMFUN *current; dprintf_crtdll(stddeb,"_initterm(%p,%p)\n",start,end); current=start; while (current=str); return NULL; } /********************************************************************* * _setmode (CRTDLL.265) * FIXME: dunno what this is. */ DWORD CRTDLL__setmode(LPVOID x,INT32 y) { /* FIXME */ fprintf(stdnimp,"CRTDLL._setmode(%p,%d), STUB.\n",x,y); return 0; } /********************************************************************* * atexit (CRTDLL.345) */ INT32 CRTDLL_atexit(LPVOID x) { /* FIXME */ fprintf(stdnimp,"CRTDLL.atexit(%p), STUB.\n",x); return 0; /* successful */ } /********************************************************************* * mbtowc (CRTDLL.430) * FIXME: check multibyte support */ WCHAR CRTDLL_mbtowc(CHAR a) { return a; } /********************************************************************* * _isctype (CRTDLL.138) */ BOOL32 CRTDLL__isctype(CHAR x,CHAR type) { if ((type & CRTDLL_SPACE) && isspace(x)) return TRUE; if ((type & CRTDLL_PUNCT) && ispunct(x)) return TRUE; if ((type & CRTDLL_LOWER) && islower(x)) return TRUE; if ((type & CRTDLL_UPPER) && isupper(x)) return TRUE; if ((type & CRTDLL_ALPHA) && isalpha(x)) return TRUE; if ((type & CRTDLL_DIGIT) && isdigit(x)) return TRUE; if ((type & CRTDLL_CONTROL) && iscntrl(x)) return TRUE; /* check CRTDLL_LEADBYTE */ return FALSE; } /********************************************************************* * _chdrive (CRTDLL.52) */ BOOL32 CRTDLL__chdrive(INT32 newdrive) { /* FIXME: generates errnos */ return DRIVE_SetCurrentDrive(newdrive); } /********************************************************************* * _chdir (CRTDLL.51) */ INT32 CRTDLL__chdir(LPCSTR newdir) { if (!SetCurrentDirectory32A(newdir)) return -1; return 0; } /********************************************************************* * _mkdir (CRTDLL.234) */ INT32 CRTDLL__mkdir(LPCSTR newdir) { if (!CreateDirectory32A(newdir,NULL)) return -1; return 0; } /********************************************************************* * _errno (CRTDLL.52) * Yes, this is a function. */ LPINT32 CRTDLL__errno() { static int crtdllerrno; extern int LastErrorToErrno(DWORD); /* FIXME: we should set the error at the failing function call time */ crtdllerrno = LastErrorToErrno(GetLastError()); return &crtdllerrno; }