Release 980517
[wine/multimedia.git] / misc / crtdll.c
blob0acad2997f8b683499ffce21d5203b44a4bab6b8
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 * Copyright 1997 Uwe Bonnes
9 */
12 Unresolved issues Uwe Bonnes 970904:
13 - Handling of Binary/Text Files is crude. If in doubt, use fromdos or recode
14 - Arguments in crtdll.spec for functions with double argument
15 - system-call calls another wine process, but without debugging arguments
16 and uses the first wine executable in the path
17 - tested with ftp://ftp.remcomp.com/pub/remcomp/lcc-win32.zip, a C-Compiler
18 for Win32, based on lcc, from Jacob Navia
21 /* FIXME: all the file handling is hopelessly broken -- AJ */
23 #include <errno.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <sys/stat.h>
29 #include <sys/times.h>
30 #include <unistd.h>
31 #include <time.h>
32 #include <ctype.h>
33 #include <math.h>
34 #include <fcntl.h>
35 #include <setjmp.h>
36 #include "win.h"
37 #include "windows.h"
38 #include "winerror.h"
39 #include "debug.h"
40 #include "module.h"
41 #include "heap.h"
42 #include "crtdll.h"
43 #include "drive.h"
44 #include "file.h"
45 #include "except.h"
46 #include "options.h"
48 extern int FILE_GetUnixHandle( HFILE32 );
50 static DOS_FULL_NAME CRTDLL_tmpname;
52 extern INT32 WIN32_wsprintf32W( DWORD *args );
54 UINT32 CRTDLL_argc_dll; /* CRTDLL.23 */
55 LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */
56 LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */
57 UINT32 CRTDLL_basemajor_dll; /* CRTDLL.42 */
58 UINT32 CRTDLL_baseminor_dll; /* CRTDLL.43 */
59 UINT32 CRTDLL_baseversion_dll; /* CRTDLL.44 */
60 UINT32 CRTDLL_commode_dll; /* CRTDLL.59 */
61 LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */
62 UINT32 CRTDLL_fmode_dll; /* CRTDLL.104 */
63 UINT32 CRTDLL_osmajor_dll; /* CRTDLL.241 */
64 UINT32 CRTDLL_osminor_dll; /* CRTDLL.242 */
65 UINT32 CRTDLL_osmode_dll; /* CRTDLL.243 */
66 UINT32 CRTDLL_osver_dll; /* CRTDLL.244 */
67 UINT32 CRTDLL_osversion_dll; /* CRTDLL.245 */
68 UINT32 CRTDLL_winmajor_dll; /* CRTDLL.329 */
69 UINT32 CRTDLL_winminor_dll; /* CRTDLL.330 */
70 UINT32 CRTDLL_winver_dll; /* CRTDLL.331 */
72 BYTE CRTDLL_iob[32*3]; /* FIXME */
74 typedef VOID (*new_handler_type)(VOID);
76 static new_handler_type new_handler;
78 /*********************************************************************
79 * _GetMainArgs (CRTDLL.022)
81 DWORD __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,
82 LPSTR *environ,DWORD flag)
84 char *cmdline;
85 char **xargv;
86 int xargc,i,afterlastspace;
87 DWORD version;
89 TRACE(crtdll,"(%p,%p,%p,%ld).\n",
90 argc,argv,environ,flag
92 CRTDLL_acmdln_dll = cmdline = HEAP_strdupA( GetProcessHeap(), 0,
93 GetCommandLine32A() );
94 TRACE(crtdll,"got '%s'\n", cmdline);
96 version = GetVersion32();
97 CRTDLL_osver_dll = version >> 16;
98 CRTDLL_winminor_dll = version & 0xFF;
99 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
100 CRTDLL_baseversion_dll = version >> 16;
101 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
102 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
103 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
104 CRTDLL_osversion_dll = version & 0xFFFF;
105 CRTDLL_osminor_dll = version & 0xFF;
106 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
108 /* missing threading init */
110 i=0;xargv=NULL;xargc=0;afterlastspace=0;
111 while (cmdline[i]) {
112 if (cmdline[i]==' ') {
113 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
114 sizeof(char*)*(++xargc));
115 cmdline[i]='\0';
116 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
117 cmdline+afterlastspace);
118 i++;
119 while (cmdline[i]==' ')
120 i++;
121 if (cmdline[i])
122 afterlastspace=i;
123 } else
124 i++;
126 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
127 sizeof(char*)*(++xargc));
128 cmdline[i]='\0';
129 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
130 cmdline+afterlastspace);
131 CRTDLL_argc_dll = xargc;
132 *argc = xargc;
133 CRTDLL_argv_dll = xargv;
134 *argv = xargv;
136 TRACE(crtdll,"found %d arguments\n",
137 CRTDLL_argc_dll);
138 CRTDLL_environ_dll = *environ = GetEnvironmentStrings32A();
139 return 0;
143 typedef void (*_INITTERMFUN)();
145 /*********************************************************************
146 * _initterm (CRTDLL.135)
148 DWORD __cdecl CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
150 _INITTERMFUN *current;
152 TRACE(crtdll,"(%p,%p)\n",start,end);
153 current=start;
154 while (current<end) {
155 if (*current) (*current)();
156 current++;
158 return 0;
161 /*********************************************************************
162 * _fdopen (CRTDLL.91)
164 DWORD __cdecl CRTDLL__fdopen(INT32 handle, LPCSTR mode)
166 FILE *file;
168 switch (handle)
170 case 0 : file=stdin;
171 break;
172 case 1 : file=stdout;
173 break;
174 case 2 : file=stderr;
175 break;
176 default:
177 file=fdopen(handle,mode);
179 TRACE(crtdll, "open handle %d mode %s got file %p\n",
180 handle, mode, file);
181 return (DWORD)file;
184 static FILE *xlat_file_ptr(void *ptr)
186 unsigned long dif;
188 /* CRT sizeof(FILE) == 32 */
189 dif = ((char *)ptr - (char *)CRTDLL_iob) / 32;
190 switch(dif)
192 case 0: return stdin;
193 case 1: return stdout;
194 case 2: return stderr;
196 return (FILE*)ptr;
199 /*******************************************************************
200 * _global_unwind2 (CRTDLL.129)
202 void __cdecl CRTDLL__global_unwind2( CONTEXT *context )
204 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
205 DWORD *args = (DWORD *)ESP_reg(context);
206 RtlUnwind( (PEXCEPTION_FRAME)args[1], (LPVOID)EIP_reg(context),
207 NULL, 0, context );
210 /*******************************************************************
211 * _local_unwind2 (CRTDLL.173)
213 void __cdecl CRTDLL__local_unwind2( CONTEXT *context )
215 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
216 DWORD *args = (DWORD *)ESP_reg(context);
217 PEXCEPTION_FRAME endframe = (PEXCEPTION_FRAME)args[1];
218 DWORD nr = args[2];
219 TRACE(crtdll,"(%p,%ld)\n",endframe,nr);
222 /*********************************************************************
223 * fopen (CRTDLL.372)
225 DWORD __cdecl CRTDLL_fopen(LPCSTR path, LPCSTR mode)
227 FILE *file;
228 HFILE32 dos_fildes;
229 #if 0
230 DOS_FULL_NAME full_name;
232 if (!DOSFS_GetFullName( path, FALSE, &full_name )) {
233 WARN(crtdll, "file %s bad name\n",path);
234 return 0;
237 file=fopen(full_name.long_name ,mode);
238 #endif
239 INT32 flagmode=0;
240 int unix_fildes=0;
242 if ((strchr(mode,'r')&&strchr(mode,'a'))||
243 (strchr(mode,'r')&&strchr(mode,'w'))||
244 (strchr(mode,'w')&&strchr(mode,'a')))
245 return 0;
247 if (strstr(mode,"r+")) flagmode=O_RDWR;
248 else if (strchr(mode,'r')) flagmode = O_RDONLY;
249 else if (strstr(mode,"w+")) flagmode= O_RDWR | O_TRUNC | O_CREAT;
250 else if (strchr(mode,'w')) flagmode = O_WRONLY | O_TRUNC | O_CREAT;
251 else if (strstr(mode,"a+")) flagmode= O_RDWR | O_CREAT | O_APPEND;
252 else if (strchr(mode,'w')) flagmode = O_RDWR | O_CREAT | O_APPEND;
253 else if (strchr(mode,'b'))
254 TRACE(crtdll, "%s in BINARY mode\n",path);
256 dos_fildes=FILE_Open(path, flagmode);
257 unix_fildes=FILE_GetUnixHandle(dos_fildes);
258 file = fdopen(unix_fildes,mode);
260 TRACE(crtdll, "file %s mode %s got ufh %d dfh %d file %p\n",
261 path,mode,unix_fildes,dos_fildes,file);
262 return (DWORD)file;
265 /*********************************************************************
266 * fread (CRTDLL.377)
268 DWORD __cdecl CRTDLL_fread(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID vfile)
270 size_t ret=1;
271 FILE *file=xlat_file_ptr(vfile);
272 #if 0
273 int i=0;
274 void *temp=ptr;
276 /* If we would honour CR/LF <-> LF translation, we could do it like this.
277 We should keep track of all files opened, and probably files with \
278 known binary extensions must be unchanged */
279 while ( (i < (nmemb*size)) && (ret==1)) {
280 ret=fread(temp,1,1,file);
281 TRACE(crtdll, "got %c 0x%02x ret %d\n",
282 (isalpha(*(unsigned char*)temp))? *(unsigned char*)temp:
283 ' ',*(unsigned char*)temp, ret);
284 if (*(unsigned char*)temp != 0xd) { /* skip CR */
285 temp++;
286 i++;
288 else
289 TRACE(crtdll, "skipping ^M\n");
291 TRACE(crtdll, "0x%08x items of size %d from file %p to %p\n",
292 nmemb,size,file,ptr,);
293 if(i!=nmemb)
294 WARN(crtdll, " failed!\n");
296 return i;
297 #else
299 ret=fread(ptr,size,nmemb,file);
300 TRACE(crtdll, "0x%08x items of size %d from file %p to %p\n",
301 nmemb,size,file,ptr);
302 if(ret!=nmemb)
303 WARN(crtdll, " failed!\n");
305 return ret;
306 #endif
309 /*********************************************************************
310 * fscanf (CRTDLL.381)
312 INT32 __cdecl CRTDLL_fscanf( LPVOID stream, LPSTR format, ... )
314 va_list valist;
315 INT32 res;
317 va_start( valist, format );
318 res = vfscanf( xlat_file_ptr(stream), format, valist );
319 va_end( valist );
320 return res;
323 /*********************************************************************
324 * fseek (CRTDLL.382)
326 LONG __cdecl CRTDLL_fseek(LPVOID stream, LONG offset, INT32 whence)
328 long ret;
330 ret=fseek(xlat_file_ptr(stream),offset,whence);
331 TRACE(crtdll, "file %p to 0x%08lx pos %s\n",
332 stream,offset,(whence==SEEK_SET)?"SEEK_SET":
333 (whence==SEEK_CUR)?"SEEK_CUR":
334 (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
335 if(ret)
336 WARN(crtdll, " failed!\n");
338 return ret;
341 /*********************************************************************
342 * fsetpos (CRTDLL.383)
344 INT32 __cdecl CRTDLL_fsetpos(LPVOID stream, fpos_t *pos)
346 TRACE(crtdll, "file %p\n", stream);
347 return fseek(xlat_file_ptr(stream), *pos, SEEK_SET);
350 /*********************************************************************
351 * ftell (CRTDLL.384)
353 LONG __cdecl CRTDLL_ftell(LPVOID stream)
355 long ret;
357 ret=ftell(xlat_file_ptr(stream));
358 TRACE(crtdll, "file %p at 0x%08lx\n",
359 stream,ret);
360 return ret;
363 /*********************************************************************
364 * fwrite (CRTDLL.386)
366 DWORD __cdecl CRTDLL_fwrite(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID vfile)
368 size_t ret;
369 FILE *file=xlat_file_ptr(vfile);
371 ret=fwrite(ptr,size,nmemb,file);
372 TRACE(crtdll, "0x%08x items of size %d from %p to file %p\n",
373 nmemb,size,ptr,file);
374 if(ret!=nmemb)
375 WARN(crtdll, " Failed!\n");
377 return ret;
380 /*********************************************************************
381 * setbuf (CRTDLL.452)
383 INT32 __cdecl CRTDLL_setbuf(LPVOID file, LPSTR buf)
385 TRACE(crtdll, "(file %p buf %p)\n", file, buf);
386 /* this doesn't work:"void value not ignored as it ought to be"
387 return setbuf(file,buf);
389 setbuf(xlat_file_ptr(file),buf);
390 return 0;
393 /*********************************************************************
394 * _open_osfhandle (CRTDLL.240)
396 HFILE32 __cdecl CRTDLL__open_osfhandle(LONG osfhandle, INT32 flags)
398 HFILE32 handle;
400 switch (osfhandle) {
401 case STD_INPUT_HANDLE :
402 case 0 :
403 handle=0;
404 break;
405 case STD_OUTPUT_HANDLE:
406 case 1:
407 handle=1;
408 break;
409 case STD_ERROR_HANDLE:
410 case 2:
411 handle=2;
412 break;
413 default:
414 return (-1);
416 TRACE(crtdll, "(handle %08lx,flags %d) return %d\n",
417 osfhandle,flags,handle);
418 return handle;
422 /*********************************************************************
423 * srand (CRTDLL.460)
425 void __cdecl CRTDLL_srand(DWORD seed)
427 /* FIXME: should of course be thread? process? local */
428 srand(seed);
431 /*********************************************************************
432 * fprintf (CRTDLL.373)
434 INT32 __cdecl CRTDLL_fprintf( FILE *file, LPSTR format, ... )
436 va_list valist;
437 INT32 res;
439 va_start( valist, format );
440 res = vfprintf( xlat_file_ptr(file), format, valist );
441 va_end( valist );
442 return res;
445 /*********************************************************************
446 * vfprintf (CRTDLL.373)
448 INT32 __cdecl CRTDLL_vfprintf( FILE *file, LPSTR format, va_list args )
450 return vfprintf( xlat_file_ptr(file), format, args );
453 /*********************************************************************
454 * time (CRTDLL.488)
456 time_t __cdecl CRTDLL_time(time_t *timeptr)
458 time_t curtime = time(NULL);
460 if (timeptr)
461 *timeptr = curtime;
462 return curtime;
465 /*********************************************************************
466 * (CRTDLL.350)
468 clock_t __cdecl CRTDLL_clock(void)
470 struct tms alltimes;
471 clock_t res;
473 times(&alltimes);
474 res = alltimes.tms_utime + alltimes.tms_stime+
475 alltimes.tms_cutime + alltimes.tms_cstime;
476 /* Fixme: We need some symbolic representation
477 for (Hostsystem_)CLOCKS_PER_SEC
478 and (Emulated_system_)CLOCKS_PER_SEC
479 10 holds only for Windows/Linux_i86)
481 return 10*res;
484 /*********************************************************************
485 * _isatty (CRTDLL.137)
487 BOOL32 __cdecl CRTDLL__isatty(DWORD x)
489 TRACE(crtdll,"(%ld)\n",x);
490 return TRUE;
493 /*********************************************************************
494 * _write (CRTDLL.332)
496 INT32 __cdecl CRTDLL__write(INT32 fd,LPCVOID buf,UINT32 count)
498 INT32 len=0;
500 if (fd == -1)
501 len = -1;
502 else if (fd<=2)
503 len = (UINT32)write(fd,buf,(LONG)count);
504 else
505 len = _lwrite32(fd,buf,count);
506 TRACE(crtdll,"%d/%d byte to dfh %d from %p,\n",
507 len,count,fd,buf);
508 return len;
512 /*********************************************************************
513 * _cexit (CRTDLL.49)
515 * FIXME: What the heck is the difference between
516 * FIXME _c_exit (CRTDLL.47)
517 * FIXME _cexit (CRTDLL.49)
518 * FIXME _exit (CRTDLL.87)
519 * FIXME exit (CRTDLL.359)
521 * atexit-processing comes to mind -- MW.
524 void __cdecl CRTDLL__cexit(INT32 ret)
526 TRACE(crtdll,"(%d)\n",ret);
527 ExitProcess(ret);
531 /*********************************************************************
532 * exit (CRTDLL.359)
534 void __cdecl CRTDLL_exit(DWORD ret)
536 TRACE(crtdll,"(%ld)\n",ret);
537 ExitProcess(ret);
541 /*********************************************************************
542 * _abnormal_termination (CRTDLL.36)
544 INT32 __cdecl CRTDLL__abnormal_termination(void)
546 TRACE(crtdll,"(void)\n");
547 return 0;
551 /*********************************************************************
552 * _access (CRTDLL.37)
554 INT32 __cdecl CRTDLL__access(LPCSTR filename, INT32 mode)
556 DWORD attr = GetFileAttributes32A(filename);
558 if (attr == -1)
560 if (GetLastError() == ERROR_INVALID_ACCESS)
561 errno = EACCES;
562 else
563 errno = ENOENT;
564 return -1;
567 if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
569 errno = EACCES;
570 return -1;
572 else
573 return 0;
577 /*********************************************************************
578 * fflush (CRTDLL.365)
580 INT32 __cdecl CRTDLL_fflush(LPVOID stream)
582 int ret;
584 ret = fflush(xlat_file_ptr(stream));
585 TRACE(crtdll,"%p returnd %d\n",stream,ret);
586 if(ret)
587 WARN(crtdll, " Failed!\n");
589 return ret;
593 /*********************************************************************
594 * gets (CRTDLL.391)
596 LPSTR __cdecl CRTDLL_gets(LPSTR buf)
598 char * ret;
599 /* BAD, for the whole WINE process blocks... just done this way to test
600 * windows95's ftp.exe.
602 ret = gets(buf);
603 TRACE(crtdll,"got %s\n",ret);
604 return ret;
608 /*********************************************************************
609 * rand (CRTDLL.446)
611 INT32 __cdecl CRTDLL_rand()
613 return rand();
617 /*********************************************************************
618 * putchar (CRTDLL.442)
620 void __cdecl CRTDLL_putchar( INT32 x )
622 putchar(x);
626 /*********************************************************************
627 * fputc (CRTDLL.374)
629 INT32 __cdecl CRTDLL_fputc( INT32 c, FILE *stream )
631 TRACE(crtdll, "%c to file %p\n",c,stream);
632 return fputc(c,xlat_file_ptr(stream));
636 /*********************************************************************
637 * fputs (CRTDLL.375)
639 INT32 __cdecl CRTDLL_fputs( LPCSTR s, FILE *stream )
641 TRACE(crtdll, "%s to file %p\n",s,stream);
642 return fputs(s,xlat_file_ptr(stream));
646 /*********************************************************************
647 * puts (CRTDLL.443)
649 INT32 __cdecl CRTDLL_puts(LPCSTR s)
651 TRACE(crtdll, "%s \n",s);
652 return puts(s);
656 /*********************************************************************
657 * putc (CRTDLL.441)
659 INT32 __cdecl CRTDLL_putc(INT32 c, FILE *stream)
661 TRACE(crtdll, " %c to file %p\n",c,stream);
662 return fputc(c,xlat_file_ptr(stream));
664 /*********************************************************************
665 * fgetc (CRTDLL.366)
667 INT32 __cdecl CRTDLL_fgetc( FILE *stream )
669 int ret= fgetc(xlat_file_ptr(stream));
670 TRACE(crtdll, "got %d\n",ret);
671 return ret;
675 /*********************************************************************
676 * getc (CRTDLL.388)
678 INT32 __cdecl CRTDLL_getc( FILE *stream )
680 int ret= fgetc(xlat_file_ptr(stream));
681 TRACE(crtdll, "got %d\n",ret);
682 return ret;
685 /*********************************************************************
686 * _rotl (CRTDLL.259)
688 UINT32 __cdecl CRTDLL__rotl(UINT32 x,INT32 shift)
690 unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift));
692 TRACE(crtdll, "got 0x%08x rot %d ret 0x%08x\n",
693 x,shift,ret);
694 return ret;
697 /*********************************************************************
698 * _lrotl (CRTDLL.176)
700 DWORD __cdecl CRTDLL__lrotl(DWORD x,INT32 shift)
702 unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift));
704 TRACE(crtdll, "got 0x%08lx rot %d ret 0x%08lx\n",
705 x,shift,ret);
706 return ret;
711 /*********************************************************************
712 * fgets (CRTDLL.368)
714 CHAR* __cdecl CRTDLL_fgets(LPSTR s,INT32 size, LPVOID stream)
716 char * ret;
717 char * control_M;
719 ret=fgets(s, size,xlat_file_ptr(stream));
720 /*FIXME: Control with CRTDLL_setmode */
721 control_M= strrchr(s,'\r');
722 /*delete CR if we read a DOS File */
723 if (control_M)
725 *control_M='\n';
726 *(control_M+1)=0;
728 TRACE(crtdll, "got %s for %d chars from file %p\n",
729 s,size,stream);
730 if(ret)
731 WARN(crtdll, " Failed!\n");
733 return ret;
737 /*********************************************************************
738 * _mbsicmp (CRTDLL.204)
740 int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
742 do {
743 if (!*x)
744 return !!*y;
745 if (!*y)
746 return !!*x;
747 /* FIXME: MBCS handling... */
748 if (*x!=*y)
749 return 1;
750 x++;
751 y++;
752 } while (1);
756 /*********************************************************************
757 * _mbsinc (CRTDLL.205)
759 unsigned char * __cdecl CRTDLL__mbsinc(unsigned char *x)
761 /* FIXME: mbcs */
762 return x++;
766 /*********************************************************************
767 * vsprintf (CRTDLL.500)
769 INT32 __cdecl CRTDLL_vsprintf( LPSTR buffer, LPCSTR spec, va_list args )
771 return wvsprintf32A( buffer, spec, args );
774 /*********************************************************************
775 * vswprintf (CRTDLL.501)
777 INT32 __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
779 return wvsprintf32W( buffer, spec, args );
782 /*********************************************************************
783 * _mbscpy (CRTDLL.200)
785 unsigned char* __cdecl CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
787 TRACE(crtdll,"CRTDLL_mbscpy %s and %s\n",x,y);
788 return strcpy(x,y);
792 /*********************************************************************
793 * _mbscat (CRTDLL.197)
795 unsigned char* __cdecl CRTDLL__mbscat(unsigned char *x,unsigned char *y)
797 return strcat(x,y);
801 /*********************************************************************
802 * _strcmpi (CRTDLL.282) (CRTDLL.287)
804 INT32 __cdecl CRTDLL__strcmpi( LPCSTR s1, LPCSTR s2 )
806 return lstrcmpi32A( s1, s2 );
810 /*********************************************************************
811 * _strnicmp (CRTDLL.293)
813 INT32 __cdecl CRTDLL__strnicmp( LPCSTR s1, LPCSTR s2, INT32 n )
815 return lstrncmpi32A( s1, s2, n );
819 /*********************************************************************
820 * _strlwr (CRTDLL.293)
822 * convert a string in place to lowercase
824 LPSTR CRTDLL__strlwr(LPSTR x)
826 unsigned char *y =x;
828 TRACE(crtdll, "CRTDLL_strlwr got %s\n", x);
829 while (*y) {
830 if ((*y > 0x40) && (*y< 0x5b))
831 *y = *y + 0x20;
832 y++;
834 TRACE(crtdll, " returned %s\n", x);
836 return x;
839 /*********************************************************************
840 * system (CRTDLL.485)
842 INT32 CRTDLL_system(LPSTR x)
844 #define SYSBUF_LENGTH 1500
845 char buffer[SYSBUF_LENGTH];
846 unsigned char *y = x;
847 unsigned char *bp;
848 int i;
850 sprintf( buffer, "%s \"", Options.argv0 );
851 bp = buffer + strlen(buffer);
852 i = strlen(buffer) + strlen(x) +2;
854 /* Calculate needed buffer size to prevent overflow. */
855 while (*y) {
856 if (*y =='\\') i++;
857 y++;
859 /* If buffer too short, exit. */
860 if (i > SYSBUF_LENGTH) {
861 TRACE(crtdll,"_system buffer to small\n");
862 return 127;
865 y =x;
867 while (*y) {
868 *bp = *y;
869 bp++; y++;
870 if (*(y-1) =='\\') *bp++ = '\\';
872 /* Remove spaces from end of string. */
873 while (*(y-1) == ' ') {
874 bp--;y--;
876 *bp++ = '"';
877 *bp = 0;
878 TRACE(crtdll, "_system got '%s', executing '%s'\n",x,buffer);
880 return system(buffer);
883 /*********************************************************************
884 * _strupr (CRTDLL.300)
886 LPSTR __cdecl CRTDLL__strupr(LPSTR x)
888 LPSTR y=x;
890 while (*y) {
891 *y=toupper(*y);
892 y++;
894 return x;
897 /*********************************************************************
898 * _wcsupr (CRTDLL.328)
900 LPWSTR __cdecl CRTDLL__wcsupr(LPWSTR x)
902 LPWSTR y=x;
904 while (*y) {
905 *y=toupper(*y);
906 y++;
908 return x;
911 /*********************************************************************
912 * _wcslwr (CRTDLL.323)
914 LPWSTR __cdecl CRTDLL__wcslwr(LPWSTR x)
916 LPWSTR y=x;
918 while (*y) {
919 *y=tolower(*y);
920 y++;
922 return x;
926 /*********************************************************************
927 * longjmp (CRTDLL.426)
929 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
931 FIXME(crtdll,"CRTDLL_longjmp semistup, expect crash\n");
932 return longjmp(env, val);
935 /*********************************************************************
936 * malloc (CRTDLL.427)
938 VOID* __cdecl CRTDLL_malloc(DWORD size)
940 return HeapAlloc(GetProcessHeap(),0,size);
943 /*********************************************************************
944 * new (CRTDLL.001)
946 VOID* __cdecl CRTDLL_new(DWORD size)
948 VOID* result;
949 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
950 (*new_handler)();
951 return result;
954 /*********************************************************************
955 * set_new_handler(CRTDLL.003)
957 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
959 new_handler_type old_handler = new_handler;
960 new_handler = func;
961 return old_handler;
964 /*********************************************************************
965 * calloc (CRTDLL.350)
967 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
969 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
972 /*********************************************************************
973 * realloc (CRTDLL.447)
975 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
977 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
980 /*********************************************************************
981 * free (CRTDLL.427)
983 VOID __cdecl CRTDLL_free(LPVOID ptr)
985 HeapFree(GetProcessHeap(),0,ptr);
988 /*********************************************************************
989 * delete (CRTDLL.002)
991 VOID __cdecl CRTDLL_delete(VOID* ptr)
993 HeapFree(GetProcessHeap(),0,ptr);
996 /*********************************************************************
997 * _strdup (CRTDLL.285)
999 LPSTR __cdecl CRTDLL__strdup(LPSTR ptr)
1001 return HEAP_strdupA(GetProcessHeap(),0,ptr);
1005 /*********************************************************************
1006 * fclose (CRTDLL.362)
1008 INT32 __cdecl CRTDLL_fclose( FILE *stream )
1010 int unix_handle;
1011 HFILE32 dos_handle=1;
1012 HFILE32 ret=EOF;
1014 stream=xlat_file_ptr(stream);
1015 unix_handle=fileno(stream);
1017 if (unix_handle<4) ret= fclose(stream);
1018 else {
1019 while(FILE_GetUnixHandle(dos_handle) != unix_handle) dos_handle++;
1020 fclose(stream);
1021 ret = _lclose32( dos_handle);
1023 TRACE(crtdll,"(%p) ufh %d dfh %d\n",
1024 stream,unix_handle,dos_handle);
1026 if(ret)
1027 WARN(crtdll, " Failed!\n");
1029 return ret;
1032 /*********************************************************************
1033 * _unlink (CRTDLL.315)
1035 INT32 __cdecl CRTDLL__unlink(LPCSTR pathname)
1037 int ret=0;
1038 DOS_FULL_NAME full_name;
1040 if (!DOSFS_GetFullName( pathname, FALSE, &full_name )) {
1041 WARN(crtdll, "CRTDLL_unlink file %s bad name\n",pathname);
1042 return EOF;
1045 ret=unlink(full_name.long_name);
1046 TRACE(crtdll,"(%s unix %s)\n",
1047 pathname,full_name.long_name);
1048 if(ret)
1049 WARN(crtdll, " Failed!\n");
1051 return ret;
1054 /*********************************************************************
1055 * rename (CRTDLL.449)
1057 INT32 __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
1059 BOOL32 ok = MoveFileEx32A( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
1060 return ok ? 0 : -1;
1064 /*********************************************************************
1065 * _stat (CRTDLL.280)
1068 struct win_stat
1070 UINT16 win_st_dev;
1071 UINT16 win_st_ino;
1072 UINT16 win_st_mode;
1073 INT16 win_st_nlink;
1074 INT16 win_st_uid;
1075 INT16 win_st_gid;
1076 UINT32 win_st_rdev;
1077 INT32 win_st_size;
1078 INT32 win_st_atime;
1079 INT32 win_st_mtime;
1080 INT32 win_st_ctime;
1083 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
1085 int ret=0;
1086 DOS_FULL_NAME full_name;
1087 struct stat mystat;
1089 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1091 WARN(crtdll, "CRTDLL__stat filename %s bad name\n",filename);
1092 return -1;
1094 ret=stat(full_name.long_name,&mystat);
1095 TRACE(crtdll,"CRTDLL__stat %s\n", filename);
1096 if(ret)
1097 WARN(crtdll, " Failed!\n");
1099 /* FIXME: should check what Windows returns */
1101 buf->win_st_dev = mystat.st_dev;
1102 buf->win_st_ino = mystat.st_ino;
1103 buf->win_st_mode = mystat.st_mode;
1104 buf->win_st_nlink = mystat.st_nlink;
1105 buf->win_st_uid = mystat.st_uid;
1106 buf->win_st_gid = mystat.st_gid;
1107 buf->win_st_rdev = mystat.st_rdev;
1108 buf->win_st_size = mystat.st_size;
1109 buf->win_st_atime = mystat.st_atime;
1110 buf->win_st_mtime = mystat.st_mtime;
1111 buf->win_st_ctime = mystat.st_ctime;
1112 return ret;
1115 /*********************************************************************
1116 * _open (CRTDLL.239)
1118 HFILE32 __cdecl CRTDLL__open(LPCSTR path,INT32 flags)
1120 HFILE32 ret=0;
1121 int wineflags=0;
1123 /* FIXME:
1124 the flags in lcc's header differ from the ones in Linux, e.g.
1125 Linux: define O_APPEND 02000 (= 0x400)
1126 lcc: define _O_APPEND 0x0008
1127 so here a scheme to translate them
1128 Probably lcc is wrong here, but at least a hack to get is going
1130 wineflags = (flags & 3);
1131 if (flags & 0x0008 ) wineflags |= O_APPEND;
1132 if (flags & 0x0100 ) wineflags |= O_CREAT;
1133 if (flags & 0x0200 ) wineflags |= O_TRUNC;
1134 if (flags & 0x0400 ) wineflags |= O_EXCL;
1135 if (flags & 0xf0f4 )
1136 TRACE(crtdll,"CRTDLL_open file unsupported flags 0x%04x\n",flags);
1137 /* End Fixme */
1139 ret = FILE_Open(path,wineflags);
1140 TRACE(crtdll,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
1141 path,wineflags,flags,ret);
1142 return ret;
1145 /*********************************************************************
1146 * _close (CRTDLL.57)
1148 INT32 __cdecl CRTDLL__close(HFILE32 fd)
1150 int ret=_lclose32(fd);
1152 TRACE(crtdll,"(%d)\n",fd);
1153 if(ret)
1154 WARN(crtdll, " Failed!\n");
1156 return ret;
1159 /*********************************************************************
1160 * feof (CRTDLL.363)
1162 INT32 __cdecl CRTDLL_feof( FILE *stream )
1164 int ret;
1166 ret=feof(xlat_file_ptr(stream));
1167 TRACE(crtdll,"(%p) %s\n",stream,(ret)?"true":"false");
1168 return ret;
1171 /*********************************************************************
1172 * setlocale (CRTDLL.453)
1174 LPSTR __cdecl CRTDLL_setlocale(INT32 category,LPCSTR locale)
1176 LPSTR categorystr;
1178 switch (category) {
1179 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1180 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1181 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1182 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1183 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1184 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1185 default: categorystr = "UNKNOWN?";break;
1187 FIXME(crtdll,"(%s,%s),stub!\n",categorystr,locale);
1188 return "C";
1191 /*********************************************************************
1192 * wcscat (CRTDLL.503)
1194 LPWSTR __cdecl CRTDLL_wcscat( LPWSTR s1, LPCWSTR s2 )
1196 return lstrcat32W( s1, s2 );
1199 /*********************************************************************
1200 * wcschr (CRTDLL.504)
1202 LPWSTR __cdecl CRTDLL_wcschr(LPCWSTR str,WCHAR xchar)
1204 LPCWSTR s;
1206 s=str;
1207 do {
1208 if (*s==xchar)
1209 return (LPWSTR)s;
1210 } while (*s++);
1211 return NULL;
1214 /*********************************************************************
1215 * wcscmp (CRTDLL.505)
1217 INT32 __cdecl CRTDLL_wcscmp( LPCWSTR s1, LPCWSTR s2 )
1219 return lstrcmp32W( s1, s2 );
1222 /*********************************************************************
1223 * wcscpy (CRTDLL.507)
1225 LPWSTR __cdecl CRTDLL_wcscpy( LPWSTR s1, LPCWSTR s2 )
1227 return lstrcpy32W( s1, s2 );
1230 /*********************************************************************
1231 * wcscspn (CRTDLL.508)
1233 INT32 __cdecl CRTDLL_wcscspn(LPWSTR str,LPWSTR reject)
1235 LPWSTR s,t;
1237 s=str;
1238 do {
1239 t=reject;
1240 while (*t) { if (*t==*s) break;t++;}
1241 if (*t) break;
1242 s++;
1243 } while (*s);
1244 return s-str; /* nr of wchars */
1247 /*********************************************************************
1248 * wcslen (CRTDLL.510)
1250 INT32 __cdecl CRTDLL_wcslen( LPCWSTR s )
1252 return lstrlen32W( s );
1255 /*********************************************************************
1256 * wcsncat (CRTDLL.511)
1258 LPWSTR __cdecl CRTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT32 n )
1260 return lstrcatn32W( s1, s2, n );
1263 /*********************************************************************
1264 * wcsncmp (CRTDLL.512)
1266 INT32 __cdecl CRTDLL_wcsncmp( LPCWSTR s1, LPCWSTR s2, INT32 n )
1268 return lstrncmp32W( s1, s2, n );
1271 /*********************************************************************
1272 * wcsncpy (CRTDLL.513)
1274 LPWSTR __cdecl CRTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT32 n )
1276 return lstrcpyn32W( s1, s2, n );
1279 /*********************************************************************
1280 * wcsspn (CRTDLL.516)
1282 INT32 __cdecl CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
1284 LPWSTR s,t;
1286 s=str;
1287 do {
1288 t=accept;
1289 while (*t) { if (*t==*s) break;t++;}
1290 if (!*t) break;
1291 s++;
1292 } while (*s);
1293 return s-str; /* nr of wchars */
1296 /*********************************************************************
1297 * towupper (CRTDLL.494)
1299 WCHAR __cdecl CRTDLL_towupper(WCHAR x)
1301 return (WCHAR)toupper((CHAR)x);
1304 /*********************************************************************
1305 * _wcsicmp (CRTDLL.321)
1307 DWORD __cdecl CRTDLL__wcsicmp( LPCWSTR s1, LPCWSTR s2 )
1309 return lstrcmpi32W( s1, s2 );
1312 /*********************************************************************
1313 * _wcsicoll (CRTDLL.322)
1315 DWORD __cdecl CRTDLL__wcsicoll(LPCWSTR a1,LPCWSTR a2)
1317 /* FIXME: handle collates */
1318 return lstrcmpi32W(a1,a2);
1321 /*********************************************************************
1322 * _wcsnicmp (CRTDLL.324)
1324 DWORD __cdecl CRTDLL__wcsnicmp( LPCWSTR s1, LPCWSTR s2, INT32 len )
1326 return lstrncmpi32W( s1, s2, len );
1329 /*********************************************************************
1330 * wcscoll (CRTDLL.506)
1332 DWORD __cdecl CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
1334 /* FIXME: handle collates */
1335 return lstrcmp32W(a1,a2);
1338 /*********************************************************************
1339 * _wcsrev (CRTDLL.326)
1341 VOID __cdecl CRTDLL__wcsrev(LPWSTR s) {
1342 LPWSTR e;
1344 e=s;
1345 while (*e)
1346 e++;
1347 while (s<e) {
1348 WCHAR a;
1350 a=*s;*s=*e;*e=a;
1351 s++;e--;
1355 /*********************************************************************
1356 * wcsstr (CRTDLL.517)
1358 LPWSTR __cdecl CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
1360 LPWSTR x,y,c;
1362 x=s;
1363 while (*x) {
1364 if (*x==*b) {
1365 y=x;c=b;
1366 while (*y && *c && *y==*c) { c++;y++; }
1367 if (!*c)
1368 return x;
1370 x++;
1372 return NULL;
1375 /*********************************************************************
1376 * wcstombs (CRTDLL.521)
1378 INT32 __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT32 len )
1380 lstrcpynWtoA( dst, src, len );
1381 return strlen(dst); /* FIXME: is this right? */
1384 /*********************************************************************
1385 * wcsrchr (CRTDLL.515)
1387 LPWSTR __cdecl CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
1389 LPWSTR s;
1391 s=str+lstrlen32W(str);
1392 do {
1393 if (*s==xchar)
1394 return s;
1395 s--;
1396 } while (s>=str);
1397 return NULL;
1400 /*********************************************************************
1401 * _setmode (CRTDLL.265)
1402 * FIXME: At present we ignore the request to translate CR/LF to LF.
1404 * We allways translate when we read with fgets, we never do with fread
1407 INT32 __cdecl CRTDLL__setmode( INT32 fh,INT32 mode)
1409 /* FIXME */
1410 #define O_TEXT 0x4000
1411 #define O_BINARY 0x8000
1413 FIXME(crtdll, "on fhandle %d mode %s, STUB.\n",
1414 fh,(mode=O_TEXT)?"O_TEXT":
1415 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1416 return -1;
1419 /*********************************************************************
1420 * _fpreset (CRTDLL.107)
1422 VOID __cdecl CRTDLL__fpreset(void)
1424 FIXME(crtdll," STUB.\n");
1427 /*********************************************************************
1428 * atexit (CRTDLL.345)
1430 INT32 __cdecl CRTDLL_atexit(LPVOID x)
1432 FIXME(crtdll,"(%p), STUB.\n",x);
1433 return 0; /* successful */
1436 /*********************************************************************
1437 * mblen (CRTDLL.428)
1438 * FIXME: check multibyte support
1440 WCHAR __cdecl CRTDLL_mblen(CHAR *mb,INT32 size)
1443 int ret=1;
1445 if (!mb)
1446 ret = 0;
1447 else if ((size<1)||(!*(mb+1)))
1448 ret = -1;
1449 else if (!(*mb))
1450 ret =0;
1452 TRACE(crtdll,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb,size,ret);
1454 return ret;
1457 /*********************************************************************
1458 * mbstowcs (CRTDLL.429)
1459 * FIXME: check multibyte support
1461 INT32 __cdecl CRTDLL_mbstowcs(LPWSTR wcs, LPCSTR mbs, INT32 size)
1464 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1465 * We need the number of characters transfered
1466 * FIXME: No multibyte support yet
1469 LPWSTR p = wcs;
1470 LPCSTR src= mbs;
1471 int ret, n=size;
1473 while ((n-- > 0) && *src) {
1474 *p++ = (WCHAR)(unsigned char)*src++;
1476 p++;
1477 ret = (p -wcs);
1479 TRACE(crtdll,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1480 mbs,size,ret);
1481 return ret;
1484 /*********************************************************************
1485 * mbtowc (CRTDLL.430)
1486 * FIXME: check multibyte support
1488 WCHAR __cdecl CRTDLL_mbtowc(WCHAR* wc,CHAR* mb,INT32 size)
1490 int ret;
1492 if (!mb)
1493 ret = 0;
1494 else if (!wc)
1495 ret =-1;
1496 else
1497 if ( (ret = mblen(mb,size)) != -1 )
1499 if (ret <= sizeof(char))
1500 *wc = (WCHAR) ((unsigned char)*mb);
1501 else
1502 ret= -1;
1504 else
1505 ret = -1;
1507 TRACE(crtdll,"CRTDLL_mbtowc %s for %d chars\n",mb,size);
1509 return ret;
1512 /*********************************************************************
1513 * _isctype (CRTDLL.138)
1515 BOOL32 __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1517 if ((type & CRTDLL_SPACE) && isspace(x))
1518 return TRUE;
1519 if ((type & CRTDLL_PUNCT) && ispunct(x))
1520 return TRUE;
1521 if ((type & CRTDLL_LOWER) && islower(x))
1522 return TRUE;
1523 if ((type & CRTDLL_UPPER) && isupper(x))
1524 return TRUE;
1525 if ((type & CRTDLL_ALPHA) && isalpha(x))
1526 return TRUE;
1527 if ((type & CRTDLL_DIGIT) && isdigit(x))
1528 return TRUE;
1529 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1530 return TRUE;
1531 /* check CRTDLL_LEADBYTE */
1532 return FALSE;
1535 /*********************************************************************
1536 * _chdrive (CRTDLL.52)
1538 * newdir [I] drive to change to, A=1
1541 BOOL32 __cdecl CRTDLL__chdrive(INT32 newdrive)
1543 /* FIXME: generates errnos */
1544 return DRIVE_SetCurrentDrive(newdrive-1);
1547 /*********************************************************************
1548 * _chdir (CRTDLL.51)
1550 INT32 __cdecl CRTDLL__chdir(LPCSTR newdir)
1552 if (!SetCurrentDirectory32A(newdir))
1553 return 1;
1554 return 0;
1557 /*********************************************************************
1558 * _fullpath (CRTDLL.114)
1560 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT32 size)
1562 DOS_FULL_NAME full_name;
1564 if (!buf)
1566 size = 256;
1567 if(!(buf = CRTDLL_malloc(size))) return NULL;
1569 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1570 lstrcpyn32A(buf,full_name.short_name,size);
1571 TRACE(crtdll,"CRTDLL_fullpath got %s\n",buf);
1572 return buf;
1575 /*********************************************************************
1576 * _splitpath (CRTDLL.279)
1578 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1580 /* drive includes :
1581 directory includes leading and trailing (forward and backward slashes)
1582 filename without dot and slashes
1583 extension with leading dot
1585 char * drivechar,*dirchar,*namechar;
1587 TRACE(crtdll,"CRTDLL__splitpath got %s\n",path);
1589 drivechar = strchr(path,':');
1590 dirchar = strrchr(path,'/');
1591 namechar = strrchr(path,'\\');
1592 dirchar = MAX(dirchar,namechar);
1593 if (dirchar)
1594 namechar = strrchr(dirchar,'.');
1595 else
1596 namechar = strrchr(path,'.');
1599 if (drive)
1601 *drive = NULL;
1602 if (drivechar)
1604 strncat(drive,path,drivechar-path+1);
1605 path = drivechar+1;
1608 if (directory)
1610 *directory = NULL;
1611 if (dirchar)
1613 strncat(directory,path,dirchar-path+1);
1614 path = dirchar+1;
1617 if (filename)
1619 *filename = NULL;
1620 if (namechar)
1622 strncat(filename,path,namechar-path);
1623 if (extension)
1625 *extension = NULL;
1626 strcat(extension,namechar);
1631 TRACE(crtdll,"CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1635 /*********************************************************************
1636 * _getcwd (CRTDLL.120)
1638 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT32 size)
1640 char test[1];
1641 int len;
1643 len = size;
1644 if (!buf) {
1645 if (size < 0) /* allocate as big as nescessary */
1646 len =GetCurrentDirectory32A(1,test) + 1;
1647 if(!(buf = CRTDLL_malloc(len)))
1649 /* set error to OutOfRange */
1650 return( NULL );
1653 size = len;
1654 if(!(len =GetCurrentDirectory32A(len,buf)))
1656 return NULL;
1658 if (len > size)
1660 /* set error to ERANGE */
1661 TRACE(crtdll,"CRTDLL_getcwd buffer to small\n");
1662 return NULL;
1664 return buf;
1668 /*********************************************************************
1669 * _getdrive (CRTDLL.124)
1671 * Return current drive, 1 for A, 2 for B
1673 INT32 __cdecl CRTDLL__getdrive(VOID)
1675 return DRIVE_GetCurrentDrive() + 1;
1678 /*********************************************************************
1679 * _mkdir (CRTDLL.234)
1681 INT32 __cdecl CRTDLL__mkdir(LPCSTR newdir)
1683 if (!CreateDirectory32A(newdir,NULL))
1684 return -1;
1685 return 0;
1688 /*********************************************************************
1689 * _errno (CRTDLL.52)
1690 * Yes, this is a function.
1692 LPINT32 __cdecl CRTDLL__errno()
1694 static int crtdllerrno;
1695 extern int LastErrorToErrno(DWORD);
1697 /* FIXME: we should set the error at the failing function call time */
1698 crtdllerrno = LastErrorToErrno(GetLastError());
1699 return &crtdllerrno;
1702 /*********************************************************************
1703 * _tempnam (CRTDLL.305)
1706 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1709 char *ret;
1710 DOS_FULL_NAME tempname;
1712 if ((ret = tempnam(dir,prefix))==NULL) {
1713 WARN(crtdll, "Unable to get unique filename\n");
1714 return NULL;
1716 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1718 TRACE(crtdll, "Wrong path?\n");
1719 return NULL;
1721 free(ret);
1722 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1723 WARN(crtdll, "CRTDL_malloc for shortname failed\n");
1724 return NULL;
1726 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1727 WARN(crtdll, "Malloc for shortname failed\n");
1728 return NULL;
1731 TRACE(crtdll,"dir %s prefix %s got %s\n",
1732 dir,prefix,ret);
1733 return ret;
1736 /*********************************************************************
1737 * tmpnam (CRTDLL.490)
1739 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1742 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1744 char *ret;
1746 if ((ret =tmpnam(s))== NULL) {
1747 WARN(crtdll, "Unable to get unique filename\n");
1748 return NULL;
1750 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1752 TRACE(crtdll, "Wrong path?\n");
1753 return NULL;
1755 strcat(CRTDLL_tmpname.short_name,".");
1756 TRACE(crtdll,"for buf %p got %s\n",
1757 s,CRTDLL_tmpname.short_name);
1758 TRACE(crtdll,"long got %s\n",
1759 CRTDLL_tmpname.long_name);
1760 if ( s != NULL)
1761 return strcpy(s,CRTDLL_tmpname.short_name);
1762 else
1763 return CRTDLL_tmpname.short_name;
1767 /*********************************************************************
1768 * _itoa (CRTDLL.165)
1770 LPSTR __cdecl CRTDLL__itoa(INT32 x,LPSTR buf,INT32 buflen)
1772 wsnprintf32A(buf,buflen,"%d",x);
1773 return buf;
1776 /*********************************************************************
1777 * _ltoa (CRTDLL.180)
1779 LPSTR __cdecl CRTDLL__ltoa(long x,LPSTR buf,INT32 radix)
1781 switch(radix) {
1782 case 2: FIXME(crtdll, "binary format not implemented !\n");
1783 break;
1784 case 8: wsnprintf32A(buf,0x80,"%o",x);
1785 break;
1786 case 10: wsnprintf32A(buf,0x80,"%d",x);
1787 break;
1788 case 16: wsnprintf32A(buf,0x80,"%x",x);
1789 break;
1790 default: FIXME(crtdll, "radix %d not implemented !\n", radix);
1792 return buf;
1795 typedef VOID (*sig_handler_type)(VOID);
1797 /*********************************************************************
1798 * signal (CRTDLL.455)
1800 VOID __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
1802 FIXME(crtdll, "(%d %p):stub.\n", sig, ptr);
1805 /*********************************************************************
1806 * _ftol (CRTDLL.113)
1808 LONG __cdecl CRTDLL__ftol(double fl) {
1809 return (LONG)fl;
1811 /*********************************************************************
1812 * _sleep (CRTDLL.267)
1814 VOID __cdecl CRTDLL__sleep(unsigned long timeout)
1816 TRACE(crtdll,"CRTDLL__sleep for %ld milliseconds\n",timeout);
1817 Sleep((timeout)?timeout:1);
1820 /*********************************************************************
1821 * getenv (CRTDLL.437)
1823 LPSTR __cdecl CRTDLL_getenv(const char *name)
1825 LPSTR environ = GetEnvironmentStrings32A();
1826 LPSTR pp,pos = NULL;
1827 unsigned int length;
1829 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
1831 pos =strchr(pp,'=');
1832 if (pos)
1833 length = pos -pp;
1834 else
1835 length = strlen(pp);
1836 if (!strncmp(pp,name,length)) break;
1838 if ((pp)&& (pos))
1840 pp = pos+1;
1841 TRACE(crtdll,"got %s\n",pp);
1843 FreeEnvironmentStrings32A( environ );
1844 return pp;
1847 /*********************************************************************
1848 * _mbsrchr (CRTDLL.223)
1850 LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x) {
1851 /* FIXME: handle multibyte strings */
1852 return strrchr(s,x);