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
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 */
45 extern int FILE_GetUnixHandle( HFILE32
);
47 static DOS_FULL_NAME CRTDLL_tmpname
;
49 extern INT32
WIN32_wsprintf32W( DWORD
*args
);
51 UINT32 CRTDLL_argc_dll
; /* CRTDLL.23 */
52 LPSTR
*CRTDLL_argv_dll
; /* CRTDLL.24 */
53 LPSTR CRTDLL_acmdln_dll
; /* CRTDLL.38 */
54 UINT32 CRTDLL_basemajor_dll
; /* CRTDLL.42 */
55 UINT32 CRTDLL_baseminor_dll
; /* CRTDLL.43 */
56 UINT32 CRTDLL_baseversion_dll
; /* CRTDLL.44 */
57 UINT32 CRTDLL_commode_dll
; /* CRTDLL.59 */
58 LPSTR CRTDLL_environ_dll
; /* CRTDLL.75 */
59 UINT32 CRTDLL_fmode_dll
; /* CRTDLL.104 */
60 UINT32 CRTDLL_osmajor_dll
; /* CRTDLL.241 */
61 UINT32 CRTDLL_osminor_dll
; /* CRTDLL.242 */
62 UINT32 CRTDLL_osmode_dll
; /* CRTDLL.243 */
63 UINT32 CRTDLL_osver_dll
; /* CRTDLL.244 */
64 UINT32 CRTDLL_osversion_dll
; /* CRTDLL.245 */
65 UINT32 CRTDLL_winmajor_dll
; /* CRTDLL.329 */
66 UINT32 CRTDLL_winminor_dll
; /* CRTDLL.330 */
67 UINT32 CRTDLL_winver_dll
; /* CRTDLL.331 */
69 typedef VOID (*new_handler_type
)(VOID
);
71 static new_handler_type new_handler
;
73 /*********************************************************************
74 * _GetMainArgs (CRTDLL.022)
76 DWORD __cdecl
CRTDLL__GetMainArgs(LPDWORD argc
,LPSTR
**argv
,
77 LPSTR
*environ
,DWORD flag
)
81 int xargc
,i
,afterlastspace
;
84 dprintf_crtdll(stddeb
,"CRTDLL__GetMainArgs(%p,%p,%p,%ld).\n",
85 argc
,argv
,environ
,flag
87 CRTDLL_acmdln_dll
= cmdline
= xstrdup( GetCommandLine32A() );
88 dprintf_crtdll(stddeb
,"CRTDLL__GetMainArgs got \"%s\"\n",
91 version
= GetVersion32();
92 CRTDLL_osver_dll
= version
>> 16;
93 CRTDLL_winminor_dll
= version
& 0xFF;
94 CRTDLL_winmajor_dll
= (version
>>8) & 0xFF;
95 CRTDLL_baseversion_dll
= version
>> 16;
96 CRTDLL_winver_dll
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
97 CRTDLL_baseminor_dll
= (version
>> 16) & 0xFF;
98 CRTDLL_basemajor_dll
= (version
>> 24) & 0xFF;
99 CRTDLL_osversion_dll
= version
& 0xFFFF;
100 CRTDLL_osminor_dll
= version
& 0xFF;
101 CRTDLL_osmajor_dll
= (version
>>8) & 0xFF;
103 /* missing threading init */
105 i
=0;xargv
=NULL
;xargc
=0;afterlastspace
=0;
107 if (cmdline
[i
]==' ') {
108 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
110 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
112 while (cmdline
[i
]==' ')
119 xargv
=(char**)xrealloc(xargv
,sizeof(char*)*(++xargc
));
121 xargv
[xargc
-1] = xstrdup(cmdline
+afterlastspace
);
122 CRTDLL_argc_dll
= xargc
;
124 CRTDLL_argv_dll
= xargv
;
127 dprintf_crtdll(stddeb
,"CRTDLL__GetMainArgs found %d arguments\n",
129 /* FIXME ... use real environment */
130 *environ
= xmalloc(sizeof(LPSTR
));
131 CRTDLL_environ_dll
= *environ
;
132 (*environ
)[0] = NULL
;
137 typedef void (*_INITTERMFUN
)();
139 /*********************************************************************
140 * _initterm (CRTDLL.135)
142 DWORD __cdecl
CRTDLL__initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
144 _INITTERMFUN
*current
;
146 dprintf_crtdll(stddeb
,"_initterm(%p,%p)\n",start
,end
);
148 while (current
<end
) {
149 if (*current
) (*current
)();
155 /*********************************************************************
156 * _fdopen (CRTDLL.91)
158 DWORD __cdecl
CRTDLL__fdopen(INT32 handle
, LPCSTR mode
)
166 case 1 : file
=stdout
;
168 case 2 : file
=stderr
;
171 file
=fdopen(handle
,mode
);
173 dprintf_crtdll(stddeb
,
174 "CRTDLL_fdopen open handle %d mode %s got file %p\n",
179 /*******************************************************************
180 * _global_unwind2 (CRTDLL.129)
182 void __cdecl
CRTDLL__global_unwind2( CONTEXT
*context
)
184 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
185 DWORD
*args
= (DWORD
*)ESP_reg(context
);
186 RtlUnwind( (PEXCEPTION_FRAME
)args
[1], (LPVOID
)EIP_reg(context
),
190 /*******************************************************************
191 * _local_unwind2 (CRTDLL.173)
193 void __cdecl
CRTDLL__local_unwind2( CONTEXT
*context
)
195 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
196 DWORD
*args
= (DWORD
*)ESP_reg(context
);
197 PEXCEPTION_FRAME endframe
= (PEXCEPTION_FRAME
)args
[1];
199 fprintf(stderr
,"CRTDLL__local_unwind2(%p,%ld)\n",endframe
,nr
);
202 /*********************************************************************
205 DWORD __cdecl
CRTDLL_fopen(LPCSTR path
, LPCSTR mode
)
210 DOS_FULL_NAME full_name
;
212 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
)) {
213 dprintf_crtdll(stddeb
,"CRTDLL_fopen file %s bad name\n",path
);
217 file
=fopen(full_name
.long_name
,mode
);
222 if ((strchr(mode
,'r')&&strchr(mode
,'a'))||
223 (strchr(mode
,'r')&&strchr(mode
,'w'))||
224 (strchr(mode
,'w')&&strchr(mode
,'a')))
227 if (strstr(mode
,"r+")) flagmode
=O_RDWR
;
228 else if (strchr(mode
,'r')) flagmode
= O_RDONLY
;
229 else if (strstr(mode
,"w+")) flagmode
= O_RDWR
| O_TRUNC
| O_CREAT
;
230 else if (strchr(mode
,'w')) flagmode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
231 else if (strstr(mode
,"a+")) flagmode
= O_RDWR
| O_CREAT
| O_APPEND
;
232 else if (strchr(mode
,'w')) flagmode
= O_RDWR
| O_CREAT
| O_APPEND
;
233 else if (strchr(mode
,'b'))
234 dprintf_crtdll(stderr
,
235 "CRTDLL_fopen %s in BINARY mode\n",path
);
237 dos_fildes
=FILE_Open(path
, flagmode
);
238 unix_fildes
=FILE_GetUnixHandle(dos_fildes
);
239 file
= fdopen(unix_fildes
,mode
);
241 dprintf_crtdll(stddeb
,
242 "CRTDLL_fopen file %s mode %s got ufh %d dfh %d file %p\n",
243 path
,mode
,unix_fildes
,dos_fildes
,file
);
247 /*********************************************************************
250 DWORD __cdecl
CRTDLL_fread(LPVOID ptr
, INT32 size
, INT32 nmemb
, LPVOID file
)
257 /* If we would honour CR/LF <-> LF translation, we could do it like this.
258 We should keep track of all files opened, and probably files with \
259 known binary extensions must be unchanged */
260 while ( (i
< (nmemb
*size
)) && (ret
==1)) {
261 ret
=fread(temp
,1,1,file
);
262 dprintf_crtdll(stddeb
,
263 "CRTDLL_fread got %c 0x%02x ret %d\n",
264 (isalpha(*(unsigned char*)temp
))? *(unsigned char*)temp
:
265 ' ',*(unsigned char*)temp
, ret
);
266 if (*(unsigned char*)temp
!= 0xd) { /* skip CR */
271 dprintf_crtdll(stddeb
, "CRTDLL_fread skipping ^M\n");
273 dprintf_crtdll(stddeb
,
274 "CRTDLL_fread 0x%08x items of size %d from file %p to %p%s\n",
275 nmemb
,size
,file
,ptr
,(i
!=nmemb
)?" failed":"");
279 ret
=fread(ptr
,size
,nmemb
,file
);
280 dprintf_crtdll(stddeb
,
281 "CRTDLL_fread 0x%08x items of size %d from file %p to %p%s\n",
282 nmemb
,size
,file
,ptr
,(ret
!=nmemb
)?" failed":"");
287 /*********************************************************************
290 LONG __cdecl
CRTDLL_fseek(LPVOID stream
, LONG offset
, INT32 whence
)
294 ret
=fseek(stream
,offset
,whence
);
295 dprintf_crtdll(stddeb
,
296 "CRTDLL_fseek file %p to 0x%08lx pos %s%s\n",
297 stream
,offset
,(whence
==SEEK_SET
)?"SEEK_SET":
298 (whence
==SEEK_CUR
)?"SEEK_CUR":
299 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN",
304 /*********************************************************************
307 LONG __cdecl
CRTDLL_ftell(LPVOID stream
)
312 dprintf_crtdll(stddeb
,
313 "CRTDLL_ftell file %p at 0x%08lx\n",
318 /*********************************************************************
319 * fwrite (CRTDLL.386)
321 DWORD __cdecl
CRTDLL_fwrite(LPVOID ptr
, INT32 size
, INT32 nmemb
, LPVOID file
)
325 ret
=fwrite(ptr
,size
,nmemb
,file
);
326 dprintf_crtdll(stddeb
,
327 "CRTDLL_fwrite 0x%08x items of size %d from %p to file %p%s\n",
328 nmemb
,size
,ptr
,file
,(ret
!=nmemb
)?" failed":"");
332 /*********************************************************************
333 * setbuf (CRTDLL.452)
335 INT32 __cdecl
CRTDLL_setbuf(LPVOID file
, LPSTR buf
)
337 dprintf_crtdll(stddeb
,
338 "CRTDLL_setbuf(file %p buf %p)\n",
340 /* this doesn't work:"void value not ignored as it ought to be"
341 return setbuf(file,buf);
347 /*********************************************************************
348 * _open_osfhandle (CRTDLL.240)
350 HFILE32 __cdecl
CRTDLL__open_osfhandle(LONG osfhandle
, INT32 flags
)
355 case STD_INPUT_HANDLE
:
359 case STD_OUTPUT_HANDLE
:
363 case STD_ERROR_HANDLE
:
370 dprintf_crtdll(stddeb
,
371 "CRTDLL_open_osfhandle(handle %08lx,flags %d) return %d\n",
372 osfhandle
,flags
,handle
);
377 /*********************************************************************
380 void __cdecl
CRTDLL_srand(DWORD seed
)
382 /* FIXME: should of course be thread? process? local */
386 /*********************************************************************
387 * fprintf (CRTDLL.373)
389 INT32 __cdecl
CRTDLL_fprintf( FILE *file
, LPSTR format
, ... )
394 va_start( valist
, format
);
395 res
= vfprintf( file
, format
, valist
);
400 /*********************************************************************
401 * vfprintf (CRTDLL.373)
403 INT32 __cdecl
CRTDLL_vfprintf( FILE *file
, LPSTR format
, va_list args
)
405 return vfprintf( file
, format
, args
);
408 /*********************************************************************
411 time_t __cdecl
CRTDLL_time(time_t *timeptr
)
413 time_t curtime
= time(NULL
);
420 /*********************************************************************
421 * _isatty (CRTDLL.137)
423 BOOL32 __cdecl
CRTDLL__isatty(DWORD x
)
425 dprintf_crtdll(stderr
,"CRTDLL__isatty(%ld)\n",x
);
429 /*********************************************************************
430 * _write (CRTDLL.332)
432 INT32 __cdecl
CRTDLL__write(INT32 fd
,LPCVOID buf
,UINT32 count
)
439 len
= (UINT32
)write(fd
,buf
,(LONG
)len
);
441 len
= _lwrite32(fd
,buf
,count
);
442 dprintf_crtdll(stddeb
,"CRTDLL_write %d/%d byte to dfh %d from %p,\n",
448 /*********************************************************************
451 * FIXME: What the heck is the difference between
452 * FIXME _c_exit (CRTDLL.47)
453 * FIXME _cexit (CRTDLL.49)
454 * FIXME _exit (CRTDLL.87)
455 * FIXME exit (CRTDLL.359)
458 void __cdecl
CRTDLL__cexit(INT32 ret
)
460 dprintf_crtdll(stddeb
,"CRTDLL__cexit(%d)\n",ret
);
465 /*********************************************************************
468 void __cdecl
CRTDLL_exit(DWORD ret
)
470 dprintf_crtdll(stddeb
,"CRTDLL_exit(%ld)\n",ret
);
475 /*********************************************************************
476 * fflush (CRTDLL.365)
478 INT32 __cdecl
CRTDLL_fflush(LPVOID stream
)
482 ret
= fflush(stream
);
483 dprintf_crtdll(stddeb
,"CRTDLL_fflush %p returnd %d %s\n",stream
,ret
,(ret
)?"":" failed");
488 /*********************************************************************
491 LPSTR __cdecl
CRTDLL_gets(LPSTR buf
)
493 /* BAD, for the whole WINE process blocks... just done this way to test
494 * windows95's ftp.exe.
500 /*********************************************************************
503 INT32 __cdecl
CRTDLL_rand()
509 /*********************************************************************
510 * putchar (CRTDLL.442)
512 void __cdecl
CRTDLL_putchar( INT32 x
)
518 /*********************************************************************
521 INT32 __cdecl
CRTDLL_fputc( INT32 c
, FILE *stream
)
523 dprintf_crtdll(stddeb
,
524 "CRTDLL_fputc %c to file %p\n",c
,stream
);
525 return fputc(c
,stream
);
529 /*********************************************************************
532 INT32 __cdecl
CRTDLL_fputs( LPCSTR s
, FILE *stream
)
534 dprintf_crtdll(stddeb
,
535 "CRTDLL_fputs %s to file %p\n",s
,stream
);
536 return fputs(s
,stream
);
540 /*********************************************************************
543 INT32 __cdecl
CRTDLL_puts(LPCSTR s
)
545 dprintf_crtdll(stddeb
,
546 "CRTDLL_fputs %s \n",s
);
551 /*********************************************************************
554 INT32 __cdecl
CRTDLL_putc(INT32 c
, FILE *stream
)
556 dprintf_crtdll(stddeb
,
557 "CRTDLL_putc %c to file %p\n",c
,stream
);
558 return fputc(c
,stream
);
560 /*********************************************************************
563 INT32 __cdecl
CRTDLL_fgetc( FILE *stream
)
565 int ret
= fgetc(stream
);
566 dprintf_crtdll(stddeb
,
567 "CRTDLL_fgetc got %d\n",ret
);
572 /*********************************************************************
575 INT32 __cdecl
CRTDLL_getc( FILE *stream
)
577 int ret
= fgetc(stream
);
578 dprintf_crtdll(stddeb
,
579 "CRTDLL_getc got %d\n",ret
);
583 /*********************************************************************
584 * _lrotl (CRTDLL.176)
586 DWORD __cdecl
CRTDLL__lrotl(DWORD x
,INT32 shift
)
588 unsigned long ret
= (x
>> shift
)|( x
>>((sizeof(x
))-shift
));
590 dprintf_crtdll(stddeb
,
591 "CRTDLL_lrotl got 0x%08lx rot %d ret 0x%08lx\n",
598 /*********************************************************************
601 CHAR
* __cdecl
CRTDLL_fgets(LPSTR s
,INT32 size
, LPVOID stream
)
606 ret
=fgets(s
, size
,stream
);
607 /*FIXME: Control with CRTDLL_setmode */
608 control_M
= strrchr(s
,'\r');
609 /*delete CR if we read a DOS File */
615 dprintf_crtdll(stddeb
,
616 "CRTDLL_fgets got %s for %d chars from file %p%s\n",
617 s
,size
,stream
,(ret
)?"":" failed");
622 /*********************************************************************
623 * _mbsicmp (CRTDLL.204)
625 int __cdecl
CRTDLL__mbsicmp(unsigned char *x
,unsigned char *y
)
632 /* FIXME: MBCS handling... */
641 /*********************************************************************
642 * _mbsinc (CRTDLL.205)
644 unsigned char * __cdecl
CRTDLL__mbsinc(unsigned char *x
)
651 /*********************************************************************
652 * vsprintf (CRTDLL.500)
654 INT32 __cdecl
CRTDLL_vsprintf( LPSTR buffer
, LPCSTR spec
, va_list args
)
656 return wvsprintf32A( buffer
, spec
, args
);
659 /*********************************************************************
660 * vswprintf (CRTDLL.501)
662 INT32 __cdecl
CRTDLL_vswprintf( LPWSTR buffer
, LPCWSTR spec
, va_list args
)
664 return wvsprintf32W( buffer
, spec
, args
);
667 /*********************************************************************
668 * _mbscpy (CRTDLL.200)
670 unsigned char* __cdecl
CRTDLL__mbscpy(unsigned char *x
,unsigned char *y
)
672 dprintf_crtdll(stddeb
,"CRTDLL_mbscpy %s and %s\n",x
,y
);
677 /*********************************************************************
678 * _mbscat (CRTDLL.197)
680 unsigned char* __cdecl
CRTDLL__mbscat(unsigned char *x
,unsigned char *y
)
686 /*********************************************************************
687 * _strcmpi (CRTDLL.282) (CRTDLL.287)
689 INT32 __cdecl
CRTDLL__strcmpi( LPCSTR s1
, LPCSTR s2
)
691 return lstrcmpi32A( s1
, s2
);
695 /*********************************************************************
696 * _strnicmp (CRTDLL.293)
698 INT32 __cdecl
CRTDLL__strnicmp( LPCSTR s1
, LPCSTR s2
, INT32 n
)
700 return lstrncmpi32A( s1
, s2
, n
);
704 /*********************************************************************
705 * _strlwr (CRTDLL.293)
707 * convert a string in place to lowercase
709 LPSTR
CRTDLL__strlwr(LPSTR x
)
713 dprintf_crtdll(stddeb
,
714 "CRTDLL_strlwr got %s",x
);
716 if ((*y
> 0x40) && (*y
< 0x5b))
720 dprintf_crtdll(stddeb
," returned %s\n",x
);
725 /*********************************************************************
726 * system (CRTDLL.485)
728 INT32
CRTDLL_system(LPSTR x
)
730 #define SYSBUF_LENGTH 1500
731 char buffer
[SYSBUF_LENGTH
];
732 unsigned char *y
= x
;
736 sprintf( buffer
, "%s \"", Options
.argv0
);
737 bp
= buffer
+ strlen(buffer
);
738 i
= strlen(buffer
) + strlen(x
) +2;
740 /* Calculate needed buffer size tp prevent overflow*/
745 /* if buffer to short, exit */
746 if (i
> SYSBUF_LENGTH
) {
747 dprintf_crtdll(stddeb
,"_system buffer to small\n");
756 if (*(y
-1) =='\\') *bp
++ = '\\';
758 /* remove spaces from end of string */
759 while (*(y
-1) == ' ') {
764 dprintf_crtdll(stddeb
,
765 "_system got \"%s\", executing \"%s\"\n",x
,buffer
);
767 return system(buffer
);
770 /*********************************************************************
771 * _strupr (CRTDLL.300)
773 LPSTR __cdecl
CRTDLL__strupr(LPSTR x
)
784 /*********************************************************************
785 * _wcsupr (CRTDLL.328)
787 LPWSTR __cdecl
CRTDLL__wcsupr(LPWSTR x
)
798 /*********************************************************************
799 * _wcslwr (CRTDLL.323)
801 LPWSTR __cdecl
CRTDLL__wcslwr(LPWSTR x
)
813 /*********************************************************************
814 * malloc (CRTDLL.427)
816 VOID
* __cdecl
CRTDLL_malloc(DWORD size
)
818 return HeapAlloc(GetProcessHeap(),0,size
);
821 /*********************************************************************
824 VOID
* __cdecl
CRTDLL_new(DWORD size
)
827 if(!(result
= HeapAlloc(GetProcessHeap(),0,size
)) && new_handler
)
832 /*********************************************************************
833 * set_new_handler(CRTDLL.003)
835 new_handler_type __cdecl
CRTDLL_set_new_handler(new_handler_type func
)
837 new_handler_type old_handler
= new_handler
;
842 /*********************************************************************
843 * calloc (CRTDLL.350)
845 VOID
* __cdecl
CRTDLL_calloc(DWORD size
, DWORD count
)
847 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
* count
);
850 /*********************************************************************
851 * realloc (CRTDLL.447)
853 VOID
* __cdecl
CRTDLL_realloc( VOID
*ptr
, DWORD size
)
855 return HeapReAlloc( GetProcessHeap(), 0, ptr
, size
);
858 /*********************************************************************
861 VOID __cdecl
CRTDLL_free(LPVOID ptr
)
863 HeapFree(GetProcessHeap(),0,ptr
);
866 /*********************************************************************
867 * delete (CRTDLL.002)
869 VOID __cdecl
CRTDLL_delete(VOID
* ptr
)
871 HeapFree(GetProcessHeap(),0,ptr
);
874 /*********************************************************************
875 * _strdup (CRTDLL.285)
877 LPSTR __cdecl
CRTDLL__strdup(LPSTR ptr
)
879 return HEAP_strdupA(GetProcessHeap(),0,ptr
);
883 /*********************************************************************
884 * fclose (CRTDLL.362)
886 INT32 __cdecl
CRTDLL_fclose( FILE *stream
)
888 int unix_handle
=fileno(stream
);
889 HFILE32 dos_handle
=1;
892 if (unix_handle
<4) ret
= fclose(stream
);
894 while(FILE_GetUnixHandle(dos_handle
) != unix_handle
) dos_handle
++;
896 ret
= _lclose32( dos_handle
);
898 dprintf_crtdll(stddeb
,"CRTDLL_fclose(%p) ufh %d dfh %d%s\n",
899 stream
,unix_handle
,dos_handle
,(ret
)?" failed":"");
903 /*********************************************************************
904 * _unlink (CRTDLL.315)
906 INT32 __cdecl
CRTDLL__unlink(LPCSTR pathname
)
909 DOS_FULL_NAME full_name
;
911 if (!DOSFS_GetFullName( pathname
, FALSE
, &full_name
)) {
912 dprintf_crtdll(stddeb
,"CRTDLL_unlink file %s bad name\n",pathname
);
916 ret
=unlink(full_name
.long_name
);
917 dprintf_crtdll(stddeb
,"CRTDLL_unlink(%s unix %s)%s\n",
918 pathname
,full_name
.long_name
, (ret
)?" failed":"");
922 /*********************************************************************
925 HFILE32 __cdecl
CRTDLL__open(LPCSTR path
,INT32 flags
)
931 the flags in lcc's header differ from the ones in Linux, e.g.
932 Linux: define O_APPEND 02000 (= 0x400)
933 lcc: define _O_APPEND 0x0008
934 so here a scheme to translate them
935 Probably lcc is wrong here, but at least a hack to get is going
937 wineflags
= (flags
& 3);
938 if (flags
& 0x0008 ) wineflags
|= O_APPEND
;
939 if (flags
& 0x0100 ) wineflags
|= O_CREAT
;
940 if (flags
& 0x0200 ) wineflags
|= O_TRUNC
;
941 if (flags
& 0x0400 ) wineflags
|= O_EXCL
;
943 dprintf_crtdll(stddeb
,"CRTDLL_open file unsupported flags 0x%04x\n",flags
);
946 ret
= FILE_Open(path
,wineflags
);
947 dprintf_crtdll(stddeb
,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
948 path
,wineflags
,flags
,ret
);
952 /*********************************************************************
955 INT32 __cdecl
CRTDLL__close(HFILE32 fd
)
957 int ret
=_lclose32(fd
);
959 dprintf_crtdll(stddeb
,"CRTDLL_close(%d)%s\n",fd
,(ret
)?" failed":"");
963 /*********************************************************************
966 INT32 __cdecl
CRTDLL_feof( FILE *stream
)
971 dprintf_crtdll(stddeb
,"CRTDLL_feof(%p) %s\n",stream
,(ret
)?"true":"false");
975 /*********************************************************************
976 * setlocale (CRTDLL.453)
978 LPSTR __cdecl
CRTDLL_setlocale(INT32 category
,LPCSTR locale
)
983 case CRTDLL_LC_ALL
: categorystr
="LC_ALL";break;
984 case CRTDLL_LC_COLLATE
: categorystr
="LC_COLLATE";break;
985 case CRTDLL_LC_CTYPE
: categorystr
="LC_CTYPE";break;
986 case CRTDLL_LC_MONETARY
: categorystr
="LC_MONETARY";break;
987 case CRTDLL_LC_NUMERIC
: categorystr
="LC_NUMERIC";break;
988 case CRTDLL_LC_TIME
: categorystr
="LC_TIME";break;
989 default: categorystr
= "UNKNOWN?";break;
991 fprintf(stderr
,"CRTDLL_setlocale(%s,%s),stub!\n",categorystr
,locale
);
995 /*********************************************************************
996 * wcscat (CRTDLL.503)
998 LPWSTR __cdecl
CRTDLL_wcscat( LPWSTR s1
, LPCWSTR s2
)
1000 return lstrcat32W( s1
, s2
);
1003 /*********************************************************************
1004 * wcschr (CRTDLL.504)
1006 LPWSTR __cdecl
CRTDLL_wcschr(LPWSTR str
,WCHAR xchar
)
1018 /*********************************************************************
1019 * wcscmp (CRTDLL.505)
1021 INT32 __cdecl
CRTDLL_wcscmp( LPCWSTR s1
, LPCWSTR s2
)
1023 return lstrcmp32W( s1
, s2
);
1026 /*********************************************************************
1027 * wcscpy (CRTDLL.507)
1029 LPWSTR __cdecl
CRTDLL_wcscpy( LPWSTR s1
, LPCWSTR s2
)
1031 return lstrcpy32W( s1
, s2
);
1034 /*********************************************************************
1035 * wcscspn (CRTDLL.508)
1037 INT32 __cdecl
CRTDLL_wcscspn(LPWSTR str
,LPWSTR reject
)
1044 while (*t
) { if (*t
==*s
) break;t
++;}
1048 return s
-str
; /* nr of wchars */
1051 /*********************************************************************
1052 * wcslen (CRTDLL.510)
1054 INT32 __cdecl
CRTDLL_wcslen( LPCWSTR s
)
1056 return lstrlen32W( s
);
1059 /*********************************************************************
1060 * wcsncat (CRTDLL.511)
1062 LPWSTR __cdecl
CRTDLL_wcsncat( LPWSTR s1
, LPCWSTR s2
, INT32 n
)
1064 return lstrcatn32W( s1
, s2
, n
);
1067 /*********************************************************************
1068 * wcsncmp (CRTDLL.512)
1070 INT32 __cdecl
CRTDLL_wcsncmp( LPCWSTR s1
, LPCWSTR s2
, INT32 n
)
1072 return lstrncmp32W( s1
, s2
, n
);
1075 /*********************************************************************
1076 * wcsncpy (CRTDLL.513)
1078 LPWSTR __cdecl
CRTDLL_wcsncpy( LPWSTR s1
, LPCWSTR s2
, INT32 n
)
1080 return lstrcpyn32W( s1
, s2
, n
);
1083 /*********************************************************************
1084 * wcsspn (CRTDLL.516)
1086 INT32 __cdecl
CRTDLL_wcsspn(LPWSTR str
,LPWSTR accept
)
1093 while (*t
) { if (*t
==*s
) break;t
++;}
1097 return s
-str
; /* nr of wchars */
1100 /*********************************************************************
1101 * towupper (CRTDLL.494)
1103 WCHAR __cdecl
CRTDLL_towupper(WCHAR x
)
1105 return (WCHAR
)toupper((CHAR
)x
);
1108 /*********************************************************************
1109 * _wcsicmp (CRTDLL.321)
1111 DWORD __cdecl
CRTDLL__wcsicmp( LPCWSTR s1
, LPCWSTR s2
)
1113 return lstrcmpi32W( s1
, s2
);
1116 /*********************************************************************
1117 * _wcsicoll (CRTDLL.322)
1119 DWORD __cdecl
CRTDLL__wcsicoll(LPCWSTR a1
,LPCWSTR a2
)
1121 /* FIXME: handle collates */
1122 return lstrcmpi32W(a1
,a2
);
1125 /*********************************************************************
1126 * _wcsnicmp (CRTDLL.324)
1128 DWORD __cdecl
CRTDLL__wcsnicmp( LPCWSTR s1
, LPCWSTR s2
, INT32 len
)
1130 return lstrncmpi32W( s1
, s2
, len
);
1133 /*********************************************************************
1134 * wcscoll (CRTDLL.506)
1136 DWORD __cdecl
CRTDLL_wcscoll(LPWSTR a1
,LPWSTR a2
)
1138 /* FIXME: handle collates */
1139 return lstrcmp32W(a1
,a2
);
1142 /*********************************************************************
1143 * _wcsrev (CRTDLL.326)
1145 VOID __cdecl
CRTDLL__wcsrev(LPWSTR s
) {
1159 /*********************************************************************
1160 * wcsstr (CRTDLL.517)
1162 LPWSTR __cdecl
CRTDLL_wcsstr(LPWSTR s
,LPWSTR b
)
1170 while (*y
&& *c
&& *y
==*c
) { c
++;y
++; }
1179 /*********************************************************************
1180 * wcstombs (CRTDLL.521)
1182 INT32 __cdecl
CRTDLL_wcstombs( LPSTR dst
, LPCWSTR src
, INT32 len
)
1184 lstrcpynWtoA( dst
, src
, len
);
1185 return strlen(dst
); /* FIXME: is this right? */
1188 /*********************************************************************
1189 * wcsrchr (CRTDLL.515)
1191 LPWSTR __cdecl
CRTDLL_wcsrchr(LPWSTR str
,WCHAR xchar
)
1195 s
=str
+lstrlen32W(str
);
1204 /*********************************************************************
1205 * _setmode (CRTDLL.265)
1206 * FIXME: At present we ignore the request to translate CR/LF to LF.
1208 * We allways translate when we read with fgets, we never do with fread
1211 INT32 __cdecl
CRTDLL__setmode( INT32 fh
,INT32 mode
)
1214 #define O_TEXT 0x4000
1215 #define O_BINARY 0x8000
1217 dprintf_crtdll(stddeb
,
1218 "CRTDLL._setmode on fhandle %d mode %s, STUB.\n",
1219 fh
,(mode
=O_TEXT
)?"O_TEXT":
1220 (mode
=O_BINARY
)?"O_BINARY":"UNKNOWN");
1224 /*********************************************************************
1225 * atexit (CRTDLL.345)
1227 INT32 __cdecl
CRTDLL_atexit(LPVOID x
)
1230 fprintf(stdnimp
,"CRTDLL.atexit(%p), STUB.\n",x
);
1231 return 0; /* successful */
1234 /*********************************************************************
1235 * mblen (CRTDLL.428)
1236 * FIXME: check multibyte support
1238 WCHAR __cdecl
CRTDLL_mblen(CHAR
*mb
,INT32 size
)
1245 else if ((size
<1)||(!*(mb
+1)))
1250 dprintf_crtdll(stderr
,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb
,size
,ret
);
1255 /*********************************************************************
1256 * mbstowcs (CRTDLL.429)
1257 * FIXME: check multibyte support
1259 INT32 __cdecl
CRTDLL_mbstowcs(LPWSTR wcs
, LPCSTR mbs
, INT32 size
)
1262 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1263 * We need the numberr of characters transfered
1264 * FIXME: No multibyte support yet
1271 while ((n
-- > 0) && *src
) {
1272 *p
++ = (WCHAR
)(unsigned char)*src
++;
1277 dprintf_crtdll(stddeb
,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1282 /*********************************************************************
1283 * mbtowc (CRTDLL.430)
1284 * FIXME: check multibyte support
1286 WCHAR __cdecl
CRTDLL_mbtowc(WCHAR
* wc
,CHAR
* mb
,INT32 size
)
1295 if ( (ret
= mblen(mb
,size
)) != -1 )
1297 if (ret
<= sizeof(char))
1298 *wc
= (WCHAR
) ((unsigned char)*mb
);
1305 dprintf_crtdll(stderr
,"CRTDLL_mbtowc %s for %d chars\n",mb
,size
);
1310 /*********************************************************************
1311 * _isctype (CRTDLL.138)
1313 BOOL32 __cdecl
CRTDLL__isctype(CHAR x
,CHAR type
)
1315 if ((type
& CRTDLL_SPACE
) && isspace(x
))
1317 if ((type
& CRTDLL_PUNCT
) && ispunct(x
))
1319 if ((type
& CRTDLL_LOWER
) && islower(x
))
1321 if ((type
& CRTDLL_UPPER
) && isupper(x
))
1323 if ((type
& CRTDLL_ALPHA
) && isalpha(x
))
1325 if ((type
& CRTDLL_DIGIT
) && isdigit(x
))
1327 if ((type
& CRTDLL_CONTROL
) && iscntrl(x
))
1329 /* check CRTDLL_LEADBYTE */
1333 /*********************************************************************
1334 * _chdrive (CRTDLL.52)
1336 BOOL32 __cdecl
CRTDLL__chdrive(INT32 newdrive
)
1338 /* FIXME: generates errnos */
1339 return DRIVE_SetCurrentDrive(newdrive
);
1342 /*********************************************************************
1343 * _chdir (CRTDLL.51)
1345 INT32 __cdecl
CRTDLL__chdir(LPCSTR newdir
)
1347 if (!SetCurrentDirectory32A(newdir
))
1352 /*********************************************************************
1353 * _getcwd (CRTDLL.120)
1355 CHAR
* __cdecl
CRTDLL__getcwd(LPSTR buf
, INT32 size
)
1357 DOS_FULL_NAME full_name
;
1360 dprintf_crtdll(stddeb
,"CRTDLL_getcwd for buf %p size %d\n",
1364 dprintf_crtdll(stderr
,"CRTDLL_getcwd malloc unsupported\n");
1365 printf("CRTDLL_getcwd malloc unsupported\n");
1368 ret
= getcwd(buf
,size
);
1369 if (!DOSFS_GetFullName( buf
, FALSE
, &full_name
))
1371 dprintf_crtdll(stddeb
,"CRTDLL_getcwd failed\n");
1374 if (strlen(full_name
.short_name
)>size
)
1376 dprintf_crtdll(stddeb
,"CRTDLL_getcwd string too long\n");
1379 ret
=strcpy(buf
,full_name
.short_name
);
1381 dprintf_crtdll(stddeb
,"CRTDLL_getcwd returned:%s\n",ret
);
1385 /*********************************************************************
1386 * _mkdir (CRTDLL.234)
1388 INT32 __cdecl
CRTDLL__mkdir(LPCSTR newdir
)
1390 if (!CreateDirectory32A(newdir
,NULL
))
1395 /*********************************************************************
1396 * _errno (CRTDLL.52)
1397 * Yes, this is a function.
1399 LPINT32 __cdecl
CRTDLL__errno()
1401 static int crtdllerrno
;
1402 extern int LastErrorToErrno(DWORD
);
1404 /* FIXME: we should set the error at the failing function call time */
1405 crtdllerrno
= LastErrorToErrno(GetLastError());
1406 return &crtdllerrno
;
1409 /*********************************************************************
1410 * _tempnam (CRTDLL.305)
1413 LPSTR __cdecl
CRTDLL__tempnam(LPCSTR dir
, LPCSTR prefix
)
1417 DOS_FULL_NAME tempname
;
1419 if ((ret
= tempnam(dir
,prefix
))==NULL
) {
1420 dprintf_crtdll(stddeb
,
1421 "CRTDLL_tempnam Unable to get unique filename\n");
1424 if (!DOSFS_GetFullName(ret
,FALSE
,&tempname
))
1426 dprintf_crtdll(stddeb
,
1427 "CRTDLL_tempnam Wrong path?\n");
1431 if ((ret
= CRTDLL_malloc(strlen(tempname
.short_name
)+1)) == NULL
) {
1432 dprintf_crtdll(stddeb
,
1433 "CRTDLL_tempnam CRTDL_malloc for shortname failed\n");
1436 if ((ret
= strcpy(ret
,tempname
.short_name
)) == NULL
) {
1437 dprintf_crtdll(stddeb
,
1438 "CRTDLL_tempnam Malloc for shortname failed\n");
1442 dprintf_crtdll(stddeb
,"CRTDLL_tempnam dir %s prefix %s got %s\n",
1447 /*********************************************************************
1448 * tmpnam (CRTDLL.490)
1450 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1453 LPSTR __cdecl
CRTDLL_tmpnam(LPSTR s
)
1457 if ((ret
=tmpnam(s
))== NULL
) {
1458 dprintf_crtdll(stddeb
,
1459 "CRTDLL_tmpnam Unable to get unique filename\n");
1462 if (!DOSFS_GetFullName(ret
,FALSE
,&CRTDLL_tmpname
))
1464 dprintf_crtdll(stddeb
,
1465 "CRTDLL_tmpnam Wrong path?\n");
1468 strcat(CRTDLL_tmpname
.short_name
,".");
1469 dprintf_crtdll(stddeb
,"CRTDLL_tmpnam for buf %p got %s\n",
1470 s
,CRTDLL_tmpname
.short_name
);
1471 dprintf_crtdll(stddeb
,"CRTDLL_tmpnam long got %s\n",
1472 CRTDLL_tmpname
.long_name
);
1474 return strcpy(s
,CRTDLL_tmpname
.short_name
);
1476 return CRTDLL_tmpname
.short_name
;
1480 /*********************************************************************
1481 * _itoa (CRTDLL.165)
1483 LPSTR __cdecl
CRTDLL__itoa(INT32 x
,LPSTR buf
,INT32 buflen
)
1485 wsnprintf32A(buf
,buflen
,"%d",x
);
1489 typedef VOID (*sig_handler_type
)(VOID
);
1491 /*********************************************************************
1492 * signal (CRTDLL.455)
1494 VOID __cdecl
CRTDLL_signal(int sig
, sig_handler_type ptr
)
1496 dprintf_crtdll(stddeb
,"CRTDLL_signal %d %p: STUB!\n",sig
,ptr
);