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 DEFAULT_DEBUG_CHANNEL(crtdll)
56 /* windows.h RAND_MAX is smaller than normal RAND_MAX */
57 #define CRTDLL_RAND_MAX 0x7fff
59 static DOS_FULL_NAME CRTDLL_tmpname;
61 UINT CRTDLL_argc_dll; /* CRTDLL.23 */
62 LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */
63 LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */
64 UINT CRTDLL_basemajor_dll; /* CRTDLL.42 */
65 UINT CRTDLL_baseminor_dll; /* CRTDLL.43 */
66 UINT CRTDLL_baseversion_dll; /* CRTDLL.44 */
67 UINT CRTDLL_commode_dll; /* CRTDLL.59 */
68 LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */
69 UINT CRTDLL_fmode_dll; /* CRTDLL.104 */
70 UINT CRTDLL_osmajor_dll; /* CRTDLL.241 */
71 UINT CRTDLL_osminor_dll; /* CRTDLL.242 */
72 UINT CRTDLL_osmode_dll; /* CRTDLL.243 */
73 UINT CRTDLL_osver_dll; /* CRTDLL.244 */
74 UINT CRTDLL_osversion_dll; /* CRTDLL.245 */
75 UINT CRTDLL_winmajor_dll; /* CRTDLL.329 */
76 UINT CRTDLL_winminor_dll; /* CRTDLL.330 */
77 UINT CRTDLL_winver_dll; /* CRTDLL.331 */
79 /* FIXME: structure layout is obviously not correct */
86 CRTDLL_FILE CRTDLL_iob[3];
88 static CRTDLL_FILE * const CRTDLL_stdin = &CRTDLL_iob[0];
89 static CRTDLL_FILE * const CRTDLL_stdout = &CRTDLL_iob[1];
90 static CRTDLL_FILE * const CRTDLL_stderr = &CRTDLL_iob[2];
92 typedef VOID (*new_handler_type)(VOID);
94 static new_handler_type new_handler;
96 #if defined(__GNUC__) && defined(__i386__)
97 #define USING_REAL_FPU
98 #define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
99 #define POP_FPU(x) DO_FPU("fstpl",x)
102 /*********************************************************************
103 * _GetMainArgs (CRTDLL.022)
105 DWORD __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,
106 LPSTR *environ,DWORD flag)
110 int xargc,i,afterlastspace;
113 TRACE(crtdll,"(%p,%p,%p,%ld).\n",
114 argc,argv,environ,flag
116 CRTDLL_acmdln_dll = cmdline = HEAP_strdupA( GetProcessHeap(), 0,
118 TRACE(crtdll,"got '%s'\n", cmdline);
120 version = GetVersion();
121 CRTDLL_osver_dll = version >> 16;
122 CRTDLL_winminor_dll = version & 0xFF;
123 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
124 CRTDLL_baseversion_dll = version >> 16;
125 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
126 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
127 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
128 CRTDLL_osversion_dll = version & 0xFFFF;
129 CRTDLL_osminor_dll = version & 0xFF;
130 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
132 /* missing threading init */
134 i=0;xargv=NULL;xargc=0;afterlastspace=0;
136 if (cmdline[i]==' ') {
137 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
138 sizeof(char*)*(++xargc));
140 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
141 cmdline+afterlastspace);
143 while (cmdline[i]==' ')
150 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
151 sizeof(char*)*(++xargc));
153 xargv[xargc-1] = HEAP_strdupA( GetProcessHeap(), 0,
154 cmdline+afterlastspace);
155 CRTDLL_argc_dll = xargc;
157 CRTDLL_argv_dll = xargv;
160 TRACE(crtdll,"found %d arguments\n",
162 CRTDLL_environ_dll = *environ = GetEnvironmentStringsA();
167 typedef void (*_INITTERMFUN)();
169 /* fixme: move to header */
172 time_t time_create; /* -1 when not avaiable */
173 time_t time_access; /* -1 when not avaiable */
175 unsigned long size; /* fixme: 64 bit ??*/
178 /*********************************************************************
179 * _findfirst (CRTDLL.099)
184 DWORD __cdecl CRTDLL__findfirst(LPCSTR fname, struct find_t * x2)
186 FIXME(crtdll, ":(%s,%p): stub\n",fname,x2);
187 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
191 /*********************************************************************
192 * _findnext (CRTDLL.100)
197 INT __cdecl CRTDLL__findnext(DWORD hand, struct find_t * x2)
199 FIXME(crtdll, ":(%ld,%p): stub\n",hand,x2);
200 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
204 /*********************************************************************
205 * _fstat (CRTDLL.111)
210 int __cdecl CRTDLL__fstat(int file, struct stat* buf)
212 FIXME(crtdll, ":(%d,%p): stub\n",file,buf);
213 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
217 /*********************************************************************
218 * _initterm (CRTDLL.135)
220 DWORD __cdecl CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
222 _INITTERMFUN *current;
224 TRACE(crtdll,"(%p,%p)\n",start,end);
226 while (current<end) {
227 if (*current) (*current)();
233 /*********************************************************************
234 * _fdopen (CRTDLL.91)
236 CRTDLL_FILE * __cdecl CRTDLL__fdopen(INT handle, LPCSTR mode)
244 if (!file->handle) file->handle = GetStdHandle( STD_INPUT_HANDLE );
247 file = CRTDLL_stdout;
248 if (!file->handle) file->handle = GetStdHandle( STD_OUTPUT_HANDLE );
252 if (!file->handle) file->handle = GetStdHandle( STD_ERROR_HANDLE );
255 file = HeapAlloc( GetProcessHeap(), 0, sizeof(*file) );
256 file->handle = handle;
259 TRACE(crtdll, "open handle %d mode %s got file %p\n",
265 /*******************************************************************
266 * _global_unwind2 (CRTDLL.129)
268 void __cdecl CRTDLL__global_unwind2( PEXCEPTION_FRAME frame )
270 RtlUnwind( frame, 0, NULL, 0 );
273 /*******************************************************************
274 * _local_unwind2 (CRTDLL.173)
276 void __cdecl CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe, DWORD nr )
278 TRACE(crtdll,"(%p,%ld)\n",endframe,nr);
280 /*********************************************************************
286 INT __cdecl CRTDLL__read(INT fd, LPVOID buf, UINT count)
288 FIXME(crtdll,":(%d,%p,%d): stub\n",fd,buf,count);
289 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
293 /*********************************************************************
296 CRTDLL_FILE * __cdecl CRTDLL_fopen(LPCSTR path, LPCSTR mode)
298 CRTDLL_FILE *file = NULL;
301 DOS_FULL_NAME full_name;
303 if (!DOSFS_GetFullName( path, FALSE, &full_name )) {
304 WARN(crtdll, "file %s bad name\n",path);
308 file=fopen(full_name.long_name ,mode);
310 DWORD access = 0, creation = 0;
312 if ((strchr(mode,'r')&&strchr(mode,'a'))||
313 (strchr(mode,'r')&&strchr(mode,'w'))||
314 (strchr(mode,'w')&&strchr(mode,'a')))
319 access = GENERIC_READ;
320 creation = OPEN_EXISTING;
321 if (mode[1] == '+') access |= GENERIC_WRITE;
323 else if (mode[0] == 'w')
325 access = GENERIC_WRITE;
326 creation = CREATE_ALWAYS;
327 if (mode[1] == '+') access |= GENERIC_READ;
329 else if (mode[0] == 'a')
331 /* FIXME: there is no O_APPEND in CreateFile, should emulate it */
332 access = GENERIC_WRITE;
333 creation = OPEN_ALWAYS;
334 if (mode[1] == '+') access |= GENERIC_READ;
336 /* FIXME: should handle text/binary mode */
338 if ((handle = CreateFileA( path, access, FILE_SHARE_READ | FILE_SHARE_WRITE,
339 NULL, creation, FILE_ATTRIBUTE_NORMAL,
340 -1 )) != INVALID_HANDLE_VALUE)
342 file = HeapAlloc( GetProcessHeap(), 0, sizeof(*file) );
343 file->handle = handle;
345 TRACE(crtdll, "file %s mode %s got handle %d file %p\n",
346 path,mode,handle,file);
350 /*********************************************************************
353 DWORD __cdecl CRTDLL_fread(LPVOID ptr, INT size, INT nmemb, CRTDLL_FILE *file)
359 /* If we would honour CR/LF <-> LF translation, we could do it like this.
360 We should keep track of all files opened, and probably files with \
361 known binary extensions must be unchanged */
362 while ( (i < (nmemb*size)) && (ret==1)) {
363 ret=fread(temp,1,1,file);
364 TRACE(crtdll, "got %c 0x%02x ret %d\n",
365 (isalpha(*(unsigned char*)temp))? *(unsigned char*)temp:
366 ' ',*(unsigned char*)temp, ret);
367 if (*(unsigned char*)temp != 0xd) { /* skip CR */
372 TRACE(crtdll, "skipping ^M\n");
374 TRACE(crtdll, "0x%08x items of size %d from file %p to %p\n",
375 nmemb,size,file,ptr,);
377 WARN(crtdll, " failed!\n");
383 TRACE(crtdll, "0x%08x items of size %d from file %p to %p\n",
384 nmemb,size,file,ptr);
385 if (!ReadFile( file->handle, ptr, size * nmemb, &ret, NULL ))
386 WARN(crtdll, " failed!\n");
391 /*********************************************************************
392 * freopen (CRTDLL.379)
397 DWORD __cdecl CRTDLL_freopen(LPCSTR path, LPCSTR mode, LPVOID stream)
399 FIXME(crtdll, ":(%s,%s,%p): stub\n", path, mode, stream);
400 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
404 /*********************************************************************
405 * fscanf (CRTDLL.381)
407 INT __cdecl CRTDLL_fscanf( CRTDLL_FILE *stream, LPSTR format, ... )
413 va_start( valist, format );
415 res = vfscanf( xlat_file_ptr(stream), format, valist );
420 FIXME(crtdll,"broken\n");
424 /*********************************************************************
427 LONG __cdecl CRTDLL_fseek( CRTDLL_FILE *file, LONG offset, INT whence)
429 TRACE(crtdll, "file %p to 0x%08lx pos %s\n",
430 file,offset,(whence==SEEK_SET)?"SEEK_SET":
431 (whence==SEEK_CUR)?"SEEK_CUR":
432 (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
433 if (SetFilePointer( file->handle, offset, NULL, whence ) != 0xffffffff)
435 WARN(crtdll, " failed!\n");
439 /*********************************************************************
440 * fsetpos (CRTDLL.383)
442 INT __cdecl CRTDLL_fsetpos( CRTDLL_FILE *file, INT *pos )
444 TRACE(crtdll, "file %p pos %d\n", file, *pos );
445 return CRTDLL_fseek(file, *pos, SEEK_SET);
448 /*********************************************************************
451 LONG __cdecl CRTDLL_ftell( CRTDLL_FILE *file )
453 return SetFilePointer( file->handle, 0, NULL, SEEK_CUR );
456 /*********************************************************************
457 * fwrite (CRTDLL.386)
459 DWORD __cdecl CRTDLL_fwrite( LPVOID ptr, INT size, INT nmemb, CRTDLL_FILE *file )
463 TRACE(crtdll, "0x%08x items of size %d to file %p from %p\n",
464 nmemb,size,file,ptr);
465 if (!WriteFile( file->handle, ptr, size * nmemb, &ret, NULL ))
466 WARN(crtdll, " failed!\n");
470 /*********************************************************************
471 * setbuf (CRTDLL.452)
473 INT __cdecl CRTDLL_setbuf(CRTDLL_FILE *file, LPSTR buf)
475 TRACE(crtdll, "(file %p buf %p)\n", file, buf);
476 /* this doesn't work:"void value not ignored as it ought to be"
477 return setbuf(file,buf);
479 /* FIXME: no buffering for now */
483 /*********************************************************************
484 * _open_osfhandle (CRTDLL.240)
486 HFILE __cdecl CRTDLL__open_osfhandle(LONG osfhandle, INT flags)
491 case STD_INPUT_HANDLE :
495 case STD_OUTPUT_HANDLE:
499 case STD_ERROR_HANDLE:
506 TRACE(crtdll, "(handle %08lx,flags %d) return %d\n",
507 osfhandle,flags,handle);
512 /*********************************************************************
515 void __cdecl CRTDLL_srand(DWORD seed)
517 /* FIXME: should of course be thread? process? local */
521 /*********************************************************************
522 * vfprintf (CRTDLL.373)
524 INT __cdecl CRTDLL_vfprintf( CRTDLL_FILE *file, LPSTR format, va_list args )
526 char buffer[1024]; /* FIXME... */
528 vsprintf( buffer, format, args );
529 return CRTDLL_fwrite( buffer, 1, strlen(buffer), file );
532 /*********************************************************************
533 * fprintf (CRTDLL.373)
535 INT __cdecl CRTDLL_fprintf( CRTDLL_FILE *file, LPSTR format, ... )
540 va_start( valist, format );
541 res = CRTDLL_vfprintf( file, format, valist );
546 /*********************************************************************
549 time_t __cdecl CRTDLL_time(time_t *timeptr)
551 time_t curtime = time(NULL);
558 /*********************************************************************
561 clock_t __cdecl CRTDLL_clock(void)
567 res = alltimes.tms_utime + alltimes.tms_stime+
568 alltimes.tms_cutime + alltimes.tms_cstime;
569 /* Fixme: We need some symbolic representation
570 for (Hostsystem_)CLOCKS_PER_SEC
571 and (Emulated_system_)CLOCKS_PER_SEC
572 10 holds only for Windows/Linux_i86)
577 /*********************************************************************
578 * _isatty (CRTDLL.137)
580 BOOL __cdecl CRTDLL__isatty(DWORD x)
582 TRACE(crtdll,"(%ld)\n",x);
586 /*********************************************************************
587 * _write (CRTDLL.332)
589 INT __cdecl CRTDLL__write(INT fd,LPCVOID buf,UINT count)
596 len = (UINT)write(fd,buf,(LONG)count);
598 len = _lwrite(fd,buf,count);
599 TRACE(crtdll,"%d/%d byte to dfh %d from %p,\n",
605 /*********************************************************************
608 * FIXME: What the heck is the difference between
609 * FIXME _c_exit (CRTDLL.47)
610 * FIXME _cexit (CRTDLL.49)
611 * FIXME _exit (CRTDLL.87)
612 * FIXME exit (CRTDLL.359)
614 * atexit-processing comes to mind -- MW.
617 void __cdecl CRTDLL__cexit(INT ret)
619 TRACE(crtdll,"(%d)\n",ret);
624 /*********************************************************************
627 void __cdecl CRTDLL_exit(DWORD ret)
629 TRACE(crtdll,"(%ld)\n",ret);
634 /*********************************************************************
635 * _abnormal_termination (CRTDLL.36)
637 INT __cdecl CRTDLL__abnormal_termination(void)
639 TRACE(crtdll,"(void)\n");
644 /*********************************************************************
645 * _access (CRTDLL.37)
647 INT __cdecl CRTDLL__access(LPCSTR filename, INT mode)
649 DWORD attr = GetFileAttributesA(filename);
653 if (GetLastError() == ERROR_INVALID_ACCESS)
660 if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
670 /*********************************************************************
671 * fflush (CRTDLL.365)
673 INT __cdecl CRTDLL_fflush( CRTDLL_FILE *file )
675 return FlushFileBuffers( file->handle ) ? 0 : -1;
679 /*********************************************************************
682 INT __cdecl CRTDLL_rand()
684 return (rand() & CRTDLL_RAND_MAX);
688 /*********************************************************************
689 * putchar (CRTDLL.442)
691 void __cdecl CRTDLL_putchar( INT x )
697 /*********************************************************************
700 INT __cdecl CRTDLL_fputc( INT c, CRTDLL_FILE *file )
704 TRACE(crtdll, "%c to file %p\n",c,file);
705 if (!WriteFile( file->handle, &ch, 1, &res, NULL )) return -1;
710 /*********************************************************************
713 INT __cdecl CRTDLL_fputs( LPCSTR s, CRTDLL_FILE *file )
716 TRACE(crtdll, "%s to file %p\n",s,file);
717 if (!WriteFile( file->handle, s, strlen(s), &res, NULL )) return -1;
722 /*********************************************************************
725 INT __cdecl CRTDLL_puts(LPCSTR s)
727 TRACE(crtdll, "%s \n",s);
732 /*********************************************************************
735 INT __cdecl CRTDLL_putc( INT c, CRTDLL_FILE *file )
737 return CRTDLL_fputc( c, file );
740 /*********************************************************************
743 INT __cdecl CRTDLL_fgetc( CRTDLL_FILE *file )
747 if (!ReadFile( file->handle, &ch, 1, &res, NULL )) return -1;
748 if (res != 1) return -1;
753 /*********************************************************************
756 INT __cdecl CRTDLL_getc( CRTDLL_FILE *file )
758 return CRTDLL_fgetc( file );
762 /*********************************************************************
765 CHAR* __cdecl CRTDLL_fgets( LPSTR s, INT size, CRTDLL_FILE *file )
770 /* BAD, for the whole WINE process blocks... just done this way to test
771 * windows95's ftp.exe.
774 for(cc = CRTDLL_fgetc(file); cc != EOF && cc != '\n'; cc = CRTDLL_fgetc(file))
777 if (--size <= 0) break;
783 TRACE(crtdll,"got '%s'\n", buf_start);
788 /*********************************************************************
791 LPSTR __cdecl CRTDLL_gets(LPSTR buf)
794 LPSTR buf_start = buf;
796 /* BAD, for the whole WINE process blocks... just done this way to test
797 * windows95's ftp.exe.
800 for(cc = fgetc(stdin); cc != EOF && cc != '\n'; cc = fgetc(stdin))
801 if(cc != '\r') *buf++ = (char)cc;
805 TRACE(crtdll,"got '%s'\n", buf_start);
810 /*********************************************************************
813 UINT __cdecl CRTDLL__rotl(UINT x,INT shift)
815 unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift));
817 TRACE(crtdll, "got 0x%08x rot %d ret 0x%08x\n",
822 /*********************************************************************
823 * _lrotl (CRTDLL.176)
825 DWORD __cdecl CRTDLL__lrotl(DWORD x,INT shift)
827 unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift));
829 TRACE(crtdll, "got 0x%08lx rot %d ret 0x%08lx\n",
836 /*********************************************************************
837 * _mbsicmp (CRTDLL.204)
839 int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
846 /* FIXME: MBCS handling... */
855 /*********************************************************************
856 * _mbsinc (CRTDLL.205)
858 unsigned char * __cdecl CRTDLL__mbsinc(unsigned char *x)
865 /*********************************************************************
866 * vsprintf (CRTDLL.500)
868 INT __cdecl CRTDLL_vsprintf( LPSTR buffer, LPCSTR spec, va_list args )
870 return wvsprintfA( buffer, spec, args );
873 /*********************************************************************
874 * vswprintf (CRTDLL.501)
876 INT __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
878 return wvsprintfW( buffer, spec, args );
881 /*********************************************************************
882 * _mbscpy (CRTDLL.200)
884 unsigned char* __cdecl CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
886 TRACE(crtdll,"CRTDLL_mbscpy %s and %s\n",x,y);
891 /*********************************************************************
892 * _mbscat (CRTDLL.197)
894 unsigned char* __cdecl CRTDLL__mbscat(unsigned char *x,unsigned char *y)
900 /*********************************************************************
901 * _strcmpi (CRTDLL.282) (CRTDLL.287)
903 INT __cdecl CRTDLL__strcmpi( LPCSTR s1, LPCSTR s2 )
905 return lstrcmpiA( s1, s2 );
909 /*********************************************************************
910 * _strnicmp (CRTDLL.293)
912 INT __cdecl CRTDLL__strnicmp( LPCSTR s1, LPCSTR s2, INT n )
914 return lstrncmpiA( s1, s2, n );
918 /*********************************************************************
919 * _strlwr (CRTDLL.293)
921 * convert a string in place to lowercase
923 LPSTR __cdecl CRTDLL__strlwr(LPSTR x)
927 TRACE(crtdll, "CRTDLL_strlwr got %s\n", x);
929 if ((*y > 0x40) && (*y< 0x5b))
933 TRACE(crtdll, " returned %s\n", x);
938 /*********************************************************************
939 * system (CRTDLL.485)
941 INT __cdecl CRTDLL_system(LPSTR x)
943 #define SYSBUF_LENGTH 1500
944 char buffer[SYSBUF_LENGTH];
945 unsigned char *y = x;
949 sprintf( buffer, "%s \"", Options.argv0 );
950 bp = buffer + strlen(buffer);
951 i = strlen(buffer) + strlen(x) +2;
953 /* Calculate needed buffer size to prevent overflow. */
958 /* If buffer too short, exit. */
959 if (i > SYSBUF_LENGTH) {
960 TRACE(crtdll,"_system buffer to small\n");
969 if (*(y-1) =='\\') *bp++ = '\\';
971 /* Remove spaces from end of string. */
972 while (*(y-1) == ' ') {
977 TRACE(crtdll, "_system got '%s', executing '%s'\n",x,buffer);
979 return system(buffer);
982 /*********************************************************************
983 * _strupr (CRTDLL.300)
985 LPSTR __cdecl CRTDLL__strupr(LPSTR x)
996 /*********************************************************************
997 * _wcsupr (CRTDLL.328)
999 LPWSTR __cdecl CRTDLL__wcsupr(LPWSTR x)
1010 /*********************************************************************
1011 * _wcslwr (CRTDLL.323)
1013 LPWSTR __cdecl CRTDLL__wcslwr(LPWSTR x)
1025 /*********************************************************************
1026 * longjmp (CRTDLL.426)
1028 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
1030 FIXME(crtdll,"CRTDLL_longjmp semistup, expect crash\n");
1034 /*********************************************************************
1035 * malloc (CRTDLL.427)
1037 VOID* __cdecl CRTDLL_malloc(DWORD size)
1039 return HeapAlloc(GetProcessHeap(),0,size);
1042 /*********************************************************************
1045 VOID* __cdecl CRTDLL_new(DWORD size)
1048 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
1053 /*********************************************************************
1054 * set_new_handler(CRTDLL.003)
1056 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
1058 new_handler_type old_handler = new_handler;
1063 /*********************************************************************
1064 * calloc (CRTDLL.350)
1066 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
1068 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
1071 /*********************************************************************
1072 * realloc (CRTDLL.447)
1074 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
1076 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
1079 /*********************************************************************
1082 VOID __cdecl CRTDLL_free(LPVOID ptr)
1084 HeapFree(GetProcessHeap(),0,ptr);
1087 /*********************************************************************
1088 * delete (CRTDLL.002)
1090 VOID __cdecl CRTDLL_delete(VOID* ptr)
1092 HeapFree(GetProcessHeap(),0,ptr);
1095 /*********************************************************************
1096 * _strdup (CRTDLL.285)
1098 LPSTR __cdecl CRTDLL__strdup(LPCSTR ptr)
1100 return HEAP_strdupA(GetProcessHeap(),0,ptr);
1103 /*********************************************************************
1104 * _wcsdup (CRTDLL.320)
1106 LPWSTR __cdecl CRTDLL__wcsdup(LPCWSTR ptr)
1108 return HEAP_strdupW(GetProcessHeap(),0,ptr);
1111 /*********************************************************************
1112 * fclose (CRTDLL.362)
1114 INT __cdecl CRTDLL_fclose( CRTDLL_FILE *file )
1116 TRACE(crtdll,"%p\n", file );
1117 if (!CloseHandle( file->handle )) return -1;
1118 HeapFree( GetProcessHeap(), 0, file );
1122 /*********************************************************************
1123 * _unlink (CRTDLL.315)
1125 INT __cdecl CRTDLL__unlink(LPCSTR pathname)
1128 DOS_FULL_NAME full_name;
1130 if (!DOSFS_GetFullName( pathname, FALSE, &full_name )) {
1131 WARN(crtdll, "CRTDLL_unlink file %s bad name\n",pathname);
1135 ret=unlink(full_name.long_name);
1136 TRACE(crtdll,"(%s unix %s)\n",
1137 pathname,full_name.long_name);
1139 WARN(crtdll, " Failed!\n");
1144 /*********************************************************************
1145 * rename (CRTDLL.449)
1147 INT __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
1149 BOOL ok = MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
1154 /*********************************************************************
1155 * _stat (CRTDLL.280)
1173 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
1176 DOS_FULL_NAME full_name;
1179 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1181 WARN(crtdll, "CRTDLL__stat filename %s bad name\n",filename);
1184 ret=stat(full_name.long_name,&mystat);
1185 TRACE(crtdll,"CRTDLL__stat %s\n", filename);
1187 WARN(crtdll, " Failed!\n");
1189 /* FIXME: should check what Windows returns */
1191 buf->win_st_dev = mystat.st_dev;
1192 buf->win_st_ino = mystat.st_ino;
1193 buf->win_st_mode = mystat.st_mode;
1194 buf->win_st_nlink = mystat.st_nlink;
1195 buf->win_st_uid = mystat.st_uid;
1196 buf->win_st_gid = mystat.st_gid;
1197 buf->win_st_rdev = mystat.st_rdev;
1198 buf->win_st_size = mystat.st_size;
1199 buf->win_st_atime = mystat.st_atime;
1200 buf->win_st_mtime = mystat.st_mtime;
1201 buf->win_st_ctime = mystat.st_ctime;
1205 /*********************************************************************
1206 * _open (CRTDLL.239)
1208 HFILE __cdecl CRTDLL__open(LPCSTR path,INT flags)
1210 DWORD access = 0, creation = 0;
1214 the flags in lcc's header differ from the ones in Linux, e.g.
1215 Linux: define O_APPEND 02000 (= 0x400)
1216 lcc: define _O_APPEND 0x0008
1217 so here a scheme to translate them
1218 Probably lcc is wrong here, but at least a hack to get is going
1222 case O_RDONLY: access |= GENERIC_READ; break;
1223 case O_WRONLY: access |= GENERIC_WRITE; break;
1224 case O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break;
1227 if (flags & 0x0100) /* O_CREAT */
1229 if (flags & 0x0400) /* O_EXCL */
1230 creation = CREATE_NEW;
1231 else if (flags & 0x0200) /* O_TRUNC */
1232 creation = CREATE_ALWAYS;
1234 creation = OPEN_ALWAYS;
1236 else /* no O_CREAT */
1238 if (flags & 0x0200) /* O_TRUNC */
1239 creation = TRUNCATE_EXISTING;
1241 creation = OPEN_EXISTING;
1243 if (flags & 0x0008) /* O_APPEND */
1244 FIXME(crtdll, "O_APPEND not supported\n" );
1246 TRACE(crtdll,"CRTDLL_open file unsupported flags 0x%04x\n",flags);
1249 ret = CreateFileA( path, access, FILE_SHARE_READ | FILE_SHARE_WRITE,
1250 NULL, creation, FILE_ATTRIBUTE_NORMAL, -1 );
1251 TRACE(crtdll,"CRTDLL_open file %s mode 0x%04x got handle %d\n", path,flags,ret);
1255 /*********************************************************************
1256 * _close (CRTDLL.57)
1258 INT __cdecl CRTDLL__close(HFILE fd)
1260 int ret=_lclose(fd);
1262 TRACE(crtdll,"(%d)\n",fd);
1264 WARN(crtdll, " Failed!\n");
1269 /*********************************************************************
1272 INT __cdecl CRTDLL_feof( CRTDLL_FILE *file )
1274 FIXME(crtdll,"stub\n" );
1278 /*********************************************************************
1279 * setlocale (CRTDLL.453)
1281 LPSTR __cdecl CRTDLL_setlocale(INT category,LPCSTR locale)
1286 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1287 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1288 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1289 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1290 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1291 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1292 default: categorystr = "UNKNOWN?";break;
1294 FIXME(crtdll,"(%s,%s),stub!\n",categorystr,locale);
1298 /*********************************************************************
1299 * wcscat (CRTDLL.503)
1301 LPWSTR __cdecl CRTDLL_wcscat( LPWSTR s1, LPCWSTR s2 )
1303 return lstrcatW( s1, s2 );
1306 /*********************************************************************
1307 * wcschr (CRTDLL.504)
1309 LPWSTR __cdecl CRTDLL_wcschr(LPCWSTR str,WCHAR xchar)
1321 /*********************************************************************
1322 * wcscmp (CRTDLL.505)
1324 INT __cdecl CRTDLL_wcscmp( LPCWSTR s1, LPCWSTR s2 )
1326 return lstrcmpW( s1, s2 );
1329 /*********************************************************************
1330 * wcscpy (CRTDLL.507)
1332 LPWSTR __cdecl CRTDLL_wcscpy( LPWSTR s1, LPCWSTR s2 )
1334 return lstrcpyW( s1, s2 );
1337 /*********************************************************************
1338 * wcscspn (CRTDLL.508)
1340 INT __cdecl CRTDLL_wcscspn(LPWSTR str,LPWSTR reject)
1347 while (*t) { if (*t==*s) break;t++;}
1351 return s-str; /* nr of wchars */
1354 /*********************************************************************
1355 * wcslen (CRTDLL.510)
1357 INT __cdecl CRTDLL_wcslen( LPCWSTR s )
1359 return lstrlenW( s );
1362 /*********************************************************************
1363 * wcsncat (CRTDLL.511)
1365 LPWSTR __cdecl CRTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT n )
1367 return lstrcatnW( s1, s2, n );
1370 /*********************************************************************
1371 * wcsncmp (CRTDLL.512)
1373 INT __cdecl CRTDLL_wcsncmp( LPCWSTR s1, LPCWSTR s2, INT n )
1375 return lstrncmpW( s1, s2, n );
1378 /*********************************************************************
1379 * wcsncpy (CRTDLL.513)
1381 LPWSTR __cdecl CRTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT n )
1383 return lstrcpynW( s1, s2, n );
1386 /*********************************************************************
1387 * wcsspn (CRTDLL.516)
1389 INT __cdecl CRTDLL_wcsspn(LPWSTR str,LPWSTR accept)
1396 while (*t) { if (*t==*s) break;t++;}
1400 return s-str; /* nr of wchars */
1403 /*********************************************************************
1404 * _wcsicmp (CRTDLL.321)
1406 DWORD __cdecl CRTDLL__wcsicmp( LPCWSTR s1, LPCWSTR s2 )
1408 return lstrcmpiW( s1, s2 );
1411 /*********************************************************************
1412 * _wcsicoll (CRTDLL.322)
1414 DWORD __cdecl CRTDLL__wcsicoll(LPCWSTR a1,LPCWSTR a2)
1416 /* FIXME: handle collates */
1417 return lstrcmpiW(a1,a2);
1420 /*********************************************************************
1421 * _wcsnicmp (CRTDLL.324)
1423 DWORD __cdecl CRTDLL__wcsnicmp( LPCWSTR s1, LPCWSTR s2, INT len )
1425 return lstrncmpiW( s1, s2, len );
1428 /*********************************************************************
1429 * wcscoll (CRTDLL.506)
1431 DWORD __cdecl CRTDLL_wcscoll(LPWSTR a1,LPWSTR a2)
1433 /* FIXME: handle collates */
1434 return lstrcmpW(a1,a2);
1437 /*********************************************************************
1438 * _wcsrev (CRTDLL.326)
1440 VOID __cdecl CRTDLL__wcsrev(LPWSTR s) {
1454 /*********************************************************************
1455 * wcsstr (CRTDLL.517)
1457 LPWSTR __cdecl CRTDLL_wcsstr(LPWSTR s,LPWSTR b)
1465 while (*y && *c && *y==*c) { c++;y++; }
1474 /*********************************************************************
1475 * wcstombs (CRTDLL.521)
1477 INT __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT len )
1479 lstrcpynWtoA( dst, src, len );
1480 return strlen(dst); /* FIXME: is this right? */
1483 /*********************************************************************
1484 * wcsrchr (CRTDLL.515)
1486 LPWSTR __cdecl CRTDLL_wcsrchr(LPWSTR str,WCHAR xchar)
1490 s=str+lstrlenW(str);
1499 /*********************************************************************
1500 * _setmode (CRTDLL.265)
1501 * FIXME: At present we ignore the request to translate CR/LF to LF.
1503 * We allways translate when we read with fgets, we never do with fread
1506 INT __cdecl CRTDLL__setmode( INT fh,INT mode)
1509 #define O_TEXT 0x4000
1510 #define O_BINARY 0x8000
1512 FIXME(crtdll, "on fhandle %d mode %s, STUB.\n",
1513 fh,(mode=O_TEXT)?"O_TEXT":
1514 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1518 /*********************************************************************
1519 * _fpreset (CRTDLL.107)
1521 VOID __cdecl CRTDLL__fpreset(void)
1523 FIXME(crtdll," STUB.\n");
1526 /*********************************************************************
1527 * atexit (CRTDLL.345)
1529 INT __cdecl CRTDLL_atexit(LPVOID x)
1531 FIXME(crtdll,"(%p), STUB.\n",x);
1532 return 0; /* successful */
1535 /*********************************************************************
1536 * mblen (CRTDLL.428)
1537 * FIXME: check multibyte support
1539 WCHAR __cdecl CRTDLL_mblen(CHAR *mb,INT size)
1546 else if ((size<1)||(!*(mb+1)))
1551 TRACE(crtdll,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb,size,ret);
1556 /*********************************************************************
1557 * mbstowcs (CRTDLL.429)
1558 * FIXME: check multibyte support
1560 INT __cdecl CRTDLL_mbstowcs(LPWSTR wcs, LPCSTR mbs, INT size)
1563 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1564 * We need the number of characters transfered
1565 * FIXME: No multibyte support yet
1572 while ((n-- > 0) && *src) {
1573 *p++ = (WCHAR)(unsigned char)*src++;
1578 TRACE(crtdll,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1583 /*********************************************************************
1584 * mbtowc (CRTDLL.430)
1585 * FIXME: check multibyte support
1587 WCHAR __cdecl CRTDLL_mbtowc(WCHAR* wc,CHAR* mb,INT size)
1596 if ( (ret = mblen(mb,size)) != -1 )
1598 if (ret <= sizeof(char))
1599 *wc = (WCHAR) ((unsigned char)*mb);
1606 TRACE(crtdll,"CRTDLL_mbtowc %s for %d chars\n",mb,size);
1611 /*********************************************************************
1612 * _isctype (CRTDLL.138)
1614 BOOL __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1616 if ((type & CRTDLL_SPACE) && isspace(x))
1618 if ((type & CRTDLL_PUNCT) && ispunct(x))
1620 if ((type & CRTDLL_LOWER) && islower(x))
1622 if ((type & CRTDLL_UPPER) && isupper(x))
1624 if ((type & CRTDLL_ALPHA) && isalpha(x))
1626 if ((type & CRTDLL_DIGIT) && isdigit(x))
1628 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1630 /* check CRTDLL_LEADBYTE */
1634 /*********************************************************************
1635 * _chdrive (CRTDLL.52)
1637 * newdir [I] drive to change to, A=1
1640 BOOL __cdecl CRTDLL__chdrive(INT newdrive)
1642 /* FIXME: generates errnos */
1643 return DRIVE_SetCurrentDrive(newdrive-1);
1646 /*********************************************************************
1647 * _chdir (CRTDLL.51)
1649 INT __cdecl CRTDLL__chdir(LPCSTR newdir)
1651 if (!SetCurrentDirectoryA(newdir))
1656 /*********************************************************************
1657 * _fullpath (CRTDLL.114)
1659 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT size)
1661 DOS_FULL_NAME full_name;
1666 if(!(buf = CRTDLL_malloc(size))) return NULL;
1668 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1669 lstrcpynA(buf,full_name.short_name,size);
1670 TRACE(crtdll,"CRTDLL_fullpath got %s\n",buf);
1674 /*********************************************************************
1675 * _splitpath (CRTDLL.279)
1677 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1680 directory includes leading and trailing (forward and backward slashes)
1681 filename without dot and slashes
1682 extension with leading dot
1684 char * drivechar,*dirchar,*namechar;
1686 TRACE(crtdll,"CRTDLL__splitpath got %s\n",path);
1688 drivechar = strchr(path,':');
1689 dirchar = strrchr(path,'/');
1690 namechar = strrchr(path,'\\');
1691 dirchar = MAX(dirchar,namechar);
1693 namechar = strrchr(dirchar,'.');
1695 namechar = strrchr(path,'.');
1703 strncat(drive,path,drivechar-path+1);
1712 strncat(directory,path,dirchar-path+1);
1721 strncat(filename,path,namechar-path);
1725 strcat(extension,namechar);
1730 TRACE(crtdll,"CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1735 /*********************************************************************
1736 * _makepath (CRTDLL.182)
1739 VOID __cdecl CRTDLL__makepath(LPSTR path, LPCSTR drive,
1740 LPCSTR directory, LPCSTR filename,
1744 TRACE(crtdll,"CRTDLL__makepath got %s %s %s %s\n", drive, directory,
1745 filename, extension);
1753 sprintf(path, "%c:", drive[0]);
1756 if ( directory[0] ) {
1757 strcat(path, directory);
1758 ch = path[strlen(path)-1];
1759 if (ch != '/' && ch != '\\')
1763 if ( filename[0] ) {
1764 strcat(path, filename);
1766 if ( extension[0] ) {
1767 if ( extension[0] != '.' ) {
1770 strcat(path,extension);
1775 TRACE(crtdll,"CRTDLL__makepath returns %s\n",path);
1778 /*********************************************************************
1779 * _getcwd (CRTDLL.120)
1781 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT size)
1788 if (size < 0) /* allocate as big as nescessary */
1789 len =GetCurrentDirectoryA(1,test) + 1;
1790 if(!(buf = CRTDLL_malloc(len)))
1792 /* set error to OutOfRange */
1797 if(!(len =GetCurrentDirectoryA(len,buf)))
1803 /* set error to ERANGE */
1804 TRACE(crtdll,"CRTDLL_getcwd buffer to small\n");
1811 /*********************************************************************
1812 * _getdcwd (CRTDLL.121)
1814 CHAR* __cdecl CRTDLL__getdcwd(INT drive,LPSTR buf, INT size)
1819 FIXME(crtdll,"(\"%c:\",%s,%d)\n",drive+'A',buf,size);
1822 if (size < 0) /* allocate as big as nescessary */
1823 len =GetCurrentDirectoryA(1,test) + 1;
1824 if(!(buf = CRTDLL_malloc(len)))
1826 /* set error to OutOfRange */
1831 if(!(len =GetCurrentDirectoryA(len,buf)))
1837 /* set error to ERANGE */
1838 TRACE(crtdll,"buffer to small\n");
1845 /*********************************************************************
1846 * _getdrive (CRTDLL.124)
1848 * Return current drive, 1 for A, 2 for B
1850 INT __cdecl CRTDLL__getdrive(VOID)
1852 return DRIVE_GetCurrentDrive() + 1;
1855 /*********************************************************************
1856 * _mkdir (CRTDLL.234)
1858 INT __cdecl CRTDLL__mkdir(LPCSTR newdir)
1860 if (!CreateDirectoryA(newdir,NULL))
1865 /*********************************************************************
1866 * remove (CRTDLL.448)
1868 INT __cdecl CRTDLL_remove(LPCSTR file)
1870 if (!DeleteFileA(file))
1875 /*********************************************************************
1876 * _errno (CRTDLL.52)
1877 * Yes, this is a function.
1879 LPINT __cdecl CRTDLL__errno()
1881 static int crtdllerrno;
1883 /* FIXME: we should set the error at the failing function call time */
1884 crtdllerrno = LastErrorToErrno(GetLastError());
1885 return &crtdllerrno;
1888 /*********************************************************************
1889 * _tempnam (CRTDLL.305)
1892 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1896 DOS_FULL_NAME tempname;
1898 if ((ret = tempnam(dir,prefix))==NULL) {
1899 WARN(crtdll, "Unable to get unique filename\n");
1902 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1904 TRACE(crtdll, "Wrong path?\n");
1908 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1909 WARN(crtdll, "CRTDL_malloc for shortname failed\n");
1912 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1913 WARN(crtdll, "Malloc for shortname failed\n");
1917 TRACE(crtdll,"dir %s prefix %s got %s\n",
1922 /*********************************************************************
1923 * tmpnam (CRTDLL.490)
1925 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1928 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1932 if ((ret =tmpnam(s))== NULL) {
1933 WARN(crtdll, "Unable to get unique filename\n");
1936 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1938 TRACE(crtdll, "Wrong path?\n");
1941 strcat(CRTDLL_tmpname.short_name,".");
1942 TRACE(crtdll,"for buf %p got %s\n",
1943 s,CRTDLL_tmpname.short_name);
1944 TRACE(crtdll,"long got %s\n",
1945 CRTDLL_tmpname.long_name);
1947 return strcpy(s,CRTDLL_tmpname.short_name);
1949 return CRTDLL_tmpname.short_name;
1953 /*********************************************************************
1954 * _itoa (CRTDLL.165)
1956 LPSTR __cdecl CRTDLL__itoa(INT x,LPSTR buf,INT buflen)
1958 wsnprintfA(buf,buflen,"%d",x);
1962 /*********************************************************************
1963 * _ltoa (CRTDLL.180)
1965 LPSTR __cdecl CRTDLL__ltoa(long x,LPSTR buf,INT radix)
1968 case 2: FIXME(crtdll, "binary format not implemented !\n");
1970 case 8: wsnprintfA(buf,0x80,"%o",x);
1972 case 10: wsnprintfA(buf,0x80,"%d",x);
1974 case 16: wsnprintfA(buf,0x80,"%x",x);
1976 default: FIXME(crtdll, "radix %d not implemented !\n", radix);
1981 /*********************************************************************
1982 * _ultoa (CRTDLL.311)
1984 LPSTR __cdecl CRTDLL__ultoa(long x,LPSTR buf,INT radix)
1987 case 2: FIXME(crtdll, "binary format not implemented !\n");
1989 case 8: wsnprintfA(buf,0x80,"%lo",x);
1991 case 10: wsnprintfA(buf,0x80,"%ld",x);
1993 case 16: wsnprintfA(buf,0x80,"%lx",x);
1995 default: FIXME(crtdll, "radix %d not implemented !\n", radix);
2000 typedef VOID (*sig_handler_type)(VOID);
2002 /*********************************************************************
2003 * signal (CRTDLL.455)
2005 VOID __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
2007 FIXME(crtdll, "(%d %p):stub.\n", sig, ptr);
2010 /*********************************************************************
2011 * _ftol (CRTDLL.113)
2013 #ifdef USING_REAL_FPU
2014 LONG __cdecl CRTDLL__ftol(void) {
2015 /* don't just do DO_FPU("fistp",retval), because the rounding
2016 * mode must also be set to "round towards zero"... */
2022 LONG __cdecl CRTDLL__ftol(double fl) {
2023 FIXME(crtdll,"should be register function\n");
2028 /*********************************************************************
2029 * _CIpow (CRTDLL.14)
2031 #ifdef USING_REAL_FPU
2032 LONG __cdecl CRTDLL__CIpow(void) {
2039 LONG __cdecl CRTDLL__CIpow(double x,double y) {
2040 FIXME(crtdll,"should be register function\n");
2045 /*********************************************************************
2046 * _sleep (CRTDLL.267)
2048 VOID __cdecl CRTDLL__sleep(unsigned long timeout)
2050 TRACE(crtdll,"CRTDLL__sleep for %ld milliseconds\n",timeout);
2051 Sleep((timeout)?timeout:1);
2054 /*********************************************************************
2055 * getenv (CRTDLL.437)
2057 LPSTR __cdecl CRTDLL_getenv(const char *name)
2059 LPSTR environ = GetEnvironmentStringsA();
2060 LPSTR pp,pos = NULL;
2061 unsigned int length;
2063 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
2065 pos =strchr(pp,'=');
2069 length = strlen(pp);
2070 if (!strncmp(pp,name,length)) break;
2075 TRACE(crtdll,"got %s\n",pp);
2077 FreeEnvironmentStringsA( environ );
2081 /*********************************************************************
2082 * _mbsrchr (CRTDLL.223)
2084 LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x) {
2085 /* FIXME: handle multibyte strings */
2086 return strrchr(s,x);
2089 /*********************************************************************
2090 * _memicmp (CRTDLL.233)(NTDLL.868)
2091 * A stringcompare, without \0 check
2093 * -1:if first string is alphabetically before second string
2094 * 1:if second '' '' '' '' first ''
2095 * 0:if both are equal.
2097 INT __cdecl CRTDLL__memicmp(
2098 LPCSTR s1, /* [in] first string */
2099 LPCSTR s2, /* [in] second string */
2100 DWORD len /* [in] length to compare */
2104 for (i=0;i<len;i++) {
2105 if (tolower(s1[i])<tolower(s2[i]))
2107 if (tolower(s1[i])>tolower(s2[i]))
2112 /*********************************************************************
2113 * __dllonexit (CRTDLL.25)
2115 VOID __cdecl CRTDLL__dllonexit ()
2117 FIXME(crtdll,"stub\n");
2120 /*********************************************************************
2121 * wcstok (CRTDLL.519)
2122 * Like strtok, but for wide character strings. s is modified, yes.
2124 LPWSTR __cdecl CRTDLL_wcstok(LPWSTR s,LPCWSTR delim) {
2125 static LPWSTR nexttok = NULL;
2133 while (*x && !CRTDLL_wcschr(delim,*x))
2144 /*********************************************************************
2145 * wcstol (CRTDLL.520)
2146 * Like strtol, but for wide character strings.
2148 INT __cdecl CRTDLL_wcstol(LPWSTR s,LPWSTR *end,INT base) {
2149 LPSTR sA = HEAP_strdupWtoA(GetProcessHeap(),0,s),endA;
2150 INT ret = strtol(sA,&endA,base);
2152 HeapFree(GetProcessHeap(),0,sA);
2153 if (end) *end = s+(endA-sA); /* pointer magic checked. */
2156 /*********************************************************************
2157 * strdate (CRTDLL.283)
2159 LPSTR __cdecl CRTDLL__strdate (LPSTR date)
2160 { FIXME (crtdll,"%p stub\n", date);
2164 /*********************************************************************
2165 * strtime (CRTDLL.299)
2167 LPSTR __cdecl CRTDLL__strtime (LPSTR date)
2168 { FIXME (crtdll,"%p stub\n", date);