Release 980601
[wine/gsoc_dplay.git] / misc / crtdll.c
blob3d410ea51a798c4189b3393bb307638f41f69d55
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 <stdlib.h>
25 #include <stdarg.h>
26 #include <string.h>
27 #include <sys/stat.h>
28 #include <sys/times.h>
29 #include <unistd.h>
30 #include <time.h>
31 #include <ctype.h>
32 #include <math.h>
33 #include <fcntl.h>
34 #include <setjmp.h>
35 #include "win.h"
36 #include "windows.h"
37 #include "winerror.h"
38 #include "debug.h"
39 #include "module.h"
40 #include "heap.h"
41 #include "crtdll.h"
42 #include "drive.h"
43 #include "file.h"
44 #include "except.h"
45 #include "options.h"
46 #include "winnls.h"
48 extern int FILE_GetUnixHandle( HFILE32 );
50 static DOS_FULL_NAME CRTDLL_tmpname;
52 UINT32 CRTDLL_argc_dll; /* CRTDLL.23 */
53 LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */
54 LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */
55 UINT32 CRTDLL_basemajor_dll; /* CRTDLL.42 */
56 UINT32 CRTDLL_baseminor_dll; /* CRTDLL.43 */
57 UINT32 CRTDLL_baseversion_dll; /* CRTDLL.44 */
58 UINT32 CRTDLL_commode_dll; /* CRTDLL.59 */
59 LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */
60 UINT32 CRTDLL_fmode_dll; /* CRTDLL.104 */
61 UINT32 CRTDLL_osmajor_dll; /* CRTDLL.241 */
62 UINT32 CRTDLL_osminor_dll; /* CRTDLL.242 */
63 UINT32 CRTDLL_osmode_dll; /* CRTDLL.243 */
64 UINT32 CRTDLL_osver_dll; /* CRTDLL.244 */
65 UINT32 CRTDLL_osversion_dll; /* CRTDLL.245 */
66 UINT32 CRTDLL_winmajor_dll; /* CRTDLL.329 */
67 UINT32 CRTDLL_winminor_dll; /* CRTDLL.330 */
68 UINT32 CRTDLL_winver_dll; /* CRTDLL.331 */
70 BYTE CRTDLL_iob[32*3]; /* FIXME */
72 typedef VOID (*new_handler_type)(VOID);
74 static new_handler_type new_handler;
76 /*********************************************************************
77 * _GetMainArgs (CRTDLL.022)
79 DWORD __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,
80 LPSTR *environ,DWORD flag)
82 char *cmdline;
83 char **xargv;
84 int xargc,i,afterlastspace;
85 DWORD version;
87 TRACE(crtdll,"(%p,%p,%p,%ld).\n",
88 argc,argv,environ,flag
90 CRTDLL_acmdln_dll = cmdline = HEAP_strdupA( GetProcessHeap(), 0,
91 GetCommandLine32A() );
92 TRACE(crtdll,"got '%s'\n", cmdline);
94 version = GetVersion32();
95 CRTDLL_osver_dll = version >> 16;
96 CRTDLL_winminor_dll = version & 0xFF;
97 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
98 CRTDLL_baseversion_dll = version >> 16;
99 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
100 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
101 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
102 CRTDLL_osversion_dll = version & 0xFFFF;
103 CRTDLL_osminor_dll = version & 0xFF;
104 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
106 /* missing threading init */
108 i=0;xargv=NULL;xargc=0;afterlastspace=0;
109 while (cmdline[i]) {
110 if (cmdline[i]==' ') {
111 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
112 sizeof(char*)*(++xargc));
113 cmdline[i]='\0';
114 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
115 cmdline+afterlastspace);
116 i++;
117 while (cmdline[i]==' ')
118 i++;
119 if (cmdline[i])
120 afterlastspace=i;
121 } else
122 i++;
124 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
125 sizeof(char*)*(++xargc));
126 cmdline[i]='\0';
127 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
128 cmdline+afterlastspace);
129 CRTDLL_argc_dll = xargc;
130 *argc = xargc;
131 CRTDLL_argv_dll = xargv;
132 *argv = xargv;
134 TRACE(crtdll,"found %d arguments\n",
135 CRTDLL_argc_dll);
136 CRTDLL_environ_dll = *environ = GetEnvironmentStrings32A();
137 return 0;
141 typedef void (*_INITTERMFUN)();
143 /*********************************************************************
144 * _initterm (CRTDLL.135)
146 DWORD __cdecl CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
148 _INITTERMFUN *current;
150 TRACE(crtdll,"(%p,%p)\n",start,end);
151 current=start;
152 while (current<end) {
153 if (*current) (*current)();
154 current++;
156 return 0;
159 /*********************************************************************
160 * _fdopen (CRTDLL.91)
162 DWORD __cdecl CRTDLL__fdopen(INT32 handle, LPCSTR mode)
164 FILE *file;
166 switch (handle)
168 case 0 : file=stdin;
169 break;
170 case 1 : file=stdout;
171 break;
172 case 2 : file=stderr;
173 break;
174 default:
175 file=fdopen(handle,mode);
177 TRACE(crtdll, "open handle %d mode %s got file %p\n",
178 handle, mode, file);
179 return (DWORD)file;
182 static FILE *xlat_file_ptr(void *ptr)
184 unsigned long dif;
186 /* CRT sizeof(FILE) == 32 */
187 dif = ((char *)ptr - (char *)CRTDLL_iob) / 32;
188 switch(dif)
190 case 0: return stdin;
191 case 1: return stdout;
192 case 2: return stderr;
194 return (FILE*)ptr;
197 /*******************************************************************
198 * _global_unwind2 (CRTDLL.129)
200 void __cdecl CRTDLL__global_unwind2( PEXCEPTION_FRAME frame )
202 RtlUnwind( frame, 0, NULL, 0 );
205 /*******************************************************************
206 * _local_unwind2 (CRTDLL.173)
208 void __cdecl CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe, DWORD nr )
210 TRACE(crtdll,"(%p,%ld)\n",endframe,nr);
213 /*********************************************************************
214 * fopen (CRTDLL.372)
216 DWORD __cdecl CRTDLL_fopen(LPCSTR path, LPCSTR mode)
218 FILE *file;
219 HFILE32 dos_fildes;
220 #if 0
221 DOS_FULL_NAME full_name;
223 if (!DOSFS_GetFullName( path, FALSE, &full_name )) {
224 WARN(crtdll, "file %s bad name\n",path);
225 return 0;
228 file=fopen(full_name.long_name ,mode);
229 #endif
230 INT32 flagmode=0;
231 int unix_fildes=0;
233 if ((strchr(mode,'r')&&strchr(mode,'a'))||
234 (strchr(mode,'r')&&strchr(mode,'w'))||
235 (strchr(mode,'w')&&strchr(mode,'a')))
236 return 0;
238 if (strstr(mode,"r+")) flagmode=O_RDWR;
239 else if (strchr(mode,'r')) flagmode = O_RDONLY;
240 else if (strstr(mode,"w+")) flagmode= O_RDWR | O_TRUNC | O_CREAT;
241 else if (strchr(mode,'w')) flagmode = O_WRONLY | O_TRUNC | O_CREAT;
242 else if (strstr(mode,"a+")) flagmode= O_RDWR | O_CREAT | O_APPEND;
243 else if (strchr(mode,'w')) flagmode = O_RDWR | O_CREAT | O_APPEND;
244 else if (strchr(mode,'b'))
245 TRACE(crtdll, "%s in BINARY mode\n",path);
247 dos_fildes=FILE_Open(path, flagmode);
248 unix_fildes=FILE_GetUnixHandle(dos_fildes);
249 file = fdopen(unix_fildes,mode);
251 TRACE(crtdll, "file %s mode %s got ufh %d dfh %d file %p\n",
252 path,mode,unix_fildes,dos_fildes,file);
253 return (DWORD)file;
256 /*********************************************************************
257 * fread (CRTDLL.377)
259 DWORD __cdecl CRTDLL_fread(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID vfile)
261 size_t ret=1;
262 FILE *file=xlat_file_ptr(vfile);
263 #if 0
264 int i=0;
265 void *temp=ptr;
267 /* If we would honour CR/LF <-> LF translation, we could do it like this.
268 We should keep track of all files opened, and probably files with \
269 known binary extensions must be unchanged */
270 while ( (i < (nmemb*size)) && (ret==1)) {
271 ret=fread(temp,1,1,file);
272 TRACE(crtdll, "got %c 0x%02x ret %d\n",
273 (isalpha(*(unsigned char*)temp))? *(unsigned char*)temp:
274 ' ',*(unsigned char*)temp, ret);
275 if (*(unsigned char*)temp != 0xd) { /* skip CR */
276 temp++;
277 i++;
279 else
280 TRACE(crtdll, "skipping ^M\n");
282 TRACE(crtdll, "0x%08x items of size %d from file %p to %p\n",
283 nmemb,size,file,ptr,);
284 if(i!=nmemb)
285 WARN(crtdll, " failed!\n");
287 return i;
288 #else
290 ret=fread(ptr,size,nmemb,file);
291 TRACE(crtdll, "0x%08x items of size %d from file %p to %p\n",
292 nmemb,size,file,ptr);
293 if(ret!=nmemb)
294 WARN(crtdll, " failed!\n");
296 return ret;
297 #endif
300 /*********************************************************************
301 * fscanf (CRTDLL.381)
303 INT32 __cdecl CRTDLL_fscanf( LPVOID stream, LPSTR format, ... )
305 va_list valist;
306 INT32 res;
308 va_start( valist, format );
309 res = vfscanf( xlat_file_ptr(stream), format, valist );
310 va_end( valist );
311 return res;
314 /*********************************************************************
315 * fseek (CRTDLL.382)
317 LONG __cdecl CRTDLL_fseek(LPVOID stream, LONG offset, INT32 whence)
319 long ret;
321 ret=fseek(xlat_file_ptr(stream),offset,whence);
322 TRACE(crtdll, "file %p to 0x%08lx pos %s\n",
323 stream,offset,(whence==SEEK_SET)?"SEEK_SET":
324 (whence==SEEK_CUR)?"SEEK_CUR":
325 (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
326 if(ret)
327 WARN(crtdll, " failed!\n");
329 return ret;
332 /*********************************************************************
333 * fsetpos (CRTDLL.383)
335 INT32 __cdecl CRTDLL_fsetpos(LPVOID stream, fpos_t *pos)
337 TRACE(crtdll, "file %p\n", stream);
338 return fseek(xlat_file_ptr(stream), *pos, SEEK_SET);
341 /*********************************************************************
342 * ftell (CRTDLL.384)
344 LONG __cdecl CRTDLL_ftell(LPVOID stream)
346 long ret;
348 ret=ftell(xlat_file_ptr(stream));
349 TRACE(crtdll, "file %p at 0x%08lx\n",
350 stream,ret);
351 return ret;
354 /*********************************************************************
355 * fwrite (CRTDLL.386)
357 DWORD __cdecl CRTDLL_fwrite(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID vfile)
359 size_t ret;
360 FILE *file=xlat_file_ptr(vfile);
362 ret=fwrite(ptr,size,nmemb,file);
363 TRACE(crtdll, "0x%08x items of size %d from %p to file %p\n",
364 nmemb,size,ptr,file);
365 if(ret!=nmemb)
366 WARN(crtdll, " Failed!\n");
368 return ret;
371 /*********************************************************************
372 * setbuf (CRTDLL.452)
374 INT32 __cdecl CRTDLL_setbuf(LPVOID file, LPSTR buf)
376 TRACE(crtdll, "(file %p buf %p)\n", file, buf);
377 /* this doesn't work:"void value not ignored as it ought to be"
378 return setbuf(file,buf);
380 setbuf(xlat_file_ptr(file),buf);
381 return 0;
384 /*********************************************************************
385 * _open_osfhandle (CRTDLL.240)
387 HFILE32 __cdecl CRTDLL__open_osfhandle(LONG osfhandle, INT32 flags)
389 HFILE32 handle;
391 switch (osfhandle) {
392 case STD_INPUT_HANDLE :
393 case 0 :
394 handle=0;
395 break;
396 case STD_OUTPUT_HANDLE:
397 case 1:
398 handle=1;
399 break;
400 case STD_ERROR_HANDLE:
401 case 2:
402 handle=2;
403 break;
404 default:
405 return (-1);
407 TRACE(crtdll, "(handle %08lx,flags %d) return %d\n",
408 osfhandle,flags,handle);
409 return handle;
413 /*********************************************************************
414 * srand (CRTDLL.460)
416 void __cdecl CRTDLL_srand(DWORD seed)
418 /* FIXME: should of course be thread? process? local */
419 srand(seed);
422 /*********************************************************************
423 * fprintf (CRTDLL.373)
425 INT32 __cdecl CRTDLL_fprintf( FILE *file, LPSTR format, ... )
427 va_list valist;
428 INT32 res;
430 va_start( valist, format );
431 res = vfprintf( xlat_file_ptr(file), format, valist );
432 va_end( valist );
433 return res;
436 /*********************************************************************
437 * vfprintf (CRTDLL.373)
439 INT32 __cdecl CRTDLL_vfprintf( FILE *file, LPSTR format, va_list args )
441 return vfprintf( xlat_file_ptr(file), format, args );
444 /*********************************************************************
445 * time (CRTDLL.488)
447 time_t __cdecl CRTDLL_time(time_t *timeptr)
449 time_t curtime = time(NULL);
451 if (timeptr)
452 *timeptr = curtime;
453 return curtime;
456 /*********************************************************************
457 * (CRTDLL.350)
459 clock_t __cdecl CRTDLL_clock(void)
461 struct tms alltimes;
462 clock_t res;
464 times(&alltimes);
465 res = alltimes.tms_utime + alltimes.tms_stime+
466 alltimes.tms_cutime + alltimes.tms_cstime;
467 /* Fixme: We need some symbolic representation
468 for (Hostsystem_)CLOCKS_PER_SEC
469 and (Emulated_system_)CLOCKS_PER_SEC
470 10 holds only for Windows/Linux_i86)
472 return 10*res;
475 /*********************************************************************
476 * _isatty (CRTDLL.137)
478 BOOL32 __cdecl CRTDLL__isatty(DWORD x)
480 TRACE(crtdll,"(%ld)\n",x);
481 return TRUE;
484 /*********************************************************************
485 * _write (CRTDLL.332)
487 INT32 __cdecl CRTDLL__write(INT32 fd,LPCVOID buf,UINT32 count)
489 INT32 len=0;
491 if (fd == -1)
492 len = -1;
493 else if (fd<=2)
494 len = (UINT32)write(fd,buf,(LONG)count);
495 else
496 len = _lwrite32(fd,buf,count);
497 TRACE(crtdll,"%d/%d byte to dfh %d from %p,\n",
498 len,count,fd,buf);
499 return len;
503 /*********************************************************************
504 * _cexit (CRTDLL.49)
506 * FIXME: What the heck is the difference between
507 * FIXME _c_exit (CRTDLL.47)
508 * FIXME _cexit (CRTDLL.49)
509 * FIXME _exit (CRTDLL.87)
510 * FIXME exit (CRTDLL.359)
512 * atexit-processing comes to mind -- MW.
515 void __cdecl CRTDLL__cexit(INT32 ret)
517 TRACE(crtdll,"(%d)\n",ret);
518 ExitProcess(ret);
522 /*********************************************************************
523 * exit (CRTDLL.359)
525 void __cdecl CRTDLL_exit(DWORD ret)
527 TRACE(crtdll,"(%ld)\n",ret);
528 ExitProcess(ret);
532 /*********************************************************************
533 * _abnormal_termination (CRTDLL.36)
535 INT32 __cdecl CRTDLL__abnormal_termination(void)
537 TRACE(crtdll,"(void)\n");
538 return 0;
542 /*********************************************************************
543 * _access (CRTDLL.37)
545 INT32 __cdecl CRTDLL__access(LPCSTR filename, INT32 mode)
547 DWORD attr = GetFileAttributes32A(filename);
549 if (attr == -1)
551 if (GetLastError() == ERROR_INVALID_ACCESS)
552 errno = EACCES;
553 else
554 errno = ENOENT;
555 return -1;
558 if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
560 errno = EACCES;
561 return -1;
563 else
564 return 0;
568 /*********************************************************************
569 * fflush (CRTDLL.365)
571 INT32 __cdecl CRTDLL_fflush(LPVOID stream)
573 int ret;
575 ret = fflush(xlat_file_ptr(stream));
576 TRACE(crtdll,"%p returnd %d\n",stream,ret);
577 if(ret)
578 WARN(crtdll, " Failed!\n");
580 return ret;
584 /*********************************************************************
585 * gets (CRTDLL.391)
587 LPSTR __cdecl CRTDLL_gets(LPSTR buf)
589 char * ret;
590 /* BAD, for the whole WINE process blocks... just done this way to test
591 * windows95's ftp.exe.
593 ret = gets(buf);
594 TRACE(crtdll,"got %s\n",ret);
595 return ret;
599 /*********************************************************************
600 * rand (CRTDLL.446)
602 INT32 __cdecl CRTDLL_rand()
604 return rand();
608 /*********************************************************************
609 * putchar (CRTDLL.442)
611 void __cdecl CRTDLL_putchar( INT32 x )
613 putchar(x);
617 /*********************************************************************
618 * fputc (CRTDLL.374)
620 INT32 __cdecl CRTDLL_fputc( INT32 c, FILE *stream )
622 TRACE(crtdll, "%c to file %p\n",c,stream);
623 return fputc(c,xlat_file_ptr(stream));
627 /*********************************************************************
628 * fputs (CRTDLL.375)
630 INT32 __cdecl CRTDLL_fputs( LPCSTR s, FILE *stream )
632 TRACE(crtdll, "%s to file %p\n",s,stream);
633 return fputs(s,xlat_file_ptr(stream));
637 /*********************************************************************
638 * puts (CRTDLL.443)
640 INT32 __cdecl CRTDLL_puts(LPCSTR s)
642 TRACE(crtdll, "%s \n",s);
643 return puts(s);
647 /*********************************************************************
648 * putc (CRTDLL.441)
650 INT32 __cdecl CRTDLL_putc(INT32 c, FILE *stream)
652 TRACE(crtdll, " %c to file %p\n",c,stream);
653 return fputc(c,xlat_file_ptr(stream));
655 /*********************************************************************
656 * fgetc (CRTDLL.366)
658 INT32 __cdecl CRTDLL_fgetc( FILE *stream )
660 int ret= fgetc(xlat_file_ptr(stream));
661 TRACE(crtdll, "got %d\n",ret);
662 return ret;
666 /*********************************************************************
667 * getc (CRTDLL.388)
669 INT32 __cdecl CRTDLL_getc( FILE *stream )
671 int ret= fgetc(xlat_file_ptr(stream));
672 TRACE(crtdll, "got %d\n",ret);
673 return ret;
676 /*********************************************************************
677 * _rotl (CRTDLL.259)
679 UINT32 __cdecl CRTDLL__rotl(UINT32 x,INT32 shift)
681 unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift));
683 TRACE(crtdll, "got 0x%08x rot %d ret 0x%08x\n",
684 x,shift,ret);
685 return ret;
688 /*********************************************************************
689 * _lrotl (CRTDLL.176)
691 DWORD __cdecl CRTDLL__lrotl(DWORD x,INT32 shift)
693 unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift));
695 TRACE(crtdll, "got 0x%08lx rot %d ret 0x%08lx\n",
696 x,shift,ret);
697 return ret;
702 /*********************************************************************
703 * fgets (CRTDLL.368)
705 CHAR* __cdecl CRTDLL_fgets(LPSTR s,INT32 size, LPVOID stream)
707 char * ret;
708 char * control_M;
710 ret=fgets(s, size,xlat_file_ptr(stream));
711 /*FIXME: Control with CRTDLL_setmode */
712 control_M= strrchr(s,'\r');
713 /*delete CR if we read a DOS File */
714 if (control_M)
716 *control_M='\n';
717 *(control_M+1)=0;
719 TRACE(crtdll, "got %s for %d chars from file %p\n",
720 s,size,stream);
721 if(ret)
722 WARN(crtdll, " Failed!\n");
724 return ret;
728 /*********************************************************************
729 * _mbsicmp (CRTDLL.204)
731 int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
733 do {
734 if (!*x)
735 return !!*y;
736 if (!*y)
737 return !!*x;
738 /* FIXME: MBCS handling... */
739 if (*x!=*y)
740 return 1;
741 x++;
742 y++;
743 } while (1);
747 /*********************************************************************
748 * _mbsinc (CRTDLL.205)
750 unsigned char * __cdecl CRTDLL__mbsinc(unsigned char *x)
752 /* FIXME: mbcs */
753 return x++;
757 /*********************************************************************
758 * vsprintf (CRTDLL.500)
760 INT32 __cdecl CRTDLL_vsprintf( LPSTR buffer, LPCSTR spec, va_list args )
762 return wvsprintf32A( buffer, spec, args );
765 /*********************************************************************
766 * vswprintf (CRTDLL.501)
768 INT32 __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
770 return wvsprintf32W( buffer, spec, args );
773 /*********************************************************************
774 * _mbscpy (CRTDLL.200)
776 unsigned char* __cdecl CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
778 TRACE(crtdll,"CRTDLL_mbscpy %s and %s\n",x,y);
779 return strcpy(x,y);
783 /*********************************************************************
784 * _mbscat (CRTDLL.197)
786 unsigned char* __cdecl CRTDLL__mbscat(unsigned char *x,unsigned char *y)
788 return strcat(x,y);
792 /*********************************************************************
793 * _strcmpi (CRTDLL.282) (CRTDLL.287)
795 INT32 __cdecl CRTDLL__strcmpi( LPCSTR s1, LPCSTR s2 )
797 return lstrcmpi32A( s1, s2 );
801 /*********************************************************************
802 * _strnicmp (CRTDLL.293)
804 INT32 __cdecl CRTDLL__strnicmp( LPCSTR s1, LPCSTR s2, INT32 n )
806 return lstrncmpi32A( s1, s2, n );
810 /*********************************************************************
811 * _strlwr (CRTDLL.293)
813 * convert a string in place to lowercase
815 LPSTR CRTDLL__strlwr(LPSTR x)
817 unsigned char *y =x;
819 TRACE(crtdll, "CRTDLL_strlwr got %s\n", x);
820 while (*y) {
821 if ((*y > 0x40) && (*y< 0x5b))
822 *y = *y + 0x20;
823 y++;
825 TRACE(crtdll, " returned %s\n", x);
827 return x;
830 /*********************************************************************
831 * system (CRTDLL.485)
833 INT32 CRTDLL_system(LPSTR x)
835 #define SYSBUF_LENGTH 1500
836 char buffer[SYSBUF_LENGTH];
837 unsigned char *y = x;
838 unsigned char *bp;
839 int i;
841 sprintf( buffer, "%s \"", Options.argv0 );
842 bp = buffer + strlen(buffer);
843 i = strlen(buffer) + strlen(x) +2;
845 /* Calculate needed buffer size to prevent overflow. */
846 while (*y) {
847 if (*y =='\\') i++;
848 y++;
850 /* If buffer too short, exit. */
851 if (i > SYSBUF_LENGTH) {
852 TRACE(crtdll,"_system buffer to small\n");
853 return 127;
856 y =x;
858 while (*y) {
859 *bp = *y;
860 bp++; y++;
861 if (*(y-1) =='\\') *bp++ = '\\';
863 /* Remove spaces from end of string. */
864 while (*(y-1) == ' ') {
865 bp--;y--;
867 *bp++ = '"';
868 *bp = 0;
869 TRACE(crtdll, "_system got '%s', executing '%s'\n",x,buffer);
871 return system(buffer);
874 /*********************************************************************
875 * _strupr (CRTDLL.300)
877 LPSTR __cdecl CRTDLL__strupr(LPSTR x)
879 LPSTR y=x;
881 while (*y) {
882 *y=toupper(*y);
883 y++;
885 return x;
888 /*********************************************************************
889 * _wcsupr (CRTDLL.328)
891 LPWSTR __cdecl CRTDLL__wcsupr(LPWSTR x)
893 LPWSTR y=x;
895 while (*y) {
896 *y=towupper(*y);
897 y++;
899 return x;
902 /*********************************************************************
903 * _wcslwr (CRTDLL.323)
905 LPWSTR __cdecl CRTDLL__wcslwr(LPWSTR x)
907 LPWSTR y=x;
909 while (*y) {
910 *y=towlower(*y);
911 y++;
913 return x;
917 /*********************************************************************
918 * longjmp (CRTDLL.426)
920 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
922 FIXME(crtdll,"CRTDLL_longjmp semistup, expect crash\n");
923 return longjmp(env, val);
926 /*********************************************************************
927 * malloc (CRTDLL.427)
929 VOID* __cdecl CRTDLL_malloc(DWORD size)
931 return HeapAlloc(GetProcessHeap(),0,size);
934 /*********************************************************************
935 * new (CRTDLL.001)
937 VOID* __cdecl CRTDLL_new(DWORD size)
939 VOID* result;
940 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
941 (*new_handler)();
942 return result;
945 /*********************************************************************
946 * set_new_handler(CRTDLL.003)
948 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
950 new_handler_type old_handler = new_handler;
951 new_handler = func;
952 return old_handler;
955 /*********************************************************************
956 * calloc (CRTDLL.350)
958 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
960 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
963 /*********************************************************************
964 * realloc (CRTDLL.447)
966 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
968 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
971 /*********************************************************************
972 * free (CRTDLL.427)
974 VOID __cdecl CRTDLL_free(LPVOID ptr)
976 HeapFree(GetProcessHeap(),0,ptr);
979 /*********************************************************************
980 * delete (CRTDLL.002)
982 VOID __cdecl CRTDLL_delete(VOID* ptr)
984 HeapFree(GetProcessHeap(),0,ptr);
987 /*********************************************************************
988 * _strdup (CRTDLL.285)
990 LPSTR __cdecl CRTDLL__strdup(LPSTR ptr)
992 return HEAP_strdupA(GetProcessHeap(),0,ptr);
996 /*********************************************************************
997 * fclose (CRTDLL.362)
999 INT32 __cdecl CRTDLL_fclose( FILE *stream )
1001 int unix_handle;
1002 HFILE32 dos_handle=1;
1003 HFILE32 ret=EOF;
1005 stream=xlat_file_ptr(stream);
1006 unix_handle=fileno(stream);
1008 if (unix_handle<4) ret= fclose(stream);
1009 else {
1010 while(FILE_GetUnixHandle(dos_handle) != unix_handle) dos_handle++;
1011 fclose(stream);
1012 ret = _lclose32( dos_handle);
1014 TRACE(crtdll,"(%p) ufh %d dfh %d\n",
1015 stream,unix_handle,dos_handle);
1017 if(ret)
1018 WARN(crtdll, " Failed!\n");
1020 return ret;
1023 /*********************************************************************
1024 * _unlink (CRTDLL.315)
1026 INT32 __cdecl CRTDLL__unlink(LPCSTR pathname)
1028 int ret=0;
1029 DOS_FULL_NAME full_name;
1031 if (!DOSFS_GetFullName( pathname, FALSE, &full_name )) {
1032 WARN(crtdll, "CRTDLL_unlink file %s bad name\n",pathname);
1033 return EOF;
1036 ret=unlink(full_name.long_name);
1037 TRACE(crtdll,"(%s unix %s)\n",
1038 pathname,full_name.long_name);
1039 if(ret)
1040 WARN(crtdll, " Failed!\n");
1042 return ret;
1045 /*********************************************************************
1046 * rename (CRTDLL.449)
1048 INT32 __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
1050 BOOL32 ok = MoveFileEx32A( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
1051 return ok ? 0 : -1;
1055 /*********************************************************************
1056 * _stat (CRTDLL.280)
1059 struct win_stat
1061 UINT16 win_st_dev;
1062 UINT16 win_st_ino;
1063 UINT16 win_st_mode;
1064 INT16 win_st_nlink;
1065 INT16 win_st_uid;
1066 INT16 win_st_gid;
1067 UINT32 win_st_rdev;
1068 INT32 win_st_size;
1069 INT32 win_st_atime;
1070 INT32 win_st_mtime;
1071 INT32 win_st_ctime;
1074 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
1076 int ret=0;
1077 DOS_FULL_NAME full_name;
1078 struct stat mystat;
1080 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1082 WARN(crtdll, "CRTDLL__stat filename %s bad name\n",filename);
1083 return -1;
1085 ret=stat(full_name.long_name,&mystat);
1086 TRACE(crtdll,"CRTDLL__stat %s\n", filename);
1087 if(ret)
1088 WARN(crtdll, " Failed!\n");
1090 /* FIXME: should check what Windows returns */
1092 buf->win_st_dev = mystat.st_dev;
1093 buf->win_st_ino = mystat.st_ino;
1094 buf->win_st_mode = mystat.st_mode;
1095 buf->win_st_nlink = mystat.st_nlink;
1096 buf->win_st_uid = mystat.st_uid;
1097 buf->win_st_gid = mystat.st_gid;
1098 buf->win_st_rdev = mystat.st_rdev;
1099 buf->win_st_size = mystat.st_size;
1100 buf->win_st_atime = mystat.st_atime;
1101 buf->win_st_mtime = mystat.st_mtime;
1102 buf->win_st_ctime = mystat.st_ctime;
1103 return ret;
1106 /*********************************************************************
1107 * _open (CRTDLL.239)
1109 HFILE32 __cdecl CRTDLL__open(LPCSTR path,INT32 flags)
1111 HFILE32 ret=0;
1112 int wineflags=0;
1114 /* FIXME:
1115 the flags in lcc's header differ from the ones in Linux, e.g.
1116 Linux: define O_APPEND 02000 (= 0x400)
1117 lcc: define _O_APPEND 0x0008
1118 so here a scheme to translate them
1119 Probably lcc is wrong here, but at least a hack to get is going
1121 wineflags = (flags & 3);
1122 if (flags & 0x0008 ) wineflags |= O_APPEND;
1123 if (flags & 0x0100 ) wineflags |= O_CREAT;
1124 if (flags & 0x0200 ) wineflags |= O_TRUNC;
1125 if (flags & 0x0400 ) wineflags |= O_EXCL;
1126 if (flags & 0xf0f4 )
1127 TRACE(crtdll,"CRTDLL_open file unsupported flags 0x%04x\n",flags);
1128 /* End Fixme */
1130 ret = FILE_Open(path,wineflags);
1131 TRACE(crtdll,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
1132 path,wineflags,flags,ret);
1133 return ret;
1136 /*********************************************************************
1137 * _close (CRTDLL.57)
1139 INT32 __cdecl CRTDLL__close(HFILE32 fd)
1141 int ret=_lclose32(fd);
1143 TRACE(crtdll,"(%d)\n",fd);
1144 if(ret)
1145 WARN(crtdll, " Failed!\n");
1147 return ret;
1150 /*********************************************************************
1151 * feof (CRTDLL.363)
1153 INT32 __cdecl CRTDLL_feof( FILE *stream )
1155 int ret;
1157 ret=feof(xlat_file_ptr(stream));
1158 TRACE(crtdll,"(%p) %s\n",stream,(ret)?"true":"false");
1159 return ret;
1162 /*********************************************************************
1163 * setlocale (CRTDLL.453)
1165 LPSTR __cdecl CRTDLL_setlocale(INT32 category,LPCSTR locale)
1167 LPSTR categorystr;
1169 switch (category) {
1170 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1171 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1172 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1173 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1174 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1175 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1176 default: categorystr = "UNKNOWN?";break;
1178 FIXME(crtdll,"(%s,%s),stub!\n",categorystr,locale);
1179 return "C";
1182 /*********************************************************************
1183 * wcscat (CRTDLL.503)
1185 LPWSTR __cdecl CRTDLL_wcscat( LPWSTR s1, LPCWSTR s2 )
1187 return lstrcat32W( s1, s2 );
1190 /*********************************************************************
1191 * wcschr (CRTDLL.504)
1193 LPWSTR __cdecl CRTDLL_wcschr(LPCWSTR str,WCHAR xchar)
1195 LPCWSTR s;
1197 s=str;
1198 do {
1199 if (*s==xchar)
1200 return (LPWSTR)s;
1201 } while (*s++);
1202 return NULL;
1205 /*********************************************************************
1206 * wcscmp (CRTDLL.505)
1208 INT32 __cdecl CRTDLL_wcscmp( LPCWSTR s1, LPCWSTR s2 )
1210 return lstrcmp32W( s1, s2 );
1213 /*********************************************************************
1214 * wcscpy (CRTDLL.507)
1216 LPWSTR __cdecl CRTDLL_wcscpy( LPWSTR s1, LPCWSTR s2 )
1218 return lstrcpy32W( s1, s2 );
1221 /*********************************************************************
1222 * wcscspn (CRTDLL.508)
1224 INT32 __cdecl CRTDLL_wcscspn(LPWSTR str,LPWSTR reject)
1226 LPWSTR s,t;
1228 s=str;
1229 do {
1230 t=reject;
1231 while (*t) { if (*t==*s) break;t++;}
1232 if (*t) break;
1233 s++;
1234 } while (*s);
1235 return s-str; /* nr of wchars */
1238 /*********************************************************************
1239 * wcslen (CRTDLL.510)
1241 INT32 __cdecl CRTDLL_wcslen( LPCWSTR s )
1243 return lstrlen32W( s );
1246 /*********************************************************************
1247 * wcsncat (CRTDLL.511)
1249 LPWSTR __cdecl CRTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT32 n )
1251 return lstrcatn32W( s1, s2, n );
1254 /*********************************************************************
1255 * wcsncmp (CRTDLL.512)
1257 INT32 __cdecl CRTDLL_wcsncmp( LPCWSTR s1, LPCWSTR s2, INT32 n )
1259 return lstrncmp32W( s1, s2, n );
1262 /*********************************************************************
1263 * wcsncpy (CRTDLL.513)
1265 LPWSTR __cdecl CRTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT32 n )
1267 return lstrcpyn32W( s1, s2, n );
1270 /*********************************************************************
1271 * wcsspn (CRTDLL.516)
1273 INT32 __cdecl CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
1275 LPWSTR s,t;
1277 s=str;
1278 do {
1279 t=accept;
1280 while (*t) { if (*t==*s) break;t++;}
1281 if (!*t) break;
1282 s++;
1283 } while (*s);
1284 return s-str; /* nr of wchars */
1287 /*********************************************************************
1288 * _wcsicmp (CRTDLL.321)
1290 DWORD __cdecl CRTDLL__wcsicmp( LPCWSTR s1, LPCWSTR s2 )
1292 return lstrcmpi32W( s1, s2 );
1295 /*********************************************************************
1296 * _wcsicoll (CRTDLL.322)
1298 DWORD __cdecl CRTDLL__wcsicoll(LPCWSTR a1,LPCWSTR a2)
1300 /* FIXME: handle collates */
1301 return lstrcmpi32W(a1,a2);
1304 /*********************************************************************
1305 * _wcsnicmp (CRTDLL.324)
1307 DWORD __cdecl CRTDLL__wcsnicmp( LPCWSTR s1, LPCWSTR s2, INT32 len )
1309 return lstrncmpi32W( s1, s2, len );
1312 /*********************************************************************
1313 * wcscoll (CRTDLL.506)
1315 DWORD __cdecl CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
1317 /* FIXME: handle collates */
1318 return lstrcmp32W(a1,a2);
1321 /*********************************************************************
1322 * _wcsrev (CRTDLL.326)
1324 VOID __cdecl CRTDLL__wcsrev(LPWSTR s) {
1325 LPWSTR e;
1327 e=s;
1328 while (*e)
1329 e++;
1330 while (s<e) {
1331 WCHAR a;
1333 a=*s;*s=*e;*e=a;
1334 s++;e--;
1338 /*********************************************************************
1339 * wcsstr (CRTDLL.517)
1341 LPWSTR __cdecl CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
1343 LPWSTR x,y,c;
1345 x=s;
1346 while (*x) {
1347 if (*x==*b) {
1348 y=x;c=b;
1349 while (*y && *c && *y==*c) { c++;y++; }
1350 if (!*c)
1351 return x;
1353 x++;
1355 return NULL;
1358 /*********************************************************************
1359 * wcstombs (CRTDLL.521)
1361 INT32 __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT32 len )
1363 lstrcpynWtoA( dst, src, len );
1364 return strlen(dst); /* FIXME: is this right? */
1367 /*********************************************************************
1368 * wcsrchr (CRTDLL.515)
1370 LPWSTR __cdecl CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
1372 LPWSTR s;
1374 s=str+lstrlen32W(str);
1375 do {
1376 if (*s==xchar)
1377 return s;
1378 s--;
1379 } while (s>=str);
1380 return NULL;
1383 /*********************************************************************
1384 * _setmode (CRTDLL.265)
1385 * FIXME: At present we ignore the request to translate CR/LF to LF.
1387 * We allways translate when we read with fgets, we never do with fread
1390 INT32 __cdecl CRTDLL__setmode( INT32 fh,INT32 mode)
1392 /* FIXME */
1393 #define O_TEXT 0x4000
1394 #define O_BINARY 0x8000
1396 FIXME(crtdll, "on fhandle %d mode %s, STUB.\n",
1397 fh,(mode=O_TEXT)?"O_TEXT":
1398 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1399 return -1;
1402 /*********************************************************************
1403 * _fpreset (CRTDLL.107)
1405 VOID __cdecl CRTDLL__fpreset(void)
1407 FIXME(crtdll," STUB.\n");
1410 /*********************************************************************
1411 * atexit (CRTDLL.345)
1413 INT32 __cdecl CRTDLL_atexit(LPVOID x)
1415 FIXME(crtdll,"(%p), STUB.\n",x);
1416 return 0; /* successful */
1419 /*********************************************************************
1420 * mblen (CRTDLL.428)
1421 * FIXME: check multibyte support
1423 WCHAR __cdecl CRTDLL_mblen(CHAR *mb,INT32 size)
1426 int ret=1;
1428 if (!mb)
1429 ret = 0;
1430 else if ((size<1)||(!*(mb+1)))
1431 ret = -1;
1432 else if (!(*mb))
1433 ret =0;
1435 TRACE(crtdll,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb,size,ret);
1437 return ret;
1440 /*********************************************************************
1441 * mbstowcs (CRTDLL.429)
1442 * FIXME: check multibyte support
1444 INT32 __cdecl CRTDLL_mbstowcs(LPWSTR wcs, LPCSTR mbs, INT32 size)
1447 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1448 * We need the number of characters transfered
1449 * FIXME: No multibyte support yet
1452 LPWSTR p = wcs;
1453 LPCSTR src= mbs;
1454 int ret, n=size;
1456 while ((n-- > 0) && *src) {
1457 *p++ = (WCHAR)(unsigned char)*src++;
1459 p++;
1460 ret = (p -wcs);
1462 TRACE(crtdll,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1463 mbs,size,ret);
1464 return ret;
1467 /*********************************************************************
1468 * mbtowc (CRTDLL.430)
1469 * FIXME: check multibyte support
1471 WCHAR __cdecl CRTDLL_mbtowc(WCHAR* wc,CHAR* mb,INT32 size)
1473 int ret;
1475 if (!mb)
1476 ret = 0;
1477 else if (!wc)
1478 ret =-1;
1479 else
1480 if ( (ret = mblen(mb,size)) != -1 )
1482 if (ret <= sizeof(char))
1483 *wc = (WCHAR) ((unsigned char)*mb);
1484 else
1485 ret= -1;
1487 else
1488 ret = -1;
1490 TRACE(crtdll,"CRTDLL_mbtowc %s for %d chars\n",mb,size);
1492 return ret;
1495 /*********************************************************************
1496 * _isctype (CRTDLL.138)
1498 BOOL32 __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1500 if ((type & CRTDLL_SPACE) && isspace(x))
1501 return TRUE;
1502 if ((type & CRTDLL_PUNCT) && ispunct(x))
1503 return TRUE;
1504 if ((type & CRTDLL_LOWER) && islower(x))
1505 return TRUE;
1506 if ((type & CRTDLL_UPPER) && isupper(x))
1507 return TRUE;
1508 if ((type & CRTDLL_ALPHA) && isalpha(x))
1509 return TRUE;
1510 if ((type & CRTDLL_DIGIT) && isdigit(x))
1511 return TRUE;
1512 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1513 return TRUE;
1514 /* check CRTDLL_LEADBYTE */
1515 return FALSE;
1518 /*********************************************************************
1519 * _chdrive (CRTDLL.52)
1521 * newdir [I] drive to change to, A=1
1524 BOOL32 __cdecl CRTDLL__chdrive(INT32 newdrive)
1526 /* FIXME: generates errnos */
1527 return DRIVE_SetCurrentDrive(newdrive-1);
1530 /*********************************************************************
1531 * _chdir (CRTDLL.51)
1533 INT32 __cdecl CRTDLL__chdir(LPCSTR newdir)
1535 if (!SetCurrentDirectory32A(newdir))
1536 return 1;
1537 return 0;
1540 /*********************************************************************
1541 * _fullpath (CRTDLL.114)
1543 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT32 size)
1545 DOS_FULL_NAME full_name;
1547 if (!buf)
1549 size = 256;
1550 if(!(buf = CRTDLL_malloc(size))) return NULL;
1552 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1553 lstrcpyn32A(buf,full_name.short_name,size);
1554 TRACE(crtdll,"CRTDLL_fullpath got %s\n",buf);
1555 return buf;
1558 /*********************************************************************
1559 * _splitpath (CRTDLL.279)
1561 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1563 /* drive includes :
1564 directory includes leading and trailing (forward and backward slashes)
1565 filename without dot and slashes
1566 extension with leading dot
1568 char * drivechar,*dirchar,*namechar;
1570 TRACE(crtdll,"CRTDLL__splitpath got %s\n",path);
1572 drivechar = strchr(path,':');
1573 dirchar = strrchr(path,'/');
1574 namechar = strrchr(path,'\\');
1575 dirchar = MAX(dirchar,namechar);
1576 if (dirchar)
1577 namechar = strrchr(dirchar,'.');
1578 else
1579 namechar = strrchr(path,'.');
1582 if (drive)
1584 *drive = NULL;
1585 if (drivechar)
1587 strncat(drive,path,drivechar-path+1);
1588 path = drivechar+1;
1591 if (directory)
1593 *directory = NULL;
1594 if (dirchar)
1596 strncat(directory,path,dirchar-path+1);
1597 path = dirchar+1;
1600 if (filename)
1602 *filename = NULL;
1603 if (namechar)
1605 strncat(filename,path,namechar-path);
1606 if (extension)
1608 *extension = NULL;
1609 strcat(extension,namechar);
1614 TRACE(crtdll,"CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1618 /*********************************************************************
1619 * _getcwd (CRTDLL.120)
1621 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT32 size)
1623 char test[1];
1624 int len;
1626 len = size;
1627 if (!buf) {
1628 if (size < 0) /* allocate as big as nescessary */
1629 len =GetCurrentDirectory32A(1,test) + 1;
1630 if(!(buf = CRTDLL_malloc(len)))
1632 /* set error to OutOfRange */
1633 return( NULL );
1636 size = len;
1637 if(!(len =GetCurrentDirectory32A(len,buf)))
1639 return NULL;
1641 if (len > size)
1643 /* set error to ERANGE */
1644 TRACE(crtdll,"CRTDLL_getcwd buffer to small\n");
1645 return NULL;
1647 return buf;
1651 /*********************************************************************
1652 * _getdrive (CRTDLL.124)
1654 * Return current drive, 1 for A, 2 for B
1656 INT32 __cdecl CRTDLL__getdrive(VOID)
1658 return DRIVE_GetCurrentDrive() + 1;
1661 /*********************************************************************
1662 * _mkdir (CRTDLL.234)
1664 INT32 __cdecl CRTDLL__mkdir(LPCSTR newdir)
1666 if (!CreateDirectory32A(newdir,NULL))
1667 return -1;
1668 return 0;
1671 /*********************************************************************
1672 * _errno (CRTDLL.52)
1673 * Yes, this is a function.
1675 LPINT32 __cdecl CRTDLL__errno()
1677 static int crtdllerrno;
1679 /* FIXME: we should set the error at the failing function call time */
1680 crtdllerrno = LastErrorToErrno(GetLastError());
1681 return &crtdllerrno;
1684 /*********************************************************************
1685 * _tempnam (CRTDLL.305)
1688 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1691 char *ret;
1692 DOS_FULL_NAME tempname;
1694 if ((ret = tempnam(dir,prefix))==NULL) {
1695 WARN(crtdll, "Unable to get unique filename\n");
1696 return NULL;
1698 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1700 TRACE(crtdll, "Wrong path?\n");
1701 return NULL;
1703 free(ret);
1704 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1705 WARN(crtdll, "CRTDL_malloc for shortname failed\n");
1706 return NULL;
1708 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1709 WARN(crtdll, "Malloc for shortname failed\n");
1710 return NULL;
1713 TRACE(crtdll,"dir %s prefix %s got %s\n",
1714 dir,prefix,ret);
1715 return ret;
1718 /*********************************************************************
1719 * tmpnam (CRTDLL.490)
1721 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1724 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1726 char *ret;
1728 if ((ret =tmpnam(s))== NULL) {
1729 WARN(crtdll, "Unable to get unique filename\n");
1730 return NULL;
1732 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1734 TRACE(crtdll, "Wrong path?\n");
1735 return NULL;
1737 strcat(CRTDLL_tmpname.short_name,".");
1738 TRACE(crtdll,"for buf %p got %s\n",
1739 s,CRTDLL_tmpname.short_name);
1740 TRACE(crtdll,"long got %s\n",
1741 CRTDLL_tmpname.long_name);
1742 if ( s != NULL)
1743 return strcpy(s,CRTDLL_tmpname.short_name);
1744 else
1745 return CRTDLL_tmpname.short_name;
1749 /*********************************************************************
1750 * _itoa (CRTDLL.165)
1752 LPSTR __cdecl CRTDLL__itoa(INT32 x,LPSTR buf,INT32 buflen)
1754 wsnprintf32A(buf,buflen,"%d",x);
1755 return buf;
1758 /*********************************************************************
1759 * _ltoa (CRTDLL.180)
1761 LPSTR __cdecl CRTDLL__ltoa(long x,LPSTR buf,INT32 radix)
1763 switch(radix) {
1764 case 2: FIXME(crtdll, "binary format not implemented !\n");
1765 break;
1766 case 8: wsnprintf32A(buf,0x80,"%o",x);
1767 break;
1768 case 10: wsnprintf32A(buf,0x80,"%d",x);
1769 break;
1770 case 16: wsnprintf32A(buf,0x80,"%x",x);
1771 break;
1772 default: FIXME(crtdll, "radix %d not implemented !\n", radix);
1774 return buf;
1777 typedef VOID (*sig_handler_type)(VOID);
1779 /*********************************************************************
1780 * signal (CRTDLL.455)
1782 VOID __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
1784 FIXME(crtdll, "(%d %p):stub.\n", sig, ptr);
1787 /*********************************************************************
1788 * _ftol (CRTDLL.113)
1790 LONG __cdecl CRTDLL__ftol(double fl) {
1791 return (LONG)fl;
1793 /*********************************************************************
1794 * _sleep (CRTDLL.267)
1796 VOID __cdecl CRTDLL__sleep(unsigned long timeout)
1798 TRACE(crtdll,"CRTDLL__sleep for %ld milliseconds\n",timeout);
1799 Sleep((timeout)?timeout:1);
1802 /*********************************************************************
1803 * getenv (CRTDLL.437)
1805 LPSTR __cdecl CRTDLL_getenv(const char *name)
1807 LPSTR environ = GetEnvironmentStrings32A();
1808 LPSTR pp,pos = NULL;
1809 unsigned int length;
1811 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
1813 pos =strchr(pp,'=');
1814 if (pos)
1815 length = pos -pp;
1816 else
1817 length = strlen(pp);
1818 if (!strncmp(pp,name,length)) break;
1820 if ((pp)&& (pos))
1822 pp = pos+1;
1823 TRACE(crtdll,"got %s\n",pp);
1825 FreeEnvironmentStrings32A( environ );
1826 return pp;
1829 /*********************************************************************
1830 * _mbsrchr (CRTDLL.223)
1832 LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x) {
1833 /* FIXME: handle multibyte strings */
1834 return strrchr(s,x);