4 * Implements C run-time functionality as known from UNIX.
6 * Copyright 1996 Marcus Meissner
7 * Copyright 1996 Jukka Iivonen
28 extern INT32
WIN32_wsprintf32W( DWORD
*args
);
30 UINT32 CRTDLL_argc_dll
; /* CRTDLL.23 */
31 LPSTR
*CRTDLL_argv_dll
; /* CRTDLL.24 */
32 LPSTR CRTDLL_acmdln_dll
; /* CRTDLL.38 */
33 UINT32 CRTDLL_basemajor_dll
; /* CRTDLL.42 */
34 UINT32 CRTDLL_baseminor_dll
; /* CRTDLL.43 */
35 UINT32 CRTDLL_baseversion_dll
; /* CRTDLL.44 */
36 LPSTR CRTDLL_environ_dll
; /* CRTDLL.75 */
37 UINT32 CRTDLL_osmajor_dll
; /* CRTDLL.241 */
38 UINT32 CRTDLL_osminor_dll
; /* CRTDLL.242 */
39 UINT32 CRTDLL_osver_dll
; /* CRTDLL.244 */
40 UINT32 CRTDLL_osversion_dll
; /* CRTDLL.245 */
41 UINT32 CRTDLL_winmajor_dll
; /* CRTDLL.329 */
42 UINT32 CRTDLL_winminor_dll
; /* CRTDLL.330 */
43 UINT32 CRTDLL_winver_dll
; /* CRTDLL.331 */
45 typedef VOID (*new_handler_type
)(VOID
);
47 static new_handler_type new_handler
;
49 /*********************************************************************
50 * _GetMainArgs (CRTDLL.022)
53 CRTDLL__GetMainArgs(LPDWORD argc
,LPSTR
**argv
,LPSTR
*environ
,DWORD flag
)
57 int xargc
,i
,afterlastspace
;
60 dprintf_crtdll(stderr
,"__GetMainArgs(%p,%p,%p,%ld).\n",
61 argc
,argv
,environ
,flag
63 CRTDLL_acmdln_dll
= cmdline
= xstrdup( GetCommandLine32A() );
65 version
= GetVersion32();
66 CRTDLL_osver_dll
= version
>> 16;
67 CRTDLL_winminor_dll
= version
& 0xFF;
68 CRTDLL_winmajor_dll
= (version
>>8) & 0xFF;
69 CRTDLL_baseversion_dll
= version
>> 16;
70 CRTDLL_winver_dll
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
71 CRTDLL_baseminor_dll
= (version
>> 16) & 0xFF;
72 CRTDLL_basemajor_dll
= (version
>> 24) & 0xFF;
73 CRTDLL_osversion_dll
= version
& 0xFFFF;
74 CRTDLL_osminor_dll
= version
& 0xFF;
75 CRTDLL_osmajor_dll
= (version
>>8) & 0xFF;
77 /* missing threading init */
79 i
=0;xargv
=NULL
;xargc
=0;afterlastspace
=0;
81 if (cmdline
[i
]==' ') {
82 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
84 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
86 while (cmdline
[i
]==' ')
93 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
95 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
96 CRTDLL_argc_dll
= xargc
;
98 CRTDLL_argv_dll
= xargv
;
101 /* FIXME ... use real environment */
102 *environ
= xmalloc(sizeof(LPSTR
));
103 CRTDLL_environ_dll
= *environ
;
104 (*environ
)[0] = NULL
;
108 typedef void (*_INITTERMFUN
)();
110 /*********************************************************************
111 * _initterm (CRTDLL.135)
113 DWORD
CRTDLL__initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
115 _INITTERMFUN
*current
;
117 dprintf_crtdll(stddeb
,"_initterm(%p,%p)\n",start
,end
);
119 while (current
<end
) {
120 if (*current
) (*current
)();
126 /*********************************************************************
129 void CRTDLL_srand(DWORD seed
)
131 /* FIXME: should of course be thread? process? local */
135 /*********************************************************************
136 * fprintf (CRTDLL.373)
138 int CRTDLL_fprintf(DWORD
*args
)
140 /* FIXME: use args[0] */
141 /* CMF - This makes a BIG assumption about va_list */
142 return vfprintf(stderr
, (LPSTR
) args
[1], (va_list) &args
[2]);
145 /*********************************************************************
146 * printf (CRTDLL.440)
148 int CRTDLL_printf(DWORD
*args
)
150 /* CMF - This makes a BIG assumption about va_list */
151 return vfprintf(stdout
, (LPSTR
) args
[0], (va_list) &args
[1]);
154 /*********************************************************************
155 * sprintf (CRTDLL.458)
157 int CRTDLL_sprintf(DWORD
*args
)
159 /* CMF - This makes a BIG assumption about va_list */
160 return vsprintf((LPSTR
) args
[0], (LPSTR
) args
[1], (va_list) &args
[2]);
163 /*********************************************************************
166 time_t CRTDLL_time(time_t *timeptr
)
168 time_t curtime
= time(NULL
);
175 /*********************************************************************
176 * _isatty (CRTDLL.137)
178 BOOL32
CRTDLL__isatty(DWORD x
)
180 dprintf_crtdll(stderr
,"CRTDLL__isatty(%ld)\n",x
);
184 /*********************************************************************
185 * _write (CRTDLL.332)
187 INT32
CRTDLL__write(DWORD x
,LPVOID buf
,DWORD len
)
190 return write(x
,buf
,len
);
192 dprintf_crtdll(stderr
,"CRTDLL__write(%ld,%p,%ld)\n",x
,buf
,len
);
197 /*********************************************************************
200 void CRTDLL_exit(DWORD ret
)
202 dprintf_crtdll(stderr
,"CRTDLL_exit(%ld)\n",ret
);
207 /*********************************************************************
208 * fflush (CRTDLL.365)
210 void CRTDLL_fflush(DWORD x
)
212 dprintf_crtdll(stderr
,"CRTDLL_fflush(%ld)\n",x
);
216 /*********************************************************************
219 LPSTR
CRTDLL_gets(LPSTR buf
)
221 /* BAD, for the whole WINE process blocks... just done this way to test
222 * windows95's ftp.exe.
228 /*********************************************************************
231 INT32
CRTDLL_abs(INT32 x
)
237 /*********************************************************************
240 float CRTDLL_acos(float x
)
246 /*********************************************************************
249 float CRTDLL_asin(float x
)
255 /*********************************************************************
258 float CRTDLL_atan(float x
)
264 /*********************************************************************
267 float CRTDLL_atan2(float x
, float y
)
273 /*********************************************************************
276 float CRTDLL_atof(LPCSTR x
)
282 /*********************************************************************
285 INT32
CRTDLL_atoi(LPCSTR x
)
291 /*********************************************************************
294 LONG
CRTDLL_atol(LPCSTR x
)
300 /*********************************************************************
303 float CRTDLL_cos(float x
)
309 /*********************************************************************
312 float CRTDLL_cosh(float x
)
318 /*********************************************************************
321 float CRTDLL_exp(float x
)
327 /*********************************************************************
330 float CRTDLL_fabs(float x
)
336 /*********************************************************************
337 * isalnum (CRTDLL.394)
339 CHAR
CRTDLL_isalnum(CHAR x
)
345 /*********************************************************************
346 * isalpha (CRTDLL.395)
348 CHAR
CRTDLL_isalpha(CHAR x
)
354 /*********************************************************************
355 * iscntrl (CRTDLL.396)
357 CHAR
CRTDLL_iscntrl(CHAR x
)
363 /*********************************************************************
364 * isdigit (CRTDLL.397)
366 CHAR
CRTDLL_isdigit(CHAR x
)
372 /*********************************************************************
373 * isgraph (CRTDLL.398)
375 CHAR
CRTDLL_isgraph(CHAR x
)
381 /*********************************************************************
382 * islower (CRTDLL.400)
384 CHAR
CRTDLL_islower(CHAR x
)
390 /*********************************************************************
391 * isprint (CRTDLL.401)
393 CHAR
CRTDLL_isprint(CHAR x
)
399 /*********************************************************************
400 * ispunct (CRTDLL.402)
402 CHAR
CRTDLL_ispunct(CHAR x
)
408 /*********************************************************************
409 * isspace (CRTDLL.403)
411 CHAR
CRTDLL_isspace(CHAR x
)
417 /*********************************************************************
418 * isupper (CRTDLL.404)
420 CHAR
CRTDLL_isupper(CHAR x
)
426 /*********************************************************************
427 * isxdigit (CRTDLL.418)
429 CHAR
CRTDLL_isxdigit(CHAR x
)
435 /*********************************************************************
438 LONG
CRTDLL_labs(LONG x
)
444 /*********************************************************************
447 float CRTDLL_log(float x
)
453 /*********************************************************************
456 float CRTDLL_log10(float x
)
462 /*********************************************************************
465 float CRTDLL_pow(float x
, float y
)
471 /*********************************************************************
480 /*********************************************************************
483 float CRTDLL_sin(float x
)
489 /*********************************************************************
492 float CRTDLL_sinh(float x
)
498 /*********************************************************************
501 float CRTDLL_sqrt(float x
)
507 /*********************************************************************
510 float CRTDLL_tan(float x
)
516 /*********************************************************************
519 float CRTDLL_tanh(float x
)
525 /*********************************************************************
526 * tolower (CRTDLL.491)
528 CHAR
CRTDLL_tolower(CHAR x
)
534 /*********************************************************************
535 * toupper (CRTDLL.492)
537 CHAR
CRTDLL_toupper(CHAR x
)
543 /*********************************************************************
544 * putchar (CRTDLL.442)
546 void CRTDLL_putchar(INT32 x
)
552 /*********************************************************************
553 * _mbsicmp (CRTDLL.204)
555 int CRTDLL__mbsicmp(unsigned char *x
,unsigned char *y
)
562 /* FIXME: MBCS handling... */
571 /*********************************************************************
572 * _mbsinc (CRTDLL.205)
574 unsigned char* CRTDLL__mbsinc(unsigned char *x
)
581 /*********************************************************************
582 * vsprintf (CRTDLL.500)
584 int CRTDLL_vsprintf(DWORD
*args
)
586 /* CMF - This makes a BIG assumption about va_list */
587 return vsprintf((char *) args
[0], (char *) args
[1], (va_list) &args
[2]);
590 /*********************************************************************
591 * vsprintf (CRTDLL.500) (NTDLL.913)
593 int CRTDLL_sscanf(DWORD
*args
)
595 /* CMF - This makes a BIG assumption about va_list */
596 return vsscanf((char *) args
[0], (char *) args
[1], (va_list) &args
[2]);
600 /*********************************************************************
601 * _mbscpy (CRTDLL.200)
603 unsigned char* CRTDLL__mbscpy(unsigned char *x
,unsigned char *y
)
609 /*********************************************************************
610 * _mbscat (CRTDLL.197)
612 unsigned char* CRTDLL__mbscat(unsigned char *x
,unsigned char *y
)
617 /*********************************************************************
618 * _strupr (CRTDLL.300)
620 LPSTR
CRTDLL__strupr(LPSTR x
)
631 /*********************************************************************
632 * _wcsupr (CRTDLL.328)
634 LPWSTR
CRTDLL__wcsupr(LPWSTR x
)
645 /*********************************************************************
646 * _wcslwr (CRTDLL.323)
648 LPWSTR
CRTDLL__wcslwr(LPWSTR x
)
660 /*********************************************************************
661 * malloc (CRTDLL.427)
663 VOID
* CRTDLL_malloc(DWORD size
)
665 return HeapAlloc(GetProcessHeap(),0,size
);
668 /*********************************************************************
671 VOID
* CRTDLL_new(DWORD size
)
674 if(!(result
= HeapAlloc(GetProcessHeap(),0,size
)) && new_handler
)
679 /*********************************************************************
680 * set_new_handler(CRTDLL.003)
682 new_handler_type
CRTDLL_set_new_handler(new_handler_type func
)
684 new_handler_type old_handler
= new_handler
;
689 /*********************************************************************
690 * calloc (CRTDLL.350)
692 VOID
* CRTDLL_calloc(DWORD size
, DWORD count
)
694 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
* count
);
697 /*********************************************************************
698 * realloc (CRTDLL.447)
700 VOID
* CRTDLL_realloc( VOID
*ptr
, DWORD size
)
702 return HeapReAlloc( GetProcessHeap(), 0, ptr
, size
);
705 /*********************************************************************
708 VOID
CRTDLL_free(LPVOID ptr
)
710 HeapFree(GetProcessHeap(),0,ptr
);
713 /*********************************************************************
714 * delete (CRTDLL.002)
716 VOID
CRTDLL_delete(VOID
* ptr
)
718 HeapFree(GetProcessHeap(),0,ptr
);
721 /*********************************************************************
722 * _strdup (CRTDLL.285)
724 LPSTR
CRTDLL__strdup(LPSTR ptr
)
726 return HEAP_strdupA(GetProcessHeap(),0,ptr
);
729 /*********************************************************************
730 * fclose (CRTDLL.362)
732 DWORD
CRTDLL_fclose(LPVOID x
)
734 dprintf_crtdll(stdnimp
,"fclose(%p)\n",x
);
738 /*********************************************************************
739 * setlocale (CRTDLL.453)
741 LPSTR
CRTDLL_setlocale(INT32 category
,LPCSTR locale
)
746 case CRTDLL_LC_ALL
: categorystr
="LC_ALL";break;
747 case CRTDLL_LC_COLLATE
: categorystr
="LC_COLLATE";break;
748 case CRTDLL_LC_CTYPE
: categorystr
="LC_CTYPE";break;
749 case CRTDLL_LC_MONETARY
: categorystr
="LC_MONETARY";break;
750 case CRTDLL_LC_NUMERIC
: categorystr
="LC_NUMERIC";break;
751 case CRTDLL_LC_TIME
: categorystr
="LC_TIME";break;
752 default: categorystr
= "UNKNOWN?";break;
754 fprintf(stderr
,"CRTDLL.setlocale(%s,%s),stub!\n",categorystr
,locale
);
758 /*********************************************************************
759 * wcsspn (CRTDLL.516)
761 INT32
CRTDLL_wcsspn(LPWSTR str
,LPWSTR accept
)
768 while (*t
) { if (*t
==*s
) break;t
++;}
772 return s
-str
; /* nr of wchars */
775 /*********************************************************************
776 * wcscspn (CRTDLL.508)
778 INT32
CRTDLL_wcscspn(LPWSTR str
,LPWSTR reject
)
785 while (*t
) { if (*t
==*s
) break;t
++;}
789 return s
-str
; /* nr of wchars */
792 /*********************************************************************
793 * wcschr (CRTDLL.504)
795 LPWSTR
CRTDLL_wcschr(LPWSTR str
,WCHAR xchar
)
807 /*********************************************************************
808 * towupper (CRTDLL.494)
810 WCHAR
CRTDLL_towupper(WCHAR x
)
812 return (WCHAR
)toupper((CHAR
)x
);
815 /*********************************************************************
816 * swprintf (CRTDLL.483)
818 DWORD
CRTDLL_swprintf(DWORD
*args
)
820 return WIN32_wsprintf32W(args
);
823 /*********************************************************************
824 * _wcsicoll (CRTDLL.322)
826 DWORD
CRTDLL__wcsicoll(LPWSTR a1
,LPWSTR a2
)
828 /* FIXME: handle collates */
829 return lstrcmpi32W(a1
,a2
);
832 /*********************************************************************
833 * wcscoll (CRTDLL.506)
835 DWORD
CRTDLL_wcscoll(LPWSTR a1
,LPWSTR a2
)
837 /* FIXME: handle collates */
838 return lstrcmp32W(a1
,a2
);
841 /*********************************************************************
842 * _wcsrev (CRTDLL.326)
844 VOID
CRTDLL__wcsrev(LPWSTR s
) {
858 /*********************************************************************
859 * wcsstr (CRTDLL.517)
861 LPWSTR
CRTDLL_wcsstr(LPWSTR s
,LPWSTR b
)
869 while (*y
&& *c
&& *y
==*c
) { c
++;y
++; }
878 /*********************************************************************
879 * wcsrchr (CRTDLL.515)
881 LPWSTR
CRTDLL_wcsrchr(LPWSTR str
,WCHAR xchar
)
885 s
=str
+lstrlen32W(str
);
894 /*********************************************************************
895 * _setmode (CRTDLL.265)
896 * FIXME: dunno what this is.
899 CRTDLL__setmode(LPVOID x
,INT32 y
) {
901 fprintf(stdnimp
,"CRTDLL._setmode(%p,%d), STUB.\n",x
,y
);
905 /*********************************************************************
906 * atexit (CRTDLL.345)
909 CRTDLL_atexit(LPVOID x
) {
911 fprintf(stdnimp
,"CRTDLL.atexit(%p), STUB.\n",x
);
912 return 0; /* successful */
915 /*********************************************************************
916 * mbstowcs (CRTDLL.429)
917 * FIXME: check multibyte support
920 CRTDLL_mbstowcs(LPWSTR a
,LPSTR b
,INT32 nr
) {
922 for (i
=0;(i
<nr
) && b
[i
];i
++) {
928 /*********************************************************************
929 * mbtowc (CRTDLL.430)
930 * FIXME: check multibyte support
933 CRTDLL_mbtowc(CHAR a
) {
937 /*********************************************************************
938 * _isctype (CRTDLL.138)
941 CRTDLL__isctype(CHAR x
,CHAR type
) {
942 if ((type
& CRTDLL_SPACE
) && isspace(x
))
944 if ((type
& CRTDLL_PUNCT
) && ispunct(x
))
946 if ((type
& CRTDLL_LOWER
) && islower(x
))
948 if ((type
& CRTDLL_UPPER
) && isupper(x
))
950 if ((type
& CRTDLL_ALPHA
) && isalpha(x
))
952 if ((type
& CRTDLL_DIGIT
) && isdigit(x
))
954 if ((type
& CRTDLL_CONTROL
) && iscntrl(x
))
956 /* check CRTDLL_LEADBYTE */
960 /*********************************************************************
961 * _chdrive (CRTDLL.52)
964 CRTDLL__chdrive(INT32 newdrive
) {
965 /* FIXME: generates errnos */
966 return DRIVE_SetCurrentDrive(newdrive
);
969 /*********************************************************************
973 CRTDLL__chdir(LPCSTR newdir
) {
974 if (!SetCurrentDirectory32A(newdir
))
979 /*********************************************************************
980 * _mkdir (CRTDLL.234)
983 CRTDLL__mkdir(LPCSTR newdir
) {
984 if (!CreateDirectory32A(newdir
,NULL
))
989 /*********************************************************************
991 * Yes, this is a function.
995 static int crtdllerrno
;
996 extern int LastErrorToErrno(DWORD
);
998 /* FIXME: we should set the error at the failing function call time */
999 crtdllerrno
= LastErrorToErrno(GetLastError());
1000 return &crtdllerrno
;