Release 961215
[wine/multimedia.git] / misc / crtdll.c
blob5a35026e7ff1f843742fa0209b340268a3b4d9a3
1 /*
2 * The C RunTime DLL
3 *
4 * Implements C run-time functionality as known from UNIX.
6 * Copyright 1996 Marcus Meissner
7 * Copyright 1996 Jukka Iivonen
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <time.h>
15 #include <ctype.h>
16 #include <math.h>
17 #include "win.h"
18 #include "windows.h"
19 #include "stddebug.h"
20 #include "debug.h"
21 #include "module.h"
22 #include "xmalloc.h"
23 #include "heap.h"
24 #include "crtdll.h"
25 #include "string32.h"
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 */
43 /*********************************************************************
44 * _GetMainArgs (CRTDLL.022)
46 DWORD
47 CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,LPSTR *environ,DWORD flag)
49 char *cmdline;
50 char **xargv;
51 int xargc,i,afterlastspace;
52 DWORD version;
54 dprintf_crtdll(stderr,"__GetMainArgs(%p,%p,%p,%ld).\n",
55 argc,argv,environ,flag
57 CRTDLL_acmdln_dll = cmdline = xstrdup( GetCommandLine32A() );
59 version = GetVersion32();
60 CRTDLL_osver_dll = version >> 16;
61 CRTDLL_winminor_dll = version & 0xFF;
62 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
63 CRTDLL_baseversion_dll = version >> 16;
64 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
65 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
66 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
67 CRTDLL_osversion_dll = version & 0xFFFF;
68 CRTDLL_osminor_dll = version & 0xFF;
69 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
71 /* missing threading init */
73 i=0;xargv=NULL;xargc=0;afterlastspace=0;
74 while (cmdline[i]) {
75 if (cmdline[i]==' ') {
76 xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc));
77 cmdline[i]='\0';
78 xargv[xargc-1] = xstrdup(cmdline+afterlastspace);
79 i++;
80 while (cmdline[i]==' ')
81 i++;
82 if (cmdline[i])
83 afterlastspace=i;
84 } else
85 i++;
87 xargv=(char**)xrealloc(xargv,sizeof(char*)*(++xargc));
88 cmdline[i]='\0';
89 xargv[xargc-1] = xstrdup(cmdline+afterlastspace);
90 CRTDLL_argc_dll = xargc;
91 *argc = xargc;
92 CRTDLL_argv_dll = xargv;
93 *argv = xargv;
95 /* FIXME ... use real environment */
96 *environ = xmalloc(sizeof(LPSTR));
97 CRTDLL_environ_dll = *environ;
98 (*environ)[0] = NULL;
99 return 0;
102 typedef void (*_INITTERMFUN)();
104 /*********************************************************************
105 * _initterm (CRTDLL.135)
107 DWORD CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
109 _INITTERMFUN *current;
111 dprintf_crtdll(stddeb,"_initterm(%p,%p)\n",start,end);
112 current=start;
113 while (current<end) {
114 if (*current) (*current)();
115 current++;
117 return 0;
120 /*********************************************************************
121 * srand (CRTDLL.460)
123 void CRTDLL_srand(DWORD seed)
125 /* FIXME: should of course be thread? process? local */
126 srand(seed);
129 /*********************************************************************
130 * fprintf (CRTDLL.373)
132 int CRTDLL_fprintf(DWORD *args)
134 /* FIXME: use args[0] */
135 return vfprintf(stderr,(LPSTR)(args[1]),args+2);
138 /*********************************************************************
139 * printf (CRTDLL.440)
141 int CRTDLL_printf(DWORD *args)
143 return vfprintf(stdout,(LPSTR)(args[0]),args+1);
146 /*********************************************************************
147 * sprintf (CRTDLL.458)
149 int CRTDLL_sprintf(DWORD *args)
151 return vsprintf((LPSTR)(args[0]),(LPSTR)(args[1]),args+2);
154 /*********************************************************************
155 * time (CRTDLL.488)
157 time_t CRTDLL_time(time_t *timeptr)
159 time_t curtime = time(NULL);
161 if (timeptr)
162 *timeptr = curtime;
163 return curtime;
166 /*********************************************************************
167 * _isatty (CRTDLL.137)
169 BOOL32 CRTDLL__isatty(DWORD x)
171 dprintf_crtdll(stderr,"CRTDLL__isatty(%ld)\n",x);
172 return TRUE;
175 /*********************************************************************
176 * _write (CRTDLL.332)
178 INT32 CRTDLL__write(DWORD x,LPVOID buf,DWORD len)
180 if (x<=2)
181 return write(x,buf,len);
182 /* hmm ... */
183 dprintf_crtdll(stderr,"CRTDLL__write(%ld,%p,%ld)\n",x,buf,len);
184 return len;
188 /*********************************************************************
189 * exit (CRTDLL.359)
191 void CRTDLL_exit(DWORD ret)
193 dprintf_crtdll(stderr,"CRTDLL_exit(%ld)\n",ret);
194 ExitProcess(ret);
198 /*********************************************************************
199 * fflush (CRTDLL.365)
201 void CRTDLL_fflush(DWORD x)
203 dprintf_crtdll(stderr,"CRTDLL_fflush(%ld)\n",x);
207 /*********************************************************************
208 * gets (CRTDLL.391)
210 LPSTR CRTDLL_gets(LPSTR buf)
212 /* BAD, for the whole WINE process blocks... just done this way to test
213 * windows95's ftp.exe.
215 return gets(buf);
219 /*********************************************************************
220 * abs (CRTDLL.339)
222 INT32 CRTDLL_abs(INT32 x)
224 return abs(x);
228 /*********************************************************************
229 * acos (CRTDLL.340)
231 float CRTDLL_acos(float x)
233 return acos(x);
237 /*********************************************************************
238 * asin (CRTDLL.342)
240 float CRTDLL_asin(float x)
242 return asin(x);
246 /*********************************************************************
247 * atan (CRTDLL.343)
249 float CRTDLL_atan(float x)
251 return atan(x);
255 /*********************************************************************
256 * atan2 (CRTDLL.344)
258 float CRTDLL_atan2(float x, float y)
260 return atan2(x,y);
264 /*********************************************************************
265 * atof (CRTDLL.346)
267 float CRTDLL_atof(LPCSTR x)
269 return atof(x);
273 /*********************************************************************
274 * atoi (CRTDLL.347)
276 INT32 CRTDLL_atoi(LPCSTR x)
278 return atoi(x);
282 /*********************************************************************
283 * atol (CRTDLL.348)
285 LONG CRTDLL_atol(LPCSTR x)
287 return atol(x);
291 /*********************************************************************
292 * cos (CRTDLL.354)
294 float CRTDLL_cos(float x)
296 return cos(x);
300 /*********************************************************************
301 * cosh (CRTDLL.355)
303 float CRTDLL_cosh(float x)
305 return cosh(x);
309 /*********************************************************************
310 * exp (CRTDLL.360)
312 float CRTDLL_exp(float x)
314 return exp(x);
318 /*********************************************************************
319 * fabs (CRTDLL.361)
321 float CRTDLL_fabs(float x)
323 return fabs(x);
327 /*********************************************************************
328 * isalnum (CRTDLL.394)
330 CHAR CRTDLL_isalnum(CHAR x)
332 return isalnum(x);
336 /*********************************************************************
337 * isalpha (CRTDLL.395)
339 CHAR CRTDLL_isalpha(CHAR x)
341 return isalpha(x);
345 /*********************************************************************
346 * iscntrl (CRTDLL.396)
348 CHAR CRTDLL_iscntrl(CHAR x)
350 return iscntrl(x);
354 /*********************************************************************
355 * isdigit (CRTDLL.397)
357 CHAR CRTDLL_isdigit(CHAR x)
359 return isdigit(x);
363 /*********************************************************************
364 * isgraph (CRTDLL.398)
366 CHAR CRTDLL_isgraph(CHAR x)
368 return isgraph(x);
372 /*********************************************************************
373 * islower (CRTDLL.400)
375 CHAR CRTDLL_islower(CHAR x)
377 return islower(x);
381 /*********************************************************************
382 * isprint (CRTDLL.401)
384 CHAR CRTDLL_isprint(CHAR x)
386 return isprint(x);
390 /*********************************************************************
391 * ispunct (CRTDLL.402)
393 CHAR CRTDLL_ispunct(CHAR x)
395 return ispunct(x);
399 /*********************************************************************
400 * isspace (CRTDLL.403)
402 CHAR CRTDLL_isspace(CHAR x)
404 return isspace(x);
408 /*********************************************************************
409 * isupper (CRTDLL.404)
411 CHAR CRTDLL_isupper(CHAR x)
413 return isupper(x);
417 /*********************************************************************
418 * isxdigit (CRTDLL.418)
420 CHAR CRTDLL_isxdigit(CHAR x)
422 return isxdigit(x);
426 /*********************************************************************
427 * labs (CRTDLL.419)
429 LONG CRTDLL_labs(LONG x)
431 return labs(x);
435 /*********************************************************************
436 * log (CRTDLL.424)
438 float CRTDLL_log(float x)
440 return log(x);
444 /*********************************************************************
445 * log10 (CRTDLL.425)
447 float CRTDLL_log10(float x)
449 return log10(x);
453 /*********************************************************************
454 * pow (CRTDLL.439)
456 float CRTDLL_pow(float x, float y)
458 return pow(x,y);
462 /*********************************************************************
463 * rand (CRTDLL.446)
465 INT32 CRTDLL_rand()
467 return rand();
471 /*********************************************************************
472 * sin (CRTDLL.456)
474 float CRTDLL_sin(float x)
476 return sin(x);
480 /*********************************************************************
481 * sinh (CRTDLL.457)
483 float CRTDLL_sinh(float x)
485 return sinh(x);
489 /*********************************************************************
490 * sqrt (CRTDLL.459)
492 float CRTDLL_sqrt(float x)
494 return sqrt(x);
498 /*********************************************************************
499 * tan (CRTDLL.486)
501 float CRTDLL_tan(float x)
503 return tan(x);
507 /*********************************************************************
508 * tanh (CRTDLL.487)
510 float CRTDLL_tanh(float x)
512 return tanh(x);
516 /*********************************************************************
517 * tolower (CRTDLL.491)
519 CHAR CRTDLL_tolower(CHAR x)
521 return tolower(x);
525 /*********************************************************************
526 * toupper (CRTDLL.492)
528 CHAR CRTDLL_toupper(CHAR x)
530 return toupper(x);
534 /*********************************************************************
535 * putchar (CRTDLL.442)
537 void CRTDLL_putchar(INT32 x)
539 putchar(x);
543 /*********************************************************************
544 * _mbsicmp (CRTDLL.204)
546 int CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
548 do {
549 if (!*x)
550 return !!*y;
551 if (!*y)
552 return !!*x;
553 /* FIXME: MBCS handling... */
554 if (*x!=*y)
555 return 1;
556 x++;
557 y++;
558 } while (1);
562 /*********************************************************************
563 * _mbsinc (CRTDLL.205)
565 unsigned char* CRTDLL__mbsinc(unsigned char *x)
567 /* FIXME: mbcs */
568 return x++;
572 /*********************************************************************
573 * vsprintf (CRTDLL.500)
575 int CRTDLL_vsprintf(DWORD *args)
577 return vsprintf((char *)args[0],(char *)args[1],args+2);
580 /*********************************************************************
581 * vsprintf (CRTDLL.500) (NTDLL.913)
583 int CRTDLL_sscanf(DWORD *args)
585 return vsscanf((char *)args[0],(char *)args[1],args+2);
589 /*********************************************************************
590 * _mbscpy (CRTDLL.200)
592 unsigned char* CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
594 return strcpy(x,y);
598 /*********************************************************************
599 * _mbscat (CRTDLL.197)
601 unsigned char* CRTDLL__mbscat(unsigned char *x,unsigned char *y)
603 return strcat(x,y);
606 /*********************************************************************
607 * _strupr (CRTDLL.300)
609 LPSTR CRTDLL__strupr(LPSTR x)
611 LPSTR y=x;
613 while (*y) {
614 *y=toupper(*y);
615 y++;
617 return x;
620 /*********************************************************************
621 * _wcsupr (CRTDLL.328)
623 LPWSTR CRTDLL__wcsupr(LPWSTR x)
625 LPWSTR y=x;
627 while (*y) {
628 *y=toupper(*y);
629 y++;
631 return x;
634 /*********************************************************************
635 * _wcslwr (CRTDLL.323)
637 LPWSTR CRTDLL__wcslwr(LPWSTR x)
639 LPWSTR y=x;
641 while (*y) {
642 *y=tolower(*y);
643 y++;
645 return x;
649 /*********************************************************************
650 * malloc (CRTDLL.427)
652 VOID* CRTDLL_malloc(DWORD size)
654 return HeapAlloc(GetProcessHeap(),0,size);
657 /*********************************************************************
658 * calloc (CRTDLL.350)
660 VOID* CRTDLL_calloc(DWORD size, DWORD count)
662 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
665 /*********************************************************************
666 * realloc (CRTDLL.447)
668 VOID* CRTDLL_realloc( VOID *ptr, DWORD size )
670 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
673 /*********************************************************************
674 * free (CRTDLL.427)
676 VOID CRTDLL_free(LPVOID ptr)
678 HeapFree(GetProcessHeap(),0,ptr);
681 /*********************************************************************
682 * _strdup (CRTDLL.285)
684 LPSTR CRTDLL__strdup(LPSTR ptr)
686 return HEAP_strdupA(GetProcessHeap(),0,ptr);
689 /*********************************************************************
690 * fclose (CRTDLL.362)
692 DWORD CRTDLL_fclose(LPVOID x)
694 dprintf_crtdll(stdnimp,"fclose(%p)\n",x);
695 return 0;
698 /*********************************************************************
699 * setlocale (CRTDLL.453)
701 LPSTR CRTDLL_setlocale(INT32 category,LPCSTR locale)
703 LPSTR categorystr;
705 switch (category) {
706 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
707 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
708 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
709 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
710 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
711 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
712 default: categorystr = "UNKNOWN?";break;
714 fprintf(stderr,"CRTDLL.setlocale(%s,%s),stub!\n",categorystr,locale);
715 return "C";
718 /*********************************************************************
719 * wcsspn (CRTDLL.516)
721 INT32 CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
723 LPWSTR s,t;
725 s=str;
726 do {
727 t=accept;
728 while (*t) { if (*t==*s) break;t++;}
729 if (!*t) break;
730 s++;
731 } while (*s);
732 return s-str; /* nr of wchars */
735 /*********************************************************************
736 * wcschr (CRTDLL.504)
738 LPWSTR CRTDLL_wcschr(LPWSTR str,WCHAR xchar)
740 LPWSTR s;
742 s=str;
743 do {
744 if (*s==xchar)
745 return s;
746 } while (*s++);
747 return NULL;
750 /*********************************************************************
751 * towupper (CRTDLL.494)
753 WCHAR CRTDLL_towupper(WCHAR x)
755 return (WCHAR)toupper((CHAR)x);
758 /*********************************************************************
759 * swprintf (CRTDLL.483)
761 DWORD CRTDLL_swprintf(DWORD *args)
763 return WIN32_wsprintf32W(args);
766 /*********************************************************************
767 * _wcsicoll (CRTDLL.322)
769 DWORD CRTDLL__wcsicoll(LPWSTR a1,LPWSTR a2)
771 /* FIXME: handle collates */
772 return lstrcmpi32W(a1,a2);
775 /*********************************************************************
776 * wcscoll (CRTDLL.506)
778 DWORD CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
780 /* FIXME: handle collates */
781 return lstrcmp32W(a1,a2);
784 /*********************************************************************
785 * wcsstr (CRTDLL.517)
787 LPWSTR CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
789 LPWSTR x,y,c;
791 x=s;
792 while (*x) {
793 if (*x==*b) {
794 y=x;c=b;
795 while (*y && *c && *y==*c) { c++;y++; }
796 if (!*c)
797 return x;
799 x++;
801 return NULL;
804 /*********************************************************************
805 * wcsrchr (CRTDLL.515)
807 LPWSTR CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
809 LPWSTR s;
811 s=str+lstrlen32W(str);
812 do {
813 if (*s==xchar)
814 return s;
815 s--;
816 } while (s>=str);
817 return NULL;