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
21 /* NOTE: This file also implements the wcs* functions. They _ARE_ in
22 * the newer Linux libcs, but use 4 byte wide characters, so are unusable,
23 * since we need 2 byte wide characters. - Marcus Meissner, 981031
26 /* FIXME: all the file handling is hopelessly broken -- AJ */
33 #include <sys/times.h>
53 extern int FILE_GetUnixHandle( HFILE32
);
55 static DOS_FULL_NAME CRTDLL_tmpname
;
57 UINT32 CRTDLL_argc_dll
; /* CRTDLL.23 */
58 LPSTR
*CRTDLL_argv_dll
; /* CRTDLL.24 */
59 LPSTR CRTDLL_acmdln_dll
; /* CRTDLL.38 */
60 UINT32 CRTDLL_basemajor_dll
; /* CRTDLL.42 */
61 UINT32 CRTDLL_baseminor_dll
; /* CRTDLL.43 */
62 UINT32 CRTDLL_baseversion_dll
; /* CRTDLL.44 */
63 UINT32 CRTDLL_commode_dll
; /* CRTDLL.59 */
64 LPSTR CRTDLL_environ_dll
; /* CRTDLL.75 */
65 UINT32 CRTDLL_fmode_dll
; /* CRTDLL.104 */
66 UINT32 CRTDLL_osmajor_dll
; /* CRTDLL.241 */
67 UINT32 CRTDLL_osminor_dll
; /* CRTDLL.242 */
68 UINT32 CRTDLL_osmode_dll
; /* CRTDLL.243 */
69 UINT32 CRTDLL_osver_dll
; /* CRTDLL.244 */
70 UINT32 CRTDLL_osversion_dll
; /* CRTDLL.245 */
71 UINT32 CRTDLL_winmajor_dll
; /* CRTDLL.329 */
72 UINT32 CRTDLL_winminor_dll
; /* CRTDLL.330 */
73 UINT32 CRTDLL_winver_dll
; /* CRTDLL.331 */
75 BYTE CRTDLL_iob
[32*3]; /* FIXME */
77 typedef VOID (*new_handler_type
)(VOID
);
79 static new_handler_type new_handler
;
81 /*********************************************************************
82 * _GetMainArgs (CRTDLL.022)
84 DWORD __cdecl
CRTDLL__GetMainArgs(LPDWORD argc
,LPSTR
**argv
,
85 LPSTR
*environ
,DWORD flag
)
89 int xargc
,i
,afterlastspace
;
92 TRACE(crtdll
,"(%p,%p,%p,%ld).\n",
93 argc
,argv
,environ
,flag
95 CRTDLL_acmdln_dll
= cmdline
= HEAP_strdupA( GetProcessHeap(), 0,
96 GetCommandLine32A() );
97 TRACE(crtdll
,"got '%s'\n", cmdline
);
99 version
= GetVersion32();
100 CRTDLL_osver_dll
= version
>> 16;
101 CRTDLL_winminor_dll
= version
& 0xFF;
102 CRTDLL_winmajor_dll
= (version
>>8) & 0xFF;
103 CRTDLL_baseversion_dll
= version
>> 16;
104 CRTDLL_winver_dll
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
105 CRTDLL_baseminor_dll
= (version
>> 16) & 0xFF;
106 CRTDLL_basemajor_dll
= (version
>> 24) & 0xFF;
107 CRTDLL_osversion_dll
= version
& 0xFFFF;
108 CRTDLL_osminor_dll
= version
& 0xFF;
109 CRTDLL_osmajor_dll
= (version
>>8) & 0xFF;
111 /* missing threading init */
113 i
=0;xargv
=NULL
;xargc
=0;afterlastspace
=0;
115 if (cmdline
[i
]==' ') {
116 xargv
=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv
,
117 sizeof(char*)*(++xargc
));
119 xargv
[xargc
-1] = HEAP_strdupA( GetProcessHeap(), 0,
120 cmdline
+afterlastspace
);
122 while (cmdline
[i
]==' ')
129 xargv
=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv
,
130 sizeof(char*)*(++xargc
));
132 xargv
[xargc
-1] = HEAP_strdupA( GetProcessHeap(), 0,
133 cmdline
+afterlastspace
);
134 CRTDLL_argc_dll
= xargc
;
136 CRTDLL_argv_dll
= xargv
;
139 TRACE(crtdll
,"found %d arguments\n",
141 CRTDLL_environ_dll
= *environ
= GetEnvironmentStrings32A();
146 typedef void (*_INITTERMFUN
)();
148 /* fixme: move to header */
151 time_t time_create
; /* -1 when not avaiable */
152 time_t time_access
; /* -1 when not avaiable */
154 unsigned long size
; /* fixme: 64 bit ??*/
157 /*********************************************************************
158 * _findfirst (CRTDLL.099)
163 DWORD __cdecl
CRTDLL__findfirst(LPCSTR fname
, struct find_t
* x2
)
165 FIXME(crtdll
, ":(%s,%p): stub\n",fname
,x2
);
166 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
170 /*********************************************************************
171 * _findnext (CRTDLL.100)
176 INT32 __cdecl
CRTDLL__findnext(DWORD hand
, struct find_t
* x2
)
178 FIXME(crtdll
, ":(%ld,%p): stub\n",hand
,x2
);
179 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
183 /*********************************************************************
184 * _fstat (CRTDLL.111)
189 int __cdecl
CRTDLL__fstat(int file
, struct stat
* buf
)
191 FIXME(crtdll
, ":(%d,%p): stub\n",file
,buf
);
192 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
196 /*********************************************************************
197 * _initterm (CRTDLL.135)
199 DWORD __cdecl
CRTDLL__initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
201 _INITTERMFUN
*current
;
203 TRACE(crtdll
,"(%p,%p)\n",start
,end
);
205 while (current
<end
) {
206 if (*current
) (*current
)();
212 /*********************************************************************
213 * _fdopen (CRTDLL.91)
215 DWORD __cdecl
CRTDLL__fdopen(INT32 handle
, LPCSTR mode
)
223 case 1 : file
=stdout
;
225 case 2 : file
=stderr
;
228 file
=fdopen(handle
,mode
);
230 TRACE(crtdll
, "open handle %d mode %s got file %p\n",
235 static FILE *xlat_file_ptr(void *ptr
)
239 /* CRT sizeof(FILE) == 32 */
240 dif
= ((char *)ptr
- (char *)CRTDLL_iob
) / 32;
243 case 0: return stdin
;
244 case 1: return stdout
;
245 case 2: return stderr
;
250 /*******************************************************************
251 * _global_unwind2 (CRTDLL.129)
253 void __cdecl
CRTDLL__global_unwind2( PEXCEPTION_FRAME frame
)
255 RtlUnwind( frame
, 0, NULL
, 0 );
258 /*******************************************************************
259 * _local_unwind2 (CRTDLL.173)
261 void __cdecl
CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe
, DWORD nr
)
263 TRACE(crtdll
,"(%p,%ld)\n",endframe
,nr
);
265 /*********************************************************************
271 INT32 __cdecl
CRTDLL__read(INT32 fd
, LPVOID buf
, UINT32 count
)
273 FIXME(crtdll
,":(%d,%p,%d): stub\n",fd
,buf
,count
);
274 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
278 /*********************************************************************
281 DWORD __cdecl
CRTDLL_fopen(LPCSTR path
, LPCSTR mode
)
286 DOS_FULL_NAME full_name
;
288 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
)) {
289 WARN(crtdll
, "file %s bad name\n",path
);
293 file
=fopen(full_name
.long_name
,mode
);
298 if ((strchr(mode
,'r')&&strchr(mode
,'a'))||
299 (strchr(mode
,'r')&&strchr(mode
,'w'))||
300 (strchr(mode
,'w')&&strchr(mode
,'a')))
303 if (strstr(mode
,"r+")) flagmode
=O_RDWR
;
304 else if (strchr(mode
,'r')) flagmode
= O_RDONLY
;
305 else if (strstr(mode
,"w+")) flagmode
= O_RDWR
| O_TRUNC
| O_CREAT
;
306 else if (strchr(mode
,'w')) flagmode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
307 else if (strstr(mode
,"a+")) flagmode
= O_RDWR
| O_CREAT
| O_APPEND
;
308 else if (strchr(mode
,'w')) flagmode
= O_RDWR
| O_CREAT
| O_APPEND
;
309 else if (strchr(mode
,'b'))
310 TRACE(crtdll
, "%s in BINARY mode\n",path
);
312 dos_fildes
=FILE_Open(path
, flagmode
,0);
313 unix_fildes
=FILE_GetUnixHandle(dos_fildes
);
314 file
= fdopen(unix_fildes
,mode
);
316 TRACE(crtdll
, "file %s mode %s got ufh %d dfh %d file %p\n",
317 path
,mode
,unix_fildes
,dos_fildes
,file
);
321 /*********************************************************************
324 DWORD __cdecl
CRTDLL_fread(LPVOID ptr
, INT32 size
, INT32 nmemb
, LPVOID vfile
)
327 FILE *file
=xlat_file_ptr(vfile
);
332 /* If we would honour CR/LF <-> LF translation, we could do it like this.
333 We should keep track of all files opened, and probably files with \
334 known binary extensions must be unchanged */
335 while ( (i
< (nmemb
*size
)) && (ret
==1)) {
336 ret
=fread(temp
,1,1,file
);
337 TRACE(crtdll
, "got %c 0x%02x ret %d\n",
338 (isalpha(*(unsigned char*)temp
))? *(unsigned char*)temp
:
339 ' ',*(unsigned char*)temp
, ret
);
340 if (*(unsigned char*)temp
!= 0xd) { /* skip CR */
345 TRACE(crtdll
, "skipping ^M\n");
347 TRACE(crtdll
, "0x%08x items of size %d from file %p to %p\n",
348 nmemb
,size
,file
,ptr
,);
350 WARN(crtdll
, " failed!\n");
355 ret
=fread(ptr
,size
,nmemb
,file
);
356 TRACE(crtdll
, "0x%08x items of size %d from file %p to %p\n",
357 nmemb
,size
,file
,ptr
);
359 WARN(crtdll
, " failed!\n");
364 /*********************************************************************
365 * freopen (CRTDLL.379)
370 DWORD __cdecl
CRTDLL_freopen(LPCSTR path
, LPCSTR mode
, LPVOID stream
)
372 FIXME(crtdll
, ":(%s,%s,%p): stub\n", path
, mode
, stream
);
373 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
377 /*********************************************************************
378 * fscanf (CRTDLL.381)
380 INT32 __cdecl
CRTDLL_fscanf( LPVOID stream
, LPSTR format
, ... )
385 va_start( valist
, format
);
387 res
= vfscanf( xlat_file_ptr(stream
), format
, valist
);
393 /*********************************************************************
396 LONG __cdecl
CRTDLL_fseek(LPVOID stream
, LONG offset
, INT32 whence
)
400 ret
=fseek(xlat_file_ptr(stream
),offset
,whence
);
401 TRACE(crtdll
, "file %p to 0x%08lx pos %s\n",
402 stream
,offset
,(whence
==SEEK_SET
)?"SEEK_SET":
403 (whence
==SEEK_CUR
)?"SEEK_CUR":
404 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
406 WARN(crtdll
, " failed!\n");
411 /*********************************************************************
412 * fsetpos (CRTDLL.383)
414 INT32 __cdecl
CRTDLL_fsetpos(LPVOID stream
, fpos_t *pos
)
416 TRACE(crtdll
, "file %p\n", stream
);
417 return fseek(xlat_file_ptr(stream
), *pos
, SEEK_SET
);
420 /*********************************************************************
423 LONG __cdecl
CRTDLL_ftell(LPVOID stream
)
427 ret
=ftell(xlat_file_ptr(stream
));
428 TRACE(crtdll
, "file %p at 0x%08lx\n",
433 /*********************************************************************
434 * fwrite (CRTDLL.386)
436 DWORD __cdecl
CRTDLL_fwrite(LPVOID ptr
, INT32 size
, INT32 nmemb
, LPVOID vfile
)
439 FILE *file
=xlat_file_ptr(vfile
);
441 ret
=fwrite(ptr
,size
,nmemb
,file
);
442 TRACE(crtdll
, "0x%08x items of size %d from %p to file %p\n",
443 nmemb
,size
,ptr
,file
);
445 WARN(crtdll
, " Failed!\n");
450 /*********************************************************************
451 * setbuf (CRTDLL.452)
453 INT32 __cdecl
CRTDLL_setbuf(LPVOID file
, LPSTR buf
)
455 TRACE(crtdll
, "(file %p buf %p)\n", file
, buf
);
456 /* this doesn't work:"void value not ignored as it ought to be"
457 return setbuf(file,buf);
459 setbuf(xlat_file_ptr(file
),buf
);
463 /*********************************************************************
464 * _open_osfhandle (CRTDLL.240)
466 HFILE32 __cdecl
CRTDLL__open_osfhandle(LONG osfhandle
, INT32 flags
)
471 case STD_INPUT_HANDLE
:
475 case STD_OUTPUT_HANDLE
:
479 case STD_ERROR_HANDLE
:
486 TRACE(crtdll
, "(handle %08lx,flags %d) return %d\n",
487 osfhandle
,flags
,handle
);
492 /*********************************************************************
495 void __cdecl
CRTDLL_srand(DWORD seed
)
497 /* FIXME: should of course be thread? process? local */
501 /*********************************************************************
502 * fprintf (CRTDLL.373)
504 INT32 __cdecl
CRTDLL_fprintf( FILE *file
, LPSTR format
, ... )
509 va_start( valist
, format
);
510 res
= vfprintf( xlat_file_ptr(file
), format
, valist
);
515 /*********************************************************************
516 * vfprintf (CRTDLL.373)
518 INT32 __cdecl
CRTDLL_vfprintf( FILE *file
, LPSTR format
, va_list args
)
520 return vfprintf( xlat_file_ptr(file
), format
, args
);
523 /*********************************************************************
526 time_t __cdecl
CRTDLL_time(time_t *timeptr
)
528 time_t curtime
= time(NULL
);
535 /*********************************************************************
538 clock_t __cdecl
CRTDLL_clock(void)
544 res
= alltimes
.tms_utime
+ alltimes
.tms_stime
+
545 alltimes
.tms_cutime
+ alltimes
.tms_cstime
;
546 /* Fixme: We need some symbolic representation
547 for (Hostsystem_)CLOCKS_PER_SEC
548 and (Emulated_system_)CLOCKS_PER_SEC
549 10 holds only for Windows/Linux_i86)
554 /*********************************************************************
555 * _isatty (CRTDLL.137)
557 BOOL32 __cdecl
CRTDLL__isatty(DWORD x
)
559 TRACE(crtdll
,"(%ld)\n",x
);
563 /*********************************************************************
564 * _write (CRTDLL.332)
566 INT32 __cdecl
CRTDLL__write(INT32 fd
,LPCVOID buf
,UINT32 count
)
573 len
= (UINT32
)write(fd
,buf
,(LONG
)count
);
575 len
= _lwrite32(fd
,buf
,count
);
576 TRACE(crtdll
,"%d/%d byte to dfh %d from %p,\n",
582 /*********************************************************************
585 * FIXME: What the heck is the difference between
586 * FIXME _c_exit (CRTDLL.47)
587 * FIXME _cexit (CRTDLL.49)
588 * FIXME _exit (CRTDLL.87)
589 * FIXME exit (CRTDLL.359)
591 * atexit-processing comes to mind -- MW.
594 void __cdecl
CRTDLL__cexit(INT32 ret
)
596 TRACE(crtdll
,"(%d)\n",ret
);
601 /*********************************************************************
604 void __cdecl
CRTDLL_exit(DWORD ret
)
606 TRACE(crtdll
,"(%ld)\n",ret
);
611 /*********************************************************************
612 * _abnormal_termination (CRTDLL.36)
614 INT32 __cdecl
CRTDLL__abnormal_termination(void)
616 TRACE(crtdll
,"(void)\n");
621 /*********************************************************************
622 * _access (CRTDLL.37)
624 INT32 __cdecl
CRTDLL__access(LPCSTR filename
, INT32 mode
)
626 DWORD attr
= GetFileAttributes32A(filename
);
630 if (GetLastError() == ERROR_INVALID_ACCESS
)
637 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
647 /*********************************************************************
648 * fflush (CRTDLL.365)
650 INT32 __cdecl
CRTDLL_fflush(LPVOID stream
)
654 ret
= fflush(xlat_file_ptr(stream
));
655 TRACE(crtdll
,"%p returnd %d\n",stream
,ret
);
657 WARN(crtdll
, " Failed!\n");
663 /*********************************************************************
666 LPSTR __cdecl
CRTDLL_gets(LPSTR buf
)
669 /* BAD, for the whole WINE process blocks... just done this way to test
670 * windows95's ftp.exe.
673 TRACE(crtdll
,"got %s\n",ret
);
678 /*********************************************************************
681 INT32 __cdecl
CRTDLL_rand()
687 /*********************************************************************
688 * putchar (CRTDLL.442)
690 void __cdecl
CRTDLL_putchar( INT32 x
)
696 /*********************************************************************
699 INT32 __cdecl
CRTDLL_fputc( INT32 c
, FILE *stream
)
701 TRACE(crtdll
, "%c to file %p\n",c
,stream
);
702 return fputc(c
,xlat_file_ptr(stream
));
706 /*********************************************************************
709 INT32 __cdecl
CRTDLL_fputs( LPCSTR s
, FILE *stream
)
711 TRACE(crtdll
, "%s to file %p\n",s
,stream
);
712 return fputs(s
,xlat_file_ptr(stream
));
716 /*********************************************************************
719 INT32 __cdecl
CRTDLL_puts(LPCSTR s
)
721 TRACE(crtdll
, "%s \n",s
);
726 /*********************************************************************
729 INT32 __cdecl
CRTDLL_putc(INT32 c
, FILE *stream
)
731 TRACE(crtdll
, " %c to file %p\n",c
,stream
);
732 return fputc(c
,xlat_file_ptr(stream
));
734 /*********************************************************************
737 INT32 __cdecl
CRTDLL_fgetc( FILE *stream
)
739 int ret
= fgetc(xlat_file_ptr(stream
));
740 TRACE(crtdll
, "got %d\n",ret
);
745 /*********************************************************************
748 INT32 __cdecl
CRTDLL_getc( FILE *stream
)
750 int ret
= fgetc(xlat_file_ptr(stream
));
751 TRACE(crtdll
, "got %d\n",ret
);
755 /*********************************************************************
758 UINT32 __cdecl
CRTDLL__rotl(UINT32 x
,INT32 shift
)
760 unsigned int ret
= (x
>> shift
)|( x
>>((sizeof(x
))-shift
));
762 TRACE(crtdll
, "got 0x%08x rot %d ret 0x%08x\n",
767 /*********************************************************************
768 * _lrotl (CRTDLL.176)
770 DWORD __cdecl
CRTDLL__lrotl(DWORD x
,INT32 shift
)
772 unsigned long ret
= (x
>> shift
)|( x
>>((sizeof(x
))-shift
));
774 TRACE(crtdll
, "got 0x%08lx rot %d ret 0x%08lx\n",
781 /*********************************************************************
784 CHAR
* __cdecl
CRTDLL_fgets(LPSTR s
,INT32 size
, LPVOID stream
)
789 ret
=fgets(s
, size
,xlat_file_ptr(stream
));
790 /*FIXME: Control with CRTDLL_setmode */
791 control_M
= strrchr(s
,'\r');
792 /*delete CR if we read a DOS File */
798 TRACE(crtdll
, "got %s for %d chars from file %p\n",
801 WARN(crtdll
, " Failed!\n");
807 /*********************************************************************
808 * _mbsicmp (CRTDLL.204)
810 int __cdecl
CRTDLL__mbsicmp(unsigned char *x
,unsigned char *y
)
817 /* FIXME: MBCS handling... */
826 /*********************************************************************
827 * _mbsinc (CRTDLL.205)
829 unsigned char * __cdecl
CRTDLL__mbsinc(unsigned char *x
)
836 /*********************************************************************
837 * vsprintf (CRTDLL.500)
839 INT32 __cdecl
CRTDLL_vsprintf( LPSTR buffer
, LPCSTR spec
, va_list args
)
841 return wvsprintf32A( buffer
, spec
, args
);
844 /*********************************************************************
845 * vswprintf (CRTDLL.501)
847 INT32 __cdecl
CRTDLL_vswprintf( LPWSTR buffer
, LPCWSTR spec
, va_list args
)
849 return wvsprintf32W( buffer
, spec
, args
);
852 /*********************************************************************
853 * _mbscpy (CRTDLL.200)
855 unsigned char* __cdecl
CRTDLL__mbscpy(unsigned char *x
,unsigned char *y
)
857 TRACE(crtdll
,"CRTDLL_mbscpy %s and %s\n",x
,y
);
862 /*********************************************************************
863 * _mbscat (CRTDLL.197)
865 unsigned char* __cdecl
CRTDLL__mbscat(unsigned char *x
,unsigned char *y
)
871 /*********************************************************************
872 * _strcmpi (CRTDLL.282) (CRTDLL.287)
874 INT32 __cdecl
CRTDLL__strcmpi( LPCSTR s1
, LPCSTR s2
)
876 return lstrcmpi32A( s1
, s2
);
880 /*********************************************************************
881 * _strnicmp (CRTDLL.293)
883 INT32 __cdecl
CRTDLL__strnicmp( LPCSTR s1
, LPCSTR s2
, INT32 n
)
885 return lstrncmpi32A( s1
, s2
, n
);
889 /*********************************************************************
890 * _strlwr (CRTDLL.293)
892 * convert a string in place to lowercase
894 LPSTR __cdecl
CRTDLL__strlwr(LPSTR x
)
898 TRACE(crtdll
, "CRTDLL_strlwr got %s\n", x
);
900 if ((*y
> 0x40) && (*y
< 0x5b))
904 TRACE(crtdll
, " returned %s\n", x
);
909 /*********************************************************************
910 * system (CRTDLL.485)
912 INT32 __cdecl
CRTDLL_system(LPSTR x
)
914 #define SYSBUF_LENGTH 1500
915 char buffer
[SYSBUF_LENGTH
];
916 unsigned char *y
= x
;
920 sprintf( buffer
, "%s \"", Options
.argv0
);
921 bp
= buffer
+ strlen(buffer
);
922 i
= strlen(buffer
) + strlen(x
) +2;
924 /* Calculate needed buffer size to prevent overflow. */
929 /* If buffer too short, exit. */
930 if (i
> SYSBUF_LENGTH
) {
931 TRACE(crtdll
,"_system buffer to small\n");
940 if (*(y
-1) =='\\') *bp
++ = '\\';
942 /* Remove spaces from end of string. */
943 while (*(y
-1) == ' ') {
948 TRACE(crtdll
, "_system got '%s', executing '%s'\n",x
,buffer
);
950 return system(buffer
);
953 /*********************************************************************
954 * _strupr (CRTDLL.300)
956 LPSTR __cdecl
CRTDLL__strupr(LPSTR x
)
967 /*********************************************************************
968 * _wcsupr (CRTDLL.328)
970 LPWSTR __cdecl
CRTDLL__wcsupr(LPWSTR x
)
981 /*********************************************************************
982 * _wcslwr (CRTDLL.323)
984 LPWSTR __cdecl
CRTDLL__wcslwr(LPWSTR x
)
996 /*********************************************************************
997 * longjmp (CRTDLL.426)
999 VOID __cdecl
CRTDLL_longjmp(jmp_buf env
, int val
)
1001 FIXME(crtdll
,"CRTDLL_longjmp semistup, expect crash\n");
1002 return longjmp(env
, val
);
1005 /*********************************************************************
1006 * malloc (CRTDLL.427)
1008 VOID
* __cdecl
CRTDLL_malloc(DWORD size
)
1010 return HeapAlloc(GetProcessHeap(),0,size
);
1013 /*********************************************************************
1016 VOID
* __cdecl
CRTDLL_new(DWORD size
)
1019 if(!(result
= HeapAlloc(GetProcessHeap(),0,size
)) && new_handler
)
1024 /*********************************************************************
1025 * set_new_handler(CRTDLL.003)
1027 new_handler_type __cdecl
CRTDLL_set_new_handler(new_handler_type func
)
1029 new_handler_type old_handler
= new_handler
;
1034 /*********************************************************************
1035 * calloc (CRTDLL.350)
1037 VOID
* __cdecl
CRTDLL_calloc(DWORD size
, DWORD count
)
1039 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
* count
);
1042 /*********************************************************************
1043 * realloc (CRTDLL.447)
1045 VOID
* __cdecl
CRTDLL_realloc( VOID
*ptr
, DWORD size
)
1047 return HeapReAlloc( GetProcessHeap(), 0, ptr
, size
);
1050 /*********************************************************************
1053 VOID __cdecl
CRTDLL_free(LPVOID ptr
)
1055 HeapFree(GetProcessHeap(),0,ptr
);
1058 /*********************************************************************
1059 * delete (CRTDLL.002)
1061 VOID __cdecl
CRTDLL_delete(VOID
* ptr
)
1063 HeapFree(GetProcessHeap(),0,ptr
);
1066 /*********************************************************************
1067 * _strdup (CRTDLL.285)
1069 LPSTR __cdecl
CRTDLL__strdup(LPCSTR ptr
)
1071 return HEAP_strdupA(GetProcessHeap(),0,ptr
);
1074 /*********************************************************************
1075 * _wcsdup (CRTDLL.320)
1077 LPWSTR __cdecl
CRTDLL__wcsdup(LPCWSTR ptr
)
1079 return HEAP_strdupW(GetProcessHeap(),0,ptr
);
1082 /*********************************************************************
1083 * fclose (CRTDLL.362)
1085 INT32 __cdecl
CRTDLL_fclose( FILE *stream
)
1088 HFILE32 dos_handle
=1;
1091 stream
=xlat_file_ptr(stream
);
1092 unix_handle
=fileno(stream
);
1094 if (unix_handle
<4) ret
= fclose(stream
);
1096 while(FILE_GetUnixHandle(dos_handle
) != unix_handle
) dos_handle
++;
1098 ret
= _lclose32( dos_handle
);
1100 TRACE(crtdll
,"(%p) ufh %d dfh %d\n",
1101 stream
,unix_handle
,dos_handle
);
1104 WARN(crtdll
, " Failed!\n");
1109 /*********************************************************************
1110 * _unlink (CRTDLL.315)
1112 INT32 __cdecl
CRTDLL__unlink(LPCSTR pathname
)
1115 DOS_FULL_NAME full_name
;
1117 if (!DOSFS_GetFullName( pathname
, FALSE
, &full_name
)) {
1118 WARN(crtdll
, "CRTDLL_unlink file %s bad name\n",pathname
);
1122 ret
=unlink(full_name
.long_name
);
1123 TRACE(crtdll
,"(%s unix %s)\n",
1124 pathname
,full_name
.long_name
);
1126 WARN(crtdll
, " Failed!\n");
1131 /*********************************************************************
1132 * rename (CRTDLL.449)
1134 INT32 __cdecl
CRTDLL_rename(LPCSTR oldpath
,LPCSTR newpath
)
1136 BOOL32 ok
= MoveFileEx32A( oldpath
, newpath
, MOVEFILE_REPLACE_EXISTING
);
1141 /*********************************************************************
1142 * _stat (CRTDLL.280)
1160 int __cdecl
CRTDLL__stat(const char * filename
, struct win_stat
* buf
)
1163 DOS_FULL_NAME full_name
;
1166 if (!DOSFS_GetFullName( filename
, TRUE
, &full_name
))
1168 WARN(crtdll
, "CRTDLL__stat filename %s bad name\n",filename
);
1171 ret
=stat(full_name
.long_name
,&mystat
);
1172 TRACE(crtdll
,"CRTDLL__stat %s\n", filename
);
1174 WARN(crtdll
, " Failed!\n");
1176 /* FIXME: should check what Windows returns */
1178 buf
->win_st_dev
= mystat
.st_dev
;
1179 buf
->win_st_ino
= mystat
.st_ino
;
1180 buf
->win_st_mode
= mystat
.st_mode
;
1181 buf
->win_st_nlink
= mystat
.st_nlink
;
1182 buf
->win_st_uid
= mystat
.st_uid
;
1183 buf
->win_st_gid
= mystat
.st_gid
;
1184 buf
->win_st_rdev
= mystat
.st_rdev
;
1185 buf
->win_st_size
= mystat
.st_size
;
1186 buf
->win_st_atime
= mystat
.st_atime
;
1187 buf
->win_st_mtime
= mystat
.st_mtime
;
1188 buf
->win_st_ctime
= mystat
.st_ctime
;
1192 /*********************************************************************
1193 * _open (CRTDLL.239)
1195 HFILE32 __cdecl
CRTDLL__open(LPCSTR path
,INT32 flags
)
1201 the flags in lcc's header differ from the ones in Linux, e.g.
1202 Linux: define O_APPEND 02000 (= 0x400)
1203 lcc: define _O_APPEND 0x0008
1204 so here a scheme to translate them
1205 Probably lcc is wrong here, but at least a hack to get is going
1207 wineflags
= (flags
& 3);
1208 if (flags
& 0x0008 ) wineflags
|= O_APPEND
;
1209 if (flags
& 0x0100 ) wineflags
|= O_CREAT
;
1210 if (flags
& 0x0200 ) wineflags
|= O_TRUNC
;
1211 if (flags
& 0x0400 ) wineflags
|= O_EXCL
;
1212 if (flags
& 0xf0f4 )
1213 TRACE(crtdll
,"CRTDLL_open file unsupported flags 0x%04x\n",flags
);
1216 ret
= FILE_Open(path
,wineflags
,0);
1217 TRACE(crtdll
,"CRTDLL_open file %s mode 0x%04x (lccmode 0x%04x) got dfh %d\n",
1218 path
,wineflags
,flags
,ret
);
1222 /*********************************************************************
1223 * _close (CRTDLL.57)
1225 INT32 __cdecl
CRTDLL__close(HFILE32 fd
)
1227 int ret
=_lclose32(fd
);
1229 TRACE(crtdll
,"(%d)\n",fd
);
1231 WARN(crtdll
, " Failed!\n");
1236 /*********************************************************************
1239 INT32 __cdecl
CRTDLL_feof( FILE *stream
)
1243 ret
=feof(xlat_file_ptr(stream
));
1244 TRACE(crtdll
,"(%p) %s\n",stream
,(ret
)?"true":"false");
1248 /*********************************************************************
1249 * setlocale (CRTDLL.453)
1251 LPSTR __cdecl
CRTDLL_setlocale(INT32 category
,LPCSTR locale
)
1256 case CRTDLL_LC_ALL
: categorystr
="LC_ALL";break;
1257 case CRTDLL_LC_COLLATE
: categorystr
="LC_COLLATE";break;
1258 case CRTDLL_LC_CTYPE
: categorystr
="LC_CTYPE";break;
1259 case CRTDLL_LC_MONETARY
: categorystr
="LC_MONETARY";break;
1260 case CRTDLL_LC_NUMERIC
: categorystr
="LC_NUMERIC";break;
1261 case CRTDLL_LC_TIME
: categorystr
="LC_TIME";break;
1262 default: categorystr
= "UNKNOWN?";break;
1264 FIXME(crtdll
,"(%s,%s),stub!\n",categorystr
,locale
);
1268 /*********************************************************************
1269 * wcscat (CRTDLL.503)
1271 LPWSTR __cdecl
CRTDLL_wcscat( LPWSTR s1
, LPCWSTR s2
)
1273 return lstrcat32W( s1
, s2
);
1276 /*********************************************************************
1277 * wcschr (CRTDLL.504)
1279 LPWSTR __cdecl
CRTDLL_wcschr(LPCWSTR str
,WCHAR xchar
)
1291 /*********************************************************************
1292 * wcscmp (CRTDLL.505)
1294 INT32 __cdecl
CRTDLL_wcscmp( LPCWSTR s1
, LPCWSTR s2
)
1296 return lstrcmp32W( s1
, s2
);
1299 /*********************************************************************
1300 * wcscpy (CRTDLL.507)
1302 LPWSTR __cdecl
CRTDLL_wcscpy( LPWSTR s1
, LPCWSTR s2
)
1304 return lstrcpy32W( s1
, s2
);
1307 /*********************************************************************
1308 * wcscspn (CRTDLL.508)
1310 INT32 __cdecl
CRTDLL_wcscspn(LPWSTR str
,LPWSTR reject
)
1317 while (*t
) { if (*t
==*s
) break;t
++;}
1321 return s
-str
; /* nr of wchars */
1324 /*********************************************************************
1325 * wcslen (CRTDLL.510)
1327 INT32 __cdecl
CRTDLL_wcslen( LPCWSTR s
)
1329 return lstrlen32W( s
);
1332 /*********************************************************************
1333 * wcsncat (CRTDLL.511)
1335 LPWSTR __cdecl
CRTDLL_wcsncat( LPWSTR s1
, LPCWSTR s2
, INT32 n
)
1337 return lstrcatn32W( s1
, s2
, n
);
1340 /*********************************************************************
1341 * wcsncmp (CRTDLL.512)
1343 INT32 __cdecl
CRTDLL_wcsncmp( LPCWSTR s1
, LPCWSTR s2
, INT32 n
)
1345 return lstrncmp32W( s1
, s2
, n
);
1348 /*********************************************************************
1349 * wcsncpy (CRTDLL.513)
1351 LPWSTR __cdecl
CRTDLL_wcsncpy( LPWSTR s1
, LPCWSTR s2
, INT32 n
)
1353 return lstrcpyn32W( s1
, s2
, n
);
1356 /*********************************************************************
1357 * wcsspn (CRTDLL.516)
1359 INT32 __cdecl
CRTDLL_wcsspn(LPWSTR str
,LPWSTR accept
)
1366 while (*t
) { if (*t
==*s
) break;t
++;}
1370 return s
-str
; /* nr of wchars */
1373 /*********************************************************************
1374 * _wcsicmp (CRTDLL.321)
1376 DWORD __cdecl
CRTDLL__wcsicmp( LPCWSTR s1
, LPCWSTR s2
)
1378 return lstrcmpi32W( s1
, s2
);
1381 /*********************************************************************
1382 * _wcsicoll (CRTDLL.322)
1384 DWORD __cdecl
CRTDLL__wcsicoll(LPCWSTR a1
,LPCWSTR a2
)
1386 /* FIXME: handle collates */
1387 return lstrcmpi32W(a1
,a2
);
1390 /*********************************************************************
1391 * _wcsnicmp (CRTDLL.324)
1393 DWORD __cdecl
CRTDLL__wcsnicmp( LPCWSTR s1
, LPCWSTR s2
, INT32 len
)
1395 return lstrncmpi32W( s1
, s2
, len
);
1398 /*********************************************************************
1399 * wcscoll (CRTDLL.506)
1401 DWORD __cdecl
CRTDLL_wcscoll(LPWSTR a1
,LPWSTR a2
)
1403 /* FIXME: handle collates */
1404 return lstrcmp32W(a1
,a2
);
1407 /*********************************************************************
1408 * _wcsrev (CRTDLL.326)
1410 VOID __cdecl
CRTDLL__wcsrev(LPWSTR s
) {
1424 /*********************************************************************
1425 * wcsstr (CRTDLL.517)
1427 LPWSTR __cdecl
CRTDLL_wcsstr(LPWSTR s
,LPWSTR b
)
1435 while (*y
&& *c
&& *y
==*c
) { c
++;y
++; }
1444 /*********************************************************************
1445 * wcstombs (CRTDLL.521)
1447 INT32 __cdecl
CRTDLL_wcstombs( LPSTR dst
, LPCWSTR src
, INT32 len
)
1449 lstrcpynWtoA( dst
, src
, len
);
1450 return strlen(dst
); /* FIXME: is this right? */
1453 /*********************************************************************
1454 * wcsrchr (CRTDLL.515)
1456 LPWSTR __cdecl
CRTDLL_wcsrchr(LPWSTR str
,WCHAR xchar
)
1460 s
=str
+lstrlen32W(str
);
1469 /*********************************************************************
1470 * _setmode (CRTDLL.265)
1471 * FIXME: At present we ignore the request to translate CR/LF to LF.
1473 * We allways translate when we read with fgets, we never do with fread
1476 INT32 __cdecl
CRTDLL__setmode( INT32 fh
,INT32 mode
)
1479 #define O_TEXT 0x4000
1480 #define O_BINARY 0x8000
1482 FIXME(crtdll
, "on fhandle %d mode %s, STUB.\n",
1483 fh
,(mode
=O_TEXT
)?"O_TEXT":
1484 (mode
=O_BINARY
)?"O_BINARY":"UNKNOWN");
1488 /*********************************************************************
1489 * _fpreset (CRTDLL.107)
1491 VOID __cdecl
CRTDLL__fpreset(void)
1493 FIXME(crtdll
," STUB.\n");
1496 /*********************************************************************
1497 * atexit (CRTDLL.345)
1499 INT32 __cdecl
CRTDLL_atexit(LPVOID x
)
1501 FIXME(crtdll
,"(%p), STUB.\n",x
);
1502 return 0; /* successful */
1505 /*********************************************************************
1506 * mblen (CRTDLL.428)
1507 * FIXME: check multibyte support
1509 WCHAR __cdecl
CRTDLL_mblen(CHAR
*mb
,INT32 size
)
1516 else if ((size
<1)||(!*(mb
+1)))
1521 TRACE(crtdll
,"CRTDLL_mlen %s for max %d bytes ret %d\n",mb
,size
,ret
);
1526 /*********************************************************************
1527 * mbstowcs (CRTDLL.429)
1528 * FIXME: check multibyte support
1530 INT32 __cdecl
CRTDLL_mbstowcs(LPWSTR wcs
, LPCSTR mbs
, INT32 size
)
1533 /* Slightly modified lstrcpynAtoW functions from memory/strings.c
1534 * We need the number of characters transfered
1535 * FIXME: No multibyte support yet
1542 while ((n
-- > 0) && *src
) {
1543 *p
++ = (WCHAR
)(unsigned char)*src
++;
1548 TRACE(crtdll
,"CRTDLL_mbstowcs %s for %d chars put %d wchars\n",
1553 /*********************************************************************
1554 * mbtowc (CRTDLL.430)
1555 * FIXME: check multibyte support
1557 WCHAR __cdecl
CRTDLL_mbtowc(WCHAR
* wc
,CHAR
* mb
,INT32 size
)
1566 if ( (ret
= mblen(mb
,size
)) != -1 )
1568 if (ret
<= sizeof(char))
1569 *wc
= (WCHAR
) ((unsigned char)*mb
);
1576 TRACE(crtdll
,"CRTDLL_mbtowc %s for %d chars\n",mb
,size
);
1581 /*********************************************************************
1582 * _isctype (CRTDLL.138)
1584 BOOL32 __cdecl
CRTDLL__isctype(CHAR x
,CHAR type
)
1586 if ((type
& CRTDLL_SPACE
) && isspace(x
))
1588 if ((type
& CRTDLL_PUNCT
) && ispunct(x
))
1590 if ((type
& CRTDLL_LOWER
) && islower(x
))
1592 if ((type
& CRTDLL_UPPER
) && isupper(x
))
1594 if ((type
& CRTDLL_ALPHA
) && isalpha(x
))
1596 if ((type
& CRTDLL_DIGIT
) && isdigit(x
))
1598 if ((type
& CRTDLL_CONTROL
) && iscntrl(x
))
1600 /* check CRTDLL_LEADBYTE */
1604 /*********************************************************************
1605 * _chdrive (CRTDLL.52)
1607 * newdir [I] drive to change to, A=1
1610 BOOL32 __cdecl
CRTDLL__chdrive(INT32 newdrive
)
1612 /* FIXME: generates errnos */
1613 return DRIVE_SetCurrentDrive(newdrive
-1);
1616 /*********************************************************************
1617 * _chdir (CRTDLL.51)
1619 INT32 __cdecl
CRTDLL__chdir(LPCSTR newdir
)
1621 if (!SetCurrentDirectory32A(newdir
))
1626 /*********************************************************************
1627 * _fullpath (CRTDLL.114)
1629 LPSTR __cdecl
CRTDLL__fullpath(LPSTR buf
, LPCSTR name
, INT32 size
)
1631 DOS_FULL_NAME full_name
;
1636 if(!(buf
= CRTDLL_malloc(size
))) return NULL
;
1638 if (!DOSFS_GetFullName( name
, FALSE
, &full_name
)) return NULL
;
1639 lstrcpyn32A(buf
,full_name
.short_name
,size
);
1640 TRACE(crtdll
,"CRTDLL_fullpath got %s\n",buf
);
1644 /*********************************************************************
1645 * _splitpath (CRTDLL.279)
1647 VOID __cdecl
CRTDLL__splitpath(LPCSTR path
, LPSTR drive
, LPSTR directory
, LPSTR filename
, LPSTR extension
)
1650 directory includes leading and trailing (forward and backward slashes)
1651 filename without dot and slashes
1652 extension with leading dot
1654 char * drivechar
,*dirchar
,*namechar
;
1656 TRACE(crtdll
,"CRTDLL__splitpath got %s\n",path
);
1658 drivechar
= strchr(path
,':');
1659 dirchar
= strrchr(path
,'/');
1660 namechar
= strrchr(path
,'\\');
1661 dirchar
= MAX(dirchar
,namechar
);
1663 namechar
= strrchr(dirchar
,'.');
1665 namechar
= strrchr(path
,'.');
1673 strncat(drive
,path
,drivechar
-path
+1);
1682 strncat(directory
,path
,dirchar
-path
+1);
1691 strncat(filename
,path
,namechar
-path
);
1695 strcat(extension
,namechar
);
1700 TRACE(crtdll
,"CRTDLL__splitpath found %s %s %s %s\n",drive
,directory
,filename
,extension
);
1704 /*********************************************************************
1705 * _getcwd (CRTDLL.120)
1707 CHAR
* __cdecl
CRTDLL__getcwd(LPSTR buf
, INT32 size
)
1714 if (size
< 0) /* allocate as big as nescessary */
1715 len
=GetCurrentDirectory32A(1,test
) + 1;
1716 if(!(buf
= CRTDLL_malloc(len
)))
1718 /* set error to OutOfRange */
1723 if(!(len
=GetCurrentDirectory32A(len
,buf
)))
1729 /* set error to ERANGE */
1730 TRACE(crtdll
,"CRTDLL_getcwd buffer to small\n");
1737 /*********************************************************************
1738 * _getdcwd (CRTDLL.121)
1740 CHAR
* __cdecl
CRTDLL__getdcwd(INT32 drive
,LPSTR buf
, INT32 size
)
1745 FIXME(crtdll
,"(\"%c:\",%s,%d)\n",drive
+'A',buf
,size
);
1748 if (size
< 0) /* allocate as big as nescessary */
1749 len
=GetCurrentDirectory32A(1,test
) + 1;
1750 if(!(buf
= CRTDLL_malloc(len
)))
1752 /* set error to OutOfRange */
1757 if(!(len
=GetCurrentDirectory32A(len
,buf
)))
1763 /* set error to ERANGE */
1764 TRACE(crtdll
,"buffer to small\n");
1771 /*********************************************************************
1772 * _getdrive (CRTDLL.124)
1774 * Return current drive, 1 for A, 2 for B
1776 INT32 __cdecl
CRTDLL__getdrive(VOID
)
1778 return DRIVE_GetCurrentDrive() + 1;
1781 /*********************************************************************
1782 * _mkdir (CRTDLL.234)
1784 INT32 __cdecl
CRTDLL__mkdir(LPCSTR newdir
)
1786 if (!CreateDirectory32A(newdir
,NULL
))
1791 /*********************************************************************
1792 * remove (CRTDLL.448)
1794 INT32 __cdecl
CRTDLL_remove(LPCSTR file
)
1796 if (!DeleteFile32A(file
))
1801 /*********************************************************************
1802 * _errno (CRTDLL.52)
1803 * Yes, this is a function.
1805 LPINT32 __cdecl
CRTDLL__errno()
1807 static int crtdllerrno
;
1809 /* FIXME: we should set the error at the failing function call time */
1810 crtdllerrno
= LastErrorToErrno(GetLastError());
1811 return &crtdllerrno
;
1814 /*********************************************************************
1815 * _tempnam (CRTDLL.305)
1818 LPSTR __cdecl
CRTDLL__tempnam(LPCSTR dir
, LPCSTR prefix
)
1822 DOS_FULL_NAME tempname
;
1824 if ((ret
= tempnam(dir
,prefix
))==NULL
) {
1825 WARN(crtdll
, "Unable to get unique filename\n");
1828 if (!DOSFS_GetFullName(ret
,FALSE
,&tempname
))
1830 TRACE(crtdll
, "Wrong path?\n");
1834 if ((ret
= CRTDLL_malloc(strlen(tempname
.short_name
)+1)) == NULL
) {
1835 WARN(crtdll
, "CRTDL_malloc for shortname failed\n");
1838 if ((ret
= strcpy(ret
,tempname
.short_name
)) == NULL
) {
1839 WARN(crtdll
, "Malloc for shortname failed\n");
1843 TRACE(crtdll
,"dir %s prefix %s got %s\n",
1848 /*********************************************************************
1849 * tmpnam (CRTDLL.490)
1851 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1854 LPSTR __cdecl
CRTDLL_tmpnam(LPSTR s
)
1858 if ((ret
=tmpnam(s
))== NULL
) {
1859 WARN(crtdll
, "Unable to get unique filename\n");
1862 if (!DOSFS_GetFullName(ret
,FALSE
,&CRTDLL_tmpname
))
1864 TRACE(crtdll
, "Wrong path?\n");
1867 strcat(CRTDLL_tmpname
.short_name
,".");
1868 TRACE(crtdll
,"for buf %p got %s\n",
1869 s
,CRTDLL_tmpname
.short_name
);
1870 TRACE(crtdll
,"long got %s\n",
1871 CRTDLL_tmpname
.long_name
);
1873 return strcpy(s
,CRTDLL_tmpname
.short_name
);
1875 return CRTDLL_tmpname
.short_name
;
1879 /*********************************************************************
1880 * _itoa (CRTDLL.165)
1882 LPSTR __cdecl
CRTDLL__itoa(INT32 x
,LPSTR buf
,INT32 buflen
)
1884 wsnprintf32A(buf
,buflen
,"%d",x
);
1888 /*********************************************************************
1889 * _ltoa (CRTDLL.180)
1891 LPSTR __cdecl
CRTDLL__ltoa(long x
,LPSTR buf
,INT32 radix
)
1894 case 2: FIXME(crtdll
, "binary format not implemented !\n");
1896 case 8: wsnprintf32A(buf
,0x80,"%o",x
);
1898 case 10: wsnprintf32A(buf
,0x80,"%d",x
);
1900 case 16: wsnprintf32A(buf
,0x80,"%x",x
);
1902 default: FIXME(crtdll
, "radix %d not implemented !\n", radix
);
1907 typedef VOID (*sig_handler_type
)(VOID
);
1909 /*********************************************************************
1910 * signal (CRTDLL.455)
1912 VOID __cdecl
CRTDLL_signal(int sig
, sig_handler_type ptr
)
1914 FIXME(crtdll
, "(%d %p):stub.\n", sig
, ptr
);
1917 /*********************************************************************
1918 * _ftol (CRTDLL.113)
1920 LONG __cdecl
CRTDLL__ftol(double fl
) {
1923 /*********************************************************************
1924 * _sleep (CRTDLL.267)
1926 VOID __cdecl
CRTDLL__sleep(unsigned long timeout
)
1928 TRACE(crtdll
,"CRTDLL__sleep for %ld milliseconds\n",timeout
);
1929 Sleep((timeout
)?timeout
:1);
1932 /*********************************************************************
1933 * getenv (CRTDLL.437)
1935 LPSTR __cdecl
CRTDLL_getenv(const char *name
)
1937 LPSTR environ
= GetEnvironmentStrings32A();
1938 LPSTR pp
,pos
= NULL
;
1939 unsigned int length
;
1941 for (pp
= environ
; (*pp
); pp
= pp
+ strlen(pp
) +1)
1943 pos
=strchr(pp
,'=');
1947 length
= strlen(pp
);
1948 if (!strncmp(pp
,name
,length
)) break;
1953 TRACE(crtdll
,"got %s\n",pp
);
1955 FreeEnvironmentStrings32A( environ
);
1959 /*********************************************************************
1960 * _mbsrchr (CRTDLL.223)
1962 LPSTR __cdecl
CRTDLL__mbsrchr(LPSTR s
,CHAR x
) {
1963 /* FIXME: handle multibyte strings */
1964 return strrchr(s
,x
);
1967 /*********************************************************************
1968 * _memicmp (CRTDLL.233)(NTDLL.868)
1969 * A stringcompare, without \0 check
1971 * -1:if first string is alphabetically before second string
1972 * 1:if second '' '' '' '' first ''
1973 * 0:if both are equal.
1975 INT32 __cdecl
CRTDLL__memicmp(
1976 LPCSTR s1
, /* [in] first string */
1977 LPCSTR s2
, /* [in] second string */
1978 DWORD len
/* [in] length to compare */
1982 for (i
=0;i
<len
;i
++) {
1983 if (tolower(s1
[i
])<tolower(s2
[i
]))
1985 if (tolower(s1
[i
])>tolower(s2
[i
]))
1990 /*********************************************************************
1991 * __dllonexit (CRTDLL.25)
1993 VOID __cdecl
CRTDLL__dllonexit ()
1995 FIXME(crtdll
,"stub\n");
1998 /*********************************************************************
1999 * wcstok (CRTDLL.519)
2000 * Like strtok, but for wide character strings. s is modified, yes.
2002 LPWSTR
CRTDLL_wcstok(LPWSTR s
,LPCWSTR delim
) {
2003 static LPWSTR nexttok
= NULL
;
2011 while (*x
&& !CRTDLL_wcschr(delim
,*x
))
2022 /*********************************************************************
2023 * wcstol (CRTDLL.520)
2024 * Like strtol, but for wide character strings.
2026 INT32
CRTDLL_wcstol(LPWSTR s
,LPWSTR
*end
,INT32 base
) {
2027 LPSTR sA
= HEAP_strdupWtoA(GetProcessHeap(),0,s
),endA
;
2028 INT32 ret
= strtol(sA
,&endA
,base
);
2030 HeapFree(GetProcessHeap(),0,sA
);
2031 if (end
) *end
= s
+(endA
-sA
); /* pointer magic checked. */