Release 980215
[wine.git] / misc / crtdll.c
blobdac9b30a6f5a6e11c50d48855a5a31f46cfbed70
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 <stdio.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 "stddebug.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"
47 extern int FILE_GetUnixHandle( HFILE32 );
49 static DOS_FULL_NAME CRTDLL_tmpname;
51 extern INT32 WIN32_wsprintf32W( DWORD *args );
53 UINT32 CRTDLL_argc_dll; /* CRTDLL.23 */
54 LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */
55 LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */
56 UINT32 CRTDLL_basemajor_dll; /* CRTDLL.42 */
57 UINT32 CRTDLL_baseminor_dll; /* CRTDLL.43 */
58 UINT32 CRTDLL_baseversion_dll; /* CRTDLL.44 */
59 UINT32 CRTDLL_commode_dll; /* CRTDLL.59 */
60 LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */
61 UINT32 CRTDLL_fmode_dll; /* CRTDLL.104 */
62 UINT32 CRTDLL_osmajor_dll; /* CRTDLL.241 */
63 UINT32 CRTDLL_osminor_dll; /* CRTDLL.242 */
64 UINT32 CRTDLL_osmode_dll; /* CRTDLL.243 */
65 UINT32 CRTDLL_osver_dll; /* CRTDLL.244 */
66 UINT32 CRTDLL_osversion_dll; /* CRTDLL.245 */
67 UINT32 CRTDLL_winmajor_dll; /* CRTDLL.329 */
68 UINT32 CRTDLL_winminor_dll; /* CRTDLL.330 */
69 UINT32 CRTDLL_winver_dll; /* CRTDLL.331 */
71 typedef VOID (*new_handler_type)(VOID);
73 static new_handler_type new_handler;
75 /*********************************************************************
76 * _GetMainArgs (CRTDLL.022)
78 DWORD __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,
79 LPSTR *environ,DWORD flag)
81 char *cmdline;
82 char **xargv;
83 int xargc,i,afterlastspace;
84 DWORD version;
86 dprintf_crtdll(stddeb,"CRTDLL__GetMainArgs(%p,%p,%p,%ld).\n",
87 argc,argv,environ,flag
89 CRTDLL_acmdln_dll = cmdline = HEAP_strdupA( GetProcessHeap(), 0,
90 GetCommandLine32A() );
91 dprintf_crtdll(stddeb,"CRTDLL__GetMainArgs got \"%s\"\n",
92 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 dprintf_crtdll(stddeb,"CRTDLL__GetMainArgs 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 dprintf_crtdll(stddeb,"_initterm(%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 dprintf_crtdll(stddeb,
178 "CRTDLL_fdopen open handle %d mode %s got file %p\n",
179 handle, mode, file);
180 return (DWORD)file;
183 /*******************************************************************
184 * _global_unwind2 (CRTDLL.129)
186 void __cdecl CRTDLL__global_unwind2( CONTEXT *context )
188 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
189 DWORD *args = (DWORD *)ESP_reg(context);
190 RtlUnwind( (PEXCEPTION_FRAME)args[1], (LPVOID)EIP_reg(context),
191 NULL, 0, context );
194 /*******************************************************************
195 * _local_unwind2 (CRTDLL.173)
197 void __cdecl CRTDLL__local_unwind2( CONTEXT *context )
199 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
200 DWORD *args = (DWORD *)ESP_reg(context);
201 PEXCEPTION_FRAME endframe = (PEXCEPTION_FRAME)args[1];
202 DWORD nr = args[2];
203 fprintf(stderr,"CRTDLL__local_unwind2(%p,%ld)\n",endframe,nr);
206 /*********************************************************************
207 * fopen (CRTDLL.372)
209 DWORD __cdecl CRTDLL_fopen(LPCSTR path, LPCSTR mode)
211 FILE *file;
212 HFILE32 dos_fildes;
213 #if 0
214 DOS_FULL_NAME full_name;
216 if (!DOSFS_GetFullName( path, FALSE, &full_name )) {
217 dprintf_crtdll(stddeb,"CRTDLL_fopen file %s bad name\n",path);
218 return 0;
221 file=fopen(full_name.long_name ,mode);
222 #endif
223 INT32 flagmode=0;
224 int unix_fildes=0;
226 if ((strchr(mode,'r')&&strchr(mode,'a'))||
227 (strchr(mode,'r')&&strchr(mode,'w'))||
228 (strchr(mode,'w')&&strchr(mode,'a')))
229 return 0;
231 if (strstr(mode,"r+")) flagmode=O_RDWR;
232 else if (strchr(mode,'r')) flagmode = O_RDONLY;
233 else if (strstr(mode,"w+")) flagmode= O_RDWR | O_TRUNC | O_CREAT;
234 else if (strchr(mode,'w')) flagmode = O_WRONLY | O_TRUNC | O_CREAT;
235 else if (strstr(mode,"a+")) flagmode= O_RDWR | O_CREAT | O_APPEND;
236 else if (strchr(mode,'w')) flagmode = O_RDWR | O_CREAT | O_APPEND;
237 else if (strchr(mode,'b'))
238 dprintf_crtdll(stderr,
239 "CRTDLL_fopen %s in BINARY mode\n",path);
241 dos_fildes=FILE_Open(path, flagmode);
242 unix_fildes=FILE_GetUnixHandle(dos_fildes);
243 file = fdopen(unix_fildes,mode);
245 dprintf_crtdll(stddeb,
246 "CRTDLL_fopen file %s mode %s got ufh %d dfh %d file %p\n",
247 path,mode,unix_fildes,dos_fildes,file);
248 return (DWORD)file;
251 /*********************************************************************
252 * fread (CRTDLL.377)
254 DWORD __cdecl CRTDLL_fread(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID file)
256 size_t ret=1;
257 #if 0
258 int i=0;
259 void *temp=ptr;
261 /* If we would honour CR/LF <-> LF translation, we could do it like this.
262 We should keep track of all files opened, and probably files with \
263 known binary extensions must be unchanged */
264 while ( (i < (nmemb*size)) && (ret==1)) {
265 ret=fread(temp,1,1,file);
266 dprintf_crtdll(stddeb,
267 "CRTDLL_fread got %c 0x%02x ret %d\n",
268 (isalpha(*(unsigned char*)temp))? *(unsigned char*)temp:
269 ' ',*(unsigned char*)temp, ret);
270 if (*(unsigned char*)temp != 0xd) { /* skip CR */
271 temp++;
272 i++;
274 else
275 dprintf_crtdll(stddeb, "CRTDLL_fread skipping ^M\n");
277 dprintf_crtdll(stddeb,
278 "CRTDLL_fread 0x%08x items of size %d from file %p to %p%s\n",
279 nmemb,size,file,ptr,(i!=nmemb)?" failed":"");
280 return i;
281 #else
283 ret=fread(ptr,size,nmemb,file);
284 dprintf_crtdll(stddeb,
285 "CRTDLL_fread 0x%08x items of size %d from file %p to %p%s\n",
286 nmemb,size,file,ptr,(ret!=nmemb)?" failed":"");
287 return ret;
288 #endif
291 /*********************************************************************
292 * fseek (CRTDLL.382)
294 LONG __cdecl CRTDLL_fseek(LPVOID stream, LONG offset, INT32 whence)
296 long ret;
298 ret=fseek(stream,offset,whence);
299 dprintf_crtdll(stddeb,
300 "CRTDLL_fseek file %p to 0x%08lx pos %s%s\n",
301 stream,offset,(whence==SEEK_SET)?"SEEK_SET":
302 (whence==SEEK_CUR)?"SEEK_CUR":
303 (whence==SEEK_END)?"SEEK_END":"UNKNOWN",
304 (ret)?"failed":"");
305 return ret;
308 /*********************************************************************
309 * ftell (CRTDLL.384)
311 LONG __cdecl CRTDLL_ftell(LPVOID stream)
313 long ret;
315 ret=ftell(stream);
316 dprintf_crtdll(stddeb,
317 "CRTDLL_ftell file %p at 0x%08lx\n",
318 stream,ret);
319 return ret;
322 /*********************************************************************
323 * fwrite (CRTDLL.386)
325 DWORD __cdecl CRTDLL_fwrite(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID file)
327 size_t ret;
329 ret=fwrite(ptr,size,nmemb,file);
330 dprintf_crtdll(stddeb,
331 "CRTDLL_fwrite 0x%08x items of size %d from %p to file %p%s\n",
332 nmemb,size,ptr,file,(ret!=nmemb)?" failed":"");
333 return ret;
336 /*********************************************************************
337 * setbuf (CRTDLL.452)
339 INT32 __cdecl CRTDLL_setbuf(LPVOID file, LPSTR buf)
341 dprintf_crtdll(stddeb,
342 "CRTDLL_setbuf(file %p buf %p)\n",
343 file,buf);
344 /* this doesn't work:"void value not ignored as it ought to be"
345 return setbuf(file,buf);
347 setbuf(file,buf);
348 return 0;
351 /*********************************************************************
352 * _open_osfhandle (CRTDLL.240)
354 HFILE32 __cdecl CRTDLL__open_osfhandle(LONG osfhandle, INT32 flags)
356 HFILE32 handle;
358 switch (osfhandle) {
359 case STD_INPUT_HANDLE :
360 case 0 :
361 handle=0;
362 break;
363 case STD_OUTPUT_HANDLE:
364 case 1:
365 handle=1;
366 break;
367 case STD_ERROR_HANDLE:
368 case 2:
369 handle=2;
370 break;
371 default:
372 return (-1);
374 dprintf_crtdll(stddeb,
375 "CRTDLL_open_osfhandle(handle %08lx,flags %d) return %d\n",
376 osfhandle,flags,handle);
377 return handle;
381 /*********************************************************************
382 * srand (CRTDLL.460)
384 void __cdecl CRTDLL_srand(DWORD seed)
386 /* FIXME: should of course be thread? process? local */
387 srand(seed);
390 /*********************************************************************
391 * fprintf (CRTDLL.373)
393 INT32 __cdecl CRTDLL_fprintf( FILE *file, LPSTR format, ... )
395 va_list valist;
396 INT32 res;
398 va_start( valist, format );
399 res = vfprintf( file, format, valist );
400 va_end( valist );
401 return res;
404 /*********************************************************************
405 * vfprintf (CRTDLL.373)
407 INT32 __cdecl CRTDLL_vfprintf( FILE *file, LPSTR format, va_list args )
409 return vfprintf( file, format, args );
412 /*********************************************************************
413 * time (CRTDLL.488)
415 time_t __cdecl CRTDLL_time(time_t *timeptr)
417 time_t curtime = time(NULL);
419 if (timeptr)
420 *timeptr = curtime;
421 return curtime;
424 /*********************************************************************
425 * (CRTDLL.350)
427 clock_t __cdecl CRTDLL_clock(void)
429 struct tms alltimes;
430 clock_t res;
432 times(&alltimes);
433 res = alltimes.tms_utime + alltimes.tms_stime+
434 alltimes.tms_cutime + alltimes.tms_cstime;
435 /* Fixme: We need some symbolic representation
436 for (Hostsystem_)CLOCKS_PER_SEC
437 and (Emulated_system_)CLOCKS_PER_SEC
438 10 holds only for Windows/Linux_i86)
440 return 10*res;
443 /*********************************************************************
444 * _isatty (CRTDLL.137)
446 BOOL32 __cdecl CRTDLL__isatty(DWORD x)
448 dprintf_crtdll(stderr,"CRTDLL__isatty(%ld)\n",x);
449 return TRUE;
452 /*********************************************************************
453 * _write (CRTDLL.332)
455 INT32 __cdecl CRTDLL__write(INT32 fd,LPCVOID buf,UINT32 count)
457 INT32 len=0;
459 if (fd == -1)
460 len = -1;
461 else if (fd<=2)
462 len = (UINT32)write(fd,buf,(LONG)count);
463 else
464 len = _lwrite32(fd,buf,count);
465 dprintf_crtdll(stddeb,"CRTDLL_write %d/%d byte to dfh %d from %p,\n",
466 len,count,fd,buf);
467 return len;
471 /*********************************************************************
472 * _cexit (CRTDLL.49)
474 * FIXME: What the heck is the difference between
475 * FIXME _c_exit (CRTDLL.47)
476 * FIXME _cexit (CRTDLL.49)
477 * FIXME _exit (CRTDLL.87)
478 * FIXME exit (CRTDLL.359)
480 * atexit-processing comes to mind -- MW.
483 void __cdecl CRTDLL__cexit(INT32 ret)
485 dprintf_crtdll(stddeb,"CRTDLL__cexit(%d)\n",ret);
486 ExitProcess(ret);
490 /*********************************************************************
491 * exit (CRTDLL.359)
493 void __cdecl CRTDLL_exit(DWORD ret)
495 dprintf_crtdll(stddeb,"CRTDLL_exit(%ld)\n",ret);
496 ExitProcess(ret);
500 /*********************************************************************
501 * _abnormal_termination (CRTDLL.36 )
503 INT32 __cdecl CRTDLL__abnormal_termination(void)
505 dprintf_crtdll(stddeb,"CRTDLL__abnormal_termination\n");
506 return 0;
510 /*********************************************************************
511 * fflush (CRTDLL.365)
513 INT32 __cdecl CRTDLL_fflush(LPVOID stream)
515 int ret;
517 ret = fflush(stream);
518 dprintf_crtdll(stddeb,"CRTDLL_fflush %p returnd %d %s\n",stream,ret,(ret)?"":" failed");
519 return ret;
523 /*********************************************************************
524 * gets (CRTDLL.391)
526 LPSTR __cdecl CRTDLL_gets(LPSTR buf)
528 char * ret;
529 /* BAD, for the whole WINE process blocks... just done this way to test
530 * windows95's ftp.exe.
532 ret = gets(buf);
533 dprintf_crtdll(stddeb,"CRTDLL_gets got %s\n",ret);
534 return ret;
538 /*********************************************************************
539 * rand (CRTDLL.446)
541 INT32 __cdecl CRTDLL_rand()
543 return rand();
547 /*********************************************************************
548 * putchar (CRTDLL.442)
550 void __cdecl CRTDLL_putchar( INT32 x )
552 putchar(x);
556 /*********************************************************************
557 * fputc (CRTDLL.374)
559 INT32 __cdecl CRTDLL_fputc( INT32 c, FILE *stream )
561 dprintf_crtdll(stddeb,
562 "CRTDLL_fputc %c to file %p\n",c,stream);
563 return fputc(c,stream);
567 /*********************************************************************
568 * fputs (CRTDLL.375)
570 INT32 __cdecl CRTDLL_fputs( LPCSTR s, FILE *stream )
572 dprintf_crtdll(stddeb,
573 "CRTDLL_fputs %s to file %p\n",s,stream);
574 return fputs(s,stream);
578 /*********************************************************************
579 * puts (CRTDLL.443)
581 INT32 __cdecl CRTDLL_puts(LPCSTR s)
583 dprintf_crtdll(stddeb,
584 "CRTDLL_fputs %s \n",s);
585 return puts(s);
589 /*********************************************************************
590 * putc (CRTDLL.441)
592 INT32 __cdecl CRTDLL_putc(INT32 c, FILE *stream)
594 dprintf_crtdll(stddeb,
595 "CRTDLL_putc %c to file %p\n",c,stream);
596 return fputc(c,stream);
598 /*********************************************************************
599 * fgetc (CRTDLL.366)
601 INT32 __cdecl CRTDLL_fgetc( FILE *stream )
603 int ret= fgetc(stream);
604 dprintf_crtdll(stddeb,
605 "CRTDLL_fgetc got %d\n",ret);
606 return ret;
610 /*********************************************************************
611 * getc (CRTDLL.388)
613 INT32 __cdecl CRTDLL_getc( FILE *stream )
615 int ret= fgetc(stream);
616 dprintf_crtdll(stddeb,
617 "CRTDLL_getc got %d\n",ret);
618 return ret;
621 /*********************************************************************
622 * _rotl (CRTDLL.259)
624 UINT32 __cdecl CRTDLL__rotl(UINT32 x,INT32 shift)
626 unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift));
628 dprintf_crtdll(stddeb,
629 "CRTDLL_rotl got 0x%08x rot %d ret 0x%08x\n",
630 x,shift,ret);
631 return ret;
634 /*********************************************************************
635 * _lrotl (CRTDLL.176)
637 DWORD __cdecl CRTDLL__lrotl(DWORD x,INT32 shift)
639 unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift));
641 dprintf_crtdll(stddeb,
642 "CRTDLL_lrotl got 0x%08lx rot %d ret 0x%08lx\n",
643 x,shift,ret);
644 return ret;
649 /*********************************************************************
650 * fgets (CRTDLL.368)
652 CHAR* __cdecl CRTDLL_fgets(LPSTR s,INT32 size, LPVOID stream)
654 char * ret;
655 char * control_M;
657 ret=fgets(s, size,stream);
658 /*FIXME: Control with CRTDLL_setmode */
659 control_M= strrchr(s,'\r');
660 /*delete CR if we read a DOS File */
661 if (control_M)
663 *control_M='\n';
664 *(control_M+1)=0;
666 dprintf_crtdll(stddeb,
667 "CRTDLL_fgets got %s for %d chars from file %p%s\n",
668 s,size,stream,(ret)?"":" failed");
669 return ret;
673 /*********************************************************************
674 * _mbsicmp (CRTDLL.204)
676 int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
678 do {
679 if (!*x)
680 return !!*y;
681 if (!*y)
682 return !!*x;
683 /* FIXME: MBCS handling... */
684 if (*x!=*y)
685 return 1;
686 x++;
687 y++;
688 } while (1);
692 /*********************************************************************
693 * _mbsinc (CRTDLL.205)
695 unsigned char * __cdecl CRTDLL__mbsinc(unsigned char *x)
697 /* FIXME: mbcs */
698 return x++;
702 /*********************************************************************
703 * vsprintf (CRTDLL.500)
705 INT32 __cdecl CRTDLL_vsprintf( LPSTR buffer, LPCSTR spec, va_list args )
707 return wvsprintf32A( buffer, spec, args );
710 /*********************************************************************
711 * vswprintf (CRTDLL.501)
713 INT32 __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
715 return wvsprintf32W( buffer, spec, args );
718 /*********************************************************************
719 * _mbscpy (CRTDLL.200)
721 unsigned char* __cdecl CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
723 dprintf_crtdll(stddeb,"CRTDLL_mbscpy %s and %s\n",x,y);
724 return strcpy(x,y);
728 /*********************************************************************
729 * _mbscat (CRTDLL.197)
731 unsigned char* __cdecl CRTDLL__mbscat(unsigned char *x,unsigned char *y)
733 return strcat(x,y);
737 /*********************************************************************
738 * _strcmpi (CRTDLL.282) (CRTDLL.287)
740 INT32 __cdecl CRTDLL__strcmpi( LPCSTR s1, LPCSTR s2 )
742 return lstrcmpi32A( s1, s2 );
746 /*********************************************************************
747 * _strnicmp (CRTDLL.293)
749 INT32 __cdecl CRTDLL__strnicmp( LPCSTR s1, LPCSTR s2, INT32 n )
751 return lstrncmpi32A( s1, s2, n );
755 /*********************************************************************
756 * _strlwr (CRTDLL.293)
758 * convert a string in place to lowercase
760 LPSTR CRTDLL__strlwr(LPSTR x)
762 unsigned char *y =x;
764 dprintf_crtdll(stddeb,
765 "CRTDLL_strlwr got %s",x);
766 while (*y) {
767 if ((*y > 0x40) && (*y< 0x5b))
768 *y = *y + 0x20;
769 y++;
771 dprintf_crtdll(stddeb," returned %s\n",x);
773 return x;
776 /*********************************************************************
777 * system (CRTDLL.485)
779 INT32 CRTDLL_system(LPSTR x)
781 #define SYSBUF_LENGTH 1500
782 char buffer[SYSBUF_LENGTH];
783 unsigned char *y = x;
784 unsigned char *bp;
785 int i;
787 sprintf( buffer, "%s \"", Options.argv0 );
788 bp = buffer + strlen(buffer);
789 i = strlen(buffer) + strlen(x) +2;
791 /* Calculate needed buffer size to prevent overflow. */
792 while (*y) {
793 if (*y =='\\') i++;
794 y++;
796 /* If buffer too short, exit. */
797 if (i > SYSBUF_LENGTH) {
798 dprintf_crtdll(stddeb,"_system buffer to small\n");
799 return 127;
802 y =x;
804 while (*y) {
805 *bp = *y;
806 bp++; y++;
807 if (*(y-1) =='\\') *bp++ = '\\';
809 /* Remove spaces from end of string. */
810 while (*(y-1) == ' ') {
811 bp--;y--;
813 *bp++ = '"';
814 *bp = 0;
815 dprintf_crtdll(stddeb,
816 "_system got \"%s\", executing \"%s\"\n",x,buffer);
818 return system(buffer);
821 /*********************************************************************
822 * _strupr (CRTDLL.300)
824 LPSTR __cdecl CRTDLL__strupr(LPSTR x)
826 LPSTR y=x;
828 while (*y) {
829 *y=toupper(*y);
830 y++;
832 return x;
835 /*********************************************************************
836 * _wcsupr (CRTDLL.328)
838 LPWSTR __cdecl CRTDLL__wcsupr(LPWSTR x)
840 LPWSTR y=x;
842 while (*y) {
843 *y=toupper(*y);
844 y++;
846 return x;
849 /*********************************************************************
850 * _wcslwr (CRTDLL.323)
852 LPWSTR __cdecl CRTDLL__wcslwr(LPWSTR x)
854 LPWSTR y=x;
856 while (*y) {
857 *y=tolower(*y);
858 y++;
860 return x;
864 /*********************************************************************
865 * longjmp (CRTDLL.426)
867 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
869 dprintf_crtdll(stdnimp,"CRTDLL_longjmp semistup, expect crash\n");
870 dprintf_crtdll(stddeb, "CRTDLL_longjmp semistup, expect crash\n");
871 return longjmp(env, val);
874 /*********************************************************************
875 * malloc (CRTDLL.427)
877 VOID* __cdecl CRTDLL_malloc(DWORD size)
879 return HeapAlloc(GetProcessHeap(),0,size);
882 /*********************************************************************
883 * new (CRTDLL.001)
885 VOID* __cdecl CRTDLL_new(DWORD size)
887 VOID* result;
888 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
889 (*new_handler)();
890 return result;
893 /*********************************************************************
894 * set_new_handler(CRTDLL.003)
896 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
898 new_handler_type old_handler = new_handler;
899 new_handler = func;
900 return old_handler;
903 /*********************************************************************
904 * calloc (CRTDLL.350)
906 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
908 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
911 /*********************************************************************
912 * realloc (CRTDLL.447)
914 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
916 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
919 /*********************************************************************
920 * free (CRTDLL.427)
922 VOID __cdecl CRTDLL_free(LPVOID ptr)
924 HeapFree(GetProcessHeap(),0,ptr);
927 /*********************************************************************
928 * delete (CRTDLL.002)
930 VOID __cdecl CRTDLL_delete(VOID* ptr)
932 HeapFree(GetProcessHeap(),0,ptr);
935 /*********************************************************************
936 * _strdup (CRTDLL.285)
938 LPSTR __cdecl CRTDLL__strdup(LPSTR ptr)
940 return HEAP_strdupA(GetProcessHeap(),0,ptr);
944 /*********************************************************************
945 * fclose (CRTDLL.362)
947 INT32 __cdecl CRTDLL_fclose( FILE *stream )
949 int unix_handle=fileno(stream);
950 HFILE32 dos_handle=1;
951 HFILE32 ret=EOF;
953 if (unix_handle<4) ret= fclose(stream);
954 else {
955 while(FILE_GetUnixHandle(dos_handle) != unix_handle) dos_handle++;
956 fclose(stream);
957 ret = _lclose32( dos_handle);
959 dprintf_crtdll(stddeb,"CRTDLL_fclose(%p) ufh %d dfh %d%s\n",
960 stream,unix_handle,dos_handle,(ret)?" failed":"");
961 return ret;
964 /*********************************************************************
965 * _unlink (CRTDLL.315)
967 INT32 __cdecl CRTDLL__unlink(LPCSTR pathname)
969 int ret=0;
970 DOS_FULL_NAME full_name;
972 if (!DOSFS_GetFullName( pathname, FALSE, &full_name )) {
973 dprintf_crtdll(stddeb,"CRTDLL_unlink file %s bad name\n",pathname);
974 return EOF;
977 ret=unlink(full_name.long_name);
978 dprintf_crtdll(stddeb,"CRTDLL_unlink(%s unix %s)%s\n",
979 pathname,full_name.long_name, (ret)?" failed":"");
980 return ret;
983 /*********************************************************************
984 * rename (CRTDLL.449)
986 INT32 __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
988 BOOL32 ok = MoveFileEx32A( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
989 return ok ? 0 : -1;
993 /*********************************************************************
994 * _stat (CRTDLL.280)
997 struct win_stat
999 UINT16 win_st_dev;
1000 UINT16 win_st_ino;
1001 UINT16 win_st_mode;
1002 INT16 win_st_nlink;
1003 INT16 win_st_uid;
1004 INT16 win_st_gid;
1005 UINT32 win_st_rdev;
1006 INT32 win_st_size;
1007 INT32 win_st_atime;
1008 INT32 win_st_mtime;
1009 INT32 win_st_ctime;
1012 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
1014 int ret=0;
1015 DOS_FULL_NAME full_name;
1016 struct stat mystat;
1018 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1020 dprintf_crtdll(stddeb,"CRTDLL__stat filename %s bad name\n",filename);
1021 return -1;
1023 ret=stat(full_name.long_name,&mystat);
1024 dprintf_crtdll(stddeb,"CRTDLL__stat %s%s\n",
1025 filename, (ret)?" failed":"");
1027 /* FIXME: should check what Windows returns */
1029 buf->win_st_dev = mystat.st_dev;
1030 buf->win_st_ino = mystat.st_ino;
1031 buf->win_st_mode = mystat.st_mode;
1032 buf->win_st_nlink = mystat.st_nlink;
1033 buf->win_st_uid = mystat.st_uid;
1034 buf->win_st_gid = mystat.st_gid;
1035 buf->win_st_rdev = mystat.st_rdev;
1036 buf->win_st_size = mystat.st_size;
1037 buf->win_st_atime = mystat.st_atime;
1038 buf->win_st_mtime = mystat.st_mtime;
1039 buf->win_st_ctime = mystat.st_ctime;
1040 return ret;
1043 /*********************************************************************
1044 * _open (CRTDLL.239)
1046 HFILE32 __cdecl CRTDLL__open(LPCSTR path,INT32 flags)
1048 HFILE32 ret=0;
1049 int wineflags=0;
1051 /* FIXME:
1052 the flags in lcc's header differ from the ones in Linux, e.g.
1053 Linux: define O_APPEND 02000 (= 0x400)
1054 lcc: define _O_APPEND 0x0008
1055 so here a scheme to translate them
1056 Probably lcc is wrong here, but at least a hack to get is going
1058 wineflags = (flags & 3);
1059 if (flags & 0x0008 ) wineflags |= O_APPEND;
1060 if (flags & 0x0100 ) wineflags |= O_CREAT;
1061 if (flags & 0x0200 ) wineflags |= O_TRUNC;
1062 if (flags & 0x0400 ) wineflags |= O_EXCL;
1063 if (flags & 0xf0f4 )
1064 dprintf_crtdll(stddeb,"CRTDLL_open file unsupported flags 0x%04x\n",flags);
1065 /* End Fixme */
1067 ret = FILE_Open(path,wineflags);
1068 dprintf_crtdll(stddeb,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
1069 path,wineflags,flags,ret);
1070 return ret;
1073 /*********************************************************************
1074 * _close (CRTDLL.57)
1076 INT32 __cdecl CRTDLL__close(HFILE32 fd)
1078 int ret=_lclose32(fd);
1080 dprintf_crtdll(stddeb,"CRTDLL_close(%d)%s\n",fd,(ret)?" failed":"");
1081 return ret;
1084 /*********************************************************************
1085 * feof (CRTDLL.363)
1087 INT32 __cdecl CRTDLL_feof( FILE *stream )
1089 int ret;
1091 ret=feof(stream);
1092 dprintf_crtdll(stddeb,"CRTDLL_feof(%p) %s\n",stream,(ret)?"true":"false");
1093 return ret;
1096 /*********************************************************************
1097 * setlocale (CRTDLL.453)
1099 LPSTR __cdecl CRTDLL_setlocale(INT32 category,LPCSTR locale)
1101 LPSTR categorystr;
1103 switch (category) {
1104 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1105 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1106 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1107 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1108 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1109 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1110 default: categorystr = "UNKNOWN?";break;
1112 fprintf(stderr,"CRTDLL_setlocale(%s,%s),stub!\n",categorystr,locale);
1113 return "C";
1116 /*********************************************************************
1117 * wcscat (CRTDLL.503)
1119 LPWSTR __cdecl CRTDLL_wcscat( LPWSTR s1, LPCWSTR s2 )
1121 return lstrcat32W( s1, s2 );
1124 /*********************************************************************
1125 * wcschr (CRTDLL.504)
1127 LPWSTR __cdecl CRTDLL_wcschr(LPCWSTR str,WCHAR xchar)
1129 LPCWSTR s;
1131 s=str;
1132 do {
1133 if (*s==xchar)
1134 return (LPWSTR)s;
1135 } while (*s++);
1136 return NULL;
1139 /*********************************************************************
1140 * wcscmp (CRTDLL.505)
1142 INT32 __cdecl CRTDLL_wcscmp( LPCWSTR s1, LPCWSTR s2 )
1144 return lstrcmp32W( s1, s2 );
1147 /*********************************************************************
1148 * wcscpy (CRTDLL.507)
1150 LPWSTR __cdecl CRTDLL_wcscpy( LPWSTR s1, LPCWSTR s2 )
1152 return lstrcpy32W( s1, s2 );
1155 /*********************************************************************
1156 * wcscspn (CRTDLL.508)
1158 INT32 __cdecl CRTDLL_wcscspn(LPWSTR str,LPWSTR reject)
1160 LPWSTR s,t;
1162 s=str;
1163 do {
1164 t=reject;
1165 while (*t) { if (*t==*s) break;t++;}
1166 if (*t) break;
1167 s++;
1168 } while (*s);
1169 return s-str; /* nr of wchars */
1172 /*********************************************************************
1173 * wcslen (CRTDLL.510)
1175 INT32 __cdecl CRTDLL_wcslen( LPCWSTR s )
1177 return lstrlen32W( s );
1180 /*********************************************************************
1181 * wcsncat (CRTDLL.511)
1183 LPWSTR __cdecl CRTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT32 n )
1185 return lstrcatn32W( s1, s2, n );
1188 /*********************************************************************
1189 * wcsncmp (CRTDLL.512)
1191 INT32 __cdecl CRTDLL_wcsncmp( LPCWSTR s1, LPCWSTR s2, INT32 n )
1193 return lstrncmp32W( s1, s2, n );
1196 /*********************************************************************
1197 * wcsncpy (CRTDLL.513)
1199 LPWSTR __cdecl CRTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT32 n )
1201 return lstrcpyn32W( s1, s2, n );
1204 /*********************************************************************
1205 * wcsspn (CRTDLL.516)
1207 INT32 __cdecl CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
1209 LPWSTR s,t;
1211 s=str;
1212 do {
1213 t=accept;
1214 while (*t) { if (*t==*s) break;t++;}
1215 if (!*t) break;
1216 s++;
1217 } while (*s);
1218 return s-str; /* nr of wchars */
1221 /*********************************************************************
1222 * towupper (CRTDLL.494)
1224 WCHAR __cdecl CRTDLL_towupper(WCHAR x)
1226 return (WCHAR)toupper((CHAR)x);
1229 /*********************************************************************
1230 * _wcsicmp (CRTDLL.321)
1232 DWORD __cdecl CRTDLL__wcsicmp( LPCWSTR s1, LPCWSTR s2 )
1234 return lstrcmpi32W( s1, s2 );
1237 /*********************************************************************
1238 * _wcsicoll (CRTDLL.322)
1240 DWORD __cdecl CRTDLL__wcsicoll(LPCWSTR a1,LPCWSTR a2)
1242 /* FIXME: handle collates */
1243 return lstrcmpi32W(a1,a2);
1246 /*********************************************************************
1247 * _wcsnicmp (CRTDLL.324)
1249 DWORD __cdecl CRTDLL__wcsnicmp( LPCWSTR s1, LPCWSTR s2, INT32 len )
1251 return lstrncmpi32W( s1, s2, len );
1254 /*********************************************************************
1255 * wcscoll (CRTDLL.506)
1257 DWORD __cdecl CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
1259 /* FIXME: handle collates */
1260 return lstrcmp32W(a1,a2);
1263 /*********************************************************************
1264 * _wcsrev (CRTDLL.326)
1266 VOID __cdecl CRTDLL__wcsrev(LPWSTR s) {
1267 LPWSTR e;
1269 e=s;
1270 while (*e)
1271 e++;
1272 while (s<e) {
1273 WCHAR a;
1275 a=*s;*s=*e;*e=a;
1276 s++;e--;
1280 /*********************************************************************
1281 * wcsstr (CRTDLL.517)
1283 LPWSTR __cdecl CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
1285 LPWSTR x,y,c;
1287 x=s;
1288 while (*x) {
1289 if (*x==*b) {
1290 y=x;c=b;
1291 while (*y && *c && *y==*c) { c++;y++; }
1292 if (!*c)
1293 return x;
1295 x++;
1297 return NULL;
1300 /*********************************************************************
1301 * wcstombs (CRTDLL.521)
1303 INT32 __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT32 len )
1305 lstrcpynWtoA( dst, src, len );
1306 return strlen(dst); /* FIXME: is this right? */
1309 /*********************************************************************
1310 * wcsrchr (CRTDLL.515)
1312 LPWSTR __cdecl CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
1314 LPWSTR s;
1316 s=str+lstrlen32W(str);
1317 do {
1318 if (*s==xchar)
1319 return s;
1320 s--;
1321 } while (s>=str);
1322 return NULL;
1325 /*********************************************************************
1326 * _setmode (CRTDLL.265)
1327 * FIXME: At present we ignore the request to translate CR/LF to LF.
1329 * We allways translate when we read with fgets, we never do with fread
1332 INT32 __cdecl CRTDLL__setmode( INT32 fh,INT32 mode)
1334 /* FIXME */
1335 #define O_TEXT 0x4000
1336 #define O_BINARY 0x8000
1338 dprintf_crtdll(stddeb,
1339 "CRTDLL._setmode on fhandle %d mode %s, STUB.\n",
1340 fh,(mode=O_TEXT)?"O_TEXT":
1341 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1342 return -1;
1345 /*********************************************************************
1346 * atexit (CRTDLL.345)
1348 INT32 __cdecl CRTDLL_atexit(LPVOID x)
1350 /* FIXME */
1351 fprintf(stdnimp,"CRTDLL.atexit(%p), STUB.\n",x);
1352 return 0; /* successful */
1355 /*********************************************************************
1356 * mblen (CRTDLL.428)
1357 * FIXME: check multibyte support
1359 WCHAR __cdecl CRTDLL_mblen(CHAR *mb,INT32 size)
1362 int ret=1;
1364 if (!mb)
1365 ret = 0;
1366 else if ((size<1)||(!*(mb+1)))
1367 ret = -1;
1368 else if (!(*mb))
1369 ret =0;
1371 dprintf_crtdll(stderr,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb,size,ret);
1373 return ret;
1376 /*********************************************************************
1377 * mbstowcs (CRTDLL.429)
1378 * FIXME: check multibyte support
1380 INT32 __cdecl CRTDLL_mbstowcs(LPWSTR wcs, LPCSTR mbs, INT32 size)
1383 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1384 * We need the number of characters transfered
1385 * FIXME: No multibyte support yet
1388 LPWSTR p = wcs;
1389 LPCSTR src= mbs;
1390 int ret, n=size;
1392 while ((n-- > 0) && *src) {
1393 *p++ = (WCHAR)(unsigned char)*src++;
1395 p++;
1396 ret = (p -wcs);
1398 dprintf_crtdll(stddeb,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1399 mbs,size,ret);
1400 return ret;
1403 /*********************************************************************
1404 * mbtowc (CRTDLL.430)
1405 * FIXME: check multibyte support
1407 WCHAR __cdecl CRTDLL_mbtowc(WCHAR* wc,CHAR* mb,INT32 size)
1409 int ret;
1411 if (!mb)
1412 ret = 0;
1413 else if (!wc)
1414 ret =-1;
1415 else
1416 if ( (ret = mblen(mb,size)) != -1 )
1418 if (ret <= sizeof(char))
1419 *wc = (WCHAR) ((unsigned char)*mb);
1420 else
1421 ret= -1;
1423 else
1424 ret = -1;
1426 dprintf_crtdll(stderr,"CRTDLL_mbtowc %s for %d chars\n",mb,size);
1428 return ret;
1431 /*********************************************************************
1432 * _isctype (CRTDLL.138)
1434 BOOL32 __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1436 if ((type & CRTDLL_SPACE) && isspace(x))
1437 return TRUE;
1438 if ((type & CRTDLL_PUNCT) && ispunct(x))
1439 return TRUE;
1440 if ((type & CRTDLL_LOWER) && islower(x))
1441 return TRUE;
1442 if ((type & CRTDLL_UPPER) && isupper(x))
1443 return TRUE;
1444 if ((type & CRTDLL_ALPHA) && isalpha(x))
1445 return TRUE;
1446 if ((type & CRTDLL_DIGIT) && isdigit(x))
1447 return TRUE;
1448 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1449 return TRUE;
1450 /* check CRTDLL_LEADBYTE */
1451 return FALSE;
1454 /*********************************************************************
1455 * _chdrive (CRTDLL.52)
1457 BOOL32 __cdecl CRTDLL__chdrive(INT32 newdrive)
1459 /* FIXME: generates errnos */
1460 return DRIVE_SetCurrentDrive(newdrive);
1463 /*********************************************************************
1464 * _chdir (CRTDLL.51)
1466 INT32 __cdecl CRTDLL__chdir(LPCSTR newdir)
1468 if (!SetCurrentDirectory32A(newdir))
1469 return -1;
1470 return 0;
1473 /*********************************************************************
1474 * _fullpath (CRTDLL.114)
1476 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT32 size)
1478 DOS_FULL_NAME full_name;
1480 if (!buf)
1482 size = 256;
1483 if(!(buf = CRTDLL_malloc(size))) return NULL;
1485 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1486 lstrcpyn32A(buf,full_name.short_name,size);
1487 dprintf_crtdll(stderr,"CRTDLL_fullpath got %s\n",buf);
1488 return buf;
1491 /*********************************************************************
1492 * _splitpath (CRTDLL.279)
1494 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1496 /* drive includes :
1497 directory includes leading and trailing (forward and backward slashes)
1498 filename without dot and slashes
1499 extension with leading dot
1501 char * drivechar,*dirchar,*namechar;
1503 dprintf_crtdll(stddeb,"CRTDLL__splitpath got %s\n",path);
1505 drivechar = strchr(path,':');
1506 dirchar = strrchr(path,'/');
1507 namechar = strrchr(path,'\\');
1508 dirchar = MAX(dirchar,namechar);
1509 if (dirchar)
1510 namechar = strrchr(dirchar,'.');
1511 else
1512 namechar = strrchr(path,'.');
1515 if (drive)
1517 *drive = NULL;
1518 if (drivechar)
1520 strncat(drive,path,drivechar-path+1);
1521 path = drivechar+1;
1524 if (directory)
1526 *directory = NULL;
1527 if (dirchar)
1529 strncat(directory,path,dirchar-path+1);
1530 path = dirchar+1;
1533 if (filename)
1535 *filename = NULL;
1536 if (namechar)
1538 strncat(filename,path,namechar-path);
1539 if (extension)
1541 *extension = NULL;
1542 strcat(extension,namechar);
1547 dprintf_crtdll(stddeb,"CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1551 /*********************************************************************
1552 * _getcwd (CRTDLL.120)
1554 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT32 size)
1556 char test[1];
1557 int len;
1559 len = size;
1560 if (!buf) {
1561 if (size < 0) /* allocate as big as nescessary */
1562 len =GetCurrentDirectory32A(1,test) + 1;
1563 if(!(buf = CRTDLL_malloc(len)))
1565 /* set error to OutOfRange */
1566 return( NULL );
1569 size = len;
1570 if(!(len =GetCurrentDirectory32A(len,buf)))
1572 return NULL;
1574 if (len > size)
1576 /* set error to ERANGE */
1577 dprintf_crtdll(stddeb,"CRTDLL_getcwd buffer to small\n");
1578 return NULL;
1580 return buf;
1584 /*********************************************************************
1585 * _mkdir (CRTDLL.234)
1587 INT32 __cdecl CRTDLL__mkdir(LPCSTR newdir)
1589 if (!CreateDirectory32A(newdir,NULL))
1590 return -1;
1591 return 0;
1594 /*********************************************************************
1595 * _errno (CRTDLL.52)
1596 * Yes, this is a function.
1598 LPINT32 __cdecl CRTDLL__errno()
1600 static int crtdllerrno;
1601 extern int LastErrorToErrno(DWORD);
1603 /* FIXME: we should set the error at the failing function call time */
1604 crtdllerrno = LastErrorToErrno(GetLastError());
1605 return &crtdllerrno;
1608 /*********************************************************************
1609 * _tempnam (CRTDLL.305)
1612 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1615 char *ret;
1616 DOS_FULL_NAME tempname;
1618 if ((ret = tempnam(dir,prefix))==NULL) {
1619 dprintf_crtdll(stddeb,
1620 "CRTDLL_tempnam Unable to get unique filename\n");
1621 return NULL;
1623 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1625 dprintf_crtdll(stddeb,
1626 "CRTDLL_tempnam Wrong path?\n");
1627 return NULL;
1629 free(ret);
1630 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1631 dprintf_crtdll(stddeb,
1632 "CRTDLL_tempnam CRTDL_malloc for shortname failed\n");
1633 return NULL;
1635 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1636 dprintf_crtdll(stddeb,
1637 "CRTDLL_tempnam Malloc for shortname failed\n");
1638 return NULL;
1641 dprintf_crtdll(stddeb,"CRTDLL_tempnam dir %s prefix %s got %s\n",
1642 dir,prefix,ret);
1643 return ret;
1646 /*********************************************************************
1647 * tmpnam (CRTDLL.490)
1649 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1652 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1654 char *ret;
1656 if ((ret =tmpnam(s))== NULL) {
1657 dprintf_crtdll(stddeb,
1658 "CRTDLL_tmpnam Unable to get unique filename\n");
1659 return NULL;
1661 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1663 dprintf_crtdll(stddeb,
1664 "CRTDLL_tmpnam Wrong path?\n");
1665 return NULL;
1667 strcat(CRTDLL_tmpname.short_name,".");
1668 dprintf_crtdll(stddeb,"CRTDLL_tmpnam for buf %p got %s\n",
1669 s,CRTDLL_tmpname.short_name);
1670 dprintf_crtdll(stddeb,"CRTDLL_tmpnam long got %s\n",
1671 CRTDLL_tmpname.long_name);
1672 if ( s != NULL)
1673 return strcpy(s,CRTDLL_tmpname.short_name);
1674 else
1675 return CRTDLL_tmpname.short_name;
1679 /*********************************************************************
1680 * _itoa (CRTDLL.165)
1682 LPSTR __cdecl CRTDLL__itoa(INT32 x,LPSTR buf,INT32 buflen)
1684 wsnprintf32A(buf,buflen,"%d",x);
1685 return buf;
1688 typedef VOID (*sig_handler_type)(VOID);
1690 /*********************************************************************
1691 * signal (CRTDLL.455)
1693 VOID __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
1695 dprintf_crtdll(stddeb,"CRTDLL_signal %d %p: STUB!\n",sig,ptr);
1698 /*********************************************************************
1699 * _ftol (CRTDLL.113)
1701 LONG __cdecl CRTDLL__ftol(double fl) {
1702 return (LONG)fl;
1704 /*********************************************************************
1705 * _sleep (CRTDLL.267)
1707 VOID __cdecl CRTDLL__sleep(unsigned long timeout)
1709 dprintf_crtdll(stddeb,"CRTDLL__sleep for %ld milliseconds\n",timeout);
1710 Sleep((timeout)?timeout:1);