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 static DOS_FULL_NAME CRTDLL_tmpname
;
56 UINT32 CRTDLL_argc_dll
; /* CRTDLL.23 */
57 LPSTR
*CRTDLL_argv_dll
; /* CRTDLL.24 */
58 LPSTR CRTDLL_acmdln_dll
; /* CRTDLL.38 */
59 UINT32 CRTDLL_basemajor_dll
; /* CRTDLL.42 */
60 UINT32 CRTDLL_baseminor_dll
; /* CRTDLL.43 */
61 UINT32 CRTDLL_baseversion_dll
; /* CRTDLL.44 */
62 UINT32 CRTDLL_commode_dll
; /* CRTDLL.59 */
63 LPSTR CRTDLL_environ_dll
; /* CRTDLL.75 */
64 UINT32 CRTDLL_fmode_dll
; /* CRTDLL.104 */
65 UINT32 CRTDLL_osmajor_dll
; /* CRTDLL.241 */
66 UINT32 CRTDLL_osminor_dll
; /* CRTDLL.242 */
67 UINT32 CRTDLL_osmode_dll
; /* CRTDLL.243 */
68 UINT32 CRTDLL_osver_dll
; /* CRTDLL.244 */
69 UINT32 CRTDLL_osversion_dll
; /* CRTDLL.245 */
70 UINT32 CRTDLL_winmajor_dll
; /* CRTDLL.329 */
71 UINT32 CRTDLL_winminor_dll
; /* CRTDLL.330 */
72 UINT32 CRTDLL_winver_dll
; /* CRTDLL.331 */
74 /* FIXME: structure layout is obviously not correct */
81 CRTDLL_FILE CRTDLL_iob
[3];
83 static CRTDLL_FILE
* const CRTDLL_stdin
= &CRTDLL_iob
[0];
84 static CRTDLL_FILE
* const CRTDLL_stdout
= &CRTDLL_iob
[1];
85 static CRTDLL_FILE
* const CRTDLL_stderr
= &CRTDLL_iob
[2];
87 typedef VOID (*new_handler_type
)(VOID
);
89 static new_handler_type new_handler
;
91 /*********************************************************************
92 * _GetMainArgs (CRTDLL.022)
94 DWORD __cdecl
CRTDLL__GetMainArgs(LPDWORD argc
,LPSTR
**argv
,
95 LPSTR
*environ
,DWORD flag
)
99 int xargc
,i
,afterlastspace
;
102 TRACE(crtdll
,"(%p,%p,%p,%ld).\n",
103 argc
,argv
,environ
,flag
105 CRTDLL_acmdln_dll
= cmdline
= HEAP_strdupA( GetProcessHeap(), 0,
106 GetCommandLine32A() );
107 TRACE(crtdll
,"got '%s'\n", cmdline
);
109 version
= GetVersion32();
110 CRTDLL_osver_dll
= version
>> 16;
111 CRTDLL_winminor_dll
= version
& 0xFF;
112 CRTDLL_winmajor_dll
= (version
>>8) & 0xFF;
113 CRTDLL_baseversion_dll
= version
>> 16;
114 CRTDLL_winver_dll
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
115 CRTDLL_baseminor_dll
= (version
>> 16) & 0xFF;
116 CRTDLL_basemajor_dll
= (version
>> 24) & 0xFF;
117 CRTDLL_osversion_dll
= version
& 0xFFFF;
118 CRTDLL_osminor_dll
= version
& 0xFF;
119 CRTDLL_osmajor_dll
= (version
>>8) & 0xFF;
121 /* missing threading init */
123 i
=0;xargv
=NULL
;xargc
=0;afterlastspace
=0;
125 if (cmdline
[i
]==' ') {
126 xargv
=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv
,
127 sizeof(char*)*(++xargc
));
129 xargv
[xargc
-1] = HEAP_strdupA( GetProcessHeap(), 0,
130 cmdline
+afterlastspace
);
132 while (cmdline
[i
]==' ')
139 xargv
=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv
,
140 sizeof(char*)*(++xargc
));
142 xargv
[xargc
-1] = HEAP_strdupA( GetProcessHeap(), 0,
143 cmdline
+afterlastspace
);
144 CRTDLL_argc_dll
= xargc
;
146 CRTDLL_argv_dll
= xargv
;
149 TRACE(crtdll
,"found %d arguments\n",
151 CRTDLL_environ_dll
= *environ
= GetEnvironmentStrings32A();
156 typedef void (*_INITTERMFUN
)();
158 /* fixme: move to header */
161 time_t time_create
; /* -1 when not avaiable */
162 time_t time_access
; /* -1 when not avaiable */
164 unsigned long size
; /* fixme: 64 bit ??*/
167 /*********************************************************************
168 * _findfirst (CRTDLL.099)
173 DWORD __cdecl
CRTDLL__findfirst(LPCSTR fname
, struct find_t
* x2
)
175 FIXME(crtdll
, ":(%s,%p): stub\n",fname
,x2
);
176 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
180 /*********************************************************************
181 * _findnext (CRTDLL.100)
186 INT32 __cdecl
CRTDLL__findnext(DWORD hand
, struct find_t
* x2
)
188 FIXME(crtdll
, ":(%ld,%p): stub\n",hand
,x2
);
189 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
193 /*********************************************************************
194 * _fstat (CRTDLL.111)
199 int __cdecl
CRTDLL__fstat(int file
, struct stat
* buf
)
201 FIXME(crtdll
, ":(%d,%p): stub\n",file
,buf
);
202 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
206 /*********************************************************************
207 * _initterm (CRTDLL.135)
209 DWORD __cdecl
CRTDLL__initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
211 _INITTERMFUN
*current
;
213 TRACE(crtdll
,"(%p,%p)\n",start
,end
);
215 while (current
<end
) {
216 if (*current
) (*current
)();
222 /*********************************************************************
223 * _fdopen (CRTDLL.91)
225 CRTDLL_FILE
* __cdecl
CRTDLL__fdopen(INT32 handle
, LPCSTR mode
)
233 if (!file
->handle
) file
->handle
= GetStdHandle( STD_INPUT_HANDLE
);
236 file
= CRTDLL_stdout
;
237 if (!file
->handle
) file
->handle
= GetStdHandle( STD_OUTPUT_HANDLE
);
241 if (!file
->handle
) file
->handle
= GetStdHandle( STD_ERROR_HANDLE
);
244 file
= HeapAlloc( GetProcessHeap(), 0, sizeof(*file
) );
245 file
->handle
= handle
;
248 TRACE(crtdll
, "open handle %d mode %s got file %p\n",
254 /*******************************************************************
255 * _global_unwind2 (CRTDLL.129)
257 void __cdecl
CRTDLL__global_unwind2( PEXCEPTION_FRAME frame
)
259 RtlUnwind( frame
, 0, NULL
, 0 );
262 /*******************************************************************
263 * _local_unwind2 (CRTDLL.173)
265 void __cdecl
CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe
, DWORD nr
)
267 TRACE(crtdll
,"(%p,%ld)\n",endframe
,nr
);
269 /*********************************************************************
275 INT32 __cdecl
CRTDLL__read(INT32 fd
, LPVOID buf
, UINT32 count
)
277 FIXME(crtdll
,":(%d,%p,%d): stub\n",fd
,buf
,count
);
278 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
282 /*********************************************************************
285 CRTDLL_FILE
* __cdecl
CRTDLL_fopen(LPCSTR path
, LPCSTR mode
)
287 CRTDLL_FILE
*file
= NULL
;
290 DOS_FULL_NAME full_name
;
292 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
)) {
293 WARN(crtdll
, "file %s bad name\n",path
);
297 file
=fopen(full_name
.long_name
,mode
);
301 if ((strchr(mode
,'r')&&strchr(mode
,'a'))||
302 (strchr(mode
,'r')&&strchr(mode
,'w'))||
303 (strchr(mode
,'w')&&strchr(mode
,'a')))
306 if (strstr(mode
,"r+")) flagmode
=O_RDWR
;
307 else if (strchr(mode
,'r')) flagmode
= O_RDONLY
;
308 else if (strstr(mode
,"w+")) flagmode
= O_RDWR
| O_TRUNC
| O_CREAT
;
309 else if (strchr(mode
,'w')) flagmode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
310 else if (strstr(mode
,"a+")) flagmode
= O_RDWR
| O_CREAT
| O_APPEND
;
311 else if (strchr(mode
,'w')) flagmode
= O_RDWR
| O_CREAT
| O_APPEND
;
312 else if (strchr(mode
,'b'))
313 TRACE(crtdll
, "%s in BINARY mode\n",path
);
315 if ((handle
= FILE_Open(path
, flagmode
,0)) != INVALID_HANDLE_VALUE32
)
317 file
= HeapAlloc( GetProcessHeap(), 0, sizeof(*file
) );
318 file
->handle
= handle
;
320 TRACE(crtdll
, "file %s mode %s got handle %d file %p\n",
321 path
,mode
,handle
,file
);
325 /*********************************************************************
328 DWORD __cdecl
CRTDLL_fread(LPVOID ptr
, INT32 size
, INT32 nmemb
, CRTDLL_FILE
*file
)
334 /* If we would honour CR/LF <-> LF translation, we could do it like this.
335 We should keep track of all files opened, and probably files with \
336 known binary extensions must be unchanged */
337 while ( (i
< (nmemb
*size
)) && (ret
==1)) {
338 ret
=fread(temp
,1,1,file
);
339 TRACE(crtdll
, "got %c 0x%02x ret %d\n",
340 (isalpha(*(unsigned char*)temp
))? *(unsigned char*)temp
:
341 ' ',*(unsigned char*)temp
, ret
);
342 if (*(unsigned char*)temp
!= 0xd) { /* skip CR */
347 TRACE(crtdll
, "skipping ^M\n");
349 TRACE(crtdll
, "0x%08x items of size %d from file %p to %p\n",
350 nmemb
,size
,file
,ptr
,);
352 WARN(crtdll
, " failed!\n");
358 TRACE(crtdll
, "0x%08x items of size %d from file %p to %p\n",
359 nmemb
,size
,file
,ptr
);
360 if (!ReadFile( file
->handle
, ptr
, size
* nmemb
, &ret
, NULL
))
361 WARN(crtdll
, " failed!\n");
366 /*********************************************************************
367 * freopen (CRTDLL.379)
372 DWORD __cdecl
CRTDLL_freopen(LPCSTR path
, LPCSTR mode
, LPVOID stream
)
374 FIXME(crtdll
, ":(%s,%s,%p): stub\n", path
, mode
, stream
);
375 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
379 /*********************************************************************
380 * fscanf (CRTDLL.381)
382 INT32 __cdecl
CRTDLL_fscanf( CRTDLL_FILE
*stream
, LPSTR format
, ... )
388 va_start( valist
, format
);
390 res
= vfscanf( xlat_file_ptr(stream
), format
, valist
);
395 FIXME(crtdll
,"broken\n");
399 /*********************************************************************
402 LONG __cdecl
CRTDLL_fseek( CRTDLL_FILE
*file
, LONG offset
, INT32 whence
)
404 TRACE(crtdll
, "file %p to 0x%08lx pos %s\n",
405 file
,offset
,(whence
==SEEK_SET
)?"SEEK_SET":
406 (whence
==SEEK_CUR
)?"SEEK_CUR":
407 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
408 if (SetFilePointer( file
->handle
, offset
, NULL
, whence
) != 0xffffffff)
410 WARN(crtdll
, " failed!\n");
414 /*********************************************************************
415 * fsetpos (CRTDLL.383)
417 INT32 __cdecl
CRTDLL_fsetpos( CRTDLL_FILE
*file
, INT32
*pos
)
419 TRACE(crtdll
, "file %p pos %d\n", file
, *pos
);
420 return CRTDLL_fseek(file
, *pos
, SEEK_SET
);
423 /*********************************************************************
426 LONG __cdecl
CRTDLL_ftell( CRTDLL_FILE
*file
)
428 return SetFilePointer( file
->handle
, 0, NULL
, SEEK_CUR
);
431 /*********************************************************************
432 * fwrite (CRTDLL.386)
434 DWORD __cdecl
CRTDLL_fwrite( LPVOID ptr
, INT32 size
, INT32 nmemb
, CRTDLL_FILE
*file
)
438 TRACE(crtdll
, "0x%08x items of size %d to file %p from %p\n",
439 nmemb
,size
,file
,ptr
);
440 if (!WriteFile( file
->handle
, ptr
, size
* nmemb
, &ret
, NULL
))
441 WARN(crtdll
, " failed!\n");
445 /*********************************************************************
446 * setbuf (CRTDLL.452)
448 INT32 __cdecl
CRTDLL_setbuf(CRTDLL_FILE
*file
, LPSTR buf
)
450 TRACE(crtdll
, "(file %p buf %p)\n", file
, buf
);
451 /* this doesn't work:"void value not ignored as it ought to be"
452 return setbuf(file,buf);
454 /* FIXME: no buffering for now */
458 /*********************************************************************
459 * _open_osfhandle (CRTDLL.240)
461 HFILE32 __cdecl
CRTDLL__open_osfhandle(LONG osfhandle
, INT32 flags
)
466 case STD_INPUT_HANDLE
:
470 case STD_OUTPUT_HANDLE
:
474 case STD_ERROR_HANDLE
:
481 TRACE(crtdll
, "(handle %08lx,flags %d) return %d\n",
482 osfhandle
,flags
,handle
);
487 /*********************************************************************
490 void __cdecl
CRTDLL_srand(DWORD seed
)
492 /* FIXME: should of course be thread? process? local */
496 /*********************************************************************
497 * vfprintf (CRTDLL.373)
499 INT32 __cdecl
CRTDLL_vfprintf( CRTDLL_FILE
*file
, LPSTR format
, va_list args
)
501 char buffer
[1024]; /* FIXME... */
503 vsprintf( buffer
, format
, args
);
504 return CRTDLL_fwrite( buffer
, 1, strlen(buffer
), file
);
507 /*********************************************************************
508 * fprintf (CRTDLL.373)
510 INT32 __cdecl
CRTDLL_fprintf( CRTDLL_FILE
*file
, LPSTR format
, ... )
515 va_start( valist
, format
);
516 res
= CRTDLL_vfprintf( file
, format
, valist
);
521 /*********************************************************************
524 time_t __cdecl
CRTDLL_time(time_t *timeptr
)
526 time_t curtime
= time(NULL
);
533 /*********************************************************************
536 clock_t __cdecl
CRTDLL_clock(void)
542 res
= alltimes
.tms_utime
+ alltimes
.tms_stime
+
543 alltimes
.tms_cutime
+ alltimes
.tms_cstime
;
544 /* Fixme: We need some symbolic representation
545 for (Hostsystem_)CLOCKS_PER_SEC
546 and (Emulated_system_)CLOCKS_PER_SEC
547 10 holds only for Windows/Linux_i86)
552 /*********************************************************************
553 * _isatty (CRTDLL.137)
555 BOOL32 __cdecl
CRTDLL__isatty(DWORD x
)
557 TRACE(crtdll
,"(%ld)\n",x
);
561 /*********************************************************************
562 * _write (CRTDLL.332)
564 INT32 __cdecl
CRTDLL__write(INT32 fd
,LPCVOID buf
,UINT32 count
)
571 len
= (UINT32
)write(fd
,buf
,(LONG
)count
);
573 len
= _lwrite32(fd
,buf
,count
);
574 TRACE(crtdll
,"%d/%d byte to dfh %d from %p,\n",
580 /*********************************************************************
583 * FIXME: What the heck is the difference between
584 * FIXME _c_exit (CRTDLL.47)
585 * FIXME _cexit (CRTDLL.49)
586 * FIXME _exit (CRTDLL.87)
587 * FIXME exit (CRTDLL.359)
589 * atexit-processing comes to mind -- MW.
592 void __cdecl
CRTDLL__cexit(INT32 ret
)
594 TRACE(crtdll
,"(%d)\n",ret
);
599 /*********************************************************************
602 void __cdecl
CRTDLL_exit(DWORD ret
)
604 TRACE(crtdll
,"(%ld)\n",ret
);
609 /*********************************************************************
610 * _abnormal_termination (CRTDLL.36)
612 INT32 __cdecl
CRTDLL__abnormal_termination(void)
614 TRACE(crtdll
,"(void)\n");
619 /*********************************************************************
620 * _access (CRTDLL.37)
622 INT32 __cdecl
CRTDLL__access(LPCSTR filename
, INT32 mode
)
624 DWORD attr
= GetFileAttributes32A(filename
);
628 if (GetLastError() == ERROR_INVALID_ACCESS
)
635 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
645 /*********************************************************************
646 * fflush (CRTDLL.365)
648 INT32 __cdecl
CRTDLL_fflush( CRTDLL_FILE
*file
)
650 return FlushFileBuffers( file
->handle
) ? 0 : -1;
654 /*********************************************************************
657 INT32 __cdecl
CRTDLL_rand()
663 /*********************************************************************
664 * putchar (CRTDLL.442)
666 void __cdecl
CRTDLL_putchar( INT32 x
)
672 /*********************************************************************
675 INT32 __cdecl
CRTDLL_fputc( INT32 c
, CRTDLL_FILE
*file
)
679 TRACE(crtdll
, "%c to file %p\n",c
,file
);
680 if (!WriteFile( file
->handle
, &ch
, 1, &res
, NULL
)) return -1;
685 /*********************************************************************
688 INT32 __cdecl
CRTDLL_fputs( LPCSTR s
, CRTDLL_FILE
*file
)
691 TRACE(crtdll
, "%s to file %p\n",s
,file
);
692 if (!WriteFile( file
->handle
, s
, strlen(s
), &res
, NULL
)) return -1;
697 /*********************************************************************
700 INT32 __cdecl
CRTDLL_puts(LPCSTR s
)
702 TRACE(crtdll
, "%s \n",s
);
707 /*********************************************************************
710 INT32 __cdecl
CRTDLL_putc( INT32 c
, CRTDLL_FILE
*file
)
712 return CRTDLL_fputc( c
, file
);
715 /*********************************************************************
718 INT32 __cdecl
CRTDLL_fgetc( CRTDLL_FILE
*file
)
722 if (!ReadFile( file
->handle
, &ch
, 1, &res
, NULL
)) return -1;
727 /*********************************************************************
730 INT32 __cdecl
CRTDLL_getc( CRTDLL_FILE
*file
)
732 return CRTDLL_fgetc( file
);
736 /*********************************************************************
739 CHAR
* __cdecl
CRTDLL_fgets( LPSTR s
, INT32 size
, CRTDLL_FILE
*file
)
744 /* BAD, for the whole WINE process blocks... just done this way to test
745 * windows95's ftp.exe.
748 for(cc
= CRTDLL_fgetc(file
); cc
!= EOF
&& cc
!= '\n'; cc
= CRTDLL_fgetc(file
))
751 if (--size
<= 0) break;
757 TRACE(crtdll
,"got '%s'\n", buf_start
);
762 /*********************************************************************
765 LPSTR __cdecl
CRTDLL_gets(LPSTR buf
)
768 LPSTR buf_start
= buf
;
770 /* BAD, for the whole WINE process blocks... just done this way to test
771 * windows95's ftp.exe.
774 for(cc
= fgetc(stdin
); cc
!= EOF
&& cc
!= '\n'; cc
= fgetc(stdin
))
775 if(cc
!= '\r') *buf
++ = (char)cc
;
779 TRACE(crtdll
,"got '%s'\n", buf_start
);
784 /*********************************************************************
787 UINT32 __cdecl
CRTDLL__rotl(UINT32 x
,INT32 shift
)
789 unsigned int ret
= (x
>> shift
)|( x
>>((sizeof(x
))-shift
));
791 TRACE(crtdll
, "got 0x%08x rot %d ret 0x%08x\n",
796 /*********************************************************************
797 * _lrotl (CRTDLL.176)
799 DWORD __cdecl
CRTDLL__lrotl(DWORD x
,INT32 shift
)
801 unsigned long ret
= (x
>> shift
)|( x
>>((sizeof(x
))-shift
));
803 TRACE(crtdll
, "got 0x%08lx rot %d ret 0x%08lx\n",
810 /*********************************************************************
811 * _mbsicmp (CRTDLL.204)
813 int __cdecl
CRTDLL__mbsicmp(unsigned char *x
,unsigned char *y
)
820 /* FIXME: MBCS handling... */
829 /*********************************************************************
830 * _mbsinc (CRTDLL.205)
832 unsigned char * __cdecl
CRTDLL__mbsinc(unsigned char *x
)
839 /*********************************************************************
840 * vsprintf (CRTDLL.500)
842 INT32 __cdecl
CRTDLL_vsprintf( LPSTR buffer
, LPCSTR spec
, va_list args
)
844 return wvsprintf32A( buffer
, spec
, args
);
847 /*********************************************************************
848 * vswprintf (CRTDLL.501)
850 INT32 __cdecl
CRTDLL_vswprintf( LPWSTR buffer
, LPCWSTR spec
, va_list args
)
852 return wvsprintf32W( buffer
, spec
, args
);
855 /*********************************************************************
856 * _mbscpy (CRTDLL.200)
858 unsigned char* __cdecl
CRTDLL__mbscpy(unsigned char *x
,unsigned char *y
)
860 TRACE(crtdll
,"CRTDLL_mbscpy %s and %s\n",x
,y
);
865 /*********************************************************************
866 * _mbscat (CRTDLL.197)
868 unsigned char* __cdecl
CRTDLL__mbscat(unsigned char *x
,unsigned char *y
)
874 /*********************************************************************
875 * _strcmpi (CRTDLL.282) (CRTDLL.287)
877 INT32 __cdecl
CRTDLL__strcmpi( LPCSTR s1
, LPCSTR s2
)
879 return lstrcmpi32A( s1
, s2
);
883 /*********************************************************************
884 * _strnicmp (CRTDLL.293)
886 INT32 __cdecl
CRTDLL__strnicmp( LPCSTR s1
, LPCSTR s2
, INT32 n
)
888 return lstrncmpi32A( s1
, s2
, n
);
892 /*********************************************************************
893 * _strlwr (CRTDLL.293)
895 * convert a string in place to lowercase
897 LPSTR __cdecl
CRTDLL__strlwr(LPSTR x
)
901 TRACE(crtdll
, "CRTDLL_strlwr got %s\n", x
);
903 if ((*y
> 0x40) && (*y
< 0x5b))
907 TRACE(crtdll
, " returned %s\n", x
);
912 /*********************************************************************
913 * system (CRTDLL.485)
915 INT32 __cdecl
CRTDLL_system(LPSTR x
)
917 #define SYSBUF_LENGTH 1500
918 char buffer
[SYSBUF_LENGTH
];
919 unsigned char *y
= x
;
923 sprintf( buffer
, "%s \"", Options
.argv0
);
924 bp
= buffer
+ strlen(buffer
);
925 i
= strlen(buffer
) + strlen(x
) +2;
927 /* Calculate needed buffer size to prevent overflow. */
932 /* If buffer too short, exit. */
933 if (i
> SYSBUF_LENGTH
) {
934 TRACE(crtdll
,"_system buffer to small\n");
943 if (*(y
-1) =='\\') *bp
++ = '\\';
945 /* Remove spaces from end of string. */
946 while (*(y
-1) == ' ') {
951 TRACE(crtdll
, "_system got '%s', executing '%s'\n",x
,buffer
);
953 return system(buffer
);
956 /*********************************************************************
957 * _strupr (CRTDLL.300)
959 LPSTR __cdecl
CRTDLL__strupr(LPSTR x
)
970 /*********************************************************************
971 * _wcsupr (CRTDLL.328)
973 LPWSTR __cdecl
CRTDLL__wcsupr(LPWSTR x
)
984 /*********************************************************************
985 * _wcslwr (CRTDLL.323)
987 LPWSTR __cdecl
CRTDLL__wcslwr(LPWSTR x
)
999 /*********************************************************************
1000 * longjmp (CRTDLL.426)
1002 VOID __cdecl
CRTDLL_longjmp(jmp_buf env
, int val
)
1004 FIXME(crtdll
,"CRTDLL_longjmp semistup, expect crash\n");
1005 return longjmp(env
, val
);
1008 /*********************************************************************
1009 * malloc (CRTDLL.427)
1011 VOID
* __cdecl
CRTDLL_malloc(DWORD size
)
1013 return HeapAlloc(GetProcessHeap(),0,size
);
1016 /*********************************************************************
1019 VOID
* __cdecl
CRTDLL_new(DWORD size
)
1022 if(!(result
= HeapAlloc(GetProcessHeap(),0,size
)) && new_handler
)
1027 /*********************************************************************
1028 * set_new_handler(CRTDLL.003)
1030 new_handler_type __cdecl
CRTDLL_set_new_handler(new_handler_type func
)
1032 new_handler_type old_handler
= new_handler
;
1037 /*********************************************************************
1038 * calloc (CRTDLL.350)
1040 VOID
* __cdecl
CRTDLL_calloc(DWORD size
, DWORD count
)
1042 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
* count
);
1045 /*********************************************************************
1046 * realloc (CRTDLL.447)
1048 VOID
* __cdecl
CRTDLL_realloc( VOID
*ptr
, DWORD size
)
1050 return HeapReAlloc( GetProcessHeap(), 0, ptr
, size
);
1053 /*********************************************************************
1056 VOID __cdecl
CRTDLL_free(LPVOID ptr
)
1058 HeapFree(GetProcessHeap(),0,ptr
);
1061 /*********************************************************************
1062 * delete (CRTDLL.002)
1064 VOID __cdecl
CRTDLL_delete(VOID
* ptr
)
1066 HeapFree(GetProcessHeap(),0,ptr
);
1069 /*********************************************************************
1070 * _strdup (CRTDLL.285)
1072 LPSTR __cdecl
CRTDLL__strdup(LPCSTR ptr
)
1074 return HEAP_strdupA(GetProcessHeap(),0,ptr
);
1077 /*********************************************************************
1078 * _wcsdup (CRTDLL.320)
1080 LPWSTR __cdecl
CRTDLL__wcsdup(LPCWSTR ptr
)
1082 return HEAP_strdupW(GetProcessHeap(),0,ptr
);
1085 /*********************************************************************
1086 * fclose (CRTDLL.362)
1088 INT32 __cdecl
CRTDLL_fclose( CRTDLL_FILE
*file
)
1090 TRACE(crtdll
,"%p\n", file
);
1091 if (!CloseHandle( file
->handle
)) return -1;
1092 HeapFree( GetProcessHeap(), 0, file
);
1096 /*********************************************************************
1097 * _unlink (CRTDLL.315)
1099 INT32 __cdecl
CRTDLL__unlink(LPCSTR pathname
)
1102 DOS_FULL_NAME full_name
;
1104 if (!DOSFS_GetFullName( pathname
, FALSE
, &full_name
)) {
1105 WARN(crtdll
, "CRTDLL_unlink file %s bad name\n",pathname
);
1109 ret
=unlink(full_name
.long_name
);
1110 TRACE(crtdll
,"(%s unix %s)\n",
1111 pathname
,full_name
.long_name
);
1113 WARN(crtdll
, " Failed!\n");
1118 /*********************************************************************
1119 * rename (CRTDLL.449)
1121 INT32 __cdecl
CRTDLL_rename(LPCSTR oldpath
,LPCSTR newpath
)
1123 BOOL32 ok
= MoveFileEx32A( oldpath
, newpath
, MOVEFILE_REPLACE_EXISTING
);
1128 /*********************************************************************
1129 * _stat (CRTDLL.280)
1147 int __cdecl
CRTDLL__stat(const char * filename
, struct win_stat
* buf
)
1150 DOS_FULL_NAME full_name
;
1153 if (!DOSFS_GetFullName( filename
, TRUE
, &full_name
))
1155 WARN(crtdll
, "CRTDLL__stat filename %s bad name\n",filename
);
1158 ret
=stat(full_name
.long_name
,&mystat
);
1159 TRACE(crtdll
,"CRTDLL__stat %s\n", filename
);
1161 WARN(crtdll
, " Failed!\n");
1163 /* FIXME: should check what Windows returns */
1165 buf
->win_st_dev
= mystat
.st_dev
;
1166 buf
->win_st_ino
= mystat
.st_ino
;
1167 buf
->win_st_mode
= mystat
.st_mode
;
1168 buf
->win_st_nlink
= mystat
.st_nlink
;
1169 buf
->win_st_uid
= mystat
.st_uid
;
1170 buf
->win_st_gid
= mystat
.st_gid
;
1171 buf
->win_st_rdev
= mystat
.st_rdev
;
1172 buf
->win_st_size
= mystat
.st_size
;
1173 buf
->win_st_atime
= mystat
.st_atime
;
1174 buf
->win_st_mtime
= mystat
.st_mtime
;
1175 buf
->win_st_ctime
= mystat
.st_ctime
;
1179 /*********************************************************************
1180 * _open (CRTDLL.239)
1182 HFILE32 __cdecl
CRTDLL__open(LPCSTR path
,INT32 flags
)
1188 the flags in lcc's header differ from the ones in Linux, e.g.
1189 Linux: define O_APPEND 02000 (= 0x400)
1190 lcc: define _O_APPEND 0x0008
1191 so here a scheme to translate them
1192 Probably lcc is wrong here, but at least a hack to get is going
1194 wineflags
= (flags
& 3);
1195 if (flags
& 0x0008 ) wineflags
|= O_APPEND
;
1196 if (flags
& 0x0100 ) wineflags
|= O_CREAT
;
1197 if (flags
& 0x0200 ) wineflags
|= O_TRUNC
;
1198 if (flags
& 0x0400 ) wineflags
|= O_EXCL
;
1199 if (flags
& 0xf0f4 )
1200 TRACE(crtdll
,"CRTDLL_open file unsupported flags 0x%04x\n",flags
);
1203 ret
= FILE_Open(path
,wineflags
,0);
1204 TRACE(crtdll
,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
1205 path
,wineflags
,flags
,ret
);
1209 /*********************************************************************
1210 * _close (CRTDLL.57)
1212 INT32 __cdecl
CRTDLL__close(HFILE32 fd
)
1214 int ret
=_lclose32(fd
);
1216 TRACE(crtdll
,"(%d)\n",fd
);
1218 WARN(crtdll
, " Failed!\n");
1223 /*********************************************************************
1226 INT32 __cdecl
CRTDLL_feof( CRTDLL_FILE
*file
)
1228 FIXME(crtdll
,"stub\n" );
1232 /*********************************************************************
1233 * setlocale (CRTDLL.453)
1235 LPSTR __cdecl
CRTDLL_setlocale(INT32 category
,LPCSTR locale
)
1240 case CRTDLL_LC_ALL
: categorystr
="LC_ALL";break;
1241 case CRTDLL_LC_COLLATE
: categorystr
="LC_COLLATE";break;
1242 case CRTDLL_LC_CTYPE
: categorystr
="LC_CTYPE";break;
1243 case CRTDLL_LC_MONETARY
: categorystr
="LC_MONETARY";break;
1244 case CRTDLL_LC_NUMERIC
: categorystr
="LC_NUMERIC";break;
1245 case CRTDLL_LC_TIME
: categorystr
="LC_TIME";break;
1246 default: categorystr
= "UNKNOWN?";break;
1248 FIXME(crtdll
,"(%s,%s),stub!\n",categorystr
,locale
);
1252 /*********************************************************************
1253 * wcscat (CRTDLL.503)
1255 LPWSTR __cdecl
CRTDLL_wcscat( LPWSTR s1
, LPCWSTR s2
)
1257 return lstrcat32W( s1
, s2
);
1260 /*********************************************************************
1261 * wcschr (CRTDLL.504)
1263 LPWSTR __cdecl
CRTDLL_wcschr(LPCWSTR str
,WCHAR xchar
)
1275 /*********************************************************************
1276 * wcscmp (CRTDLL.505)
1278 INT32 __cdecl
CRTDLL_wcscmp( LPCWSTR s1
, LPCWSTR s2
)
1280 return lstrcmp32W( s1
, s2
);
1283 /*********************************************************************
1284 * wcscpy (CRTDLL.507)
1286 LPWSTR __cdecl
CRTDLL_wcscpy( LPWSTR s1
, LPCWSTR s2
)
1288 return lstrcpy32W( s1
, s2
);
1291 /*********************************************************************
1292 * wcscspn (CRTDLL.508)
1294 INT32 __cdecl
CRTDLL_wcscspn(LPWSTR str
,LPWSTR reject
)
1301 while (*t
) { if (*t
==*s
) break;t
++;}
1305 return s
-str
; /* nr of wchars */
1308 /*********************************************************************
1309 * wcslen (CRTDLL.510)
1311 INT32 __cdecl
CRTDLL_wcslen( LPCWSTR s
)
1313 return lstrlen32W( s
);
1316 /*********************************************************************
1317 * wcsncat (CRTDLL.511)
1319 LPWSTR __cdecl
CRTDLL_wcsncat( LPWSTR s1
, LPCWSTR s2
, INT32 n
)
1321 return lstrcatn32W( s1
, s2
, n
);
1324 /*********************************************************************
1325 * wcsncmp (CRTDLL.512)
1327 INT32 __cdecl
CRTDLL_wcsncmp( LPCWSTR s1
, LPCWSTR s2
, INT32 n
)
1329 return lstrncmp32W( s1
, s2
, n
);
1332 /*********************************************************************
1333 * wcsncpy (CRTDLL.513)
1335 LPWSTR __cdecl
CRTDLL_wcsncpy( LPWSTR s1
, LPCWSTR s2
, INT32 n
)
1337 return lstrcpyn32W( s1
, s2
, n
);
1340 /*********************************************************************
1341 * wcsspn (CRTDLL.516)
1343 INT32 __cdecl
CRTDLL_wcsspn(LPWSTR str
,LPWSTR accept
)
1350 while (*t
) { if (*t
==*s
) break;t
++;}
1354 return s
-str
; /* nr of wchars */
1357 /*********************************************************************
1358 * _wcsicmp (CRTDLL.321)
1360 DWORD __cdecl
CRTDLL__wcsicmp( LPCWSTR s1
, LPCWSTR s2
)
1362 return lstrcmpi32W( s1
, s2
);
1365 /*********************************************************************
1366 * _wcsicoll (CRTDLL.322)
1368 DWORD __cdecl
CRTDLL__wcsicoll(LPCWSTR a1
,LPCWSTR a2
)
1370 /* FIXME: handle collates */
1371 return lstrcmpi32W(a1
,a2
);
1374 /*********************************************************************
1375 * _wcsnicmp (CRTDLL.324)
1377 DWORD __cdecl
CRTDLL__wcsnicmp( LPCWSTR s1
, LPCWSTR s2
, INT32 len
)
1379 return lstrncmpi32W( s1
, s2
, len
);
1382 /*********************************************************************
1383 * wcscoll (CRTDLL.506)
1385 DWORD __cdecl
CRTDLL_wcscoll(LPWSTR a1
,LPWSTR a2
)
1387 /* FIXME: handle collates */
1388 return lstrcmp32W(a1
,a2
);
1391 /*********************************************************************
1392 * _wcsrev (CRTDLL.326)
1394 VOID __cdecl
CRTDLL__wcsrev(LPWSTR s
) {
1408 /*********************************************************************
1409 * wcsstr (CRTDLL.517)
1411 LPWSTR __cdecl
CRTDLL_wcsstr(LPWSTR s
,LPWSTR b
)
1419 while (*y
&& *c
&& *y
==*c
) { c
++;y
++; }
1428 /*********************************************************************
1429 * wcstombs (CRTDLL.521)
1431 INT32 __cdecl
CRTDLL_wcstombs( LPSTR dst
, LPCWSTR src
, INT32 len
)
1433 lstrcpynWtoA( dst
, src
, len
);
1434 return strlen(dst
); /* FIXME: is this right? */
1437 /*********************************************************************
1438 * wcsrchr (CRTDLL.515)
1440 LPWSTR __cdecl
CRTDLL_wcsrchr(LPWSTR str
,WCHAR xchar
)
1444 s
=str
+lstrlen32W(str
);
1453 /*********************************************************************
1454 * _setmode (CRTDLL.265)
1455 * FIXME: At present we ignore the request to translate CR/LF to LF.
1457 * We allways translate when we read with fgets, we never do with fread
1460 INT32 __cdecl
CRTDLL__setmode( INT32 fh
,INT32 mode
)
1463 #define O_TEXT 0x4000
1464 #define O_BINARY 0x8000
1466 FIXME(crtdll
, "on fhandle %d mode %s, STUB.\n",
1467 fh
,(mode
=O_TEXT
)?"O_TEXT":
1468 (mode
=O_BINARY
)?"O_BINARY":"UNKNOWN");
1472 /*********************************************************************
1473 * _fpreset (CRTDLL.107)
1475 VOID __cdecl
CRTDLL__fpreset(void)
1477 FIXME(crtdll
," STUB.\n");
1480 /*********************************************************************
1481 * atexit (CRTDLL.345)
1483 INT32 __cdecl
CRTDLL_atexit(LPVOID x
)
1485 FIXME(crtdll
,"(%p), STUB.\n",x
);
1486 return 0; /* successful */
1489 /*********************************************************************
1490 * mblen (CRTDLL.428)
1491 * FIXME: check multibyte support
1493 WCHAR __cdecl
CRTDLL_mblen(CHAR
*mb
,INT32 size
)
1500 else if ((size
<1)||(!*(mb
+1)))
1505 TRACE(crtdll
,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb
,size
,ret
);
1510 /*********************************************************************
1511 * mbstowcs (CRTDLL.429)
1512 * FIXME: check multibyte support
1514 INT32 __cdecl
CRTDLL_mbstowcs(LPWSTR wcs
, LPCSTR mbs
, INT32 size
)
1517 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1518 * We need the number of characters transfered
1519 * FIXME: No multibyte support yet
1526 while ((n
-- > 0) && *src
) {
1527 *p
++ = (WCHAR
)(unsigned char)*src
++;
1532 TRACE(crtdll
,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1537 /*********************************************************************
1538 * mbtowc (CRTDLL.430)
1539 * FIXME: check multibyte support
1541 WCHAR __cdecl
CRTDLL_mbtowc(WCHAR
* wc
,CHAR
* mb
,INT32 size
)
1550 if ( (ret
= mblen(mb
,size
)) != -1 )
1552 if (ret
<= sizeof(char))
1553 *wc
= (WCHAR
) ((unsigned char)*mb
);
1560 TRACE(crtdll
,"CRTDLL_mbtowc %s for %d chars\n",mb
,size
);
1565 /*********************************************************************
1566 * _isctype (CRTDLL.138)
1568 BOOL32 __cdecl
CRTDLL__isctype(CHAR x
,CHAR type
)
1570 if ((type
& CRTDLL_SPACE
) && isspace(x
))
1572 if ((type
& CRTDLL_PUNCT
) && ispunct(x
))
1574 if ((type
& CRTDLL_LOWER
) && islower(x
))
1576 if ((type
& CRTDLL_UPPER
) && isupper(x
))
1578 if ((type
& CRTDLL_ALPHA
) && isalpha(x
))
1580 if ((type
& CRTDLL_DIGIT
) && isdigit(x
))
1582 if ((type
& CRTDLL_CONTROL
) && iscntrl(x
))
1584 /* check CRTDLL_LEADBYTE */
1588 /*********************************************************************
1589 * _chdrive (CRTDLL.52)
1591 * newdir [I] drive to change to, A=1
1594 BOOL32 __cdecl
CRTDLL__chdrive(INT32 newdrive
)
1596 /* FIXME: generates errnos */
1597 return DRIVE_SetCurrentDrive(newdrive
-1);
1600 /*********************************************************************
1601 * _chdir (CRTDLL.51)
1603 INT32 __cdecl
CRTDLL__chdir(LPCSTR newdir
)
1605 if (!SetCurrentDirectory32A(newdir
))
1610 /*********************************************************************
1611 * _fullpath (CRTDLL.114)
1613 LPSTR __cdecl
CRTDLL__fullpath(LPSTR buf
, LPCSTR name
, INT32 size
)
1615 DOS_FULL_NAME full_name
;
1620 if(!(buf
= CRTDLL_malloc(size
))) return NULL
;
1622 if (!DOSFS_GetFullName( name
, FALSE
, &full_name
)) return NULL
;
1623 lstrcpyn32A(buf
,full_name
.short_name
,size
);
1624 TRACE(crtdll
,"CRTDLL_fullpath got %s\n",buf
);
1628 /*********************************************************************
1629 * _splitpath (CRTDLL.279)
1631 VOID __cdecl
CRTDLL__splitpath(LPCSTR path
, LPSTR drive
, LPSTR directory
, LPSTR filename
, LPSTR extension
)
1634 directory includes leading and trailing (forward and backward slashes)
1635 filename without dot and slashes
1636 extension with leading dot
1638 char * drivechar
,*dirchar
,*namechar
;
1640 TRACE(crtdll
,"CRTDLL__splitpath got %s\n",path
);
1642 drivechar
= strchr(path
,':');
1643 dirchar
= strrchr(path
,'/');
1644 namechar
= strrchr(path
,'\\');
1645 dirchar
= MAX(dirchar
,namechar
);
1647 namechar
= strrchr(dirchar
,'.');
1649 namechar
= strrchr(path
,'.');
1657 strncat(drive
,path
,drivechar
-path
+1);
1666 strncat(directory
,path
,dirchar
-path
+1);
1675 strncat(filename
,path
,namechar
-path
);
1679 strcat(extension
,namechar
);
1684 TRACE(crtdll
,"CRTDLL__splitpath found %s %s %s %s\n",drive
,directory
,filename
,extension
);
1688 /*********************************************************************
1689 * _getcwd (CRTDLL.120)
1691 CHAR
* __cdecl
CRTDLL__getcwd(LPSTR buf
, INT32 size
)
1698 if (size
< 0) /* allocate as big as nescessary */
1699 len
=GetCurrentDirectory32A(1,test
) + 1;
1700 if(!(buf
= CRTDLL_malloc(len
)))
1702 /* set error to OutOfRange */
1707 if(!(len
=GetCurrentDirectory32A(len
,buf
)))
1713 /* set error to ERANGE */
1714 TRACE(crtdll
,"CRTDLL_getcwd buffer to small\n");
1721 /*********************************************************************
1722 * _getdcwd (CRTDLL.121)
1724 CHAR
* __cdecl
CRTDLL__getdcwd(INT32 drive
,LPSTR buf
, INT32 size
)
1729 FIXME(crtdll
,"(\"%c:\",%s,%d)\n",drive
+'A',buf
,size
);
1732 if (size
< 0) /* allocate as big as nescessary */
1733 len
=GetCurrentDirectory32A(1,test
) + 1;
1734 if(!(buf
= CRTDLL_malloc(len
)))
1736 /* set error to OutOfRange */
1741 if(!(len
=GetCurrentDirectory32A(len
,buf
)))
1747 /* set error to ERANGE */
1748 TRACE(crtdll
,"buffer to small\n");
1755 /*********************************************************************
1756 * _getdrive (CRTDLL.124)
1758 * Return current drive, 1 for A, 2 for B
1760 INT32 __cdecl
CRTDLL__getdrive(VOID
)
1762 return DRIVE_GetCurrentDrive() + 1;
1765 /*********************************************************************
1766 * _mkdir (CRTDLL.234)
1768 INT32 __cdecl
CRTDLL__mkdir(LPCSTR newdir
)
1770 if (!CreateDirectory32A(newdir
,NULL
))
1775 /*********************************************************************
1776 * remove (CRTDLL.448)
1778 INT32 __cdecl
CRTDLL_remove(LPCSTR file
)
1780 if (!DeleteFile32A(file
))
1785 /*********************************************************************
1786 * _errno (CRTDLL.52)
1787 * Yes, this is a function.
1789 LPINT32 __cdecl
CRTDLL__errno()
1791 static int crtdllerrno
;
1793 /* FIXME: we should set the error at the failing function call time */
1794 crtdllerrno
= LastErrorToErrno(GetLastError());
1795 return &crtdllerrno
;
1798 /*********************************************************************
1799 * _tempnam (CRTDLL.305)
1802 LPSTR __cdecl
CRTDLL__tempnam(LPCSTR dir
, LPCSTR prefix
)
1806 DOS_FULL_NAME tempname
;
1808 if ((ret
= tempnam(dir
,prefix
))==NULL
) {
1809 WARN(crtdll
, "Unable to get unique filename\n");
1812 if (!DOSFS_GetFullName(ret
,FALSE
,&tempname
))
1814 TRACE(crtdll
, "Wrong path?\n");
1818 if ((ret
= CRTDLL_malloc(strlen(tempname
.short_name
)+1)) == NULL
) {
1819 WARN(crtdll
, "CRTDL_malloc for shortname failed\n");
1822 if ((ret
= strcpy(ret
,tempname
.short_name
)) == NULL
) {
1823 WARN(crtdll
, "Malloc for shortname failed\n");
1827 TRACE(crtdll
,"dir %s prefix %s got %s\n",
1832 /*********************************************************************
1833 * tmpnam (CRTDLL.490)
1835 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1838 LPSTR __cdecl
CRTDLL_tmpnam(LPSTR s
)
1842 if ((ret
=tmpnam(s
))== NULL
) {
1843 WARN(crtdll
, "Unable to get unique filename\n");
1846 if (!DOSFS_GetFullName(ret
,FALSE
,&CRTDLL_tmpname
))
1848 TRACE(crtdll
, "Wrong path?\n");
1851 strcat(CRTDLL_tmpname
.short_name
,".");
1852 TRACE(crtdll
,"for buf %p got %s\n",
1853 s
,CRTDLL_tmpname
.short_name
);
1854 TRACE(crtdll
,"long got %s\n",
1855 CRTDLL_tmpname
.long_name
);
1857 return strcpy(s
,CRTDLL_tmpname
.short_name
);
1859 return CRTDLL_tmpname
.short_name
;
1863 /*********************************************************************
1864 * _itoa (CRTDLL.165)
1866 LPSTR __cdecl
CRTDLL__itoa(INT32 x
,LPSTR buf
,INT32 buflen
)
1868 wsnprintf32A(buf
,buflen
,"%d",x
);
1872 /*********************************************************************
1873 * _ltoa (CRTDLL.180)
1875 LPSTR __cdecl
CRTDLL__ltoa(long x
,LPSTR buf
,INT32 radix
)
1878 case 2: FIXME(crtdll
, "binary format not implemented !\n");
1880 case 8: wsnprintf32A(buf
,0x80,"%o",x
);
1882 case 10: wsnprintf32A(buf
,0x80,"%d",x
);
1884 case 16: wsnprintf32A(buf
,0x80,"%x",x
);
1886 default: FIXME(crtdll
, "radix %d not implemented !\n", radix
);
1891 /*********************************************************************
1892 * _ultoa (CRTDLL.311)
1894 LPSTR __cdecl
CRTDLL__ultoa(long x
,LPSTR buf
,INT32 radix
)
1897 case 2: FIXME(crtdll
, "binary format not implemented !\n");
1899 case 8: wsnprintf32A(buf
,0x80,"%lo",x
);
1901 case 10: wsnprintf32A(buf
,0x80,"%ld",x
);
1903 case 16: wsnprintf32A(buf
,0x80,"%lx",x
);
1905 default: FIXME(crtdll
, "radix %d not implemented !\n", radix
);
1910 typedef VOID (*sig_handler_type
)(VOID
);
1912 /*********************************************************************
1913 * signal (CRTDLL.455)
1915 VOID __cdecl
CRTDLL_signal(int sig
, sig_handler_type ptr
)
1917 FIXME(crtdll
, "(%d %p):stub.\n", sig
, ptr
);
1920 /*********************************************************************
1921 * _ftol (CRTDLL.113)
1923 LONG __cdecl
CRTDLL__ftol(double fl
) {
1926 /*********************************************************************
1927 * _sleep (CRTDLL.267)
1929 VOID __cdecl
CRTDLL__sleep(unsigned long timeout
)
1931 TRACE(crtdll
,"CRTDLL__sleep for %ld milliseconds\n",timeout
);
1932 Sleep((timeout
)?timeout
:1);
1935 /*********************************************************************
1936 * getenv (CRTDLL.437)
1938 LPSTR __cdecl
CRTDLL_getenv(const char *name
)
1940 LPSTR environ
= GetEnvironmentStrings32A();
1941 LPSTR pp
,pos
= NULL
;
1942 unsigned int length
;
1944 for (pp
= environ
; (*pp
); pp
= pp
+ strlen(pp
) +1)
1946 pos
=strchr(pp
,'=');
1950 length
= strlen(pp
);
1951 if (!strncmp(pp
,name
,length
)) break;
1956 TRACE(crtdll
,"got %s\n",pp
);
1958 FreeEnvironmentStrings32A( environ
);
1962 /*********************************************************************
1963 * _mbsrchr (CRTDLL.223)
1965 LPSTR __cdecl
CRTDLL__mbsrchr(LPSTR s
,CHAR x
) {
1966 /* FIXME: handle multibyte strings */
1967 return strrchr(s
,x
);
1970 /*********************************************************************
1971 * _memicmp (CRTDLL.233)(NTDLL.868)
1972 * A stringcompare, without \0 check
1974 * -1:if first string is alphabetically before second string
1975 * 1:if second '' '' '' '' first ''
1976 * 0:if both are equal.
1978 INT32 __cdecl
CRTDLL__memicmp(
1979 LPCSTR s1
, /* [in] first string */
1980 LPCSTR s2
, /* [in] second string */
1981 DWORD len
/* [in] length to compare */
1985 for (i
=0;i
<len
;i
++) {
1986 if (tolower(s1
[i
])<tolower(s2
[i
]))
1988 if (tolower(s1
[i
])>tolower(s2
[i
]))
1993 /*********************************************************************
1994 * __dllonexit (CRTDLL.25)
1996 VOID __cdecl
CRTDLL__dllonexit ()
1998 FIXME(crtdll
,"stub\n");
2001 /*********************************************************************
2002 * wcstok (CRTDLL.519)
2003 * Like strtok, but for wide character strings. s is modified, yes.
2005 LPWSTR
CRTDLL_wcstok(LPWSTR s
,LPCWSTR delim
) {
2006 static LPWSTR nexttok
= NULL
;
2014 while (*x
&& !CRTDLL_wcschr(delim
,*x
))
2025 /*********************************************************************
2026 * wcstol (CRTDLL.520)
2027 * Like strtol, but for wide character strings.
2029 INT32
CRTDLL_wcstol(LPWSTR s
,LPWSTR
*end
,INT32 base
) {
2030 LPSTR sA
= HEAP_strdupWtoA(GetProcessHeap(),0,s
),endA
;
2031 INT32 ret
= strtol(sA
,&endA
,base
);
2033 HeapFree(GetProcessHeap(),0,sA
);
2034 if (end
) *end
= s
+(endA
-sA
); /* pointer magic checked. */
2037 /*********************************************************************
2038 * strdate (CRTDLL.283)
2040 LPSTR __cdecl
CRTDLL__strdate (LPSTR date
)
2041 { FIXME (crtdll
,"%p stub\n", date
);
2045 /*********************************************************************
2046 * strtime (CRTDLL.299)
2048 LPSTR __cdecl
CRTDLL__strtime (LPSTR date
)
2049 { FIXME (crtdll
,"%p stub\n", date
);