4 * Implements C run-time functionality as known from UNIX.
6 * Copyright 1996 Marcus Meissner
7 * Copyright 1996 Jukka Iivonen
28 UINT32 CRTDLL_argc_dll
; /* CRTDLL.23 */
29 LPSTR
*CRTDLL_argv_dll
; /* CRTDLL.24 */
30 LPSTR CRTDLL_acmdln_dll
; /* CRTDLL.38 */
31 UINT32 CRTDLL_basemajor_dll
; /* CRTDLL.42 */
32 UINT32 CRTDLL_baseminor_dll
; /* CRTDLL.43 */
33 UINT32 CRTDLL_baseversion_dll
; /* CRTDLL.44 */
34 LPSTR CRTDLL_environ_dll
; /* CRTDLL.75 */
35 UINT32 CRTDLL_osmajor_dll
; /* CRTDLL.241 */
36 UINT32 CRTDLL_osminor_dll
; /* CRTDLL.242 */
37 UINT32 CRTDLL_osver_dll
; /* CRTDLL.244 */
38 UINT32 CRTDLL_osversion_dll
; /* CRTDLL.245 */
39 UINT32 CRTDLL_winmajor_dll
; /* CRTDLL.329 */
40 UINT32 CRTDLL_winminor_dll
; /* CRTDLL.330 */
41 UINT32 CRTDLL_winver_dll
; /* CRTDLL.331 */
43 typedef VOID (*new_handler_type
)(VOID
);
45 static new_handler_type new_handler
;
47 /*********************************************************************
48 * _GetMainArgs (CRTDLL.022)
51 CRTDLL__GetMainArgs(LPDWORD argc
,LPSTR
**argv
,LPSTR
*environ
,DWORD flag
)
55 int xargc
,i
,afterlastspace
;
58 dprintf_crtdll(stderr
,"__GetMainArgs(%p,%p,%p,%ld).\n",
59 argc
,argv
,environ
,flag
61 CRTDLL_acmdln_dll
= cmdline
= xstrdup( GetCommandLine32A() );
63 version
= GetVersion32();
64 CRTDLL_osver_dll
= version
>> 16;
65 CRTDLL_winminor_dll
= version
& 0xFF;
66 CRTDLL_winmajor_dll
= (version
>>8) & 0xFF;
67 CRTDLL_baseversion_dll
= version
>> 16;
68 CRTDLL_winver_dll
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
69 CRTDLL_baseminor_dll
= (version
>> 16) & 0xFF;
70 CRTDLL_basemajor_dll
= (version
>> 24) & 0xFF;
71 CRTDLL_osversion_dll
= version
& 0xFFFF;
72 CRTDLL_osminor_dll
= version
& 0xFF;
73 CRTDLL_osmajor_dll
= (version
>>8) & 0xFF;
75 /* missing threading init */
77 i
=0;xargv
=NULL
;xargc
=0;afterlastspace
=0;
79 if (cmdline
[i
]==' ') {
80 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
82 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
84 while (cmdline
[i
]==' ')
91 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
93 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
94 CRTDLL_argc_dll
= xargc
;
96 CRTDLL_argv_dll
= xargv
;
99 /* FIXME ... use real environment */
100 *environ
= xmalloc(sizeof(LPSTR
));
101 CRTDLL_environ_dll
= *environ
;
102 (*environ
)[0] = NULL
;
106 typedef void (*_INITTERMFUN
)();
108 /*********************************************************************
109 * _initterm (CRTDLL.135)
111 DWORD
CRTDLL__initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
113 _INITTERMFUN
*current
;
115 dprintf_crtdll(stddeb
,"_initterm(%p,%p)\n",start
,end
);
117 while (current
<end
) {
118 if (*current
) (*current
)();
124 /*********************************************************************
127 void CRTDLL_srand(DWORD seed
)
129 /* FIXME: should of course be thread? process? local */
133 /*********************************************************************
134 * fprintf (CRTDLL.373)
136 int CRTDLL_fprintf(DWORD
*args
)
138 /* FIXME: use args[0] */
139 /* CMF - This makes a BIG assumption about va_list */
140 return vfprintf(stderr
, (LPSTR
) args
[1], (va_list) &args
[2]);
143 /*********************************************************************
144 * printf (CRTDLL.440)
146 int CRTDLL_printf(DWORD
*args
)
148 /* CMF - This makes a BIG assumption about va_list */
149 return vfprintf(stdout
, (LPSTR
) args
[0], (va_list) &args
[1]);
152 /*********************************************************************
153 * sprintf (CRTDLL.458)
155 int CRTDLL_sprintf(DWORD
*args
)
157 /* CMF - This makes a BIG assumption about va_list */
158 return vsprintf((LPSTR
) args
[0], (LPSTR
) args
[1], (va_list) &args
[2]);
161 /*********************************************************************
164 time_t CRTDLL_time(time_t *timeptr
)
166 time_t curtime
= time(NULL
);
173 /*********************************************************************
174 * _isatty (CRTDLL.137)
176 BOOL32
CRTDLL__isatty(DWORD x
)
178 dprintf_crtdll(stderr
,"CRTDLL__isatty(%ld)\n",x
);
182 /*********************************************************************
183 * _write (CRTDLL.332)
185 INT32
CRTDLL__write(DWORD x
,LPVOID buf
,DWORD len
)
188 return write(x
,buf
,len
);
190 dprintf_crtdll(stderr
,"CRTDLL__write(%ld,%p,%ld)\n",x
,buf
,len
);
195 /*********************************************************************
198 void CRTDLL_exit(DWORD ret
)
200 dprintf_crtdll(stderr
,"CRTDLL_exit(%ld)\n",ret
);
205 /*********************************************************************
206 * fflush (CRTDLL.365)
208 void CRTDLL_fflush(DWORD x
)
210 dprintf_crtdll(stderr
,"CRTDLL_fflush(%ld)\n",x
);
214 /*********************************************************************
217 LPSTR
CRTDLL_gets(LPSTR buf
)
219 /* BAD, for the whole WINE process blocks... just done this way to test
220 * windows95's ftp.exe.
226 /*********************************************************************
229 INT32
CRTDLL_abs(INT32 x
)
235 /*********************************************************************
238 float CRTDLL_acos(float x
)
244 /*********************************************************************
247 float CRTDLL_asin(float x
)
253 /*********************************************************************
256 float CRTDLL_atan(float x
)
262 /*********************************************************************
265 float CRTDLL_atan2(float x
, float y
)
271 /*********************************************************************
274 float CRTDLL_atof(LPCSTR x
)
280 /*********************************************************************
283 INT32
CRTDLL_atoi(LPCSTR x
)
289 /*********************************************************************
292 LONG
CRTDLL_atol(LPCSTR x
)
298 /*********************************************************************
301 float CRTDLL_cos(float x
)
307 /*********************************************************************
310 float CRTDLL_cosh(float x
)
316 /*********************************************************************
319 float CRTDLL_exp(float x
)
325 /*********************************************************************
328 float CRTDLL_fabs(float x
)
334 /*********************************************************************
335 * isalnum (CRTDLL.394)
337 CHAR
CRTDLL_isalnum(CHAR x
)
343 /*********************************************************************
344 * isalpha (CRTDLL.395)
346 CHAR
CRTDLL_isalpha(CHAR x
)
352 /*********************************************************************
353 * iscntrl (CRTDLL.396)
355 CHAR
CRTDLL_iscntrl(CHAR x
)
361 /*********************************************************************
362 * isdigit (CRTDLL.397)
364 CHAR
CRTDLL_isdigit(CHAR x
)
370 /*********************************************************************
371 * isgraph (CRTDLL.398)
373 CHAR
CRTDLL_isgraph(CHAR x
)
379 /*********************************************************************
380 * islower (CRTDLL.400)
382 CHAR
CRTDLL_islower(CHAR x
)
388 /*********************************************************************
389 * isprint (CRTDLL.401)
391 CHAR
CRTDLL_isprint(CHAR x
)
397 /*********************************************************************
398 * ispunct (CRTDLL.402)
400 CHAR
CRTDLL_ispunct(CHAR x
)
406 /*********************************************************************
407 * isspace (CRTDLL.403)
409 CHAR
CRTDLL_isspace(CHAR x
)
415 /*********************************************************************
416 * isupper (CRTDLL.404)
418 CHAR
CRTDLL_isupper(CHAR x
)
424 /*********************************************************************
425 * isxdigit (CRTDLL.418)
427 CHAR
CRTDLL_isxdigit(CHAR x
)
433 /*********************************************************************
436 LONG
CRTDLL_labs(LONG x
)
442 /*********************************************************************
445 float CRTDLL_log(float x
)
451 /*********************************************************************
454 float CRTDLL_log10(float x
)
460 /*********************************************************************
463 float CRTDLL_pow(float x
, float y
)
469 /*********************************************************************
478 /*********************************************************************
481 float CRTDLL_sin(float x
)
487 /*********************************************************************
490 float CRTDLL_sinh(float x
)
496 /*********************************************************************
499 float CRTDLL_sqrt(float x
)
505 /*********************************************************************
508 float CRTDLL_tan(float x
)
514 /*********************************************************************
517 float CRTDLL_tanh(float x
)
523 /*********************************************************************
524 * tolower (CRTDLL.491)
526 CHAR
CRTDLL_tolower(CHAR x
)
532 /*********************************************************************
533 * toupper (CRTDLL.492)
535 CHAR
CRTDLL_toupper(CHAR x
)
541 /*********************************************************************
542 * putchar (CRTDLL.442)
544 void CRTDLL_putchar(INT32 x
)
550 /*********************************************************************
551 * _mbsicmp (CRTDLL.204)
553 int CRTDLL__mbsicmp(unsigned char *x
,unsigned char *y
)
560 /* FIXME: MBCS handling... */
569 /*********************************************************************
570 * _mbsinc (CRTDLL.205)
572 unsigned char* CRTDLL__mbsinc(unsigned char *x
)
579 /*********************************************************************
580 * vsprintf (CRTDLL.500)
582 int CRTDLL_vsprintf(DWORD
*args
)
584 /* CMF - This makes a BIG assumption about va_list */
585 return vsprintf((char *) args
[0], (char *) args
[1], (va_list) &args
[2]);
588 /*********************************************************************
589 * vsprintf (CRTDLL.500) (NTDLL.913)
591 int CRTDLL_sscanf(DWORD
*args
)
593 /* CMF - This makes a BIG assumption about va_list */
594 return vsscanf((char *) args
[0], (char *) args
[1], (va_list) &args
[2]);
598 /*********************************************************************
599 * _mbscpy (CRTDLL.200)
601 unsigned char* CRTDLL__mbscpy(unsigned char *x
,unsigned char *y
)
607 /*********************************************************************
608 * _mbscat (CRTDLL.197)
610 unsigned char* CRTDLL__mbscat(unsigned char *x
,unsigned char *y
)
615 /*********************************************************************
616 * _strupr (CRTDLL.300)
618 LPSTR
CRTDLL__strupr(LPSTR x
)
629 /*********************************************************************
630 * _wcsupr (CRTDLL.328)
632 LPWSTR
CRTDLL__wcsupr(LPWSTR x
)
643 /*********************************************************************
644 * _wcslwr (CRTDLL.323)
646 LPWSTR
CRTDLL__wcslwr(LPWSTR x
)
658 /*********************************************************************
659 * malloc (CRTDLL.427)
661 VOID
* CRTDLL_malloc(DWORD size
)
663 return HeapAlloc(GetProcessHeap(),0,size
);
666 /*********************************************************************
669 VOID
* CRTDLL_new(DWORD size
)
672 if(!(result
= HeapAlloc(GetProcessHeap(),0,size
)) && new_handler
)
677 /*********************************************************************
678 * set_new_handler(CRTDLL.003)
680 new_handler_type
CRTDLL_set_new_handler(new_handler_type func
)
682 new_handler_type old_handler
= new_handler
;
687 /*********************************************************************
688 * calloc (CRTDLL.350)
690 VOID
* CRTDLL_calloc(DWORD size
, DWORD count
)
692 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
* count
);
695 /*********************************************************************
696 * realloc (CRTDLL.447)
698 VOID
* CRTDLL_realloc( VOID
*ptr
, DWORD size
)
700 return HeapReAlloc( GetProcessHeap(), 0, ptr
, size
);
703 /*********************************************************************
706 VOID
CRTDLL_free(LPVOID ptr
)
708 HeapFree(GetProcessHeap(),0,ptr
);
711 /*********************************************************************
712 * delete (CRTDLL.002)
714 VOID
CRTDLL_delete(VOID
* ptr
)
716 HeapFree(GetProcessHeap(),0,ptr
);
719 /*********************************************************************
720 * _strdup (CRTDLL.285)
722 LPSTR
CRTDLL__strdup(LPSTR ptr
)
724 return HEAP_strdupA(GetProcessHeap(),0,ptr
);
727 /*********************************************************************
728 * fclose (CRTDLL.362)
730 DWORD
CRTDLL_fclose(LPVOID x
)
732 dprintf_crtdll(stdnimp
,"fclose(%p)\n",x
);
736 /*********************************************************************
737 * setlocale (CRTDLL.453)
739 LPSTR
CRTDLL_setlocale(INT32 category
,LPCSTR locale
)
744 case CRTDLL_LC_ALL
: categorystr
="LC_ALL";break;
745 case CRTDLL_LC_COLLATE
: categorystr
="LC_COLLATE";break;
746 case CRTDLL_LC_CTYPE
: categorystr
="LC_CTYPE";break;
747 case CRTDLL_LC_MONETARY
: categorystr
="LC_MONETARY";break;
748 case CRTDLL_LC_NUMERIC
: categorystr
="LC_NUMERIC";break;
749 case CRTDLL_LC_TIME
: categorystr
="LC_TIME";break;
750 default: categorystr
= "UNKNOWN?";break;
752 fprintf(stderr
,"CRTDLL.setlocale(%s,%s),stub!\n",categorystr
,locale
);
756 /*********************************************************************
757 * wcsspn (CRTDLL.516)
759 INT32
CRTDLL_wcsspn(LPWSTR str
,LPWSTR accept
)
766 while (*t
) { if (*t
==*s
) break;t
++;}
770 return s
-str
; /* nr of wchars */
773 /*********************************************************************
774 * wcscspn (CRTDLL.508)
776 INT32
CRTDLL_wcscspn(LPWSTR str
,LPWSTR reject
)
783 while (*t
) { if (*t
==*s
) break;t
++;}
787 return s
-str
; /* nr of wchars */
790 /*********************************************************************
791 * wcschr (CRTDLL.504)
793 LPWSTR
CRTDLL_wcschr(LPWSTR str
,WCHAR xchar
)
805 /*********************************************************************
806 * towupper (CRTDLL.494)
808 WCHAR
CRTDLL_towupper(WCHAR x
)
810 return (WCHAR
)toupper((CHAR
)x
);
813 /*********************************************************************
814 * swprintf (CRTDLL.483)
816 DWORD
CRTDLL_swprintf(DWORD
*args
)
818 return WIN32_wsprintf32W(args
);
821 /*********************************************************************
822 * _wcsicoll (CRTDLL.322)
824 DWORD
CRTDLL__wcsicoll(LPWSTR a1
,LPWSTR a2
)
826 /* FIXME: handle collates */
827 return lstrcmpi32W(a1
,a2
);
830 /*********************************************************************
831 * wcscoll (CRTDLL.506)
833 DWORD
CRTDLL_wcscoll(LPWSTR a1
,LPWSTR a2
)
835 /* FIXME: handle collates */
836 return lstrcmp32W(a1
,a2
);
839 /*********************************************************************
840 * _wcsrev (CRTDLL.326)
842 VOID
CRTDLL__wcsrev(LPWSTR s
) {
856 /*********************************************************************
857 * wcsstr (CRTDLL.517)
859 LPWSTR
CRTDLL_wcsstr(LPWSTR s
,LPWSTR b
)
867 while (*y
&& *c
&& *y
==*c
) { c
++;y
++; }
876 /*********************************************************************
877 * wcsrchr (CRTDLL.515)
879 LPWSTR
CRTDLL_wcsrchr(LPWSTR str
,WCHAR xchar
)
883 s
=str
+lstrlen32W(str
);
892 /*********************************************************************
893 * _setmode (CRTDLL.265)
894 * FIXME: dunno what this is.
897 CRTDLL__setmode(LPVOID x
,INT32 y
) {
899 fprintf(stdnimp
,"CRTDLL._setmode(%p,%d), STUB.\n",x
,y
);
903 /*********************************************************************
904 * atexit (CRTDLL.345)
907 CRTDLL_atexit(LPVOID x
) {
909 fprintf(stdnimp
,"CRTDLL.atexit(%p), STUB.\n",x
);
910 return 0; /* successful */
913 /*********************************************************************
914 * mbtowc (CRTDLL.430)
915 * FIXME: check multibyte support
918 CRTDLL_mbtowc(CHAR a
) {
922 /*********************************************************************
923 * _isctype (CRTDLL.138)
926 CRTDLL__isctype(CHAR x
,CHAR type
) {
927 if ((type
& CRTDLL_SPACE
) && isspace(x
))
929 if ((type
& CRTDLL_PUNCT
) && ispunct(x
))
931 if ((type
& CRTDLL_LOWER
) && islower(x
))
933 if ((type
& CRTDLL_UPPER
) && isupper(x
))
935 if ((type
& CRTDLL_ALPHA
) && isalpha(x
))
937 if ((type
& CRTDLL_DIGIT
) && isdigit(x
))
939 if ((type
& CRTDLL_CONTROL
) && iscntrl(x
))
941 /* check CRTDLL_LEADBYTE */
945 /*********************************************************************
946 * _chdrive (CRTDLL.52)
949 CRTDLL__chdrive(INT32 newdrive
) {
950 /* FIXME: generates errnos */
951 return DRIVE_SetCurrentDrive(newdrive
);
954 /*********************************************************************
958 CRTDLL__chdir(LPCSTR newdir
) {
959 if (!SetCurrentDirectory32A(newdir
))
964 /*********************************************************************
965 * _mkdir (CRTDLL.234)
968 CRTDLL__mkdir(LPCSTR newdir
) {
969 if (!CreateDirectory32A(newdir
,NULL
))
974 /*********************************************************************
976 * Yes, this is a function.
980 static int crtdllerrno
;
981 extern int LastErrorToErrno(DWORD
);
983 /* FIXME: we should set the error at the failing function call time */
984 crtdllerrno
= LastErrorToErrno(GetLastError());