4 * Implements C run-time functionality as known from UNIX.
6 * Copyright 1996,1998 Marcus Meissner
7 * Copyright 1996 Jukka Iivonen
8 * Copyright 1997 Uwe Bonnes
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
20 - needs a proper stdio emulation based on Win32 file handles
21 - should set CRTDLL errno from GetLastError() in every function
24 /* NOTE: This file also implements the wcs* functions. They _ARE_ in
25 * the newer Linux libcs, but use 4 byte wide characters, so are unusable,
26 * since we need 2 byte wide characters. - Marcus Meissner, 981031
34 #include <sys/times.h>
54 /* windows.h RAND_MAX is smaller than normal RAND_MAX */
55 #define CRTDLL_RAND_MAX 0x7fff
57 static DOS_FULL_NAME CRTDLL_tmpname
;
59 UINT CRTDLL_argc_dll
; /* CRTDLL.23 */
60 LPSTR
*CRTDLL_argv_dll
; /* CRTDLL.24 */
61 LPSTR CRTDLL_acmdln_dll
; /* CRTDLL.38 */
62 UINT CRTDLL_basemajor_dll
; /* CRTDLL.42 */
63 UINT CRTDLL_baseminor_dll
; /* CRTDLL.43 */
64 UINT CRTDLL_baseversion_dll
; /* CRTDLL.44 */
65 UINT CRTDLL_commode_dll
; /* CRTDLL.59 */
66 LPSTR CRTDLL_environ_dll
; /* CRTDLL.75 */
67 UINT CRTDLL_fmode_dll
; /* CRTDLL.104 */
68 UINT CRTDLL_osmajor_dll
; /* CRTDLL.241 */
69 UINT CRTDLL_osminor_dll
; /* CRTDLL.242 */
70 UINT CRTDLL_osmode_dll
; /* CRTDLL.243 */
71 UINT CRTDLL_osver_dll
; /* CRTDLL.244 */
72 UINT CRTDLL_osversion_dll
; /* CRTDLL.245 */
73 UINT CRTDLL_winmajor_dll
; /* CRTDLL.329 */
74 UINT CRTDLL_winminor_dll
; /* CRTDLL.330 */
75 UINT CRTDLL_winver_dll
; /* CRTDLL.331 */
77 /* FIXME: structure layout is obviously not correct */
84 CRTDLL_FILE CRTDLL_iob
[3];
86 static CRTDLL_FILE
* const CRTDLL_stdin
= &CRTDLL_iob
[0];
87 static CRTDLL_FILE
* const CRTDLL_stdout
= &CRTDLL_iob
[1];
88 static CRTDLL_FILE
* const CRTDLL_stderr
= &CRTDLL_iob
[2];
90 typedef VOID (*new_handler_type
)(VOID
);
92 static new_handler_type new_handler
;
94 #if defined(__GNUC__) && defined(__i386__)
95 #define USING_REAL_FPU
96 #define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
97 #define POP_FPU(x) DO_FPU("fstpl",x)
100 /*********************************************************************
101 * _GetMainArgs (CRTDLL.022)
103 DWORD __cdecl
CRTDLL__GetMainArgs(LPDWORD argc
,LPSTR
**argv
,
104 LPSTR
*environ
,DWORD flag
)
108 int xargc
,i
,afterlastspace
;
111 TRACE(crtdll
,"(%p,%p,%p,%ld).\n",
112 argc
,argv
,environ
,flag
114 CRTDLL_acmdln_dll
= cmdline
= HEAP_strdupA( GetProcessHeap(), 0,
116 TRACE(crtdll
,"got '%s'\n", cmdline
);
118 version
= GetVersion();
119 CRTDLL_osver_dll
= version
>> 16;
120 CRTDLL_winminor_dll
= version
& 0xFF;
121 CRTDLL_winmajor_dll
= (version
>>8) & 0xFF;
122 CRTDLL_baseversion_dll
= version
>> 16;
123 CRTDLL_winver_dll
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
124 CRTDLL_baseminor_dll
= (version
>> 16) & 0xFF;
125 CRTDLL_basemajor_dll
= (version
>> 24) & 0xFF;
126 CRTDLL_osversion_dll
= version
& 0xFFFF;
127 CRTDLL_osminor_dll
= version
& 0xFF;
128 CRTDLL_osmajor_dll
= (version
>>8) & 0xFF;
130 /* missing threading init */
132 i
=0;xargv
=NULL
;xargc
=0;afterlastspace
=0;
134 if (cmdline
[i
]==' ') {
135 xargv
=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv
,
136 sizeof(char*)*(++xargc
));
138 xargv
[xargc
-1] = HEAP_strdupA( GetProcessHeap(), 0,
139 cmdline
+afterlastspace
);
141 while (cmdline
[i
]==' ')
148 xargv
=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv
,
149 sizeof(char*)*(++xargc
));
151 xargv
[xargc
-1] = HEAP_strdupA( GetProcessHeap(), 0,
152 cmdline
+afterlastspace
);
153 CRTDLL_argc_dll
= xargc
;
155 CRTDLL_argv_dll
= xargv
;
158 TRACE(crtdll
,"found %d arguments\n",
160 CRTDLL_environ_dll
= *environ
= GetEnvironmentStringsA();
165 typedef void (*_INITTERMFUN
)();
167 /* fixme: move to header */
170 time_t time_create
; /* -1 when not avaiable */
171 time_t time_access
; /* -1 when not avaiable */
173 unsigned long size
; /* fixme: 64 bit ??*/
176 /*********************************************************************
177 * _findfirst (CRTDLL.099)
182 DWORD __cdecl
CRTDLL__findfirst(LPCSTR fname
, struct find_t
* x2
)
184 FIXME(crtdll
, ":(%s,%p): stub\n",fname
,x2
);
185 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
189 /*********************************************************************
190 * _findnext (CRTDLL.100)
195 INT __cdecl
CRTDLL__findnext(DWORD hand
, struct find_t
* x2
)
197 FIXME(crtdll
, ":(%ld,%p): stub\n",hand
,x2
);
198 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
202 /*********************************************************************
203 * _fstat (CRTDLL.111)
208 int __cdecl
CRTDLL__fstat(int file
, struct stat
* buf
)
210 FIXME(crtdll
, ":(%d,%p): stub\n",file
,buf
);
211 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
215 /*********************************************************************
216 * _initterm (CRTDLL.135)
218 DWORD __cdecl
CRTDLL__initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
220 _INITTERMFUN
*current
;
222 TRACE(crtdll
,"(%p,%p)\n",start
,end
);
224 while (current
<end
) {
225 if (*current
) (*current
)();
231 /*********************************************************************
232 * _fdopen (CRTDLL.91)
234 CRTDLL_FILE
* __cdecl
CRTDLL__fdopen(INT handle
, LPCSTR mode
)
242 if (!file
->handle
) file
->handle
= GetStdHandle( STD_INPUT_HANDLE
);
245 file
= CRTDLL_stdout
;
246 if (!file
->handle
) file
->handle
= GetStdHandle( STD_OUTPUT_HANDLE
);
250 if (!file
->handle
) file
->handle
= GetStdHandle( STD_ERROR_HANDLE
);
253 file
= HeapAlloc( GetProcessHeap(), 0, sizeof(*file
) );
254 file
->handle
= handle
;
257 TRACE(crtdll
, "open handle %d mode %s got file %p\n",
263 /*******************************************************************
264 * _global_unwind2 (CRTDLL.129)
266 void __cdecl
CRTDLL__global_unwind2( PEXCEPTION_FRAME frame
)
268 RtlUnwind( frame
, 0, NULL
, 0 );
271 /*******************************************************************
272 * _local_unwind2 (CRTDLL.173)
274 void __cdecl
CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe
, DWORD nr
)
276 TRACE(crtdll
,"(%p,%ld)\n",endframe
,nr
);
278 /*********************************************************************
284 INT __cdecl
CRTDLL__read(INT fd
, LPVOID buf
, UINT count
)
286 FIXME(crtdll
,":(%d,%p,%d): stub\n",fd
,buf
,count
);
287 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
291 /*********************************************************************
294 CRTDLL_FILE
* __cdecl
CRTDLL_fopen(LPCSTR path
, LPCSTR mode
)
296 CRTDLL_FILE
*file
= NULL
;
299 DOS_FULL_NAME full_name
;
301 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
)) {
302 WARN(crtdll
, "file %s bad name\n",path
);
306 file
=fopen(full_name
.long_name
,mode
);
308 DWORD access
= 0, creation
= 0;
310 if ((strchr(mode
,'r')&&strchr(mode
,'a'))||
311 (strchr(mode
,'r')&&strchr(mode
,'w'))||
312 (strchr(mode
,'w')&&strchr(mode
,'a')))
317 access
= GENERIC_READ
;
318 creation
= OPEN_EXISTING
;
319 if (mode
[1] == '+') access
|= GENERIC_WRITE
;
321 else if (mode
[0] == 'w')
323 access
= GENERIC_WRITE
;
324 creation
= CREATE_ALWAYS
;
325 if (mode
[1] == '+') access
|= GENERIC_READ
;
327 else if (mode
[0] == 'a')
329 /* FIXME: there is no O_APPEND in CreateFile, should emulate it */
330 access
= GENERIC_WRITE
;
331 creation
= OPEN_ALWAYS
;
332 if (mode
[1] == '+') access
|= GENERIC_READ
;
334 /* FIXME: should handle text/binary mode */
336 if ((handle
= CreateFileA( path
, access
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
337 NULL
, creation
, FILE_ATTRIBUTE_NORMAL
,
338 -1 )) != INVALID_HANDLE_VALUE
)
340 file
= HeapAlloc( GetProcessHeap(), 0, sizeof(*file
) );
341 file
->handle
= handle
;
343 TRACE(crtdll
, "file %s mode %s got handle %d file %p\n",
344 path
,mode
,handle
,file
);
348 /*********************************************************************
351 DWORD __cdecl
CRTDLL_fread(LPVOID ptr
, INT size
, INT nmemb
, CRTDLL_FILE
*file
)
357 /* If we would honour CR/LF <-> LF translation, we could do it like this.
358 We should keep track of all files opened, and probably files with \
359 known binary extensions must be unchanged */
360 while ( (i
< (nmemb
*size
)) && (ret
==1)) {
361 ret
=fread(temp
,1,1,file
);
362 TRACE(crtdll
, "got %c 0x%02x ret %d\n",
363 (isalpha(*(unsigned char*)temp
))? *(unsigned char*)temp
:
364 ' ',*(unsigned char*)temp
, ret
);
365 if (*(unsigned char*)temp
!= 0xd) { /* skip CR */
370 TRACE(crtdll
, "skipping ^M\n");
372 TRACE(crtdll
, "0x%08x items of size %d from file %p to %p\n",
373 nmemb
,size
,file
,ptr
,);
375 WARN(crtdll
, " failed!\n");
381 TRACE(crtdll
, "0x%08x items of size %d from file %p to %p\n",
382 nmemb
,size
,file
,ptr
);
383 if (!ReadFile( file
->handle
, ptr
, size
* nmemb
, &ret
, NULL
))
384 WARN(crtdll
, " failed!\n");
389 /*********************************************************************
390 * freopen (CRTDLL.379)
395 DWORD __cdecl
CRTDLL_freopen(LPCSTR path
, LPCSTR mode
, LPVOID stream
)
397 FIXME(crtdll
, ":(%s,%s,%p): stub\n", path
, mode
, stream
);
398 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
402 /*********************************************************************
403 * fscanf (CRTDLL.381)
405 INT __cdecl
CRTDLL_fscanf( CRTDLL_FILE
*stream
, LPSTR format
, ... )
411 va_start( valist
, format
);
413 res
= vfscanf( xlat_file_ptr(stream
), format
, valist
);
418 FIXME(crtdll
,"broken\n");
422 /*********************************************************************
425 LONG __cdecl
CRTDLL_fseek( CRTDLL_FILE
*file
, LONG offset
, INT whence
)
427 TRACE(crtdll
, "file %p to 0x%08lx pos %s\n",
428 file
,offset
,(whence
==SEEK_SET
)?"SEEK_SET":
429 (whence
==SEEK_CUR
)?"SEEK_CUR":
430 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
431 if (SetFilePointer( file
->handle
, offset
, NULL
, whence
) != 0xffffffff)
433 WARN(crtdll
, " failed!\n");
437 /*********************************************************************
438 * fsetpos (CRTDLL.383)
440 INT __cdecl
CRTDLL_fsetpos( CRTDLL_FILE
*file
, INT
*pos
)
442 TRACE(crtdll
, "file %p pos %d\n", file
, *pos
);
443 return CRTDLL_fseek(file
, *pos
, SEEK_SET
);
446 /*********************************************************************
449 LONG __cdecl
CRTDLL_ftell( CRTDLL_FILE
*file
)
451 return SetFilePointer( file
->handle
, 0, NULL
, SEEK_CUR
);
454 /*********************************************************************
455 * fwrite (CRTDLL.386)
457 DWORD __cdecl
CRTDLL_fwrite( LPVOID ptr
, INT size
, INT nmemb
, CRTDLL_FILE
*file
)
461 TRACE(crtdll
, "0x%08x items of size %d to file %p from %p\n",
462 nmemb
,size
,file
,ptr
);
463 if (!WriteFile( file
->handle
, ptr
, size
* nmemb
, &ret
, NULL
))
464 WARN(crtdll
, " failed!\n");
468 /*********************************************************************
469 * setbuf (CRTDLL.452)
471 INT __cdecl
CRTDLL_setbuf(CRTDLL_FILE
*file
, LPSTR buf
)
473 TRACE(crtdll
, "(file %p buf %p)\n", file
, buf
);
474 /* this doesn't work:"void value not ignored as it ought to be"
475 return setbuf(file,buf);
477 /* FIXME: no buffering for now */
481 /*********************************************************************
482 * _open_osfhandle (CRTDLL.240)
484 HFILE __cdecl
CRTDLL__open_osfhandle(LONG osfhandle
, INT flags
)
489 case STD_INPUT_HANDLE
:
493 case STD_OUTPUT_HANDLE
:
497 case STD_ERROR_HANDLE
:
504 TRACE(crtdll
, "(handle %08lx,flags %d) return %d\n",
505 osfhandle
,flags
,handle
);
510 /*********************************************************************
513 void __cdecl
CRTDLL_srand(DWORD seed
)
515 /* FIXME: should of course be thread? process? local */
519 /*********************************************************************
520 * vfprintf (CRTDLL.373)
522 INT __cdecl
CRTDLL_vfprintf( CRTDLL_FILE
*file
, LPSTR format
, va_list args
)
524 char buffer
[1024]; /* FIXME... */
526 vsprintf( buffer
, format
, args
);
527 return CRTDLL_fwrite( buffer
, 1, strlen(buffer
), file
);
530 /*********************************************************************
531 * fprintf (CRTDLL.373)
533 INT __cdecl
CRTDLL_fprintf( CRTDLL_FILE
*file
, LPSTR format
, ... )
538 va_start( valist
, format
);
539 res
= CRTDLL_vfprintf( file
, format
, valist
);
544 /*********************************************************************
547 time_t __cdecl
CRTDLL_time(time_t *timeptr
)
549 time_t curtime
= time(NULL
);
556 /*********************************************************************
559 clock_t __cdecl
CRTDLL_clock(void)
565 res
= alltimes
.tms_utime
+ alltimes
.tms_stime
+
566 alltimes
.tms_cutime
+ alltimes
.tms_cstime
;
567 /* Fixme: We need some symbolic representation
568 for (Hostsystem_)CLOCKS_PER_SEC
569 and (Emulated_system_)CLOCKS_PER_SEC
570 10 holds only for Windows/Linux_i86)
575 /*********************************************************************
576 * _isatty (CRTDLL.137)
578 BOOL __cdecl
CRTDLL__isatty(DWORD x
)
580 TRACE(crtdll
,"(%ld)\n",x
);
584 /*********************************************************************
585 * _write (CRTDLL.332)
587 INT __cdecl
CRTDLL__write(INT fd
,LPCVOID buf
,UINT count
)
594 len
= (UINT
)write(fd
,buf
,(LONG
)count
);
596 len
= _lwrite(fd
,buf
,count
);
597 TRACE(crtdll
,"%d/%d byte to dfh %d from %p,\n",
603 /*********************************************************************
606 * FIXME: What the heck is the difference between
607 * FIXME _c_exit (CRTDLL.47)
608 * FIXME _cexit (CRTDLL.49)
609 * FIXME _exit (CRTDLL.87)
610 * FIXME exit (CRTDLL.359)
612 * atexit-processing comes to mind -- MW.
615 void __cdecl
CRTDLL__cexit(INT ret
)
617 TRACE(crtdll
,"(%d)\n",ret
);
622 /*********************************************************************
625 void __cdecl
CRTDLL_exit(DWORD ret
)
627 TRACE(crtdll
,"(%ld)\n",ret
);
632 /*********************************************************************
633 * _abnormal_termination (CRTDLL.36)
635 INT __cdecl
CRTDLL__abnormal_termination(void)
637 TRACE(crtdll
,"(void)\n");
642 /*********************************************************************
643 * _access (CRTDLL.37)
645 INT __cdecl
CRTDLL__access(LPCSTR filename
, INT mode
)
647 DWORD attr
= GetFileAttributesA(filename
);
651 if (GetLastError() == ERROR_INVALID_ACCESS
)
658 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
668 /*********************************************************************
669 * fflush (CRTDLL.365)
671 INT __cdecl
CRTDLL_fflush( CRTDLL_FILE
*file
)
673 return FlushFileBuffers( file
->handle
) ? 0 : -1;
677 /*********************************************************************
680 INT __cdecl
CRTDLL_rand()
682 return (rand() & CRTDLL_RAND_MAX
);
686 /*********************************************************************
687 * putchar (CRTDLL.442)
689 void __cdecl
CRTDLL_putchar( INT x
)
695 /*********************************************************************
698 INT __cdecl
CRTDLL_fputc( INT c
, CRTDLL_FILE
*file
)
702 TRACE(crtdll
, "%c to file %p\n",c
,file
);
703 if (!WriteFile( file
->handle
, &ch
, 1, &res
, NULL
)) return -1;
708 /*********************************************************************
711 INT __cdecl
CRTDLL_fputs( LPCSTR s
, CRTDLL_FILE
*file
)
714 TRACE(crtdll
, "%s to file %p\n",s
,file
);
715 if (!WriteFile( file
->handle
, s
, strlen(s
), &res
, NULL
)) return -1;
720 /*********************************************************************
723 INT __cdecl
CRTDLL_puts(LPCSTR s
)
725 TRACE(crtdll
, "%s \n",s
);
730 /*********************************************************************
733 INT __cdecl
CRTDLL_putc( INT c
, CRTDLL_FILE
*file
)
735 return CRTDLL_fputc( c
, file
);
738 /*********************************************************************
741 INT __cdecl
CRTDLL_fgetc( CRTDLL_FILE
*file
)
745 if (!ReadFile( file
->handle
, &ch
, 1, &res
, NULL
)) return -1;
746 if (res
!= 1) return -1;
751 /*********************************************************************
754 INT __cdecl
CRTDLL_getc( CRTDLL_FILE
*file
)
756 return CRTDLL_fgetc( file
);
760 /*********************************************************************
763 CHAR
* __cdecl
CRTDLL_fgets( LPSTR s
, INT size
, CRTDLL_FILE
*file
)
768 /* BAD, for the whole WINE process blocks... just done this way to test
769 * windows95's ftp.exe.
772 for(cc
= CRTDLL_fgetc(file
); cc
!= EOF
&& cc
!= '\n'; cc
= CRTDLL_fgetc(file
))
775 if (--size
<= 0) break;
781 TRACE(crtdll
,"got '%s'\n", buf_start
);
786 /*********************************************************************
789 LPSTR __cdecl
CRTDLL_gets(LPSTR buf
)
792 LPSTR buf_start
= buf
;
794 /* BAD, for the whole WINE process blocks... just done this way to test
795 * windows95's ftp.exe.
798 for(cc
= fgetc(stdin
); cc
!= EOF
&& cc
!= '\n'; cc
= fgetc(stdin
))
799 if(cc
!= '\r') *buf
++ = (char)cc
;
803 TRACE(crtdll
,"got '%s'\n", buf_start
);
808 /*********************************************************************
811 UINT __cdecl
CRTDLL__rotl(UINT x
,INT shift
)
813 unsigned int ret
= (x
>> shift
)|( x
>>((sizeof(x
))-shift
));
815 TRACE(crtdll
, "got 0x%08x rot %d ret 0x%08x\n",
820 /*********************************************************************
821 * _lrotl (CRTDLL.176)
823 DWORD __cdecl
CRTDLL__lrotl(DWORD x
,INT shift
)
825 unsigned long ret
= (x
>> shift
)|( x
>>((sizeof(x
))-shift
));
827 TRACE(crtdll
, "got 0x%08lx rot %d ret 0x%08lx\n",
834 /*********************************************************************
835 * _mbsicmp (CRTDLL.204)
837 int __cdecl
CRTDLL__mbsicmp(unsigned char *x
,unsigned char *y
)
844 /* FIXME: MBCS handling... */
853 /*********************************************************************
854 * _mbsinc (CRTDLL.205)
856 unsigned char * __cdecl
CRTDLL__mbsinc(unsigned char *x
)
863 /*********************************************************************
864 * vsprintf (CRTDLL.500)
866 INT __cdecl
CRTDLL_vsprintf( LPSTR buffer
, LPCSTR spec
, va_list args
)
868 return wvsprintfA( buffer
, spec
, args
);
871 /*********************************************************************
872 * vswprintf (CRTDLL.501)
874 INT __cdecl
CRTDLL_vswprintf( LPWSTR buffer
, LPCWSTR spec
, va_list args
)
876 return wvsprintfW( buffer
, spec
, args
);
879 /*********************************************************************
880 * _mbscpy (CRTDLL.200)
882 unsigned char* __cdecl
CRTDLL__mbscpy(unsigned char *x
,unsigned char *y
)
884 TRACE(crtdll
,"CRTDLL_mbscpy %s and %s\n",x
,y
);
889 /*********************************************************************
890 * _mbscat (CRTDLL.197)
892 unsigned char* __cdecl
CRTDLL__mbscat(unsigned char *x
,unsigned char *y
)
898 /*********************************************************************
899 * _strcmpi (CRTDLL.282) (CRTDLL.287)
901 INT __cdecl
CRTDLL__strcmpi( LPCSTR s1
, LPCSTR s2
)
903 return lstrcmpiA( s1
, s2
);
907 /*********************************************************************
908 * _strnicmp (CRTDLL.293)
910 INT __cdecl
CRTDLL__strnicmp( LPCSTR s1
, LPCSTR s2
, INT n
)
912 return lstrncmpiA( s1
, s2
, n
);
916 /*********************************************************************
917 * _strlwr (CRTDLL.293)
919 * convert a string in place to lowercase
921 LPSTR __cdecl
CRTDLL__strlwr(LPSTR x
)
925 TRACE(crtdll
, "CRTDLL_strlwr got %s\n", x
);
927 if ((*y
> 0x40) && (*y
< 0x5b))
931 TRACE(crtdll
, " returned %s\n", x
);
936 /*********************************************************************
937 * system (CRTDLL.485)
939 INT __cdecl
CRTDLL_system(LPSTR x
)
941 #define SYSBUF_LENGTH 1500
942 char buffer
[SYSBUF_LENGTH
];
943 unsigned char *y
= x
;
947 sprintf( buffer
, "%s \"", Options
.argv0
);
948 bp
= buffer
+ strlen(buffer
);
949 i
= strlen(buffer
) + strlen(x
) +2;
951 /* Calculate needed buffer size to prevent overflow. */
956 /* If buffer too short, exit. */
957 if (i
> SYSBUF_LENGTH
) {
958 TRACE(crtdll
,"_system buffer to small\n");
967 if (*(y
-1) =='\\') *bp
++ = '\\';
969 /* Remove spaces from end of string. */
970 while (*(y
-1) == ' ') {
975 TRACE(crtdll
, "_system got '%s', executing '%s'\n",x
,buffer
);
977 return system(buffer
);
980 /*********************************************************************
981 * _strupr (CRTDLL.300)
983 LPSTR __cdecl
CRTDLL__strupr(LPSTR x
)
994 /*********************************************************************
995 * _wcsupr (CRTDLL.328)
997 LPWSTR __cdecl
CRTDLL__wcsupr(LPWSTR x
)
1008 /*********************************************************************
1009 * _wcslwr (CRTDLL.323)
1011 LPWSTR __cdecl
CRTDLL__wcslwr(LPWSTR x
)
1023 /*********************************************************************
1024 * longjmp (CRTDLL.426)
1026 VOID __cdecl
CRTDLL_longjmp(jmp_buf env
, int val
)
1028 FIXME(crtdll
,"CRTDLL_longjmp semistup, expect crash\n");
1029 return longjmp(env
, val
);
1032 /*********************************************************************
1033 * malloc (CRTDLL.427)
1035 VOID
* __cdecl
CRTDLL_malloc(DWORD size
)
1037 return HeapAlloc(GetProcessHeap(),0,size
);
1040 /*********************************************************************
1043 VOID
* __cdecl
CRTDLL_new(DWORD size
)
1046 if(!(result
= HeapAlloc(GetProcessHeap(),0,size
)) && new_handler
)
1051 /*********************************************************************
1052 * set_new_handler(CRTDLL.003)
1054 new_handler_type __cdecl
CRTDLL_set_new_handler(new_handler_type func
)
1056 new_handler_type old_handler
= new_handler
;
1061 /*********************************************************************
1062 * calloc (CRTDLL.350)
1064 VOID
* __cdecl
CRTDLL_calloc(DWORD size
, DWORD count
)
1066 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
* count
);
1069 /*********************************************************************
1070 * realloc (CRTDLL.447)
1072 VOID
* __cdecl
CRTDLL_realloc( VOID
*ptr
, DWORD size
)
1074 return HeapReAlloc( GetProcessHeap(), 0, ptr
, size
);
1077 /*********************************************************************
1080 VOID __cdecl
CRTDLL_free(LPVOID ptr
)
1082 HeapFree(GetProcessHeap(),0,ptr
);
1085 /*********************************************************************
1086 * delete (CRTDLL.002)
1088 VOID __cdecl
CRTDLL_delete(VOID
* ptr
)
1090 HeapFree(GetProcessHeap(),0,ptr
);
1093 /*********************************************************************
1094 * _strdup (CRTDLL.285)
1096 LPSTR __cdecl
CRTDLL__strdup(LPCSTR ptr
)
1098 return HEAP_strdupA(GetProcessHeap(),0,ptr
);
1101 /*********************************************************************
1102 * _wcsdup (CRTDLL.320)
1104 LPWSTR __cdecl
CRTDLL__wcsdup(LPCWSTR ptr
)
1106 return HEAP_strdupW(GetProcessHeap(),0,ptr
);
1109 /*********************************************************************
1110 * fclose (CRTDLL.362)
1112 INT __cdecl
CRTDLL_fclose( CRTDLL_FILE
*file
)
1114 TRACE(crtdll
,"%p\n", file
);
1115 if (!CloseHandle( file
->handle
)) return -1;
1116 HeapFree( GetProcessHeap(), 0, file
);
1120 /*********************************************************************
1121 * _unlink (CRTDLL.315)
1123 INT __cdecl
CRTDLL__unlink(LPCSTR pathname
)
1126 DOS_FULL_NAME full_name
;
1128 if (!DOSFS_GetFullName( pathname
, FALSE
, &full_name
)) {
1129 WARN(crtdll
, "CRTDLL_unlink file %s bad name\n",pathname
);
1133 ret
=unlink(full_name
.long_name
);
1134 TRACE(crtdll
,"(%s unix %s)\n",
1135 pathname
,full_name
.long_name
);
1137 WARN(crtdll
, " Failed!\n");
1142 /*********************************************************************
1143 * rename (CRTDLL.449)
1145 INT __cdecl
CRTDLL_rename(LPCSTR oldpath
,LPCSTR newpath
)
1147 BOOL ok
= MoveFileExA( oldpath
, newpath
, MOVEFILE_REPLACE_EXISTING
);
1152 /*********************************************************************
1153 * _stat (CRTDLL.280)
1171 int __cdecl
CRTDLL__stat(const char * filename
, struct win_stat
* buf
)
1174 DOS_FULL_NAME full_name
;
1177 if (!DOSFS_GetFullName( filename
, TRUE
, &full_name
))
1179 WARN(crtdll
, "CRTDLL__stat filename %s bad name\n",filename
);
1182 ret
=stat(full_name
.long_name
,&mystat
);
1183 TRACE(crtdll
,"CRTDLL__stat %s\n", filename
);
1185 WARN(crtdll
, " Failed!\n");
1187 /* FIXME: should check what Windows returns */
1189 buf
->win_st_dev
= mystat
.st_dev
;
1190 buf
->win_st_ino
= mystat
.st_ino
;
1191 buf
->win_st_mode
= mystat
.st_mode
;
1192 buf
->win_st_nlink
= mystat
.st_nlink
;
1193 buf
->win_st_uid
= mystat
.st_uid
;
1194 buf
->win_st_gid
= mystat
.st_gid
;
1195 buf
->win_st_rdev
= mystat
.st_rdev
;
1196 buf
->win_st_size
= mystat
.st_size
;
1197 buf
->win_st_atime
= mystat
.st_atime
;
1198 buf
->win_st_mtime
= mystat
.st_mtime
;
1199 buf
->win_st_ctime
= mystat
.st_ctime
;
1203 /*********************************************************************
1204 * _open (CRTDLL.239)
1206 HFILE __cdecl
CRTDLL__open(LPCSTR path
,INT flags
)
1208 DWORD access
= 0, creation
= 0;
1212 the flags in lcc's header differ from the ones in Linux, e.g.
1213 Linux: define O_APPEND 02000 (= 0x400)
1214 lcc: define _O_APPEND 0x0008
1215 so here a scheme to translate them
1216 Probably lcc is wrong here, but at least a hack to get is going
1220 case O_RDONLY
: access
|= GENERIC_READ
; break;
1221 case O_WRONLY
: access
|= GENERIC_WRITE
; break;
1222 case O_RDWR
: access
|= GENERIC_WRITE
| GENERIC_READ
; break;
1225 if (flags
& 0x0100) /* O_CREAT */
1227 if (flags
& 0x0400) /* O_EXCL */
1228 creation
= CREATE_NEW
;
1229 else if (flags
& 0x0200) /* O_TRUNC */
1230 creation
= CREATE_ALWAYS
;
1232 creation
= OPEN_ALWAYS
;
1234 else /* no O_CREAT */
1236 if (flags
& 0x0200) /* O_TRUNC */
1237 creation
= TRUNCATE_EXISTING
;
1239 creation
= OPEN_EXISTING
;
1241 if (flags
& 0x0008) /* O_APPEND */
1242 FIXME(crtdll
, "O_APPEND not supported\n" );
1244 TRACE(crtdll
,"CRTDLL_open file unsupported flags 0x%04x\n",flags
);
1247 ret
= CreateFileA( path
, access
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1248 NULL
, creation
, FILE_ATTRIBUTE_NORMAL
, -1 );
1249 TRACE(crtdll
,"CRTDLL_open file %s mode 0x%04x got handle %d\n", path
,flags
,ret
);
1253 /*********************************************************************
1254 * _close (CRTDLL.57)
1256 INT __cdecl
CRTDLL__close(HFILE fd
)
1258 int ret
=_lclose(fd
);
1260 TRACE(crtdll
,"(%d)\n",fd
);
1262 WARN(crtdll
, " Failed!\n");
1267 /*********************************************************************
1270 INT __cdecl
CRTDLL_feof( CRTDLL_FILE
*file
)
1272 FIXME(crtdll
,"stub\n" );
1276 /*********************************************************************
1277 * setlocale (CRTDLL.453)
1279 LPSTR __cdecl
CRTDLL_setlocale(INT category
,LPCSTR locale
)
1284 case CRTDLL_LC_ALL
: categorystr
="LC_ALL";break;
1285 case CRTDLL_LC_COLLATE
: categorystr
="LC_COLLATE";break;
1286 case CRTDLL_LC_CTYPE
: categorystr
="LC_CTYPE";break;
1287 case CRTDLL_LC_MONETARY
: categorystr
="LC_MONETARY";break;
1288 case CRTDLL_LC_NUMERIC
: categorystr
="LC_NUMERIC";break;
1289 case CRTDLL_LC_TIME
: categorystr
="LC_TIME";break;
1290 default: categorystr
= "UNKNOWN?";break;
1292 FIXME(crtdll
,"(%s,%s),stub!\n",categorystr
,locale
);
1296 /*********************************************************************
1297 * wcscat (CRTDLL.503)
1299 LPWSTR __cdecl
CRTDLL_wcscat( LPWSTR s1
, LPCWSTR s2
)
1301 return lstrcatW( s1
, s2
);
1304 /*********************************************************************
1305 * wcschr (CRTDLL.504)
1307 LPWSTR __cdecl
CRTDLL_wcschr(LPCWSTR str
,WCHAR xchar
)
1319 /*********************************************************************
1320 * wcscmp (CRTDLL.505)
1322 INT __cdecl
CRTDLL_wcscmp( LPCWSTR s1
, LPCWSTR s2
)
1324 return lstrcmpW( s1
, s2
);
1327 /*********************************************************************
1328 * wcscpy (CRTDLL.507)
1330 LPWSTR __cdecl
CRTDLL_wcscpy( LPWSTR s1
, LPCWSTR s2
)
1332 return lstrcpyW( s1
, s2
);
1335 /*********************************************************************
1336 * wcscspn (CRTDLL.508)
1338 INT __cdecl
CRTDLL_wcscspn(LPWSTR str
,LPWSTR reject
)
1345 while (*t
) { if (*t
==*s
) break;t
++;}
1349 return s
-str
; /* nr of wchars */
1352 /*********************************************************************
1353 * wcslen (CRTDLL.510)
1355 INT __cdecl
CRTDLL_wcslen( LPCWSTR s
)
1357 return lstrlenW( s
);
1360 /*********************************************************************
1361 * wcsncat (CRTDLL.511)
1363 LPWSTR __cdecl
CRTDLL_wcsncat( LPWSTR s1
, LPCWSTR s2
, INT n
)
1365 return lstrcatnW( s1
, s2
, n
);
1368 /*********************************************************************
1369 * wcsncmp (CRTDLL.512)
1371 INT __cdecl
CRTDLL_wcsncmp( LPCWSTR s1
, LPCWSTR s2
, INT n
)
1373 return lstrncmpW( s1
, s2
, n
);
1376 /*********************************************************************
1377 * wcsncpy (CRTDLL.513)
1379 LPWSTR __cdecl
CRTDLL_wcsncpy( LPWSTR s1
, LPCWSTR s2
, INT n
)
1381 return lstrcpynW( s1
, s2
, n
);
1384 /*********************************************************************
1385 * wcsspn (CRTDLL.516)
1387 INT __cdecl
CRTDLL_wcsspn(LPWSTR str
,LPWSTR accept
)
1394 while (*t
) { if (*t
==*s
) break;t
++;}
1398 return s
-str
; /* nr of wchars */
1401 /*********************************************************************
1402 * _wcsicmp (CRTDLL.321)
1404 DWORD __cdecl
CRTDLL__wcsicmp( LPCWSTR s1
, LPCWSTR s2
)
1406 return lstrcmpiW( s1
, s2
);
1409 /*********************************************************************
1410 * _wcsicoll (CRTDLL.322)
1412 DWORD __cdecl
CRTDLL__wcsicoll(LPCWSTR a1
,LPCWSTR a2
)
1414 /* FIXME: handle collates */
1415 return lstrcmpiW(a1
,a2
);
1418 /*********************************************************************
1419 * _wcsnicmp (CRTDLL.324)
1421 DWORD __cdecl
CRTDLL__wcsnicmp( LPCWSTR s1
, LPCWSTR s2
, INT len
)
1423 return lstrncmpiW( s1
, s2
, len
);
1426 /*********************************************************************
1427 * wcscoll (CRTDLL.506)
1429 DWORD __cdecl
CRTDLL_wcscoll(LPWSTR a1
,LPWSTR a2
)
1431 /* FIXME: handle collates */
1432 return lstrcmpW(a1
,a2
);
1435 /*********************************************************************
1436 * _wcsrev (CRTDLL.326)
1438 VOID __cdecl
CRTDLL__wcsrev(LPWSTR s
) {
1452 /*********************************************************************
1453 * wcsstr (CRTDLL.517)
1455 LPWSTR __cdecl
CRTDLL_wcsstr(LPWSTR s
,LPWSTR b
)
1463 while (*y
&& *c
&& *y
==*c
) { c
++;y
++; }
1472 /*********************************************************************
1473 * wcstombs (CRTDLL.521)
1475 INT __cdecl
CRTDLL_wcstombs( LPSTR dst
, LPCWSTR src
, INT len
)
1477 lstrcpynWtoA( dst
, src
, len
);
1478 return strlen(dst
); /* FIXME: is this right? */
1481 /*********************************************************************
1482 * wcsrchr (CRTDLL.515)
1484 LPWSTR __cdecl
CRTDLL_wcsrchr(LPWSTR str
,WCHAR xchar
)
1488 s
=str
+lstrlenW(str
);
1497 /*********************************************************************
1498 * _setmode (CRTDLL.265)
1499 * FIXME: At present we ignore the request to translate CR/LF to LF.
1501 * We allways translate when we read with fgets, we never do with fread
1504 INT __cdecl
CRTDLL__setmode( INT fh
,INT mode
)
1507 #define O_TEXT 0x4000
1508 #define O_BINARY 0x8000
1510 FIXME(crtdll
, "on fhandle %d mode %s, STUB.\n",
1511 fh
,(mode
=O_TEXT
)?"O_TEXT":
1512 (mode
=O_BINARY
)?"O_BINARY":"UNKNOWN");
1516 /*********************************************************************
1517 * _fpreset (CRTDLL.107)
1519 VOID __cdecl
CRTDLL__fpreset(void)
1521 FIXME(crtdll
," STUB.\n");
1524 /*********************************************************************
1525 * atexit (CRTDLL.345)
1527 INT __cdecl
CRTDLL_atexit(LPVOID x
)
1529 FIXME(crtdll
,"(%p), STUB.\n",x
);
1530 return 0; /* successful */
1533 /*********************************************************************
1534 * mblen (CRTDLL.428)
1535 * FIXME: check multibyte support
1537 WCHAR __cdecl
CRTDLL_mblen(CHAR
*mb
,INT size
)
1544 else if ((size
<1)||(!*(mb
+1)))
1549 TRACE(crtdll
,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb
,size
,ret
);
1554 /*********************************************************************
1555 * mbstowcs (CRTDLL.429)
1556 * FIXME: check multibyte support
1558 INT __cdecl
CRTDLL_mbstowcs(LPWSTR wcs
, LPCSTR mbs
, INT size
)
1561 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1562 * We need the number of characters transfered
1563 * FIXME: No multibyte support yet
1570 while ((n
-- > 0) && *src
) {
1571 *p
++ = (WCHAR
)(unsigned char)*src
++;
1576 TRACE(crtdll
,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1581 /*********************************************************************
1582 * mbtowc (CRTDLL.430)
1583 * FIXME: check multibyte support
1585 WCHAR __cdecl
CRTDLL_mbtowc(WCHAR
* wc
,CHAR
* mb
,INT size
)
1594 if ( (ret
= mblen(mb
,size
)) != -1 )
1596 if (ret
<= sizeof(char))
1597 *wc
= (WCHAR
) ((unsigned char)*mb
);
1604 TRACE(crtdll
,"CRTDLL_mbtowc %s for %d chars\n",mb
,size
);
1609 /*********************************************************************
1610 * _isctype (CRTDLL.138)
1612 BOOL __cdecl
CRTDLL__isctype(CHAR x
,CHAR type
)
1614 if ((type
& CRTDLL_SPACE
) && isspace(x
))
1616 if ((type
& CRTDLL_PUNCT
) && ispunct(x
))
1618 if ((type
& CRTDLL_LOWER
) && islower(x
))
1620 if ((type
& CRTDLL_UPPER
) && isupper(x
))
1622 if ((type
& CRTDLL_ALPHA
) && isalpha(x
))
1624 if ((type
& CRTDLL_DIGIT
) && isdigit(x
))
1626 if ((type
& CRTDLL_CONTROL
) && iscntrl(x
))
1628 /* check CRTDLL_LEADBYTE */
1632 /*********************************************************************
1633 * _chdrive (CRTDLL.52)
1635 * newdir [I] drive to change to, A=1
1638 BOOL __cdecl
CRTDLL__chdrive(INT newdrive
)
1640 /* FIXME: generates errnos */
1641 return DRIVE_SetCurrentDrive(newdrive
-1);
1644 /*********************************************************************
1645 * _chdir (CRTDLL.51)
1647 INT __cdecl
CRTDLL__chdir(LPCSTR newdir
)
1649 if (!SetCurrentDirectoryA(newdir
))
1654 /*********************************************************************
1655 * _fullpath (CRTDLL.114)
1657 LPSTR __cdecl
CRTDLL__fullpath(LPSTR buf
, LPCSTR name
, INT size
)
1659 DOS_FULL_NAME full_name
;
1664 if(!(buf
= CRTDLL_malloc(size
))) return NULL
;
1666 if (!DOSFS_GetFullName( name
, FALSE
, &full_name
)) return NULL
;
1667 lstrcpynA(buf
,full_name
.short_name
,size
);
1668 TRACE(crtdll
,"CRTDLL_fullpath got %s\n",buf
);
1672 /*********************************************************************
1673 * _splitpath (CRTDLL.279)
1675 VOID __cdecl
CRTDLL__splitpath(LPCSTR path
, LPSTR drive
, LPSTR directory
, LPSTR filename
, LPSTR extension
)
1678 directory includes leading and trailing (forward and backward slashes)
1679 filename without dot and slashes
1680 extension with leading dot
1682 char * drivechar
,*dirchar
,*namechar
;
1684 TRACE(crtdll
,"CRTDLL__splitpath got %s\n",path
);
1686 drivechar
= strchr(path
,':');
1687 dirchar
= strrchr(path
,'/');
1688 namechar
= strrchr(path
,'\\');
1689 dirchar
= MAX(dirchar
,namechar
);
1691 namechar
= strrchr(dirchar
,'.');
1693 namechar
= strrchr(path
,'.');
1701 strncat(drive
,path
,drivechar
-path
+1);
1710 strncat(directory
,path
,dirchar
-path
+1);
1719 strncat(filename
,path
,namechar
-path
);
1723 strcat(extension
,namechar
);
1728 TRACE(crtdll
,"CRTDLL__splitpath found %s %s %s %s\n",drive
,directory
,filename
,extension
);
1733 /*********************************************************************
1734 * _makepath (CRTDLL.182)
1737 VOID __cdecl
CRTDLL__makepath(LPSTR path
, LPCSTR drive
,
1738 LPCSTR directory
, LPCSTR filename
,
1742 TRACE(crtdll
,"CRTDLL__makepath got %s %s %s %s\n", drive
, directory
,
1743 filename
, extension
);
1751 sprintf(path
, "%c:", drive
[0]);
1754 if ( directory
[0] ) {
1755 strcat(path
, directory
);
1756 ch
= path
[strlen(path
)-1];
1757 if (ch
!= '/' && ch
!= '\\')
1761 if ( filename
[0] ) {
1762 strcat(path
, filename
);
1764 if ( extension
[0] ) {
1765 if ( extension
[0] != '.' ) {
1768 strcat(path
,extension
);
1773 TRACE(crtdll
,"CRTDLL__makepath returns %s\n",path
);
1776 /*********************************************************************
1777 * _getcwd (CRTDLL.120)
1779 CHAR
* __cdecl
CRTDLL__getcwd(LPSTR buf
, INT size
)
1786 if (size
< 0) /* allocate as big as nescessary */
1787 len
=GetCurrentDirectoryA(1,test
) + 1;
1788 if(!(buf
= CRTDLL_malloc(len
)))
1790 /* set error to OutOfRange */
1795 if(!(len
=GetCurrentDirectoryA(len
,buf
)))
1801 /* set error to ERANGE */
1802 TRACE(crtdll
,"CRTDLL_getcwd buffer to small\n");
1809 /*********************************************************************
1810 * _getdcwd (CRTDLL.121)
1812 CHAR
* __cdecl
CRTDLL__getdcwd(INT drive
,LPSTR buf
, INT size
)
1817 FIXME(crtdll
,"(\"%c:\",%s,%d)\n",drive
+'A',buf
,size
);
1820 if (size
< 0) /* allocate as big as nescessary */
1821 len
=GetCurrentDirectoryA(1,test
) + 1;
1822 if(!(buf
= CRTDLL_malloc(len
)))
1824 /* set error to OutOfRange */
1829 if(!(len
=GetCurrentDirectoryA(len
,buf
)))
1835 /* set error to ERANGE */
1836 TRACE(crtdll
,"buffer to small\n");
1843 /*********************************************************************
1844 * _getdrive (CRTDLL.124)
1846 * Return current drive, 1 for A, 2 for B
1848 INT __cdecl
CRTDLL__getdrive(VOID
)
1850 return DRIVE_GetCurrentDrive() + 1;
1853 /*********************************************************************
1854 * _mkdir (CRTDLL.234)
1856 INT __cdecl
CRTDLL__mkdir(LPCSTR newdir
)
1858 if (!CreateDirectoryA(newdir
,NULL
))
1863 /*********************************************************************
1864 * remove (CRTDLL.448)
1866 INT __cdecl
CRTDLL_remove(LPCSTR file
)
1868 if (!DeleteFileA(file
))
1873 /*********************************************************************
1874 * _errno (CRTDLL.52)
1875 * Yes, this is a function.
1877 LPINT __cdecl
CRTDLL__errno()
1879 static int crtdllerrno
;
1881 /* FIXME: we should set the error at the failing function call time */
1882 crtdllerrno
= LastErrorToErrno(GetLastError());
1883 return &crtdllerrno
;
1886 /*********************************************************************
1887 * _tempnam (CRTDLL.305)
1890 LPSTR __cdecl
CRTDLL__tempnam(LPCSTR dir
, LPCSTR prefix
)
1894 DOS_FULL_NAME tempname
;
1896 if ((ret
= tempnam(dir
,prefix
))==NULL
) {
1897 WARN(crtdll
, "Unable to get unique filename\n");
1900 if (!DOSFS_GetFullName(ret
,FALSE
,&tempname
))
1902 TRACE(crtdll
, "Wrong path?\n");
1906 if ((ret
= CRTDLL_malloc(strlen(tempname
.short_name
)+1)) == NULL
) {
1907 WARN(crtdll
, "CRTDL_malloc for shortname failed\n");
1910 if ((ret
= strcpy(ret
,tempname
.short_name
)) == NULL
) {
1911 WARN(crtdll
, "Malloc for shortname failed\n");
1915 TRACE(crtdll
,"dir %s prefix %s got %s\n",
1920 /*********************************************************************
1921 * tmpnam (CRTDLL.490)
1923 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1926 LPSTR __cdecl
CRTDLL_tmpnam(LPSTR s
)
1930 if ((ret
=tmpnam(s
))== NULL
) {
1931 WARN(crtdll
, "Unable to get unique filename\n");
1934 if (!DOSFS_GetFullName(ret
,FALSE
,&CRTDLL_tmpname
))
1936 TRACE(crtdll
, "Wrong path?\n");
1939 strcat(CRTDLL_tmpname
.short_name
,".");
1940 TRACE(crtdll
,"for buf %p got %s\n",
1941 s
,CRTDLL_tmpname
.short_name
);
1942 TRACE(crtdll
,"long got %s\n",
1943 CRTDLL_tmpname
.long_name
);
1945 return strcpy(s
,CRTDLL_tmpname
.short_name
);
1947 return CRTDLL_tmpname
.short_name
;
1951 /*********************************************************************
1952 * _itoa (CRTDLL.165)
1954 LPSTR __cdecl
CRTDLL__itoa(INT x
,LPSTR buf
,INT buflen
)
1956 wsnprintfA(buf
,buflen
,"%d",x
);
1960 /*********************************************************************
1961 * _ltoa (CRTDLL.180)
1963 LPSTR __cdecl
CRTDLL__ltoa(long x
,LPSTR buf
,INT radix
)
1966 case 2: FIXME(crtdll
, "binary format not implemented !\n");
1968 case 8: wsnprintfA(buf
,0x80,"%o",x
);
1970 case 10: wsnprintfA(buf
,0x80,"%d",x
);
1972 case 16: wsnprintfA(buf
,0x80,"%x",x
);
1974 default: FIXME(crtdll
, "radix %d not implemented !\n", radix
);
1979 /*********************************************************************
1980 * _ultoa (CRTDLL.311)
1982 LPSTR __cdecl
CRTDLL__ultoa(long x
,LPSTR buf
,INT radix
)
1985 case 2: FIXME(crtdll
, "binary format not implemented !\n");
1987 case 8: wsnprintfA(buf
,0x80,"%lo",x
);
1989 case 10: wsnprintfA(buf
,0x80,"%ld",x
);
1991 case 16: wsnprintfA(buf
,0x80,"%lx",x
);
1993 default: FIXME(crtdll
, "radix %d not implemented !\n", radix
);
1998 typedef VOID (*sig_handler_type
)(VOID
);
2000 /*********************************************************************
2001 * signal (CRTDLL.455)
2003 VOID __cdecl
CRTDLL_signal(int sig
, sig_handler_type ptr
)
2005 FIXME(crtdll
, "(%d %p):stub.\n", sig
, ptr
);
2008 /*********************************************************************
2009 * _ftol (CRTDLL.113)
2011 #ifdef USING_REAL_FPU
2012 LONG __cdecl
CRTDLL__ftol(void) {
2013 /* don't just do DO_FPU("fistp",retval), because the rounding
2014 * mode must also be set to "round towards zero"... */
2020 LONG __cdecl
CRTDLL__ftol(double fl
) {
2021 FIXME(crtdll
,"should be register function\n");
2026 /*********************************************************************
2027 * _CIpow (CRTDLL.14)
2029 #ifdef USING_REAL_FPU
2030 LONG __cdecl
CRTDLL__CIpow(void) {
2034 FIXME(crtdll
,"(%f,%f): argument order unknown! Please report!\n",x
,y
);
2038 LONG __cdecl
CRTDLL__CIpow(double x
,double y
) {
2039 FIXME(crtdll
,"should be register function\n");
2044 /*********************************************************************
2045 * _sleep (CRTDLL.267)
2047 VOID __cdecl
CRTDLL__sleep(unsigned long timeout
)
2049 TRACE(crtdll
,"CRTDLL__sleep for %ld milliseconds\n",timeout
);
2050 Sleep((timeout
)?timeout
:1);
2053 /*********************************************************************
2054 * getenv (CRTDLL.437)
2056 LPSTR __cdecl
CRTDLL_getenv(const char *name
)
2058 LPSTR environ
= GetEnvironmentStringsA();
2059 LPSTR pp
,pos
= NULL
;
2060 unsigned int length
;
2062 for (pp
= environ
; (*pp
); pp
= pp
+ strlen(pp
) +1)
2064 pos
=strchr(pp
,'=');
2068 length
= strlen(pp
);
2069 if (!strncmp(pp
,name
,length
)) break;
2074 TRACE(crtdll
,"got %s\n",pp
);
2076 FreeEnvironmentStringsA( environ
);
2080 /*********************************************************************
2081 * _mbsrchr (CRTDLL.223)
2083 LPSTR __cdecl
CRTDLL__mbsrchr(LPSTR s
,CHAR x
) {
2084 /* FIXME: handle multibyte strings */
2085 return strrchr(s
,x
);
2088 /*********************************************************************
2089 * _memicmp (CRTDLL.233)(NTDLL.868)
2090 * A stringcompare, without \0 check
2092 * -1:if first string is alphabetically before second string
2093 * 1:if second '' '' '' '' first ''
2094 * 0:if both are equal.
2096 INT __cdecl
CRTDLL__memicmp(
2097 LPCSTR s1
, /* [in] first string */
2098 LPCSTR s2
, /* [in] second string */
2099 DWORD len
/* [in] length to compare */
2103 for (i
=0;i
<len
;i
++) {
2104 if (tolower(s1
[i
])<tolower(s2
[i
]))
2106 if (tolower(s1
[i
])>tolower(s2
[i
]))
2111 /*********************************************************************
2112 * __dllonexit (CRTDLL.25)
2114 VOID __cdecl
CRTDLL__dllonexit ()
2116 FIXME(crtdll
,"stub\n");
2119 /*********************************************************************
2120 * wcstok (CRTDLL.519)
2121 * Like strtok, but for wide character strings. s is modified, yes.
2123 LPWSTR __cdecl
CRTDLL_wcstok(LPWSTR s
,LPCWSTR delim
) {
2124 static LPWSTR nexttok
= NULL
;
2132 while (*x
&& !CRTDLL_wcschr(delim
,*x
))
2143 /*********************************************************************
2144 * wcstol (CRTDLL.520)
2145 * Like strtol, but for wide character strings.
2147 INT __cdecl
CRTDLL_wcstol(LPWSTR s
,LPWSTR
*end
,INT base
) {
2148 LPSTR sA
= HEAP_strdupWtoA(GetProcessHeap(),0,s
),endA
;
2149 INT ret
= strtol(sA
,&endA
,base
);
2151 HeapFree(GetProcessHeap(),0,sA
);
2152 if (end
) *end
= s
+(endA
-sA
); /* pointer magic checked. */
2155 /*********************************************************************
2156 * strdate (CRTDLL.283)
2158 LPSTR __cdecl
CRTDLL__strdate (LPSTR date
)
2159 { FIXME (crtdll
,"%p stub\n", date
);
2163 /*********************************************************************
2164 * strtime (CRTDLL.299)
2166 LPSTR __cdecl
CRTDLL__strtime (LPSTR date
)
2167 { FIXME (crtdll
,"%p stub\n", date
);