4 * Implements C run-time functionality as known from UNIX.
6 * Copyright 1996 Marcus Meissner
7 * Copyright 1996 Jukka Iivonen
26 UINT32 CRTDLL_argc_dll; /* CRTDLL.23 */
27 LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */
28 LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */
29 UINT32 CRTDLL_basemajor_dll; /* CRTDLL.42 */
30 UINT32 CRTDLL_baseminor_dll; /* CRTDLL.43 */
31 UINT32 CRTDLL_baseversion_dll; /* CRTDLL.44 */
32 LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */
33 UINT32 CRTDLL_osmajor_dll; /* CRTDLL.241 */
34 UINT32 CRTDLL_osminor_dll; /* CRTDLL.242 */
35 UINT32 CRTDLL_osver_dll; /* CRTDLL.244 */
36 UINT32 CRTDLL_osversion_dll; /* CRTDLL.245 */
37 UINT32 CRTDLL_winmajor_dll; /* CRTDLL.329 */
38 UINT32 CRTDLL_winminor_dll; /* CRTDLL.330 */
39 UINT32 CRTDLL_winver_dll; /* CRTDLL.331 */
41 typedef VOID (*new_handler_type)(VOID);
43 static new_handler_type new_handler;
45 /*********************************************************************
46 * _GetMainArgs (CRTDLL.022)
49 CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,LPSTR *environ,DWORD flag)
53 int xargc,i,afterlastspace;
56 dprintf_crtdll(stderr,"__GetMainArgs(%p,%p,%p,%ld).\n",
57 argc,argv,environ,flag
59 CRTDLL_acmdln_dll = cmdline = xstrdup( GetCommandLine32A() );
61 version = GetVersion32();
62 CRTDLL_osver_dll = version >> 16;
63 CRTDLL_winminor_dll = version & 0xFF;
64 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
65 CRTDLL_baseversion_dll = version >> 16;
66 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
67 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
68 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
69 CRTDLL_osversion_dll = version & 0xFFFF;
70 CRTDLL_osminor_dll = version & 0xFF;
71 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
73 /* missing threading init */
75 i=0;xargv=NULL;xargc=0;afterlastspace=0;
77 if (cmdline[i]==' ') {
78 xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc));
80 xargv[xargc-1] = xstrdup(cmdline+afterlastspace);
82 while (cmdline[i]==' ')
89 xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc));
91 xargv[xargc-1] = xstrdup(cmdline+afterlastspace);
92 CRTDLL_argc_dll = xargc;
94 CRTDLL_argv_dll = xargv;
97 /* FIXME ... use real environment */
98 *environ = xmalloc(sizeof(LPSTR));
99 CRTDLL_environ_dll = *environ;
100 (*environ)[0] = NULL;
104 typedef void (*_INITTERMFUN)();
106 /*********************************************************************
107 * _initterm (CRTDLL.135)
109 DWORD CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
111 _INITTERMFUN *current;
113 dprintf_crtdll(stddeb,"_initterm(%p,%p)\n",start,end);
115 while (current<end) {
116 if (*current) (*current)();
122 /*********************************************************************
125 void CRTDLL_srand(DWORD seed)
127 /* FIXME: should of course be thread? process? local */
131 /*********************************************************************
132 * fprintf (CRTDLL.373)
134 int CRTDLL_fprintf(DWORD *args)
136 /* FIXME: use args[0] */
137 return vfprintf(stderr,(LPSTR)(args[1]),args+2);
140 /*********************************************************************
141 * printf (CRTDLL.440)
143 int CRTDLL_printf(DWORD *args)
145 return vfprintf(stdout,(LPSTR)(args[0]),args+1);
148 /*********************************************************************
149 * sprintf (CRTDLL.458)
151 int CRTDLL_sprintf(DWORD *args)
153 return vsprintf((LPSTR)(args[0]),(LPSTR)(args[1]),args+2);
156 /*********************************************************************
159 time_t CRTDLL_time(time_t *timeptr)
161 time_t curtime = time(NULL);
168 /*********************************************************************
169 * _isatty (CRTDLL.137)
171 BOOL32 CRTDLL__isatty(DWORD x)
173 dprintf_crtdll(stderr,"CRTDLL__isatty(%ld)\n",x);
177 /*********************************************************************
178 * _write (CRTDLL.332)
180 INT32 CRTDLL__write(DWORD x,LPVOID buf,DWORD len)
183 return write(x,buf,len);
185 dprintf_crtdll(stderr,"CRTDLL__write(%ld,%p,%ld)\n",x,buf,len);
190 /*********************************************************************
193 void CRTDLL_exit(DWORD ret)
195 dprintf_crtdll(stderr,"CRTDLL_exit(%ld)\n",ret);
200 /*********************************************************************
201 * fflush (CRTDLL.365)
203 void CRTDLL_fflush(DWORD x)
205 dprintf_crtdll(stderr,"CRTDLL_fflush(%ld)\n",x);
209 /*********************************************************************
212 LPSTR CRTDLL_gets(LPSTR buf)
214 /* BAD, for the whole WINE process blocks... just done this way to test
215 * windows95's ftp.exe.
221 /*********************************************************************
224 INT32 CRTDLL_abs(INT32 x)
230 /*********************************************************************
233 float CRTDLL_acos(float x)
239 /*********************************************************************
242 float CRTDLL_asin(float x)
248 /*********************************************************************
251 float CRTDLL_atan(float x)
257 /*********************************************************************
260 float CRTDLL_atan2(float x, float y)
266 /*********************************************************************
269 float CRTDLL_atof(LPCSTR x)
275 /*********************************************************************
278 INT32 CRTDLL_atoi(LPCSTR x)
284 /*********************************************************************
287 LONG CRTDLL_atol(LPCSTR x)
293 /*********************************************************************
296 float CRTDLL_cos(float x)
302 /*********************************************************************
305 float CRTDLL_cosh(float x)
311 /*********************************************************************
314 float CRTDLL_exp(float x)
320 /*********************************************************************
323 float CRTDLL_fabs(float x)
329 /*********************************************************************
330 * isalnum (CRTDLL.394)
332 CHAR CRTDLL_isalnum(CHAR x)
338 /*********************************************************************
339 * isalpha (CRTDLL.395)
341 CHAR CRTDLL_isalpha(CHAR x)
347 /*********************************************************************
348 * iscntrl (CRTDLL.396)
350 CHAR CRTDLL_iscntrl(CHAR x)
356 /*********************************************************************
357 * isdigit (CRTDLL.397)
359 CHAR CRTDLL_isdigit(CHAR x)
365 /*********************************************************************
366 * isgraph (CRTDLL.398)
368 CHAR CRTDLL_isgraph(CHAR x)
374 /*********************************************************************
375 * islower (CRTDLL.400)
377 CHAR CRTDLL_islower(CHAR x)
383 /*********************************************************************
384 * isprint (CRTDLL.401)
386 CHAR CRTDLL_isprint(CHAR x)
392 /*********************************************************************
393 * ispunct (CRTDLL.402)
395 CHAR CRTDLL_ispunct(CHAR x)
401 /*********************************************************************
402 * isspace (CRTDLL.403)
404 CHAR CRTDLL_isspace(CHAR x)
410 /*********************************************************************
411 * isupper (CRTDLL.404)
413 CHAR CRTDLL_isupper(CHAR x)
419 /*********************************************************************
420 * isxdigit (CRTDLL.418)
422 CHAR CRTDLL_isxdigit(CHAR x)
428 /*********************************************************************
431 LONG CRTDLL_labs(LONG x)
437 /*********************************************************************
440 float CRTDLL_log(float x)
446 /*********************************************************************
449 float CRTDLL_log10(float x)
455 /*********************************************************************
458 float CRTDLL_pow(float x, float y)
464 /*********************************************************************
473 /*********************************************************************
476 float CRTDLL_sin(float x)
482 /*********************************************************************
485 float CRTDLL_sinh(float x)
491 /*********************************************************************
494 float CRTDLL_sqrt(float x)
500 /*********************************************************************
503 float CRTDLL_tan(float x)
509 /*********************************************************************
512 float CRTDLL_tanh(float x)
518 /*********************************************************************
519 * tolower (CRTDLL.491)
521 CHAR CRTDLL_tolower(CHAR x)
527 /*********************************************************************
528 * toupper (CRTDLL.492)
530 CHAR CRTDLL_toupper(CHAR x)
536 /*********************************************************************
537 * putchar (CRTDLL.442)
539 void CRTDLL_putchar(INT32 x)
545 /*********************************************************************
546 * _mbsicmp (CRTDLL.204)
548 int CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
555 /* FIXME: MBCS handling... */
564 /*********************************************************************
565 * _mbsinc (CRTDLL.205)
567 unsigned char* CRTDLL__mbsinc(unsigned char *x)
574 /*********************************************************************
575 * vsprintf (CRTDLL.500)
577 int CRTDLL_vsprintf(DWORD *args)
579 return vsprintf((char *)args[0],(char *)args[1],args+2);
582 /*********************************************************************
583 * vsprintf (CRTDLL.500) (NTDLL.913)
585 int CRTDLL_sscanf(DWORD *args)
587 return vsscanf((char *)args[0],(char *)args[1],args+2);
591 /*********************************************************************
592 * _mbscpy (CRTDLL.200)
594 unsigned char* CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
600 /*********************************************************************
601 * _mbscat (CRTDLL.197)
603 unsigned char* CRTDLL__mbscat(unsigned char *x,unsigned char *y)
608 /*********************************************************************
609 * _strupr (CRTDLL.300)
611 LPSTR CRTDLL__strupr(LPSTR x)
622 /*********************************************************************
623 * _wcsupr (CRTDLL.328)
625 LPWSTR CRTDLL__wcsupr(LPWSTR x)
636 /*********************************************************************
637 * _wcslwr (CRTDLL.323)
639 LPWSTR CRTDLL__wcslwr(LPWSTR x)
651 /*********************************************************************
652 * malloc (CRTDLL.427)
654 VOID* CRTDLL_malloc(DWORD size)
656 return HeapAlloc(GetProcessHeap(),0,size);
659 /*********************************************************************
662 VOID* CRTDLL_new(DWORD size)
665 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
670 /*********************************************************************
671 * set_new_handler(CRTDLL.003)
673 new_handler_type CRTDLL_set_new_handler(new_handler_type func)
675 new_handler_type old_handler = new_handler;
680 /*********************************************************************
681 * calloc (CRTDLL.350)
683 VOID* CRTDLL_calloc(DWORD size, DWORD count)
685 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
688 /*********************************************************************
689 * realloc (CRTDLL.447)
691 VOID* CRTDLL_realloc( VOID *ptr, DWORD size )
693 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
696 /*********************************************************************
699 VOID CRTDLL_free(LPVOID ptr)
701 HeapFree(GetProcessHeap(),0,ptr);
704 /*********************************************************************
705 * delete (CRTDLL.002)
707 VOID CRTDLL_delete(VOID* ptr)
709 HeapFree(GetProcessHeap(),0,ptr);
712 /*********************************************************************
713 * _strdup (CRTDLL.285)
715 LPSTR CRTDLL__strdup(LPSTR ptr)
717 return HEAP_strdupA(GetProcessHeap(),0,ptr);
720 /*********************************************************************
721 * fclose (CRTDLL.362)
723 DWORD CRTDLL_fclose(LPVOID x)
725 dprintf_crtdll(stdnimp,"fclose(%p)\n",x);
729 /*********************************************************************
730 * setlocale (CRTDLL.453)
732 LPSTR CRTDLL_setlocale(INT32 category,LPCSTR locale)
737 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
738 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
739 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
740 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
741 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
742 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
743 default: categorystr = "UNKNOWN?";break;
745 fprintf(stderr,"CRTDLL.setlocale(%s,%s),stub!\n",categorystr,locale);
749 /*********************************************************************
750 * wcsspn (CRTDLL.516)
752 INT32 CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
759 while (*t) { if (*t==*s) break;t++;}
763 return s-str; /* nr of wchars */
766 /*********************************************************************
767 * wcschr (CRTDLL.504)
769 LPWSTR CRTDLL_wcschr(LPWSTR str,WCHAR xchar)
781 /*********************************************************************
782 * towupper (CRTDLL.494)
784 WCHAR CRTDLL_towupper(WCHAR x)
786 return (WCHAR)toupper((CHAR)x);
789 /*********************************************************************
790 * swprintf (CRTDLL.483)
792 DWORD CRTDLL_swprintf(DWORD *args)
794 return WIN32_wsprintf32W(args);
797 /*********************************************************************
798 * _wcsicoll (CRTDLL.322)
800 DWORD CRTDLL__wcsicoll(LPWSTR a1,LPWSTR a2)
802 /* FIXME: handle collates */
803 return lstrcmpi32W(a1,a2);
806 /*********************************************************************
807 * wcscoll (CRTDLL.506)
809 DWORD CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
811 /* FIXME: handle collates */
812 return lstrcmp32W(a1,a2);
815 /*********************************************************************
816 * wcsstr (CRTDLL.517)
818 LPWSTR CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
826 while (*y && *c && *y==*c) { c++;y++; }
835 /*********************************************************************
836 * wcsrchr (CRTDLL.515)
838 LPWSTR CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
842 s=str+lstrlen32W(str);
851 /*********************************************************************
852 * _setmode (CRTDLL.265)
853 * FIXME: dunno what this is.
856 CRTDLL__setmode(LPVOID x,INT32 y) {
858 fprintf(stdnimp,"CRTDLL._setmode(%p,%d), STUB.\n",x,y);
862 /*********************************************************************
863 * atexit (CRTDLL.345)
866 CRTDLL_atexit(LPVOID x) {
868 fprintf(stdnimp,"CRTDLL.atexit(%p), STUB.\n",x);
869 return 0; /* successful */