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 */
28 #include <sys/times.h>
46 extern int FILE_GetUnixHandle( HFILE32 );
48 static DOS_FULL_NAME CRTDLL_tmpname;
50 extern INT32 WIN32_wsprintf32W( DWORD *args );
52 UINT32 CRTDLL_argc_dll; /* CRTDLL.23 */
53 LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */
54 LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */
55 UINT32 CRTDLL_basemajor_dll; /* CRTDLL.42 */
56 UINT32 CRTDLL_baseminor_dll; /* CRTDLL.43 */
57 UINT32 CRTDLL_baseversion_dll; /* CRTDLL.44 */
58 UINT32 CRTDLL_commode_dll; /* CRTDLL.59 */
59 LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */
60 UINT32 CRTDLL_fmode_dll; /* CRTDLL.104 */
61 UINT32 CRTDLL_osmajor_dll; /* CRTDLL.241 */
62 UINT32 CRTDLL_osminor_dll; /* CRTDLL.242 */
63 UINT32 CRTDLL_osmode_dll; /* CRTDLL.243 */
64 UINT32 CRTDLL_osver_dll; /* CRTDLL.244 */
65 UINT32 CRTDLL_osversion_dll; /* CRTDLL.245 */
66 UINT32 CRTDLL_winmajor_dll; /* CRTDLL.329 */
67 UINT32 CRTDLL_winminor_dll; /* CRTDLL.330 */
68 UINT32 CRTDLL_winver_dll; /* CRTDLL.331 */
70 typedef VOID (*new_handler_type)(VOID);
72 static new_handler_type new_handler;
74 /*********************************************************************
75 * _GetMainArgs (CRTDLL.022)
77 DWORD __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,
78 LPSTR *environ,DWORD flag)
82 int xargc,i,afterlastspace;
85 dprintf_info(crtdll,"CRTDLL__GetMainArgs(%p,%p,%p,%ld).\n",
86 argc,argv,environ,flag
88 CRTDLL_acmdln_dll = cmdline = HEAP_strdupA( GetProcessHeap(), 0,
89 GetCommandLine32A() );
90 dprintf_info(crtdll,"CRTDLL__GetMainArgs got \"%s\"\n",
93 version = GetVersion32();
94 CRTDLL_osver_dll = version >> 16;
95 CRTDLL_winminor_dll = version & 0xFF;
96 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
97 CRTDLL_baseversion_dll = version >> 16;
98 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
99 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
100 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
101 CRTDLL_osversion_dll = version & 0xFFFF;
102 CRTDLL_osminor_dll = version & 0xFF;
103 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
105 /* missing threading init */
107 i=0;xargv=NULL;xargc=0;afterlastspace=0;
109 if (cmdline[i]==' ') {
110 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
111 sizeof(char*)*(++xargc));
113 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
114 cmdline+afterlastspace);
116 while (cmdline[i]==' ')
123 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
124 sizeof(char*)*(++xargc));
126 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
127 cmdline+afterlastspace);
128 CRTDLL_argc_dll = xargc;
130 CRTDLL_argv_dll = xargv;
133 dprintf_info(crtdll,"CRTDLL__GetMainArgs found %d arguments\n",
135 CRTDLL_environ_dll = *environ = GetEnvironmentStrings32A();
140 typedef void (*_INITTERMFUN)();
142 /*********************************************************************
143 * _initterm (CRTDLL.135)
145 DWORD __cdecl CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
147 _INITTERMFUN *current;
149 dprintf_info(crtdll,"_initterm(%p,%p)\n",start,end);
151 while (current<end) {
152 if (*current) (*current)();
158 /*********************************************************************
159 * _fdopen (CRTDLL.91)
161 DWORD __cdecl CRTDLL__fdopen(INT32 handle, LPCSTR mode)
169 case 1 : file=stdout;
171 case 2 : file=stderr;
174 file=fdopen(handle,mode);
177 "CRTDLL_fdopen open handle %d mode %s got file %p\n",
182 /*******************************************************************
183 * _global_unwind2 (CRTDLL.129)
185 void __cdecl CRTDLL__global_unwind2( CONTEXT *context )
187 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
188 DWORD *args = (DWORD *)ESP_reg(context);
189 RtlUnwind( (PEXCEPTION_FRAME)args[1], (LPVOID)EIP_reg(context),
193 /*******************************************************************
194 * _local_unwind2 (CRTDLL.173)
196 void __cdecl CRTDLL__local_unwind2( CONTEXT *context )
198 /* Retrieve the arguments (args[0] is return addr, args[1] is first arg) */
199 DWORD *args = (DWORD *)ESP_reg(context);
200 PEXCEPTION_FRAME endframe = (PEXCEPTION_FRAME)args[1];
202 fprintf(stderr,"CRTDLL__local_unwind2(%p,%ld)\n",endframe,nr);
205 /*********************************************************************
208 DWORD __cdecl CRTDLL_fopen(LPCSTR path, LPCSTR mode)
213 DOS_FULL_NAME full_name;
215 if (!DOSFS_GetFullName( path, FALSE, &full_name )) {
216 dprintf_warn(crtdll, "CRTDLL_fopen file %s bad name\n",path);
220 file=fopen(full_name.long_name ,mode);
225 if ((strchr(mode,'r')&&strchr(mode,'a'))||
226 (strchr(mode,'r')&&strchr(mode,'w'))||
227 (strchr(mode,'w')&&strchr(mode,'a')))
230 if (strstr(mode,"r+")) flagmode=O_RDWR;
231 else if (strchr(mode,'r')) flagmode = O_RDONLY;
232 else if (strstr(mode,"w+")) flagmode= O_RDWR | O_TRUNC | O_CREAT;
233 else if (strchr(mode,'w')) flagmode = O_WRONLY | O_TRUNC | O_CREAT;
234 else if (strstr(mode,"a+")) flagmode= O_RDWR | O_CREAT | O_APPEND;
235 else if (strchr(mode,'w')) flagmode = O_RDWR | O_CREAT | O_APPEND;
236 else if (strchr(mode,'b'))
238 "CRTDLL_fopen %s in BINARY mode\n",path);
240 dos_fildes=FILE_Open(path, flagmode);
241 unix_fildes=FILE_GetUnixHandle(dos_fildes);
242 file = fdopen(unix_fildes,mode);
245 "CRTDLL_fopen file %s mode %s got ufh %d dfh %d file %p\n",
246 path,mode,unix_fildes,dos_fildes,file);
250 /*********************************************************************
253 DWORD __cdecl CRTDLL_fread(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID file)
260 /* If we would honour CR/LF <-> LF translation, we could do it like this.
261 We should keep track of all files opened, and probably files with \
262 known binary extensions must be unchanged */
263 while ( (i < (nmemb*size)) && (ret==1)) {
264 ret=fread(temp,1,1,file);
266 "CRTDLL_fread got %c 0x%02x ret %d\n",
267 (isalpha(*(unsigned char*)temp))? *(unsigned char*)temp:
268 ' ',*(unsigned char*)temp, ret);
269 if (*(unsigned char*)temp != 0xd) { /* skip CR */
274 dprintf_info(crtdll, "CRTDLL_fread skipping ^M\n");
277 "CRTDLL_fread 0x%08x items of size %d from file %p to %p\n",
278 nmemb,size,file,ptr,);
280 dprintf_warn(crtdll, " failed!\n");
285 ret=fread(ptr,size,nmemb,file);
287 "CRTDLL_fread 0x%08x items of size %d from file %p to %p\n",
288 nmemb,size,file,ptr);
290 dprintf_warn(crtdll, " failed!\n");
296 /*********************************************************************
299 LONG __cdecl CRTDLL_fseek(LPVOID stream, LONG offset, INT32 whence)
303 ret=fseek(stream,offset,whence);
305 "CRTDLL_fseek file %p to 0x%08lx pos %s\n",
306 stream,offset,(whence==SEEK_SET)?"SEEK_SET":
307 (whence==SEEK_CUR)?"SEEK_CUR":
308 (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
310 dprintf_warn(crtdll, " failed!\n");
315 /*********************************************************************
318 LONG __cdecl CRTDLL_ftell(LPVOID stream)
324 "CRTDLL_ftell file %p at 0x%08lx\n",
329 /*********************************************************************
330 * fwrite (CRTDLL.386)
332 DWORD __cdecl CRTDLL_fwrite(LPVOID ptr, INT32 size, INT32 nmemb, LPVOID file)
336 ret=fwrite(ptr,size,nmemb,file);
338 "CRTDLL_fwrite 0x%08x items of size %d from %p to file %p\n",
339 nmemb,size,ptr,file);
341 dprintf_warn(crtdll, " Failed!\n");
346 /*********************************************************************
347 * setbuf (CRTDLL.452)
349 INT32 __cdecl CRTDLL_setbuf(LPVOID file, LPSTR buf)
352 "CRTDLL_setbuf(file %p buf %p)\n",
354 /* this doesn't work:"void value not ignored as it ought to be"
355 return setbuf(file,buf);
361 /*********************************************************************
362 * _open_osfhandle (CRTDLL.240)
364 HFILE32 __cdecl CRTDLL__open_osfhandle(LONG osfhandle, INT32 flags)
369 case STD_INPUT_HANDLE :
373 case STD_OUTPUT_HANDLE:
377 case STD_ERROR_HANDLE:
385 "CRTDLL_open_osfhandle(handle %08lx,flags %d) return %d\n",
386 osfhandle,flags,handle);
391 /*********************************************************************
394 void __cdecl CRTDLL_srand(DWORD seed)
396 /* FIXME: should of course be thread? process? local */
400 /*********************************************************************
401 * fprintf (CRTDLL.373)
403 INT32 __cdecl CRTDLL_fprintf( FILE *file, LPSTR format, ... )
408 va_start( valist, format );
409 res = vfprintf( file, format, valist );
414 /*********************************************************************
415 * vfprintf (CRTDLL.373)
417 INT32 __cdecl CRTDLL_vfprintf( FILE *file, LPSTR format, va_list args )
419 return vfprintf( file, format, args );
422 /*********************************************************************
425 time_t __cdecl CRTDLL_time(time_t *timeptr)
427 time_t curtime = time(NULL);
434 /*********************************************************************
437 clock_t __cdecl CRTDLL_clock(void)
443 res = alltimes.tms_utime + alltimes.tms_stime+
444 alltimes.tms_cutime + alltimes.tms_cstime;
445 /* Fixme: We need some symbolic representation
446 for (Hostsystem_)CLOCKS_PER_SEC
447 and (Emulated_system_)CLOCKS_PER_SEC
448 10 holds only for Windows/Linux_i86)
453 /*********************************************************************
454 * _isatty (CRTDLL.137)
456 BOOL32 __cdecl CRTDLL__isatty(DWORD x)
458 dprintf_info(crtdll,"CRTDLL__isatty(%ld)\n",x);
462 /*********************************************************************
463 * _write (CRTDLL.332)
465 INT32 __cdecl CRTDLL__write(INT32 fd,LPCVOID buf,UINT32 count)
472 len = (UINT32)write(fd,buf,(LONG)count);
474 len = _lwrite32(fd,buf,count);
475 dprintf_info(crtdll,"CRTDLL_write %d/%d byte to dfh %d from %p,\n",
481 /*********************************************************************
484 * FIXME: What the heck is the difference between
485 * FIXME _c_exit (CRTDLL.47)
486 * FIXME _cexit (CRTDLL.49)
487 * FIXME _exit (CRTDLL.87)
488 * FIXME exit (CRTDLL.359)
490 * atexit-processing comes to mind -- MW.
493 void __cdecl CRTDLL__cexit(INT32 ret)
495 dprintf_info(crtdll,"CRTDLL__cexit(%d)\n",ret);
500 /*********************************************************************
503 void __cdecl CRTDLL_exit(DWORD ret)
505 dprintf_info(crtdll,"CRTDLL_exit(%ld)\n",ret);
510 /*********************************************************************
511 * _abnormal_termination (CRTDLL.36 )
513 INT32 __cdecl CRTDLL__abnormal_termination(void)
515 dprintf_info(crtdll,"CRTDLL__abnormal_termination\n");
520 /*********************************************************************
521 * fflush (CRTDLL.365)
523 INT32 __cdecl CRTDLL_fflush(LPVOID stream)
527 ret = fflush(stream);
528 dprintf_info(crtdll,"CRTDLL_fflush %p returnd %d\n",stream,ret);
530 dprintf_warn(crtdll, " Failed!\n");
536 /*********************************************************************
539 LPSTR __cdecl CRTDLL_gets(LPSTR buf)
542 /* BAD, for the whole WINE process blocks... just done this way to test
543 * windows95's ftp.exe.
546 dprintf_info(crtdll,"CRTDLL_gets got %s\n",ret);
551 /*********************************************************************
554 INT32 __cdecl CRTDLL_rand()
560 /*********************************************************************
561 * putchar (CRTDLL.442)
563 void __cdecl CRTDLL_putchar( INT32 x )
569 /*********************************************************************
572 INT32 __cdecl CRTDLL_fputc( INT32 c, FILE *stream )
575 "CRTDLL_fputc %c to file %p\n",c,stream);
576 return fputc(c,stream);
580 /*********************************************************************
583 INT32 __cdecl CRTDLL_fputs( LPCSTR s, FILE *stream )
586 "CRTDLL_fputs %s to file %p\n",s,stream);
587 return fputs(s,stream);
591 /*********************************************************************
594 INT32 __cdecl CRTDLL_puts(LPCSTR s)
597 "CRTDLL_fputs %s \n",s);
602 /*********************************************************************
605 INT32 __cdecl CRTDLL_putc(INT32 c, FILE *stream)
608 "CRTDLL_putc %c to file %p\n",c,stream);
609 return fputc(c,stream);
611 /*********************************************************************
614 INT32 __cdecl CRTDLL_fgetc( FILE *stream )
616 int ret= fgetc(stream);
618 "CRTDLL_fgetc got %d\n",ret);
623 /*********************************************************************
626 INT32 __cdecl CRTDLL_getc( FILE *stream )
628 int ret= fgetc(stream);
630 "CRTDLL_getc got %d\n",ret);
634 /*********************************************************************
637 UINT32 __cdecl CRTDLL__rotl(UINT32 x,INT32 shift)
639 unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift));
642 "CRTDLL_rotl got 0x%08x rot %d ret 0x%08x\n",
647 /*********************************************************************
648 * _lrotl (CRTDLL.176)
650 DWORD __cdecl CRTDLL__lrotl(DWORD x,INT32 shift)
652 unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift));
655 "CRTDLL_lrotl got 0x%08lx rot %d ret 0x%08lx\n",
662 /*********************************************************************
665 CHAR* __cdecl CRTDLL_fgets(LPSTR s,INT32 size, LPVOID stream)
670 ret=fgets(s, size,stream);
671 /*FIXME: Control with CRTDLL_setmode */
672 control_M= strrchr(s,'\r');
673 /*delete CR if we read a DOS File */
680 "CRTDLL_fgets got %s for %d chars from file %p\n",
683 dprintf_warn(crtdll, " Failed!\n");
689 /*********************************************************************
690 * _mbsicmp (CRTDLL.204)
692 int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
699 /* FIXME: MBCS handling... */
708 /*********************************************************************
709 * _mbsinc (CRTDLL.205)
711 unsigned char * __cdecl CRTDLL__mbsinc(unsigned char *x)
718 /*********************************************************************
719 * vsprintf (CRTDLL.500)
721 INT32 __cdecl CRTDLL_vsprintf( LPSTR buffer, LPCSTR spec, va_list args )
723 return wvsprintf32A( buffer, spec, args );
726 /*********************************************************************
727 * vswprintf (CRTDLL.501)
729 INT32 __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
731 return wvsprintf32W( buffer, spec, args );
734 /*********************************************************************
735 * _mbscpy (CRTDLL.200)
737 unsigned char* __cdecl CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
739 dprintf_info(crtdll,"CRTDLL_mbscpy %s and %s\n",x,y);
744 /*********************************************************************
745 * _mbscat (CRTDLL.197)
747 unsigned char* __cdecl CRTDLL__mbscat(unsigned char *x,unsigned char *y)
753 /*********************************************************************
754 * _strcmpi (CRTDLL.282) (CRTDLL.287)
756 INT32 __cdecl CRTDLL__strcmpi( LPCSTR s1, LPCSTR s2 )
758 return lstrcmpi32A( s1, s2 );
762 /*********************************************************************
763 * _strnicmp (CRTDLL.293)
765 INT32 __cdecl CRTDLL__strnicmp( LPCSTR s1, LPCSTR s2, INT32 n )
767 return lstrncmpi32A( s1, s2, n );
771 /*********************************************************************
772 * _strlwr (CRTDLL.293)
774 * convert a string in place to lowercase
776 LPSTR CRTDLL__strlwr(LPSTR x)
780 dprintf_info(crtdll, "CRTDLL_strlwr got %s\n", x);
782 if ((*y > 0x40) && (*y< 0x5b))
786 dprintf_info(crtdll, " returned %s\n", x);
791 /*********************************************************************
792 * system (CRTDLL.485)
794 INT32 CRTDLL_system(LPSTR x)
796 #define SYSBUF_LENGTH 1500
797 char buffer[SYSBUF_LENGTH];
798 unsigned char *y = x;
802 sprintf( buffer, "%s \"", Options.argv0 );
803 bp = buffer + strlen(buffer);
804 i = strlen(buffer) + strlen(x) +2;
806 /* Calculate needed buffer size to prevent overflow. */
811 /* If buffer too short, exit. */
812 if (i > SYSBUF_LENGTH) {
813 dprintf_info(crtdll,"_system buffer to small\n");
822 if (*(y-1) =='\\') *bp++ = '\\';
824 /* Remove spaces from end of string. */
825 while (*(y-1) == ' ') {
831 "_system got \"%s\", executing \"%s\"\n",x,buffer);
833 return system(buffer);
836 /*********************************************************************
837 * _strupr (CRTDLL.300)
839 LPSTR __cdecl CRTDLL__strupr(LPSTR x)
850 /*********************************************************************
851 * _wcsupr (CRTDLL.328)
853 LPWSTR __cdecl CRTDLL__wcsupr(LPWSTR x)
864 /*********************************************************************
865 * _wcslwr (CRTDLL.323)
867 LPWSTR __cdecl CRTDLL__wcslwr(LPWSTR x)
879 /*********************************************************************
880 * longjmp (CRTDLL.426)
882 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
884 dprintf_fixme(crtdll,"CRTDLL_longjmp semistup, expect crash\n");
885 return longjmp(env, val);
888 /*********************************************************************
889 * malloc (CRTDLL.427)
891 VOID* __cdecl CRTDLL_malloc(DWORD size)
893 return HeapAlloc(GetProcessHeap(),0,size);
896 /*********************************************************************
899 VOID* __cdecl CRTDLL_new(DWORD size)
902 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
907 /*********************************************************************
908 * set_new_handler(CRTDLL.003)
910 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
912 new_handler_type old_handler = new_handler;
917 /*********************************************************************
918 * calloc (CRTDLL.350)
920 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
922 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
925 /*********************************************************************
926 * realloc (CRTDLL.447)
928 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
930 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
933 /*********************************************************************
936 VOID __cdecl CRTDLL_free(LPVOID ptr)
938 HeapFree(GetProcessHeap(),0,ptr);
941 /*********************************************************************
942 * delete (CRTDLL.002)
944 VOID __cdecl CRTDLL_delete(VOID* ptr)
946 HeapFree(GetProcessHeap(),0,ptr);
949 /*********************************************************************
950 * _strdup (CRTDLL.285)
952 LPSTR __cdecl CRTDLL__strdup(LPSTR ptr)
954 return HEAP_strdupA(GetProcessHeap(),0,ptr);
958 /*********************************************************************
959 * fclose (CRTDLL.362)
961 INT32 __cdecl CRTDLL_fclose( FILE *stream )
963 int unix_handle=fileno(stream);
964 HFILE32 dos_handle=1;
967 if (unix_handle<4) ret= fclose(stream);
969 while(FILE_GetUnixHandle(dos_handle) != unix_handle) dos_handle++;
971 ret = _lclose32( dos_handle);
973 dprintf_info(crtdll,"CRTDLL_fclose(%p) ufh %d dfh %d\n",
974 stream,unix_handle,dos_handle);
977 dprintf_warn(crtdll, " Failed!\n");
982 /*********************************************************************
983 * _unlink (CRTDLL.315)
985 INT32 __cdecl CRTDLL__unlink(LPCSTR pathname)
988 DOS_FULL_NAME full_name;
990 if (!DOSFS_GetFullName( pathname, FALSE, &full_name )) {
991 dprintf_warn(crtdll, "CRTDLL_unlink file %s bad name\n",pathname);
995 ret=unlink(full_name.long_name);
996 dprintf_info(crtdll,"CRTDLL_unlink(%s unix %s)\n",
997 pathname,full_name.long_name);
999 dprintf_warn(crtdll, " Failed!\n");
1004 /*********************************************************************
1005 * rename (CRTDLL.449)
1007 INT32 __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
1009 BOOL32 ok = MoveFileEx32A( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
1014 /*********************************************************************
1015 * _stat (CRTDLL.280)
1033 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
1036 DOS_FULL_NAME full_name;
1039 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1041 dprintf_warn(crtdll, "CRTDLL__stat filename %s bad name\n",filename);
1044 ret=stat(full_name.long_name,&mystat);
1045 dprintf_info(crtdll,"CRTDLL__stat %s\n", filename);
1047 dprintf_warn(crtdll, " Failed!\n");
1049 /* FIXME: should check what Windows returns */
1051 buf->win_st_dev = mystat.st_dev;
1052 buf->win_st_ino = mystat.st_ino;
1053 buf->win_st_mode = mystat.st_mode;
1054 buf->win_st_nlink = mystat.st_nlink;
1055 buf->win_st_uid = mystat.st_uid;
1056 buf->win_st_gid = mystat.st_gid;
1057 buf->win_st_rdev = mystat.st_rdev;
1058 buf->win_st_size = mystat.st_size;
1059 buf->win_st_atime = mystat.st_atime;
1060 buf->win_st_mtime = mystat.st_mtime;
1061 buf->win_st_ctime = mystat.st_ctime;
1065 /*********************************************************************
1066 * _open (CRTDLL.239)
1068 HFILE32 __cdecl CRTDLL__open(LPCSTR path,INT32 flags)
1074 the flags in lcc's header differ from the ones in Linux, e.g.
1075 Linux: define O_APPEND 02000 (= 0x400)
1076 lcc: define _O_APPEND 0x0008
1077 so here a scheme to translate them
1078 Probably lcc is wrong here, but at least a hack to get is going
1080 wineflags = (flags & 3);
1081 if (flags & 0x0008 ) wineflags |= O_APPEND;
1082 if (flags & 0x0100 ) wineflags |= O_CREAT;
1083 if (flags & 0x0200 ) wineflags |= O_TRUNC;
1084 if (flags & 0x0400 ) wineflags |= O_EXCL;
1085 if (flags & 0xf0f4 )
1086 dprintf_info(crtdll,"CRTDLL_open file unsupported flags 0x%04x\n",flags);
1089 ret = FILE_Open(path,wineflags);
1090 dprintf_info(crtdll,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
1091 path,wineflags,flags,ret);
1095 /*********************************************************************
1096 * _close (CRTDLL.57)
1098 INT32 __cdecl CRTDLL__close(HFILE32 fd)
1100 int ret=_lclose32(fd);
1102 dprintf_info(crtdll,"CRTDLL_close(%d)\n",fd);
1104 dprintf_warn(crtdll, " Failed!\n");
1109 /*********************************************************************
1112 INT32 __cdecl CRTDLL_feof( FILE *stream )
1117 dprintf_info(crtdll,"CRTDLL_feof(%p) %s\n",stream,(ret)?"true":"false");
1121 /*********************************************************************
1122 * setlocale (CRTDLL.453)
1124 LPSTR __cdecl CRTDLL_setlocale(INT32 category,LPCSTR locale)
1129 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1130 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1131 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1132 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1133 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1134 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1135 default: categorystr = "UNKNOWN?";break;
1137 fprintf(stderr,"CRTDLL_setlocale(%s,%s),stub!\n",categorystr,locale);
1141 /*********************************************************************
1142 * wcscat (CRTDLL.503)
1144 LPWSTR __cdecl CRTDLL_wcscat( LPWSTR s1, LPCWSTR s2 )
1146 return lstrcat32W( s1, s2 );
1149 /*********************************************************************
1150 * wcschr (CRTDLL.504)
1152 LPWSTR __cdecl CRTDLL_wcschr(LPCWSTR str,WCHAR xchar)
1164 /*********************************************************************
1165 * wcscmp (CRTDLL.505)
1167 INT32 __cdecl CRTDLL_wcscmp( LPCWSTR s1, LPCWSTR s2 )
1169 return lstrcmp32W( s1, s2 );
1172 /*********************************************************************
1173 * wcscpy (CRTDLL.507)
1175 LPWSTR __cdecl CRTDLL_wcscpy( LPWSTR s1, LPCWSTR s2 )
1177 return lstrcpy32W( s1, s2 );
1180 /*********************************************************************
1181 * wcscspn (CRTDLL.508)
1183 INT32 __cdecl CRTDLL_wcscspn(LPWSTR str,LPWSTR reject)
1190 while (*t) { if (*t==*s) break;t++;}
1194 return s-str; /* nr of wchars */
1197 /*********************************************************************
1198 * wcslen (CRTDLL.510)
1200 INT32 __cdecl CRTDLL_wcslen( LPCWSTR s )
1202 return lstrlen32W( s );
1205 /*********************************************************************
1206 * wcsncat (CRTDLL.511)
1208 LPWSTR __cdecl CRTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT32 n )
1210 return lstrcatn32W( s1, s2, n );
1213 /*********************************************************************
1214 * wcsncmp (CRTDLL.512)
1216 INT32 __cdecl CRTDLL_wcsncmp( LPCWSTR s1, LPCWSTR s2, INT32 n )
1218 return lstrncmp32W( s1, s2, n );
1221 /*********************************************************************
1222 * wcsncpy (CRTDLL.513)
1224 LPWSTR __cdecl CRTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT32 n )
1226 return lstrcpyn32W( s1, s2, n );
1229 /*********************************************************************
1230 * wcsspn (CRTDLL.516)
1232 INT32 __cdecl CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
1239 while (*t) { if (*t==*s) break;t++;}
1243 return s-str; /* nr of wchars */
1246 /*********************************************************************
1247 * towupper (CRTDLL.494)
1249 WCHAR __cdecl CRTDLL_towupper(WCHAR x)
1251 return (WCHAR)toupper((CHAR)x);
1254 /*********************************************************************
1255 * _wcsicmp (CRTDLL.321)
1257 DWORD __cdecl CRTDLL__wcsicmp( LPCWSTR s1, LPCWSTR s2 )
1259 return lstrcmpi32W( s1, s2 );
1262 /*********************************************************************
1263 * _wcsicoll (CRTDLL.322)
1265 DWORD __cdecl CRTDLL__wcsicoll(LPCWSTR a1,LPCWSTR a2)
1267 /* FIXME: handle collates */
1268 return lstrcmpi32W(a1,a2);
1271 /*********************************************************************
1272 * _wcsnicmp (CRTDLL.324)
1274 DWORD __cdecl CRTDLL__wcsnicmp( LPCWSTR s1, LPCWSTR s2, INT32 len )
1276 return lstrncmpi32W( s1, s2, len );
1279 /*********************************************************************
1280 * wcscoll (CRTDLL.506)
1282 DWORD __cdecl CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
1284 /* FIXME: handle collates */
1285 return lstrcmp32W(a1,a2);
1288 /*********************************************************************
1289 * _wcsrev (CRTDLL.326)
1291 VOID __cdecl CRTDLL__wcsrev(LPWSTR s) {
1305 /*********************************************************************
1306 * wcsstr (CRTDLL.517)
1308 LPWSTR __cdecl CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
1316 while (*y && *c && *y==*c) { c++;y++; }
1325 /*********************************************************************
1326 * wcstombs (CRTDLL.521)
1328 INT32 __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT32 len )
1330 lstrcpynWtoA( dst, src, len );
1331 return strlen(dst); /* FIXME: is this right? */
1334 /*********************************************************************
1335 * wcsrchr (CRTDLL.515)
1337 LPWSTR __cdecl CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
1341 s=str+lstrlen32W(str);
1350 /*********************************************************************
1351 * _setmode (CRTDLL.265)
1352 * FIXME: At present we ignore the request to translate CR/LF to LF.
1354 * We allways translate when we read with fgets, we never do with fread
1357 INT32 __cdecl CRTDLL__setmode( INT32 fh,INT32 mode)
1360 #define O_TEXT 0x4000
1361 #define O_BINARY 0x8000
1363 dprintf_fixme(crtdll, "CRTDLL._setmode on fhandle %d mode %s, STUB.\n",
1364 fh,(mode=O_TEXT)?"O_TEXT":
1365 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1369 /*********************************************************************
1370 * atexit (CRTDLL.345)
1372 INT32 __cdecl CRTDLL_atexit(LPVOID x)
1375 fprintf(stdnimp,"CRTDLL.atexit(%p), STUB.\n",x);
1376 return 0; /* successful */
1379 /*********************************************************************
1380 * mblen (CRTDLL.428)
1381 * FIXME: check multibyte support
1383 WCHAR __cdecl CRTDLL_mblen(CHAR *mb,INT32 size)
1390 else if ((size<1)||(!*(mb+1)))
1395 dprintf_info(crtdll,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb,size,ret);
1400 /*********************************************************************
1401 * mbstowcs (CRTDLL.429)
1402 * FIXME: check multibyte support
1404 INT32 __cdecl CRTDLL_mbstowcs(LPWSTR wcs, LPCSTR mbs, INT32 size)
1407 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1408 * We need the number of characters transfered
1409 * FIXME: No multibyte support yet
1416 while ((n-- > 0) && *src) {
1417 *p++ = (WCHAR)(unsigned char)*src++;
1422 dprintf_info(crtdll,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1427 /*********************************************************************
1428 * mbtowc (CRTDLL.430)
1429 * FIXME: check multibyte support
1431 WCHAR __cdecl CRTDLL_mbtowc(WCHAR* wc,CHAR* mb,INT32 size)
1440 if ( (ret = mblen(mb,size)) != -1 )
1442 if (ret <= sizeof(char))
1443 *wc = (WCHAR) ((unsigned char)*mb);
1450 dprintf_info(crtdll,"CRTDLL_mbtowc %s for %d chars\n",mb,size);
1455 /*********************************************************************
1456 * _isctype (CRTDLL.138)
1458 BOOL32 __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1460 if ((type & CRTDLL_SPACE) && isspace(x))
1462 if ((type & CRTDLL_PUNCT) && ispunct(x))
1464 if ((type & CRTDLL_LOWER) && islower(x))
1466 if ((type & CRTDLL_UPPER) && isupper(x))
1468 if ((type & CRTDLL_ALPHA) && isalpha(x))
1470 if ((type & CRTDLL_DIGIT) && isdigit(x))
1472 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1474 /* check CRTDLL_LEADBYTE */
1478 /*********************************************************************
1479 * _chdrive (CRTDLL.52)
1481 BOOL32 __cdecl CRTDLL__chdrive(INT32 newdrive)
1483 /* FIXME: generates errnos */
1484 return DRIVE_SetCurrentDrive(newdrive);
1487 /*********************************************************************
1488 * _chdir (CRTDLL.51)
1490 INT32 __cdecl CRTDLL__chdir(LPCSTR newdir)
1492 if (!SetCurrentDirectory32A(newdir))
1497 /*********************************************************************
1498 * _fullpath (CRTDLL.114)
1500 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT32 size)
1502 DOS_FULL_NAME full_name;
1507 if(!(buf = CRTDLL_malloc(size))) return NULL;
1509 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1510 lstrcpyn32A(buf,full_name.short_name,size);
1511 dprintf_info(crtdll,"CRTDLL_fullpath got %s\n",buf);
1515 /*********************************************************************
1516 * _splitpath (CRTDLL.279)
1518 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1521 directory includes leading and trailing (forward and backward slashes)
1522 filename without dot and slashes
1523 extension with leading dot
1525 char * drivechar,*dirchar,*namechar;
1527 dprintf_info(crtdll,"CRTDLL__splitpath got %s\n",path);
1529 drivechar = strchr(path,':');
1530 dirchar = strrchr(path,'/');
1531 namechar = strrchr(path,'\\');
1532 dirchar = MAX(dirchar,namechar);
1534 namechar = strrchr(dirchar,'.');
1536 namechar = strrchr(path,'.');
1544 strncat(drive,path,drivechar-path+1);
1553 strncat(directory,path,dirchar-path+1);
1562 strncat(filename,path,namechar-path);
1566 strcat(extension,namechar);
1571 dprintf_info(crtdll,"CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1575 /*********************************************************************
1576 * _getcwd (CRTDLL.120)
1578 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT32 size)
1585 if (size < 0) /* allocate as big as nescessary */
1586 len =GetCurrentDirectory32A(1,test) + 1;
1587 if(!(buf = CRTDLL_malloc(len)))
1589 /* set error to OutOfRange */
1594 if(!(len =GetCurrentDirectory32A(len,buf)))
1600 /* set error to ERANGE */
1601 dprintf_info(crtdll,"CRTDLL_getcwd buffer to small\n");
1608 /*********************************************************************
1609 * _mkdir (CRTDLL.234)
1611 INT32 __cdecl CRTDLL__mkdir(LPCSTR newdir)
1613 if (!CreateDirectory32A(newdir,NULL))
1618 /*********************************************************************
1619 * _errno (CRTDLL.52)
1620 * Yes, this is a function.
1622 LPINT32 __cdecl CRTDLL__errno()
1624 static int crtdllerrno;
1625 extern int LastErrorToErrno(DWORD);
1627 /* FIXME: we should set the error at the failing function call time */
1628 crtdllerrno = LastErrorToErrno(GetLastError());
1629 return &crtdllerrno;
1632 /*********************************************************************
1633 * _tempnam (CRTDLL.305)
1636 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1640 DOS_FULL_NAME tempname;
1642 if ((ret = tempnam(dir,prefix))==NULL) {
1643 dprintf_warn(crtdll, "Unable to get unique filename\n");
1646 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1648 dprintf_info(crtdll,
1649 "CRTDLL_tempnam Wrong path?\n");
1653 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1654 dprintf_warn(crtdll,
1655 "CRTDLL_tempnam CRTDL_malloc for shortname failed\n");
1658 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1659 dprintf_warn(crtdll,
1660 "CRTDLL_tempnam Malloc for shortname failed\n");
1664 dprintf_info(crtdll,"CRTDLL_tempnam dir %s prefix %s got %s\n",
1669 /*********************************************************************
1670 * tmpnam (CRTDLL.490)
1672 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1675 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1679 if ((ret =tmpnam(s))== NULL) {
1680 dprintf_warn(crtdll, "Unable to get unique filename\n");
1683 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1685 dprintf_info(crtdll,
1686 "CRTDLL_tmpnam Wrong path?\n");
1689 strcat(CRTDLL_tmpname.short_name,".");
1690 dprintf_info(crtdll,"CRTDLL_tmpnam for buf %p got %s\n",
1691 s,CRTDLL_tmpname.short_name);
1692 dprintf_info(crtdll,"CRTDLL_tmpnam long got %s\n",
1693 CRTDLL_tmpname.long_name);
1695 return strcpy(s,CRTDLL_tmpname.short_name);
1697 return CRTDLL_tmpname.short_name;
1701 /*********************************************************************
1702 * _itoa (CRTDLL.165)
1704 LPSTR __cdecl CRTDLL__itoa(INT32 x,LPSTR buf,INT32 buflen)
1706 wsnprintf32A(buf,buflen,"%d",x);
1710 typedef VOID (*sig_handler_type)(VOID);
1712 /*********************************************************************
1713 * signal (CRTDLL.455)
1715 VOID __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
1717 dprintf_fixme(crtdll, "CRTDLL_signal %d %p: STUB!\n", sig, ptr);
1720 /*********************************************************************
1721 * _ftol (CRTDLL.113)
1723 LONG __cdecl CRTDLL__ftol(double fl) {
1726 /*********************************************************************
1727 * _sleep (CRTDLL.267)
1729 VOID __cdecl CRTDLL__sleep(unsigned long timeout)
1731 dprintf_info(crtdll,"CRTDLL__sleep for %ld milliseconds\n",timeout);
1732 Sleep((timeout)?timeout:1);