Release 971221
[wine/multimedia.git] / misc / crtdll.c
blob3a12c9bb81ddbf58a6e6720cd40c9b7572ad69a1
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 <unistd.h>
29 #include <time.h>
30 #include <ctype.h>
31 #include <math.h>
32 #include <fcntl.h>
33 #include <setjmp.h>
34 #include "win.h"
35 #include "windows.h"
36 #include "stddebug.h"
37 #include "debug.h"
38 #include "module.h"
39 #include "heap.h"
40 #include "crtdll.h"
41 #include "drive.h"
42 #include "file.h"
43 #include "except.h"
44 #include "options.h"
46 extern int FILE_GetUnixHandle( HFILE32 );
48 static DOS_FULL_NAME CRTDLL_tmpname;
50 extern INT32 WIN32_wsprintf32W( DWORD *args );
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 typedef VOID (*new_handler_type)(VOID);
72 static new_handler_type new_handler;
74 /*********************************************************************
75 * _GetMainArgs (CRTDLL.022)
77 DWORD __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,
78 LPSTR *environ,DWORD flag)
80 char *cmdline;
81 char **xargv;
82 int xargc,i,afterlastspace;
83 DWORD version;
85 dprintf_crtdll(stddeb,"CRTDLL__GetMainArgs(%p,%p,%p,%ld).\n",
86 argc,argv,environ,flag
88 CRTDLL_acmdln_dll = cmdline = HEAP_strdupA( GetProcessHeap(), 0,
89 GetCommandLine32A() );
90 dprintf_crtdll(stddeb,"CRTDLL__GetMainArgs got \"%s\"\n",
91 cmdline);
93 version = GetVersion32();
94 CRTDLL_osver_dll = version >> 16;
95 CRTDLL_winminor_dll = version & 0xFF;
96 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
97 CRTDLL_baseversion_dll = version >> 16;
98 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
99 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
100 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
101 CRTDLL_osversion_dll = version & 0xFFFF;
102 CRTDLL_osminor_dll = version & 0xFF;
103 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
105 /* missing threading init */
107 i=0;xargv=NULL;xargc=0;afterlastspace=0;
108 while (cmdline[i]) {
109 if (cmdline[i]==' ') {
110 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
111 sizeof(char*)*(++xargc));
112 cmdline[i]='\0';
113 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
114 cmdline+afterlastspace);
115 i++;
116 while (cmdline[i]==' ')
117 i++;
118 if (cmdline[i])
119 afterlastspace=i;
120 } else
121 i++;
123 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
124 sizeof(char*)*(++xargc));
125 cmdline[i]='\0';
126 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
127 cmdline+afterlastspace);
128 CRTDLL_argc_dll = xargc;
129 *argc = xargc;
130 CRTDLL_argv_dll = xargv;
131 *argv = xargv;
133 dprintf_crtdll(stddeb,"CRTDLL__GetMainArgs found %d arguments\n",
134 CRTDLL_argc_dll);
135 CRTDLL_environ_dll = *environ = GetEnvironmentStrings32A();
136 return 0;
140 typedef void (*_INITTERMFUN)();
142 /*********************************************************************
143 * _initterm (CRTDLL.135)
145 DWORD __cdecl CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
147 _INITTERMFUN *current;
149 dprintf_crtdll(stddeb,"_initterm(%p,%p)\n",start,end);
150 current=start;
151 while (current<end) {
152 if (*current) (*current)();
153 current++;
155 return 0;
158 /*********************************************************************
159 * _fdopen (CRTDLL.91)
161 DWORD __cdecl CRTDLL__fdopen(INT32 handle, LPCSTR mode)
163 FILE *file;
165 switch (handle)
167 case 0 : file=stdin;
168 break;
169 case 1 : file=stdout;
170 break;
171 case 2 : file=stderr;
172 break;
173 default:
174 file=fdopen(handle,mode);
176 dprintf_crtdll(stddeb,
177 "CRTDLL_fdopen open handle %d mode %s got file %p\n",
178 handle, mode, file);
179 return (DWORD)file;
182 /*******************************************************************
183 * _global_unwind2 (CRTDLL.129)
185 void __cdecl CRTDLL__global_unwind2( CONTEXT *context )
187 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
188 DWORD *args = (DWORD *)ESP_reg(context);
189 RtlUnwind( (PEXCEPTION_FRAME)args[1], (LPVOID)EIP_reg(context),
190 NULL, 0, context );
193 /*******************************************************************
194 * _local_unwind2 (CRTDLL.173)
196 void __cdecl CRTDLL__local_unwind2( CONTEXT *context )
198 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
199 DWORD *args = (DWORD *)ESP_reg(context);
200 PEXCEPTION_FRAME endframe = (PEXCEPTION_FRAME)args[1];
201 DWORD nr = args[2];
202 fprintf(stderr,"CRTDLL__local_unwind2(%p,%ld)\n",endframe,nr);
205 /*********************************************************************
206 * fopen (CRTDLL.372)
208 DWORD __cdecl CRTDLL_fopen(LPCSTR path, LPCSTR mode)
210 FILE *file;
211 HFILE32 dos_fildes;
212 #if 0
213 DOS_FULL_NAME full_name;
215 if (!DOSFS_GetFullName( path, FALSE, &full_name )) {
216 dprintf_crtdll(stddeb,"CRTDLL_fopen file %s bad name\n",path);
217 return 0;
220 file=fopen(full_name.long_name ,mode);
221 #endif
222 INT32 flagmode=0;
223 int unix_fildes=0;
225 if ((strchr(mode,'r')&&strchr(mode,'a'))||
226 (strchr(mode,'r')&&strchr(mode,'w'))||
227 (strchr(mode,'w')&&strchr(mode,'a')))
228 return 0;
230 if (strstr(mode,"r+")) flagmode=O_RDWR;
231 else if (strchr(mode,'r')) flagmode = O_RDONLY;
232 else if (strstr(mode,"w+")) flagmode= O_RDWR | O_TRUNC | O_CREAT;
233 else if (strchr(mode,'w')) flagmode = O_WRONLY | O_TRUNC | O_CREAT;
234 else if (strstr(mode,"a+")) flagmode= O_RDWR | O_CREAT | O_APPEND;
235 else if (strchr(mode,'w')) flagmode = O_RDWR | O_CREAT | O_APPEND;
236 else if (strchr(mode,'b'))
237 dprintf_crtdll(stderr,
238 "CRTDLL_fopen %s in BINARY mode\n",path);
240 dos_fildes=FILE_Open(path, flagmode);
241 unix_fildes=FILE_GetUnixHandle(dos_fildes);
242 file = fdopen(unix_fildes,mode);
244 dprintf_crtdll(stddeb,
245 "CRTDLL_fopen file %s mode %s got ufh %d dfh %d file %p\n",
246 path,mode,unix_fildes,dos_fildes,file);
247 return (DWORD)file;
250 /*********************************************************************
251 * fread (CRTDLL.377)
253 DWORD __cdecl CRTDLL_fread(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID file)
255 size_t ret=1;
256 #if 0
257 int i=0;
258 void *temp=ptr;
260 /* If we would honour CR/LF <-> LF translation, we could do it like this.
261 We should keep track of all files opened, and probably files with \
262 known binary extensions must be unchanged */
263 while ( (i < (nmemb*size)) && (ret==1)) {
264 ret=fread(temp,1,1,file);
265 dprintf_crtdll(stddeb,
266 "CRTDLL_fread got %c 0x%02x ret %d\n",
267 (isalpha(*(unsigned char*)temp))? *(unsigned char*)temp:
268 ' ',*(unsigned char*)temp, ret);
269 if (*(unsigned char*)temp != 0xd) { /* skip CR */
270 temp++;
271 i++;
273 else
274 dprintf_crtdll(stddeb, "CRTDLL_fread skipping ^M\n");
276 dprintf_crtdll(stddeb,
277 "CRTDLL_fread 0x%08x items of size %d from file %p to %p%s\n",
278 nmemb,size,file,ptr,(i!=nmemb)?" failed":"");
279 return i;
280 #else
282 ret=fread(ptr,size,nmemb,file);
283 dprintf_crtdll(stddeb,
284 "CRTDLL_fread 0x%08x items of size %d from file %p to %p%s\n",
285 nmemb,size,file,ptr,(ret!=nmemb)?" failed":"");
286 return ret;
287 #endif
290 /*********************************************************************
291 * fseek (CRTDLL.382)
293 LONG __cdecl CRTDLL_fseek(LPVOID stream, LONG offset, INT32 whence)
295 long ret;
297 ret=fseek(stream,offset,whence);
298 dprintf_crtdll(stddeb,
299 "CRTDLL_fseek file %p to 0x%08lx pos %s%s\n",
300 stream,offset,(whence==SEEK_SET)?"SEEK_SET":
301 (whence==SEEK_CUR)?"SEEK_CUR":
302 (whence==SEEK_END)?"SEEK_END":"UNKNOWN",
303 (ret)?"failed":"");
304 return ret;
307 /*********************************************************************
308 * ftell (CRTDLL.384)
310 LONG __cdecl CRTDLL_ftell(LPVOID stream)
312 long ret;
314 ret=ftell(stream);
315 dprintf_crtdll(stddeb,
316 "CRTDLL_ftell file %p at 0x%08lx\n",
317 stream,ret);
318 return ret;
321 /*********************************************************************
322 * fwrite (CRTDLL.386)
324 DWORD __cdecl CRTDLL_fwrite(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID file)
326 size_t ret;
328 ret=fwrite(ptr,size,nmemb,file);
329 dprintf_crtdll(stddeb,
330 "CRTDLL_fwrite 0x%08x items of size %d from %p to file %p%s\n",
331 nmemb,size,ptr,file,(ret!=nmemb)?" failed":"");
332 return ret;
335 /*********************************************************************
336 * setbuf (CRTDLL.452)
338 INT32 __cdecl CRTDLL_setbuf(LPVOID file, LPSTR buf)
340 dprintf_crtdll(stddeb,
341 "CRTDLL_setbuf(file %p buf %p)\n",
342 file,buf);
343 /* this doesn't work:"void value not ignored as it ought to be"
344 return setbuf(file,buf);
346 setbuf(file,buf);
347 return 0;
350 /*********************************************************************
351 * _open_osfhandle (CRTDLL.240)
353 HFILE32 __cdecl CRTDLL__open_osfhandle(LONG osfhandle, INT32 flags)
355 HFILE32 handle;
357 switch (osfhandle) {
358 case STD_INPUT_HANDLE :
359 case 0 :
360 handle=0;
361 break;
362 case STD_OUTPUT_HANDLE:
363 case 1:
364 handle=1;
365 break;
366 case STD_ERROR_HANDLE:
367 case 2:
368 handle=2;
369 break;
370 default:
371 return (-1);
373 dprintf_crtdll(stddeb,
374 "CRTDLL_open_osfhandle(handle %08lx,flags %d) return %d\n",
375 osfhandle,flags,handle);
376 return handle;
380 /*********************************************************************
381 * srand (CRTDLL.460)
383 void __cdecl CRTDLL_srand(DWORD seed)
385 /* FIXME: should of course be thread? process? local */
386 srand(seed);
389 /*********************************************************************
390 * fprintf (CRTDLL.373)
392 INT32 __cdecl CRTDLL_fprintf( FILE *file, LPSTR format, ... )
394 va_list valist;
395 INT32 res;
397 va_start( valist, format );
398 res = vfprintf( file, format, valist );
399 va_end( valist );
400 return res;
403 /*********************************************************************
404 * vfprintf (CRTDLL.373)
406 INT32 __cdecl CRTDLL_vfprintf( FILE *file, LPSTR format, va_list args )
408 return vfprintf( file, format, args );
411 /*********************************************************************
412 * time (CRTDLL.488)
414 time_t __cdecl CRTDLL_time(time_t *timeptr)
416 time_t curtime = time(NULL);
418 if (timeptr)
419 *timeptr = curtime;
420 return curtime;
423 /*********************************************************************
424 * _isatty (CRTDLL.137)
426 BOOL32 __cdecl CRTDLL__isatty(DWORD x)
428 dprintf_crtdll(stderr,"CRTDLL__isatty(%ld)\n",x);
429 return TRUE;
432 /*********************************************************************
433 * _write (CRTDLL.332)
435 INT32 __cdecl CRTDLL__write(INT32 fd,LPCVOID buf,UINT32 count)
437 INT32 len=0;
439 if (fd == -1)
440 len = -1;
441 else if (fd<=2)
442 len = (UINT32)write(fd,buf,(LONG)count);
443 else
444 len = _lwrite32(fd,buf,count);
445 dprintf_crtdll(stddeb,"CRTDLL_write %d/%d byte to dfh %d from %p,\n",
446 len,count,fd,buf);
447 return len;
451 /*********************************************************************
452 * _cexit (CRTDLL.49)
454 * FIXME: What the heck is the difference between
455 * FIXME _c_exit (CRTDLL.47)
456 * FIXME _cexit (CRTDLL.49)
457 * FIXME _exit (CRTDLL.87)
458 * FIXME exit (CRTDLL.359)
460 * atexit-processing comes to mind -- MW.
463 void __cdecl CRTDLL__cexit(INT32 ret)
465 dprintf_crtdll(stddeb,"CRTDLL__cexit(%d)\n",ret);
466 ExitProcess(ret);
470 /*********************************************************************
471 * exit (CRTDLL.359)
473 void __cdecl CRTDLL_exit(DWORD ret)
475 dprintf_crtdll(stddeb,"CRTDLL_exit(%ld)\n",ret);
476 ExitProcess(ret);
480 /*********************************************************************
481 * _abnormal_termination (CRTDLL.36 )
483 INT32 __cdecl CRTDLL__abnormal_termination(void)
485 dprintf_crtdll(stddeb,"CRTDLL__abnormal_termination\n");
486 return 0;
490 /*********************************************************************
491 * fflush (CRTDLL.365)
493 INT32 __cdecl CRTDLL_fflush(LPVOID stream)
495 int ret;
497 ret = fflush(stream);
498 dprintf_crtdll(stddeb,"CRTDLL_fflush %p returnd %d %s\n",stream,ret,(ret)?"":" failed");
499 return ret;
503 /*********************************************************************
504 * gets (CRTDLL.391)
506 LPSTR __cdecl CRTDLL_gets(LPSTR buf)
508 char * ret;
509 /* BAD, for the whole WINE process blocks... just done this way to test
510 * windows95's ftp.exe.
512 ret = gets(buf);
513 dprintf_crtdll(stddeb,"CRTDLL_gets got %s\n",ret);
514 return ret;
518 /*********************************************************************
519 * rand (CRTDLL.446)
521 INT32 __cdecl CRTDLL_rand()
523 return rand();
527 /*********************************************************************
528 * putchar (CRTDLL.442)
530 void __cdecl CRTDLL_putchar( INT32 x )
532 putchar(x);
536 /*********************************************************************
537 * fputc (CRTDLL.374)
539 INT32 __cdecl CRTDLL_fputc( INT32 c, FILE *stream )
541 dprintf_crtdll(stddeb,
542 "CRTDLL_fputc %c to file %p\n",c,stream);
543 return fputc(c,stream);
547 /*********************************************************************
548 * fputs (CRTDLL.375)
550 INT32 __cdecl CRTDLL_fputs( LPCSTR s, FILE *stream )
552 dprintf_crtdll(stddeb,
553 "CRTDLL_fputs %s to file %p\n",s,stream);
554 return fputs(s,stream);
558 /*********************************************************************
559 * puts (CRTDLL.443)
561 INT32 __cdecl CRTDLL_puts(LPCSTR s)
563 dprintf_crtdll(stddeb,
564 "CRTDLL_fputs %s \n",s);
565 return puts(s);
569 /*********************************************************************
570 * putc (CRTDLL.441)
572 INT32 __cdecl CRTDLL_putc(INT32 c, FILE *stream)
574 dprintf_crtdll(stddeb,
575 "CRTDLL_putc %c to file %p\n",c,stream);
576 return fputc(c,stream);
578 /*********************************************************************
579 * fgetc (CRTDLL.366)
581 INT32 __cdecl CRTDLL_fgetc( FILE *stream )
583 int ret= fgetc(stream);
584 dprintf_crtdll(stddeb,
585 "CRTDLL_fgetc got %d\n",ret);
586 return ret;
590 /*********************************************************************
591 * getc (CRTDLL.388)
593 INT32 __cdecl CRTDLL_getc( FILE *stream )
595 int ret= fgetc(stream);
596 dprintf_crtdll(stddeb,
597 "CRTDLL_getc got %d\n",ret);
598 return ret;
601 /*********************************************************************
602 * _rotl (CRTDLL.259)
604 UINT32 __cdecl CRTDLL__rotl(UINT32 x,INT32 shift)
606 unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift));
608 dprintf_crtdll(stddeb,
609 "CRTDLL_rotl got 0x%08x rot %d ret 0x%08x\n",
610 x,shift,ret);
611 return ret;
614 /*********************************************************************
615 * _lrotl (CRTDLL.176)
617 DWORD __cdecl CRTDLL__lrotl(DWORD x,INT32 shift)
619 unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift));
621 dprintf_crtdll(stddeb,
622 "CRTDLL_lrotl got 0x%08lx rot %d ret 0x%08lx\n",
623 x,shift,ret);
624 return ret;
629 /*********************************************************************
630 * fgets (CRTDLL.368)
632 CHAR* __cdecl CRTDLL_fgets(LPSTR s,INT32 size, LPVOID stream)
634 char * ret;
635 char * control_M;
637 ret=fgets(s, size,stream);
638 /*FIXME: Control with CRTDLL_setmode */
639 control_M= strrchr(s,'\r');
640 /*delete CR if we read a DOS File */
641 if (control_M)
643 *control_M='\n';
644 *(control_M+1)=0;
646 dprintf_crtdll(stddeb,
647 "CRTDLL_fgets got %s for %d chars from file %p%s\n",
648 s,size,stream,(ret)?"":" failed");
649 return ret;
653 /*********************************************************************
654 * _mbsicmp (CRTDLL.204)
656 int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
658 do {
659 if (!*x)
660 return !!*y;
661 if (!*y)
662 return !!*x;
663 /* FIXME: MBCS handling... */
664 if (*x!=*y)
665 return 1;
666 x++;
667 y++;
668 } while (1);
672 /*********************************************************************
673 * _mbsinc (CRTDLL.205)
675 unsigned char * __cdecl CRTDLL__mbsinc(unsigned char *x)
677 /* FIXME: mbcs */
678 return x++;
682 /*********************************************************************
683 * vsprintf (CRTDLL.500)
685 INT32 __cdecl CRTDLL_vsprintf( LPSTR buffer, LPCSTR spec, va_list args )
687 return wvsprintf32A( buffer, spec, args );
690 /*********************************************************************
691 * vswprintf (CRTDLL.501)
693 INT32 __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
695 return wvsprintf32W( buffer, spec, args );
698 /*********************************************************************
699 * _mbscpy (CRTDLL.200)
701 unsigned char* __cdecl CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
703 dprintf_crtdll(stddeb,"CRTDLL_mbscpy %s and %s\n",x,y);
704 return strcpy(x,y);
708 /*********************************************************************
709 * _mbscat (CRTDLL.197)
711 unsigned char* __cdecl CRTDLL__mbscat(unsigned char *x,unsigned char *y)
713 return strcat(x,y);
717 /*********************************************************************
718 * _strcmpi (CRTDLL.282) (CRTDLL.287)
720 INT32 __cdecl CRTDLL__strcmpi( LPCSTR s1, LPCSTR s2 )
722 return lstrcmpi32A( s1, s2 );
726 /*********************************************************************
727 * _strnicmp (CRTDLL.293)
729 INT32 __cdecl CRTDLL__strnicmp( LPCSTR s1, LPCSTR s2, INT32 n )
731 return lstrncmpi32A( s1, s2, n );
735 /*********************************************************************
736 * _strlwr (CRTDLL.293)
738 * convert a string in place to lowercase
740 LPSTR CRTDLL__strlwr(LPSTR x)
742 unsigned char *y =x;
744 dprintf_crtdll(stddeb,
745 "CRTDLL_strlwr got %s",x);
746 while (*y) {
747 if ((*y > 0x40) && (*y< 0x5b))
748 *y = *y + 0x20;
749 y++;
751 dprintf_crtdll(stddeb," returned %s\n",x);
753 return x;
756 /*********************************************************************
757 * system (CRTDLL.485)
759 INT32 CRTDLL_system(LPSTR x)
761 #define SYSBUF_LENGTH 1500
762 char buffer[SYSBUF_LENGTH];
763 unsigned char *y = x;
764 unsigned char *bp;
765 int i;
767 sprintf( buffer, "%s \"", Options.argv0 );
768 bp = buffer + strlen(buffer);
769 i = strlen(buffer) + strlen(x) +2;
771 /* Calculate needed buffer size to prevent overflow. */
772 while (*y) {
773 if (*y =='\\') i++;
774 y++;
776 /* If buffer too short, exit. */
777 if (i > SYSBUF_LENGTH) {
778 dprintf_crtdll(stddeb,"_system buffer to small\n");
779 return 127;
782 y =x;
784 while (*y) {
785 *bp = *y;
786 bp++; y++;
787 if (*(y-1) =='\\') *bp++ = '\\';
789 /* Remove spaces from end of string. */
790 while (*(y-1) == ' ') {
791 bp--;y--;
793 *bp++ = '"';
794 *bp = 0;
795 dprintf_crtdll(stddeb,
796 "_system got \"%s\", executing \"%s\"\n",x,buffer);
798 return system(buffer);
801 /*********************************************************************
802 * _strupr (CRTDLL.300)
804 LPSTR __cdecl CRTDLL__strupr(LPSTR x)
806 LPSTR y=x;
808 while (*y) {
809 *y=toupper(*y);
810 y++;
812 return x;
815 /*********************************************************************
816 * _wcsupr (CRTDLL.328)
818 LPWSTR __cdecl CRTDLL__wcsupr(LPWSTR x)
820 LPWSTR y=x;
822 while (*y) {
823 *y=toupper(*y);
824 y++;
826 return x;
829 /*********************************************************************
830 * _wcslwr (CRTDLL.323)
832 LPWSTR __cdecl CRTDLL__wcslwr(LPWSTR x)
834 LPWSTR y=x;
836 while (*y) {
837 *y=tolower(*y);
838 y++;
840 return x;
844 /*********************************************************************
845 * longjmp (CRTDLL.426)
847 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
849 dprintf_crtdll(stdnimp,"CRTDLL_longjmp semistup, expect crash\n");
850 dprintf_crtdll(stddeb, "CRTDLL_longjmp semistup, expect crash\n");
851 return longjmp(env, val);
854 /*********************************************************************
855 * malloc (CRTDLL.427)
857 VOID* __cdecl CRTDLL_malloc(DWORD size)
859 return HeapAlloc(GetProcessHeap(),0,size);
862 /*********************************************************************
863 * new (CRTDLL.001)
865 VOID* __cdecl CRTDLL_new(DWORD size)
867 VOID* result;
868 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
869 (*new_handler)();
870 return result;
873 /*********************************************************************
874 * set_new_handler(CRTDLL.003)
876 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
878 new_handler_type old_handler = new_handler;
879 new_handler = func;
880 return old_handler;
883 /*********************************************************************
884 * calloc (CRTDLL.350)
886 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
888 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
891 /*********************************************************************
892 * realloc (CRTDLL.447)
894 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
896 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
899 /*********************************************************************
900 * free (CRTDLL.427)
902 VOID __cdecl CRTDLL_free(LPVOID ptr)
904 HeapFree(GetProcessHeap(),0,ptr);
907 /*********************************************************************
908 * delete (CRTDLL.002)
910 VOID __cdecl CRTDLL_delete(VOID* ptr)
912 HeapFree(GetProcessHeap(),0,ptr);
915 /*********************************************************************
916 * _strdup (CRTDLL.285)
918 LPSTR __cdecl CRTDLL__strdup(LPSTR ptr)
920 return HEAP_strdupA(GetProcessHeap(),0,ptr);
924 /*********************************************************************
925 * fclose (CRTDLL.362)
927 INT32 __cdecl CRTDLL_fclose( FILE *stream )
929 int unix_handle=fileno(stream);
930 HFILE32 dos_handle=1;
931 HFILE32 ret=EOF;
933 if (unix_handle<4) ret= fclose(stream);
934 else {
935 while(FILE_GetUnixHandle(dos_handle) != unix_handle) dos_handle++;
936 fclose(stream);
937 ret = _lclose32( dos_handle);
939 dprintf_crtdll(stddeb,"CRTDLL_fclose(%p) ufh %d dfh %d%s\n",
940 stream,unix_handle,dos_handle,(ret)?" failed":"");
941 return ret;
944 /*********************************************************************
945 * _unlink (CRTDLL.315)
947 INT32 __cdecl CRTDLL__unlink(LPCSTR pathname)
949 int ret=0;
950 DOS_FULL_NAME full_name;
952 if (!DOSFS_GetFullName( pathname, FALSE, &full_name )) {
953 dprintf_crtdll(stddeb,"CRTDLL_unlink file %s bad name\n",pathname);
954 return EOF;
957 ret=unlink(full_name.long_name);
958 dprintf_crtdll(stddeb,"CRTDLL_unlink(%s unix %s)%s\n",
959 pathname,full_name.long_name, (ret)?" failed":"");
960 return ret;
963 /*********************************************************************
964 * rename (CRTDLL.449)
966 INT32 __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
968 BOOL32 ok = MoveFileEx32A( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
969 return ok ? 0 : -1;
973 /*********************************************************************
974 * _stat (CRTDLL.280)
977 struct win_stat
979 UINT16 win_st_dev;
980 UINT16 win_st_ino;
981 UINT16 win_st_mode;
982 INT16 win_st_nlink;
983 INT16 win_st_uid;
984 INT16 win_st_gid;
985 UINT32 win_st_rdev;
986 INT32 win_st_size;
987 INT32 win_st_atime;
988 INT32 win_st_mtime;
989 INT32 win_st_ctime;
992 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
994 int ret=0;
995 DOS_FULL_NAME full_name;
996 struct stat mystat;
998 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1000 dprintf_crtdll(stddeb,"CRTDLL__stat filename %s bad name\n",filename);
1001 return -1;
1003 ret=stat(full_name.long_name,&mystat);
1004 dprintf_crtdll(stddeb,"CRTDLL__stat %s%s\n",
1005 filename, (ret)?" failed":"");
1007 /* FIXME: should check what Windows returns */
1009 buf->win_st_dev = mystat.st_dev;
1010 buf->win_st_ino = mystat.st_ino;
1011 buf->win_st_mode = mystat.st_mode;
1012 buf->win_st_nlink = mystat.st_nlink;
1013 buf->win_st_uid = mystat.st_uid;
1014 buf->win_st_gid = mystat.st_gid;
1015 buf->win_st_rdev = mystat.st_rdev;
1016 buf->win_st_size = mystat.st_size;
1017 buf->win_st_atime = mystat.st_atime;
1018 buf->win_st_mtime = mystat.st_mtime;
1019 buf->win_st_ctime = mystat.st_ctime;
1020 return ret;
1023 /*********************************************************************
1024 * _open (CRTDLL.239)
1026 HFILE32 __cdecl CRTDLL__open(LPCSTR path,INT32 flags)
1028 HFILE32 ret=0;
1029 int wineflags=0;
1031 /* FIXME:
1032 the flags in lcc's header differ from the ones in Linux, e.g.
1033 Linux: define O_APPEND 02000 (= 0x400)
1034 lcc: define _O_APPEND 0x0008
1035 so here a scheme to translate them
1036 Probably lcc is wrong here, but at least a hack to get is going
1038 wineflags = (flags & 3);
1039 if (flags & 0x0008 ) wineflags |= O_APPEND;
1040 if (flags & 0x0100 ) wineflags |= O_CREAT;
1041 if (flags & 0x0200 ) wineflags |= O_TRUNC;
1042 if (flags & 0x0400 ) wineflags |= O_EXCL;
1043 if (flags & 0xf0f4 )
1044 dprintf_crtdll(stddeb,"CRTDLL_open file unsupported flags 0x%04x\n",flags);
1045 /* End Fixme */
1047 ret = FILE_Open(path,wineflags);
1048 dprintf_crtdll(stddeb,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
1049 path,wineflags,flags,ret);
1050 return ret;
1053 /*********************************************************************
1054 * _close (CRTDLL.57)
1056 INT32 __cdecl CRTDLL__close(HFILE32 fd)
1058 int ret=_lclose32(fd);
1060 dprintf_crtdll(stddeb,"CRTDLL_close(%d)%s\n",fd,(ret)?" failed":"");
1061 return ret;
1064 /*********************************************************************
1065 * feof (CRTDLL.363)
1067 INT32 __cdecl CRTDLL_feof( FILE *stream )
1069 int ret;
1071 ret=feof(stream);
1072 dprintf_crtdll(stddeb,"CRTDLL_feof(%p) %s\n",stream,(ret)?"true":"false");
1073 return ret;
1076 /*********************************************************************
1077 * setlocale (CRTDLL.453)
1079 LPSTR __cdecl CRTDLL_setlocale(INT32 category,LPCSTR locale)
1081 LPSTR categorystr;
1083 switch (category) {
1084 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1085 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1086 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1087 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1088 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1089 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1090 default: categorystr = "UNKNOWN?";break;
1092 fprintf(stderr,"CRTDLL_setlocale(%s,%s),stub!\n",categorystr,locale);
1093 return "C";
1096 /*********************************************************************
1097 * wcscat (CRTDLL.503)
1099 LPWSTR __cdecl CRTDLL_wcscat( LPWSTR s1, LPCWSTR s2 )
1101 return lstrcat32W( s1, s2 );
1104 /*********************************************************************
1105 * wcschr (CRTDLL.504)
1107 LPWSTR __cdecl CRTDLL_wcschr(LPCWSTR str,WCHAR xchar)
1109 LPCWSTR s;
1111 s=str;
1112 do {
1113 if (*s==xchar)
1114 return (LPWSTR)s;
1115 } while (*s++);
1116 return NULL;
1119 /*********************************************************************
1120 * wcscmp (CRTDLL.505)
1122 INT32 __cdecl CRTDLL_wcscmp( LPCWSTR s1, LPCWSTR s2 )
1124 return lstrcmp32W( s1, s2 );
1127 /*********************************************************************
1128 * wcscpy (CRTDLL.507)
1130 LPWSTR __cdecl CRTDLL_wcscpy( LPWSTR s1, LPCWSTR s2 )
1132 return lstrcpy32W( s1, s2 );
1135 /*********************************************************************
1136 * wcscspn (CRTDLL.508)
1138 INT32 __cdecl CRTDLL_wcscspn(LPWSTR str,LPWSTR reject)
1140 LPWSTR s,t;
1142 s=str;
1143 do {
1144 t=reject;
1145 while (*t) { if (*t==*s) break;t++;}
1146 if (*t) break;
1147 s++;
1148 } while (*s);
1149 return s-str; /* nr of wchars */
1152 /*********************************************************************
1153 * wcslen (CRTDLL.510)
1155 INT32 __cdecl CRTDLL_wcslen( LPCWSTR s )
1157 return lstrlen32W( s );
1160 /*********************************************************************
1161 * wcsncat (CRTDLL.511)
1163 LPWSTR __cdecl CRTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT32 n )
1165 return lstrcatn32W( s1, s2, n );
1168 /*********************************************************************
1169 * wcsncmp (CRTDLL.512)
1171 INT32 __cdecl CRTDLL_wcsncmp( LPCWSTR s1, LPCWSTR s2, INT32 n )
1173 return lstrncmp32W( s1, s2, n );
1176 /*********************************************************************
1177 * wcsncpy (CRTDLL.513)
1179 LPWSTR __cdecl CRTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT32 n )
1181 return lstrcpyn32W( s1, s2, n );
1184 /*********************************************************************
1185 * wcsspn (CRTDLL.516)
1187 INT32 __cdecl CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
1189 LPWSTR s,t;
1191 s=str;
1192 do {
1193 t=accept;
1194 while (*t) { if (*t==*s) break;t++;}
1195 if (!*t) break;
1196 s++;
1197 } while (*s);
1198 return s-str; /* nr of wchars */
1201 /*********************************************************************
1202 * towupper (CRTDLL.494)
1204 WCHAR __cdecl CRTDLL_towupper(WCHAR x)
1206 return (WCHAR)toupper((CHAR)x);
1209 /*********************************************************************
1210 * _wcsicmp (CRTDLL.321)
1212 DWORD __cdecl CRTDLL__wcsicmp( LPCWSTR s1, LPCWSTR s2 )
1214 return lstrcmpi32W( s1, s2 );
1217 /*********************************************************************
1218 * _wcsicoll (CRTDLL.322)
1220 DWORD __cdecl CRTDLL__wcsicoll(LPCWSTR a1,LPCWSTR a2)
1222 /* FIXME: handle collates */
1223 return lstrcmpi32W(a1,a2);
1226 /*********************************************************************
1227 * _wcsnicmp (CRTDLL.324)
1229 DWORD __cdecl CRTDLL__wcsnicmp( LPCWSTR s1, LPCWSTR s2, INT32 len )
1231 return lstrncmpi32W( s1, s2, len );
1234 /*********************************************************************
1235 * wcscoll (CRTDLL.506)
1237 DWORD __cdecl CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
1239 /* FIXME: handle collates */
1240 return lstrcmp32W(a1,a2);
1243 /*********************************************************************
1244 * _wcsrev (CRTDLL.326)
1246 VOID __cdecl CRTDLL__wcsrev(LPWSTR s) {
1247 LPWSTR e;
1249 e=s;
1250 while (*e)
1251 e++;
1252 while (s<e) {
1253 WCHAR a;
1255 a=*s;*s=*e;*e=a;
1256 s++;e--;
1260 /*********************************************************************
1261 * wcsstr (CRTDLL.517)
1263 LPWSTR __cdecl CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
1265 LPWSTR x,y,c;
1267 x=s;
1268 while (*x) {
1269 if (*x==*b) {
1270 y=x;c=b;
1271 while (*y && *c && *y==*c) { c++;y++; }
1272 if (!*c)
1273 return x;
1275 x++;
1277 return NULL;
1280 /*********************************************************************
1281 * wcstombs (CRTDLL.521)
1283 INT32 __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT32 len )
1285 lstrcpynWtoA( dst, src, len );
1286 return strlen(dst); /* FIXME: is this right? */
1289 /*********************************************************************
1290 * wcsrchr (CRTDLL.515)
1292 LPWSTR __cdecl CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
1294 LPWSTR s;
1296 s=str+lstrlen32W(str);
1297 do {
1298 if (*s==xchar)
1299 return s;
1300 s--;
1301 } while (s>=str);
1302 return NULL;
1305 /*********************************************************************
1306 * _setmode (CRTDLL.265)
1307 * FIXME: At present we ignore the request to translate CR/LF to LF.
1309 * We allways translate when we read with fgets, we never do with fread
1312 INT32 __cdecl CRTDLL__setmode( INT32 fh,INT32 mode)
1314 /* FIXME */
1315 #define O_TEXT 0x4000
1316 #define O_BINARY 0x8000
1318 dprintf_crtdll(stddeb,
1319 "CRTDLL._setmode on fhandle %d mode %s, STUB.\n",
1320 fh,(mode=O_TEXT)?"O_TEXT":
1321 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1322 return -1;
1325 /*********************************************************************
1326 * atexit (CRTDLL.345)
1328 INT32 __cdecl CRTDLL_atexit(LPVOID x)
1330 /* FIXME */
1331 fprintf(stdnimp,"CRTDLL.atexit(%p), STUB.\n",x);
1332 return 0; /* successful */
1335 /*********************************************************************
1336 * mblen (CRTDLL.428)
1337 * FIXME: check multibyte support
1339 WCHAR __cdecl CRTDLL_mblen(CHAR *mb,INT32 size)
1342 int ret=1;
1344 if (!mb)
1345 ret = 0;
1346 else if ((size<1)||(!*(mb+1)))
1347 ret = -1;
1348 else if (!(*mb))
1349 ret =0;
1351 dprintf_crtdll(stderr,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb,size,ret);
1353 return ret;
1356 /*********************************************************************
1357 * mbstowcs (CRTDLL.429)
1358 * FIXME: check multibyte support
1360 INT32 __cdecl CRTDLL_mbstowcs(LPWSTR wcs, LPCSTR mbs, INT32 size)
1363 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1364 * We need the number of characters transfered
1365 * FIXME: No multibyte support yet
1368 LPWSTR p = wcs;
1369 LPCSTR src= mbs;
1370 int ret, n=size;
1372 while ((n-- > 0) && *src) {
1373 *p++ = (WCHAR)(unsigned char)*src++;
1375 p++;
1376 ret = (p -wcs);
1378 dprintf_crtdll(stddeb,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1379 mbs,size,ret);
1380 return ret;
1383 /*********************************************************************
1384 * mbtowc (CRTDLL.430)
1385 * FIXME: check multibyte support
1387 WCHAR __cdecl CRTDLL_mbtowc(WCHAR* wc,CHAR* mb,INT32 size)
1389 int ret;
1391 if (!mb)
1392 ret = 0;
1393 else if (!wc)
1394 ret =-1;
1395 else
1396 if ( (ret = mblen(mb,size)) != -1 )
1398 if (ret <= sizeof(char))
1399 *wc = (WCHAR) ((unsigned char)*mb);
1400 else
1401 ret= -1;
1403 else
1404 ret = -1;
1406 dprintf_crtdll(stderr,"CRTDLL_mbtowc %s for %d chars\n",mb,size);
1408 return ret;
1411 /*********************************************************************
1412 * _isctype (CRTDLL.138)
1414 BOOL32 __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1416 if ((type & CRTDLL_SPACE) && isspace(x))
1417 return TRUE;
1418 if ((type & CRTDLL_PUNCT) && ispunct(x))
1419 return TRUE;
1420 if ((type & CRTDLL_LOWER) && islower(x))
1421 return TRUE;
1422 if ((type & CRTDLL_UPPER) && isupper(x))
1423 return TRUE;
1424 if ((type & CRTDLL_ALPHA) && isalpha(x))
1425 return TRUE;
1426 if ((type & CRTDLL_DIGIT) && isdigit(x))
1427 return TRUE;
1428 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1429 return TRUE;
1430 /* check CRTDLL_LEADBYTE */
1431 return FALSE;
1434 /*********************************************************************
1435 * _chdrive (CRTDLL.52)
1437 BOOL32 __cdecl CRTDLL__chdrive(INT32 newdrive)
1439 /* FIXME: generates errnos */
1440 return DRIVE_SetCurrentDrive(newdrive);
1443 /*********************************************************************
1444 * _chdir (CRTDLL.51)
1446 INT32 __cdecl CRTDLL__chdir(LPCSTR newdir)
1448 if (!SetCurrentDirectory32A(newdir))
1449 return -1;
1450 return 0;
1453 /*********************************************************************
1454 * _fullpath (CRTDLL.114)
1456 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT32 size)
1458 DOS_FULL_NAME full_name;
1460 if (!buf)
1462 size = 256;
1463 if(!(buf = CRTDLL_malloc(size))) return NULL;
1465 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1466 lstrcpyn32A(buf,full_name.short_name,size);
1467 dprintf_crtdll(stderr,"CRTDLL_fullpath got %s\n",buf);
1468 return buf;
1471 /*********************************************************************
1472 * _splitpath (CRTDLL.279)
1474 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1476 /* drive includes :
1477 directory includes leading and trailing (forward and backward slashes)
1478 filename without dot and slashes
1479 extension with leading dot
1481 char * drivechar,*dirchar,*namechar;
1483 dprintf_crtdll(stddeb,"CRTDLL__splitpath got %s\n",path);
1485 drivechar = strchr(path,':');
1486 dirchar = strrchr(path,'/');
1487 namechar = strrchr(path,'\\');
1488 dirchar = MAX(dirchar,namechar);
1489 if (dirchar)
1490 namechar = strrchr(dirchar,'.');
1491 else
1492 namechar = strrchr(path,'.');
1495 if (drive)
1497 *drive = NULL;
1498 if (drivechar)
1500 strncat(drive,path,drivechar-path+1);
1501 path = drivechar+1;
1504 if (directory)
1506 *directory = NULL;
1507 if (dirchar)
1509 strncat(directory,path,dirchar-path+1);
1510 path = dirchar+1;
1513 if (filename)
1515 *filename = NULL;
1516 if (namechar)
1518 strncat(filename,path,namechar-path);
1519 if (extension)
1521 *extension = NULL;
1522 strcat(extension,namechar);
1527 dprintf_crtdll(stddeb,"CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1531 /*********************************************************************
1532 * _getcwd (CRTDLL.120)
1534 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT32 size)
1536 char test[1];
1537 int len;
1539 len = size;
1540 if (!buf) {
1541 if (size < 0) /* allocate as big as nescessary */
1542 len =GetCurrentDirectory32A(1,test) + 1;
1543 if(!(buf = CRTDLL_malloc(len)))
1545 /* set error to OutOfRange */
1546 return( NULL );
1549 size = len;
1550 if(!(len =GetCurrentDirectory32A(len,buf)))
1552 return NULL;
1554 if (len > size)
1556 /* set error to ERANGE */
1557 dprintf_crtdll(stddeb,"CRTDLL_getcwd buffer to small\n");
1558 return NULL;
1560 return buf;
1564 /*********************************************************************
1565 * _mkdir (CRTDLL.234)
1567 INT32 __cdecl CRTDLL__mkdir(LPCSTR newdir)
1569 if (!CreateDirectory32A(newdir,NULL))
1570 return -1;
1571 return 0;
1574 /*********************************************************************
1575 * _errno (CRTDLL.52)
1576 * Yes, this is a function.
1578 LPINT32 __cdecl CRTDLL__errno()
1580 static int crtdllerrno;
1581 extern int LastErrorToErrno(DWORD);
1583 /* FIXME: we should set the error at the failing function call time */
1584 crtdllerrno = LastErrorToErrno(GetLastError());
1585 return &crtdllerrno;
1588 /*********************************************************************
1589 * _tempnam (CRTDLL.305)
1592 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1595 char *ret;
1596 DOS_FULL_NAME tempname;
1598 if ((ret = tempnam(dir,prefix))==NULL) {
1599 dprintf_crtdll(stddeb,
1600 "CRTDLL_tempnam Unable to get unique filename\n");
1601 return NULL;
1603 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1605 dprintf_crtdll(stddeb,
1606 "CRTDLL_tempnam Wrong path?\n");
1607 return NULL;
1609 free(ret);
1610 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1611 dprintf_crtdll(stddeb,
1612 "CRTDLL_tempnam CRTDL_malloc for shortname failed\n");
1613 return NULL;
1615 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1616 dprintf_crtdll(stddeb,
1617 "CRTDLL_tempnam Malloc for shortname failed\n");
1618 return NULL;
1621 dprintf_crtdll(stddeb,"CRTDLL_tempnam dir %s prefix %s got %s\n",
1622 dir,prefix,ret);
1623 return ret;
1626 /*********************************************************************
1627 * tmpnam (CRTDLL.490)
1629 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1632 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1634 char *ret;
1636 if ((ret =tmpnam(s))== NULL) {
1637 dprintf_crtdll(stddeb,
1638 "CRTDLL_tmpnam Unable to get unique filename\n");
1639 return NULL;
1641 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1643 dprintf_crtdll(stddeb,
1644 "CRTDLL_tmpnam Wrong path?\n");
1645 return NULL;
1647 strcat(CRTDLL_tmpname.short_name,".");
1648 dprintf_crtdll(stddeb,"CRTDLL_tmpnam for buf %p got %s\n",
1649 s,CRTDLL_tmpname.short_name);
1650 dprintf_crtdll(stddeb,"CRTDLL_tmpnam long got %s\n",
1651 CRTDLL_tmpname.long_name);
1652 if ( s != NULL)
1653 return strcpy(s,CRTDLL_tmpname.short_name);
1654 else
1655 return CRTDLL_tmpname.short_name;
1659 /*********************************************************************
1660 * _itoa (CRTDLL.165)
1662 LPSTR __cdecl CRTDLL__itoa(INT32 x,LPSTR buf,INT32 buflen)
1664 wsnprintf32A(buf,buflen,"%d",x);
1665 return buf;
1668 typedef VOID (*sig_handler_type)(VOID);
1670 /*********************************************************************
1671 * signal (CRTDLL.455)
1673 VOID __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
1675 dprintf_crtdll(stddeb,"CRTDLL_signal %d %p: STUB!\n",sig,ptr);
1678 /*********************************************************************
1679 * _ftol (CRTDLL.113)
1681 LONG __cdecl CRTDLL__ftol(double fl) {
1682 return (LONG)fl;