4 * Implements C run-time functionality as known from UNIX.
6 * Copyright 1996 Marcus Meissner
7 * Copyright 1996 Jukka Iivonen
27 UINT32 CRTDLL_argc_dll
; /* CRTDLL.23 */
28 LPSTR
*CRTDLL_argv_dll
; /* CRTDLL.24 */
29 LPSTR CRTDLL_acmdln_dll
; /* CRTDLL.38 */
30 UINT32 CRTDLL_basemajor_dll
; /* CRTDLL.42 */
31 UINT32 CRTDLL_baseminor_dll
; /* CRTDLL.43 */
32 UINT32 CRTDLL_baseversion_dll
; /* CRTDLL.44 */
33 LPSTR CRTDLL_environ_dll
; /* CRTDLL.75 */
34 UINT32 CRTDLL_osmajor_dll
; /* CRTDLL.241 */
35 UINT32 CRTDLL_osminor_dll
; /* CRTDLL.242 */
36 UINT32 CRTDLL_osver_dll
; /* CRTDLL.244 */
37 UINT32 CRTDLL_osversion_dll
; /* CRTDLL.245 */
38 UINT32 CRTDLL_winmajor_dll
; /* CRTDLL.329 */
39 UINT32 CRTDLL_winminor_dll
; /* CRTDLL.330 */
40 UINT32 CRTDLL_winver_dll
; /* CRTDLL.331 */
42 typedef VOID (*new_handler_type
)(VOID
);
44 static new_handler_type new_handler
;
46 /*********************************************************************
47 * _GetMainArgs (CRTDLL.022)
50 CRTDLL__GetMainArgs(LPDWORD argc
,LPSTR
**argv
,LPSTR
*environ
,DWORD flag
)
54 int xargc
,i
,afterlastspace
;
57 dprintf_crtdll(stderr
,"__GetMainArgs(%p,%p,%p,%ld).\n",
58 argc
,argv
,environ
,flag
60 CRTDLL_acmdln_dll
= cmdline
= xstrdup( GetCommandLine32A() );
62 version
= GetVersion32();
63 CRTDLL_osver_dll
= version
>> 16;
64 CRTDLL_winminor_dll
= version
& 0xFF;
65 CRTDLL_winmajor_dll
= (version
>>8) & 0xFF;
66 CRTDLL_baseversion_dll
= version
>> 16;
67 CRTDLL_winver_dll
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
68 CRTDLL_baseminor_dll
= (version
>> 16) & 0xFF;
69 CRTDLL_basemajor_dll
= (version
>> 24) & 0xFF;
70 CRTDLL_osversion_dll
= version
& 0xFFFF;
71 CRTDLL_osminor_dll
= version
& 0xFF;
72 CRTDLL_osmajor_dll
= (version
>>8) & 0xFF;
74 /* missing threading init */
76 i
=0;xargv
=NULL
;xargc
=0;afterlastspace
=0;
78 if (cmdline
[i
]==' ') {
79 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
81 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
83 while (cmdline
[i
]==' ')
90 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
92 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
93 CRTDLL_argc_dll
= xargc
;
95 CRTDLL_argv_dll
= xargv
;
98 /* FIXME ... use real environment */
99 *environ
= xmalloc(sizeof(LPSTR
));
100 CRTDLL_environ_dll
= *environ
;
101 (*environ
)[0] = NULL
;
105 typedef void (*_INITTERMFUN
)();
107 /*********************************************************************
108 * _initterm (CRTDLL.135)
110 DWORD
CRTDLL__initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
112 _INITTERMFUN
*current
;
114 dprintf_crtdll(stddeb
,"_initterm(%p,%p)\n",start
,end
);
116 while (current
<end
) {
117 if (*current
) (*current
)();
123 /*********************************************************************
126 void CRTDLL_srand(DWORD seed
)
128 /* FIXME: should of course be thread? process? local */
132 /*********************************************************************
133 * fprintf (CRTDLL.373)
135 int CRTDLL_fprintf(DWORD
*args
)
137 /* FIXME: use args[0] */
138 return vfprintf(stderr
,(LPSTR
)(args
[1]),args
+2);
141 /*********************************************************************
142 * printf (CRTDLL.440)
144 int CRTDLL_printf(DWORD
*args
)
146 return vfprintf(stdout
,(LPSTR
)(args
[0]),args
+1);
149 /*********************************************************************
150 * sprintf (CRTDLL.458)
152 int CRTDLL_sprintf(DWORD
*args
)
154 return vsprintf((LPSTR
)(args
[0]),(LPSTR
)(args
[1]),args
+2);
157 /*********************************************************************
160 time_t CRTDLL_time(time_t *timeptr
)
162 time_t curtime
= time(NULL
);
169 /*********************************************************************
170 * _isatty (CRTDLL.137)
172 BOOL32
CRTDLL__isatty(DWORD x
)
174 dprintf_crtdll(stderr
,"CRTDLL__isatty(%ld)\n",x
);
178 /*********************************************************************
179 * _write (CRTDLL.332)
181 INT32
CRTDLL__write(DWORD x
,LPVOID buf
,DWORD len
)
184 return write(x
,buf
,len
);
186 dprintf_crtdll(stderr
,"CRTDLL__write(%ld,%p,%ld)\n",x
,buf
,len
);
191 /*********************************************************************
194 void CRTDLL_exit(DWORD ret
)
196 dprintf_crtdll(stderr
,"CRTDLL_exit(%ld)\n",ret
);
201 /*********************************************************************
202 * fflush (CRTDLL.365)
204 void CRTDLL_fflush(DWORD x
)
206 dprintf_crtdll(stderr
,"CRTDLL_fflush(%ld)\n",x
);
210 /*********************************************************************
213 LPSTR
CRTDLL_gets(LPSTR buf
)
215 /* BAD, for the whole WINE process blocks... just done this way to test
216 * windows95's ftp.exe.
222 /*********************************************************************
225 INT32
CRTDLL_abs(INT32 x
)
231 /*********************************************************************
234 float CRTDLL_acos(float x
)
240 /*********************************************************************
243 float CRTDLL_asin(float x
)
249 /*********************************************************************
252 float CRTDLL_atan(float x
)
258 /*********************************************************************
261 float CRTDLL_atan2(float x
, float y
)
267 /*********************************************************************
270 float CRTDLL_atof(LPCSTR x
)
276 /*********************************************************************
279 INT32
CRTDLL_atoi(LPCSTR x
)
285 /*********************************************************************
288 LONG
CRTDLL_atol(LPCSTR x
)
294 /*********************************************************************
297 float CRTDLL_cos(float x
)
303 /*********************************************************************
306 float CRTDLL_cosh(float x
)
312 /*********************************************************************
315 float CRTDLL_exp(float x
)
321 /*********************************************************************
324 float CRTDLL_fabs(float x
)
330 /*********************************************************************
331 * isalnum (CRTDLL.394)
333 CHAR
CRTDLL_isalnum(CHAR x
)
339 /*********************************************************************
340 * isalpha (CRTDLL.395)
342 CHAR
CRTDLL_isalpha(CHAR x
)
348 /*********************************************************************
349 * iscntrl (CRTDLL.396)
351 CHAR
CRTDLL_iscntrl(CHAR x
)
357 /*********************************************************************
358 * isdigit (CRTDLL.397)
360 CHAR
CRTDLL_isdigit(CHAR x
)
366 /*********************************************************************
367 * isgraph (CRTDLL.398)
369 CHAR
CRTDLL_isgraph(CHAR x
)
375 /*********************************************************************
376 * islower (CRTDLL.400)
378 CHAR
CRTDLL_islower(CHAR x
)
384 /*********************************************************************
385 * isprint (CRTDLL.401)
387 CHAR
CRTDLL_isprint(CHAR x
)
393 /*********************************************************************
394 * ispunct (CRTDLL.402)
396 CHAR
CRTDLL_ispunct(CHAR x
)
402 /*********************************************************************
403 * isspace (CRTDLL.403)
405 CHAR
CRTDLL_isspace(CHAR x
)
411 /*********************************************************************
412 * isupper (CRTDLL.404)
414 CHAR
CRTDLL_isupper(CHAR x
)
420 /*********************************************************************
421 * isxdigit (CRTDLL.418)
423 CHAR
CRTDLL_isxdigit(CHAR x
)
429 /*********************************************************************
432 LONG
CRTDLL_labs(LONG x
)
438 /*********************************************************************
441 float CRTDLL_log(float x
)
447 /*********************************************************************
450 float CRTDLL_log10(float x
)
456 /*********************************************************************
459 float CRTDLL_pow(float x
, float y
)
465 /*********************************************************************
474 /*********************************************************************
477 float CRTDLL_sin(float x
)
483 /*********************************************************************
486 float CRTDLL_sinh(float x
)
492 /*********************************************************************
495 float CRTDLL_sqrt(float x
)
501 /*********************************************************************
504 float CRTDLL_tan(float x
)
510 /*********************************************************************
513 float CRTDLL_tanh(float x
)
519 /*********************************************************************
520 * tolower (CRTDLL.491)
522 CHAR
CRTDLL_tolower(CHAR x
)
528 /*********************************************************************
529 * toupper (CRTDLL.492)
531 CHAR
CRTDLL_toupper(CHAR x
)
537 /*********************************************************************
538 * putchar (CRTDLL.442)
540 void CRTDLL_putchar(INT32 x
)
546 /*********************************************************************
547 * _mbsicmp (CRTDLL.204)
549 int CRTDLL__mbsicmp(unsigned char *x
,unsigned char *y
)
556 /* FIXME: MBCS handling... */
565 /*********************************************************************
566 * _mbsinc (CRTDLL.205)
568 unsigned char* CRTDLL__mbsinc(unsigned char *x
)
575 /*********************************************************************
576 * vsprintf (CRTDLL.500)
578 int CRTDLL_vsprintf(DWORD
*args
)
580 return vsprintf((char *)args
[0],(char *)args
[1],args
+2);
583 /*********************************************************************
584 * vsprintf (CRTDLL.500) (NTDLL.913)
586 int CRTDLL_sscanf(DWORD
*args
)
588 return vsscanf((char *)args
[0],(char *)args
[1],args
+2);
592 /*********************************************************************
593 * _mbscpy (CRTDLL.200)
595 unsigned char* CRTDLL__mbscpy(unsigned char *x
,unsigned char *y
)
601 /*********************************************************************
602 * _mbscat (CRTDLL.197)
604 unsigned char* CRTDLL__mbscat(unsigned char *x
,unsigned char *y
)
609 /*********************************************************************
610 * _strupr (CRTDLL.300)
612 LPSTR
CRTDLL__strupr(LPSTR x
)
623 /*********************************************************************
624 * _wcsupr (CRTDLL.328)
626 LPWSTR
CRTDLL__wcsupr(LPWSTR x
)
637 /*********************************************************************
638 * _wcslwr (CRTDLL.323)
640 LPWSTR
CRTDLL__wcslwr(LPWSTR x
)
652 /*********************************************************************
653 * malloc (CRTDLL.427)
655 VOID
* CRTDLL_malloc(DWORD size
)
657 return HeapAlloc(GetProcessHeap(),0,size
);
660 /*********************************************************************
663 VOID
* CRTDLL_new(DWORD size
)
666 if(!(result
= HeapAlloc(GetProcessHeap(),0,size
)) && new_handler
)
671 /*********************************************************************
672 * set_new_handler(CRTDLL.003)
674 new_handler_type
CRTDLL_set_new_handler(new_handler_type func
)
676 new_handler_type old_handler
= new_handler
;
681 /*********************************************************************
682 * calloc (CRTDLL.350)
684 VOID
* CRTDLL_calloc(DWORD size
, DWORD count
)
686 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
* count
);
689 /*********************************************************************
690 * realloc (CRTDLL.447)
692 VOID
* CRTDLL_realloc( VOID
*ptr
, DWORD size
)
694 return HeapReAlloc( GetProcessHeap(), 0, ptr
, size
);
697 /*********************************************************************
700 VOID
CRTDLL_free(LPVOID ptr
)
702 HeapFree(GetProcessHeap(),0,ptr
);
705 /*********************************************************************
706 * delete (CRTDLL.002)
708 VOID
CRTDLL_delete(VOID
* ptr
)
710 HeapFree(GetProcessHeap(),0,ptr
);
713 /*********************************************************************
714 * _strdup (CRTDLL.285)
716 LPSTR
CRTDLL__strdup(LPSTR ptr
)
718 return HEAP_strdupA(GetProcessHeap(),0,ptr
);
721 /*********************************************************************
722 * fclose (CRTDLL.362)
724 DWORD
CRTDLL_fclose(LPVOID x
)
726 dprintf_crtdll(stdnimp
,"fclose(%p)\n",x
);
730 /*********************************************************************
731 * setlocale (CRTDLL.453)
733 LPSTR
CRTDLL_setlocale(INT32 category
,LPCSTR locale
)
738 case CRTDLL_LC_ALL
: categorystr
="LC_ALL";break;
739 case CRTDLL_LC_COLLATE
: categorystr
="LC_COLLATE";break;
740 case CRTDLL_LC_CTYPE
: categorystr
="LC_CTYPE";break;
741 case CRTDLL_LC_MONETARY
: categorystr
="LC_MONETARY";break;
742 case CRTDLL_LC_NUMERIC
: categorystr
="LC_NUMERIC";break;
743 case CRTDLL_LC_TIME
: categorystr
="LC_TIME";break;
744 default: categorystr
= "UNKNOWN?";break;
746 fprintf(stderr
,"CRTDLL.setlocale(%s,%s),stub!\n",categorystr
,locale
);
750 /*********************************************************************
751 * wcsspn (CRTDLL.516)
753 INT32
CRTDLL_wcsspn(LPWSTR str
,LPWSTR accept
)
760 while (*t
) { if (*t
==*s
) break;t
++;}
764 return s
-str
; /* nr of wchars */
767 /*********************************************************************
768 * wcscspn (CRTDLL.508)
770 INT32
CRTDLL_wcscspn(LPWSTR str
,LPWSTR reject
)
777 while (*t
) { if (*t
==*s
) break;t
++;}
781 return s
-str
; /* nr of wchars */
784 /*********************************************************************
785 * wcschr (CRTDLL.504)
787 LPWSTR
CRTDLL_wcschr(LPWSTR str
,WCHAR xchar
)
799 /*********************************************************************
800 * towupper (CRTDLL.494)
802 WCHAR
CRTDLL_towupper(WCHAR x
)
804 return (WCHAR
)toupper((CHAR
)x
);
807 /*********************************************************************
808 * swprintf (CRTDLL.483)
810 DWORD
CRTDLL_swprintf(DWORD
*args
)
812 return WIN32_wsprintf32W(args
);
815 /*********************************************************************
816 * _wcsicoll (CRTDLL.322)
818 DWORD
CRTDLL__wcsicoll(LPWSTR a1
,LPWSTR a2
)
820 /* FIXME: handle collates */
821 return lstrcmpi32W(a1
,a2
);
824 /*********************************************************************
825 * wcscoll (CRTDLL.506)
827 DWORD
CRTDLL_wcscoll(LPWSTR a1
,LPWSTR a2
)
829 /* FIXME: handle collates */
830 return lstrcmp32W(a1
,a2
);
833 /*********************************************************************
834 * _wcsrev (CRTDLL.326)
836 VOID
CRTDLL__wcsrev(LPWSTR s
) {
850 /*********************************************************************
851 * wcsstr (CRTDLL.517)
853 LPWSTR
CRTDLL_wcsstr(LPWSTR s
,LPWSTR b
)
861 while (*y
&& *c
&& *y
==*c
) { c
++;y
++; }
870 /*********************************************************************
871 * wcsrchr (CRTDLL.515)
873 LPWSTR
CRTDLL_wcsrchr(LPWSTR str
,WCHAR xchar
)
877 s
=str
+lstrlen32W(str
);
886 /*********************************************************************
887 * _setmode (CRTDLL.265)
888 * FIXME: dunno what this is.
891 CRTDLL__setmode(LPVOID x
,INT32 y
) {
893 fprintf(stdnimp
,"CRTDLL._setmode(%p,%d), STUB.\n",x
,y
);
897 /*********************************************************************
898 * atexit (CRTDLL.345)
901 CRTDLL_atexit(LPVOID x
) {
903 fprintf(stdnimp
,"CRTDLL.atexit(%p), STUB.\n",x
);
904 return 0; /* successful */
907 /*********************************************************************
908 * mbtowc (CRTDLL.430)
909 * FIXME: check multibyte support
912 CRTDLL_mbtowc(CHAR a
) {
916 /*********************************************************************
917 * _isctype (CRTDLL.138)
920 CRTDLL__isctype(CHAR x
,CHAR type
) {
921 if ((type
& CRTDLL_SPACE
) && isspace(x
))
923 if ((type
& CRTDLL_PUNCT
) && ispunct(x
))
925 if ((type
& CRTDLL_LOWER
) && islower(x
))
927 if ((type
& CRTDLL_UPPER
) && isupper(x
))
929 if ((type
& CRTDLL_ALPHA
) && isalpha(x
))
931 if ((type
& CRTDLL_DIGIT
) && isdigit(x
))
933 if ((type
& CRTDLL_CONTROL
) && iscntrl(x
))
935 /* check CRTDLL_LEADBYTE */
939 /*********************************************************************
940 * _chdrive (CRTDLL.52)
943 CRTDLL__chdrive(INT32 newdrive
) {
944 /* FIXME: generates errnos */
945 return DRIVE_SetCurrentDrive(newdrive
);
948 /*********************************************************************
950 * Yes, this is a function.
954 static int crtdllerrno
;
955 extern int LastErrorToErrno(DWORD
);
957 /* FIXME: we should set the error at the failing function call time */
958 crtdllerrno
= LastErrorToErrno(GetLastError());