Use MZ_Current() instead of pModule->lpDosTask. Cleaned up the RMCB32
[wine/dcerpc.git] / dlls / crtdll / crtdll_main.c
blobe6d4c311b7ed5d27c35acb15231e361348ba35c4
1 /*
2 * The C RunTime DLL
3 *
4 * Implements C run-time functionality as known from UNIX.
6 * Copyright 1996,1998 Marcus Meissner
7 * Copyright 1996 Jukka Iivonen
8 * Copyright 1997,2000 Uwe Bonnes
9 */
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
19 AJ 990101:
20 - needs a proper stdio emulation based on Win32 file handles
21 - should set CRTDLL errno from GetLastError() in every function
22 UB 000416:
23 - probably not thread safe
26 /* NOTE: This file also implements the wcs* functions. They _ARE_ in
27 * the newer Linux libcs, but use 4 byte wide characters, so are unusable,
28 * since we need 2 byte wide characters. - Marcus Meissner, 981031
31 #include "config.h"
33 #include <errno.h>
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <string.h>
37 #include <stdio.h>
38 #include <sys/stat.h>
39 #include <sys/times.h>
40 #include <unistd.h>
41 #include <time.h>
42 #include <ctype.h>
43 #include <math.h>
44 #include <fcntl.h>
45 #include <setjmp.h>
46 #include "winbase.h"
47 #include "windef.h"
48 #include "wingdi.h"
49 #include "winuser.h"
50 #include "winerror.h"
51 #include "ntddk.h"
52 #include "debugtools.h"
53 #include "module.h"
54 #include "heap.h"
55 #include "crtdll.h"
56 #include "drive.h"
57 #include "file.h"
58 #include "options.h"
59 #include "winnls.h"
61 DEFAULT_DEBUG_CHANNEL(crtdll);
63 /* windows.h RAND_MAX is smaller than normal RAND_MAX */
64 #define CRTDLL_RAND_MAX 0x7fff
66 static DOS_FULL_NAME CRTDLL_tmpname;
68 UINT CRTDLL_argc_dll; /* CRTDLL.23 */
69 LPSTR *CRTDLL_argv_dll; /* CRTDLL.24 */
70 LPSTR CRTDLL_acmdln_dll; /* CRTDLL.38 */
71 UINT CRTDLL_basemajor_dll; /* CRTDLL.42 */
72 UINT CRTDLL_baseminor_dll; /* CRTDLL.43 */
73 UINT CRTDLL_baseversion_dll; /* CRTDLL.44 */
74 UINT CRTDLL_commode_dll; /* CRTDLL.59 */
75 LPSTR CRTDLL_environ_dll; /* CRTDLL.75 */
76 UINT CRTDLL_fmode_dll; /* CRTDLL.104 */
77 UINT CRTDLL_osmajor_dll; /* CRTDLL.241 */
78 UINT CRTDLL_osminor_dll; /* CRTDLL.242 */
79 UINT CRTDLL_osmode_dll; /* CRTDLL.243 */
80 UINT CRTDLL_osver_dll; /* CRTDLL.244 */
81 UINT CRTDLL_osversion_dll; /* CRTDLL.245 */
82 UINT CRTDLL_winmajor_dll; /* CRTDLL.329 */
83 UINT CRTDLL_winminor_dll; /* CRTDLL.330 */
84 UINT CRTDLL_winver_dll; /* CRTDLL.331 */
86 /* FIXME: structure layout is obviously not correct */
87 typedef struct
89 HANDLE handle;
90 int pad[7];
91 } CRTDLL_FILE;
93 CRTDLL_FILE CRTDLL_iob[3];
95 static CRTDLL_FILE * const CRTDLL_stdin = &CRTDLL_iob[0];
96 static CRTDLL_FILE * const CRTDLL_stdout = &CRTDLL_iob[1];
97 static CRTDLL_FILE * const CRTDLL_stderr = &CRTDLL_iob[2];
99 typedef VOID (*new_handler_type)(VOID);
101 static new_handler_type new_handler;
103 CRTDLL_FILE * __cdecl CRTDLL__fdopen(INT handle, LPCSTR mode);
105 /*********************************************************************
106 * CRTDLL_MainInit (CRTDLL.init)
108 BOOL WINAPI CRTDLL_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
110 TRACE("(0x%08x,%ld,%p)\n",hinstDLL,fdwReason,lpvReserved);
112 if (fdwReason == DLL_PROCESS_ATTACH) {
113 CRTDLL__fdopen(0,"r");
114 CRTDLL__fdopen(1,"w");
115 CRTDLL__fdopen(2,"w");
117 return TRUE;
120 /*********************************************************************
121 * _GetMainArgs (CRTDLL.022)
123 LPSTR * __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,
124 LPSTR *environ,DWORD flag)
126 char *cmdline;
127 char **xargv;
128 int xargc,end,last_arg,afterlastspace;
129 DWORD version;
131 TRACE("(%p,%p,%p,%ld).\n",
132 argc,argv,environ,flag
135 if (CRTDLL_acmdln_dll != NULL)
136 HeapFree(GetProcessHeap(), 0, CRTDLL_acmdln_dll);
138 CRTDLL_acmdln_dll = cmdline = HEAP_strdupA( GetProcessHeap(), 0,
139 GetCommandLineA() );
140 TRACE("got '%s'\n", cmdline);
142 version = GetVersion();
143 CRTDLL_osver_dll = version >> 16;
144 CRTDLL_winminor_dll = version & 0xFF;
145 CRTDLL_winmajor_dll = (version>>8) & 0xFF;
146 CRTDLL_baseversion_dll = version >> 16;
147 CRTDLL_winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
148 CRTDLL_baseminor_dll = (version >> 16) & 0xFF;
149 CRTDLL_basemajor_dll = (version >> 24) & 0xFF;
150 CRTDLL_osversion_dll = version & 0xFFFF;
151 CRTDLL_osminor_dll = version & 0xFF;
152 CRTDLL_osmajor_dll = (version>>8) & 0xFF;
154 /* missing threading init */
156 end=0;last_arg=0;xargv=NULL;xargc=0;afterlastspace=0;
157 while (1)
159 if ((cmdline[end]==' ') || (cmdline[end]=='\0'))
161 if (cmdline[end]=='\0')
162 last_arg=1;
163 else
164 cmdline[end]='\0';
165 /* alloc xargc + NULL entry */
166 xargv=(char**)HeapReAlloc( GetProcessHeap(), 0, xargv,
167 sizeof(char*)*(xargc+1));
168 if (strlen(cmdline+afterlastspace))
170 xargv[xargc] = HEAP_strdupA( GetProcessHeap(), 0,
171 cmdline+afterlastspace);
172 xargc++;
173 if (!last_arg) /* need to seek to the next arg ? */
175 end++;
176 while (cmdline[end]==' ')
177 end++;
179 afterlastspace=end;
181 else
183 xargv[xargc] = NULL; /* the last entry is NULL */
184 break;
187 else
188 end++;
190 CRTDLL_argc_dll = xargc;
191 *argc = xargc;
192 CRTDLL_argv_dll = xargv;
193 *argv = xargv;
195 TRACE("found %d arguments\n",
196 CRTDLL_argc_dll);
197 CRTDLL_environ_dll = *environ = GetEnvironmentStringsA();
198 return environ;
202 typedef void (*_INITTERMFUN)();
204 /* fixme: move to header */
205 struct find_t
206 { unsigned attrib;
207 time_t time_create; /* -1 when not avaiable */
208 time_t time_access; /* -1 when not avaiable */
209 time_t time_write;
210 unsigned long size; /* fixme: 64 bit ??*/
211 char name[260];
213 /*********************************************************************
214 * _findfirst (CRTDLL.099)
216 * BUGS
217 * Unimplemented
219 DWORD __cdecl CRTDLL__findfirst(LPCSTR fname, struct find_t * x2)
221 FIXME(":(%s,%p): stub\n",fname,x2);
222 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
223 return FALSE;
226 /*********************************************************************
227 * _findnext (CRTDLL.100)
229 * BUGS
230 * Unimplemented
232 INT __cdecl CRTDLL__findnext(DWORD hand, struct find_t * x2)
234 FIXME(":(%ld,%p): stub\n",hand,x2);
235 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
236 return FALSE;
239 /*********************************************************************
240 * _fstat (CRTDLL.111)
242 * BUGS
243 * Unimplemented
245 int __cdecl CRTDLL__fstat(int file, struct stat* buf)
247 FIXME(":(%d,%p): stub\n",file,buf);
248 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
249 return FALSE;
252 /*********************************************************************
253 * _initterm (CRTDLL.135)
255 DWORD __cdecl CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
257 _INITTERMFUN *current;
259 TRACE("(%p,%p)\n",start,end);
260 current=start;
261 while (current<end) {
262 if (*current) (*current)();
263 current++;
265 return 0;
268 /*********************************************************************
269 * _fsopen (CRTDLL.110)
271 CRTDLL_FILE * __cdecl CRTDLL__fsopen(LPCSTR x, LPCSTR y, INT z) {
272 FIXME("(%s,%s,%d),stub!\n",x,y,z);
273 return NULL;
276 /*********************************************************************
277 * _fdopen (CRTDLL.91)
279 CRTDLL_FILE * __cdecl CRTDLL__fdopen(INT handle, LPCSTR mode)
281 CRTDLL_FILE *file;
283 switch (handle)
285 case 0:
286 file = CRTDLL_stdin;
287 if (!file->handle) file->handle = GetStdHandle( STD_INPUT_HANDLE );
288 break;
289 case 1:
290 file = CRTDLL_stdout;
291 if (!file->handle) file->handle = GetStdHandle( STD_OUTPUT_HANDLE );
292 break;
293 case 2:
294 file=CRTDLL_stderr;
295 if (!file->handle) file->handle = GetStdHandle( STD_ERROR_HANDLE );
296 break;
297 default:
298 file = HeapAlloc( GetProcessHeap(), 0, sizeof(*file) );
299 file->handle = handle;
300 break;
302 TRACE("open handle %d mode %s got file %p\n",
303 handle, mode, file);
304 return file;
308 /*******************************************************************
309 * _global_unwind2 (CRTDLL.129)
311 void __cdecl CRTDLL__global_unwind2( PEXCEPTION_FRAME frame )
313 RtlUnwind( frame, 0, NULL, 0 );
316 /*******************************************************************
317 * _local_unwind2 (CRTDLL.173)
319 void __cdecl CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe, DWORD nr )
321 TRACE("(%p,%ld)\n",endframe,nr);
323 /*******************************************************************
324 * _setjmp (CRTDLL.264)
326 INT __cdecl CRTDLL__setjmp(LPDWORD *jmpbuf)
328 FIXME(":(%p): stub\n",jmpbuf);
329 return 0;
332 /*********************************************************************
333 * fopen (CRTDLL.372)
335 CRTDLL_FILE * __cdecl CRTDLL_fopen(LPCSTR path, LPCSTR mode)
337 CRTDLL_FILE *file = NULL;
338 HFILE handle;
339 #if 0
340 DOS_FULL_NAME full_name;
342 if (!DOSFS_GetFullName( path, FALSE, &full_name )) {
343 WARN("file %s bad name\n",path);
344 return 0;
347 file=fopen(full_name.long_name ,mode);
348 #endif
349 DWORD access = 0, creation = 0;
351 if ((strchr(mode,'r')&&strchr(mode,'a'))||
352 (strchr(mode,'r')&&strchr(mode,'w'))||
353 (strchr(mode,'w')&&strchr(mode,'a')))
354 return NULL;
356 if (mode[0] == 'r')
358 access = GENERIC_READ;
359 creation = OPEN_EXISTING;
360 if (mode[1] == '+') access |= GENERIC_WRITE;
362 else if (mode[0] == 'w')
364 access = GENERIC_WRITE;
365 creation = CREATE_ALWAYS;
366 if (mode[1] == '+') access |= GENERIC_READ;
368 else if (mode[0] == 'a')
370 /* FIXME: there is no O_APPEND in CreateFile, should emulate it */
371 access = GENERIC_WRITE;
372 creation = OPEN_ALWAYS;
373 if (mode[1] == '+') access |= GENERIC_READ;
375 /* FIXME: should handle text/binary mode */
377 if ((handle = CreateFileA( path, access, FILE_SHARE_READ | FILE_SHARE_WRITE,
378 NULL, creation, FILE_ATTRIBUTE_NORMAL,
379 -1 )) != INVALID_HANDLE_VALUE)
381 file = HeapAlloc( GetProcessHeap(), 0, sizeof(*file) );
382 file->handle = handle;
384 TRACE("file %s mode %s got handle %d file %p\n",
385 path,mode,handle,file);
386 return file;
389 /*********************************************************************
390 * fread (CRTDLL.377)
392 DWORD __cdecl CRTDLL_fread(LPVOID ptr, INT size, INT nmemb, CRTDLL_FILE *file)
394 #if 0
395 int i=0;
396 void *temp=ptr;
398 /* If we would honour CR/LF <-> LF translation, we could do it like this.
399 We should keep track of all files opened, and probably files with \
400 known binary extensions must be unchanged */
401 while ( (i < (nmemb*size)) && (ret==1)) {
402 ret=fread(temp,1,1,file);
403 TRACE("got %c 0x%02x ret %d\n",
404 (isalpha(*(unsigned char*)temp))? *(unsigned char*)temp:
405 ' ',*(unsigned char*)temp, ret);
406 if (*(unsigned char*)temp != 0xd) { /* skip CR */
407 temp++;
408 i++;
410 else
411 TRACE("skipping ^M\n");
413 TRACE("0x%08x items of size %d from file %p to %p\n",
414 nmemb,size,file,ptr,);
415 if(i!=nmemb)
416 WARN(" failed!\n");
418 return i;
419 #else
420 DWORD ret;
422 TRACE("0x%08x items of size %d from file %p to %p\n",
423 nmemb,size,file,ptr);
424 if (!ReadFile( file->handle, ptr, size * nmemb, &ret, NULL ))
425 WARN(" failed!\n");
427 return ret / size;
428 #endif
430 /*********************************************************************
431 * freopen (CRTDLL.379)
433 * BUGS
434 * Unimplemented
436 DWORD __cdecl CRTDLL_freopen(LPCSTR path, LPCSTR mode, LPVOID stream)
438 FIXME(":(%s,%s,%p): stub\n", path, mode, stream);
439 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
440 return FALSE;
443 /*********************************************************************
444 * fscanf (CRTDLL.381)
446 INT __cdecl CRTDLL_fscanf( CRTDLL_FILE *stream, LPSTR format, ... )
448 #if 0
449 va_list valist;
450 INT res;
452 va_start( valist, format );
453 #ifdef HAVE_VFSCANF
454 res = vfscanf( xlat_file_ptr(stream), format, valist );
455 #endif
456 va_end( valist );
457 return res;
458 #endif
459 FIXME("broken\n");
460 return 0;
463 /*********************************************************************
464 * _lseek (CRTDLL.179)
466 LONG __cdecl CRTDLL__lseek( INT fd, LONG offset, INT whence)
468 TRACE("fd %d to 0x%08lx pos %s\n",
469 fd,offset,(whence==SEEK_SET)?"SEEK_SET":
470 (whence==SEEK_CUR)?"SEEK_CUR":
471 (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
472 return SetFilePointer( fd, offset, NULL, whence );
475 /*********************************************************************
476 * fseek (CRTDLL.382)
478 LONG __cdecl CRTDLL_fseek( CRTDLL_FILE *file, LONG offset, INT whence)
480 TRACE("file %p to 0x%08lx pos %s\n",
481 file,offset,(whence==SEEK_SET)?"SEEK_SET":
482 (whence==SEEK_CUR)?"SEEK_CUR":
483 (whence==SEEK_END)?"SEEK_END":"UNKNOWN");
484 if (SetFilePointer( file->handle, offset, NULL, whence ) != 0xffffffff)
485 return 0;
486 WARN(" failed!\n");
487 return -1;
490 /*********************************************************************
491 * fsetpos (CRTDLL.383)
493 INT __cdecl CRTDLL_fsetpos( CRTDLL_FILE *file, INT *pos )
495 TRACE("file %p pos %d\n", file, *pos );
496 return CRTDLL_fseek(file, *pos, SEEK_SET);
499 /*********************************************************************
500 * ftell (CRTDLL.384)
502 LONG __cdecl CRTDLL_ftell( CRTDLL_FILE *file )
504 return SetFilePointer( file->handle, 0, NULL, SEEK_CUR );
507 /*********************************************************************
508 * fwrite (CRTDLL.386)
510 DWORD __cdecl CRTDLL_fwrite( LPVOID ptr, INT size, INT nmemb, CRTDLL_FILE *file )
512 DWORD ret;
514 TRACE("0x%08x items of size %d to file %p(%d) from %p\n",
515 nmemb,size,file,file-(CRTDLL_FILE*)CRTDLL_iob,ptr);
518 if (!WriteFile( file->handle, ptr, size * nmemb, &ret, NULL ))
519 WARN(" failed!\n");
520 return ret / size;
523 /*********************************************************************
524 * setbuf (CRTDLL.452)
526 INT __cdecl CRTDLL_setbuf(CRTDLL_FILE *file, LPSTR buf)
528 TRACE("(file %p buf %p)\n", file, buf);
529 /* this doesn't work:"void value not ignored as it ought to be"
530 return setbuf(file,buf);
532 /* FIXME: no buffering for now */
533 return 0;
536 /*********************************************************************
537 * _open_osfhandle (CRTDLL.240)
539 HFILE __cdecl CRTDLL__open_osfhandle(LONG osfhandle, INT flags)
541 HFILE handle;
543 switch (osfhandle) {
544 case STD_INPUT_HANDLE :
545 case 0 :
546 handle=0;
547 break;
548 case STD_OUTPUT_HANDLE:
549 case 1:
550 handle=1;
551 break;
552 case STD_ERROR_HANDLE:
553 case 2:
554 handle=2;
555 break;
556 default:
557 return (-1);
559 TRACE("(handle %08lx,flags %d) return %d\n",
560 osfhandle,flags,handle);
561 return handle;
565 /*********************************************************************
566 * srand (CRTDLL.460)
568 void __cdecl CRTDLL_srand(DWORD seed)
570 /* FIXME: should of course be thread? process? local */
571 srand(seed);
574 /*********************************************************************
575 * vfprintf (CRTDLL.373)
577 INT __cdecl CRTDLL_vfprintf( CRTDLL_FILE *file, LPSTR format, va_list args )
579 char buffer[2048]; /* FIXME... */
581 vsprintf( buffer, format, args );
582 return CRTDLL_fwrite( buffer, 1, strlen(buffer), file );
585 /*********************************************************************
586 * fprintf (CRTDLL.373)
588 INT __cdecl CRTDLL_fprintf( CRTDLL_FILE *file, LPSTR format, ... )
590 va_list valist;
591 INT res;
593 va_start( valist, format );
594 res = CRTDLL_vfprintf( file, format, valist );
595 va_end( valist );
596 return res;
599 /*********************************************************************
600 * time (CRTDLL.488)
602 time_t __cdecl CRTDLL_time(time_t *timeptr)
604 time_t curtime = time(NULL);
606 if (timeptr)
607 *timeptr = curtime;
608 return curtime;
611 /*********************************************************************
612 * difftime (CRTDLL.357)
614 double __cdecl CRTDLL_difftime (time_t time1, time_t time2)
616 double timediff;
618 timediff = (double)(time1 - time2);
619 return timediff;
622 /*********************************************************************
623 * clock (CRTDLL.350)
625 clock_t __cdecl CRTDLL_clock(void)
627 struct tms alltimes;
628 clock_t res;
630 times(&alltimes);
631 res = alltimes.tms_utime + alltimes.tms_stime+
632 alltimes.tms_cutime + alltimes.tms_cstime;
633 /* Fixme: We need some symbolic representation
634 for (Hostsystem_)CLOCKS_PER_SEC
635 and (Emulated_system_)CLOCKS_PER_SEC
636 10 holds only for Windows/Linux_i86)
638 return 10*res;
641 /*********************************************************************
642 * _isatty (CRTDLL.137)
644 BOOL __cdecl CRTDLL__isatty(DWORD x)
646 TRACE("(%ld)\n",x);
647 return TRUE;
650 /*********************************************************************
651 * _read (CRTDLL.256)
654 INT __cdecl CRTDLL__read(INT fd, LPVOID buf, UINT count)
656 TRACE("0x%08x bytes fd %d to %p\n", count,fd,buf);
657 if (!fd) fd = GetStdHandle( STD_INPUT_HANDLE );
658 return _lread( fd, buf, count );
661 /*********************************************************************
662 * _write (CRTDLL.332)
664 INT __cdecl CRTDLL__write(INT fd,LPCVOID buf,UINT count)
666 INT len=0;
668 if (fd == -1)
669 len = -1;
670 else if (fd<=2)
671 len = (UINT)write(fd,buf,(LONG)count);
672 else
673 len = _lwrite(fd,buf,count);
674 TRACE("%d/%d byte to dfh %d from %p,\n",
675 len,count,fd,buf);
676 return len;
680 /*********************************************************************
681 * _cexit (CRTDLL.49)
683 * FIXME: What the heck is the difference between
684 * FIXME _c_exit (CRTDLL.47)
685 * FIXME _cexit (CRTDLL.49)
686 * FIXME _exit (CRTDLL.87)
687 * FIXME exit (CRTDLL.359)
689 * atexit-processing comes to mind -- MW.
692 void __cdecl CRTDLL__cexit(INT ret)
694 TRACE("(%d)\n",ret);
695 ExitProcess(ret);
699 /*********************************************************************
700 * exit (CRTDLL.359)
702 void __cdecl CRTDLL_exit(DWORD ret)
704 TRACE("(%ld)\n",ret);
705 ExitProcess(ret);
709 /*********************************************************************
710 * _abnormal_termination (CRTDLL.36)
712 INT __cdecl CRTDLL__abnormal_termination(void)
714 TRACE("(void)\n");
715 return 0;
719 /*********************************************************************
720 * _access (CRTDLL.37)
722 INT __cdecl CRTDLL__access(LPCSTR filename, INT mode)
724 DWORD attr = GetFileAttributesA(filename);
726 if (attr == -1)
728 if (GetLastError() == ERROR_INVALID_ACCESS)
729 errno = EACCES;
730 else
731 errno = ENOENT;
732 return -1;
735 if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
737 errno = EACCES;
738 return -1;
740 else
741 return 0;
745 /*********************************************************************
746 * fflush (CRTDLL.365)
748 INT __cdecl CRTDLL_fflush( CRTDLL_FILE *file )
750 return FlushFileBuffers( file->handle ) ? 0 : -1;
754 /*********************************************************************
755 * rand (CRTDLL.446)
757 INT __cdecl CRTDLL_rand()
759 return (rand() & CRTDLL_RAND_MAX);
763 /*********************************************************************
764 * putchar (CRTDLL.442)
766 void __cdecl CRTDLL_putchar( INT x )
768 putchar(x);
772 /*********************************************************************
773 * fputc (CRTDLL.374)
775 INT __cdecl CRTDLL_fputc( INT c, CRTDLL_FILE *file )
777 char ch = (char)c;
778 DWORD res;
779 TRACE("%c to file %p\n",c,file);
780 if (!WriteFile( file->handle, &ch, 1, &res, NULL )) return -1;
781 return c;
785 /*********************************************************************
786 * fputs (CRTDLL.375)
788 INT __cdecl CRTDLL_fputs( LPCSTR s, CRTDLL_FILE *file )
790 DWORD res;
791 TRACE("%s to file %p\n",s,file);
792 if (!WriteFile( file->handle, s, strlen(s), &res, NULL )) return -1;
793 return res;
797 /*********************************************************************
798 * puts (CRTDLL.443)
800 INT __cdecl CRTDLL_puts(LPCSTR s)
802 TRACE("%s \n",s);
803 return puts(s);
807 /*********************************************************************
808 * putc (CRTDLL.441)
810 INT __cdecl CRTDLL_putc( INT c, CRTDLL_FILE *file )
812 return CRTDLL_fputc( c, file );
815 /*********************************************************************
816 * fgetc (CRTDLL.366)
818 INT __cdecl CRTDLL_fgetc( CRTDLL_FILE *file )
820 DWORD res;
821 char ch;
822 if (!ReadFile( file->handle, &ch, 1, &res, NULL )) return -1;
823 if (res != 1) return -1;
824 return ch;
828 /*********************************************************************
829 * getc (CRTDLL.388)
831 INT __cdecl CRTDLL_getc( CRTDLL_FILE *file )
833 return CRTDLL_fgetc( file );
837 /*********************************************************************
838 * fgets (CRTDLL.368)
840 CHAR* __cdecl CRTDLL_fgets( LPSTR s, INT size, CRTDLL_FILE *file )
842 int cc;
843 LPSTR buf_start = s;
845 /* BAD, for the whole WINE process blocks... just done this way to test
846 * windows95's ftp.exe.
849 for(cc = CRTDLL_fgetc(file); cc != EOF && cc != '\n'; cc = CRTDLL_fgetc(file))
850 if (cc != '\r')
852 if (--size <= 0) break;
853 *s++ = (char)cc;
855 if ((cc == EOF) &&(s == buf_start)) /* If nothing read, return 0*/
856 return 0;
857 if (cc == '\n')
858 if (--size > 0)
859 *s++ = '\n';
860 *s = '\0';
862 TRACE("got '%s'\n", buf_start);
863 return buf_start;
867 /*********************************************************************
868 * gets (CRTDLL.391)
870 LPSTR __cdecl CRTDLL_gets(LPSTR buf)
872 int cc;
873 LPSTR buf_start = buf;
875 /* BAD, for the whole WINE process blocks... just done this way to test
876 * windows95's ftp.exe.
879 for(cc = fgetc(stdin); cc != EOF && cc != '\n'; cc = fgetc(stdin))
880 if(cc != '\r') *buf++ = (char)cc;
882 *buf = '\0';
884 TRACE("got '%s'\n", buf_start);
885 return buf_start;
889 /*********************************************************************
890 * _rotl (CRTDLL.259)
892 UINT __cdecl CRTDLL__rotl(UINT x,INT shift)
894 unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift));
896 TRACE("got 0x%08x rot %d ret 0x%08x\n",
897 x,shift,ret);
898 return ret;
901 /*********************************************************************
902 * _lrotl (CRTDLL.176)
904 DWORD __cdecl CRTDLL__lrotl(DWORD x,INT shift)
906 unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift));
908 TRACE("got 0x%08lx rot %d ret 0x%08lx\n",
909 x,shift,ret);
910 return ret;
915 /*********************************************************************
916 * _mbsicmp (CRTDLL.204)
918 int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
920 do {
921 if (!*x)
922 return !!*y;
923 if (!*y)
924 return !!*x;
925 /* FIXME: MBCS handling... */
926 if (*x!=*y)
927 return 1;
928 x++;
929 y++;
930 } while (1);
934 /*********************************************************************
935 * vswprintf (CRTDLL.501)
937 INT __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
939 return wvsprintfW( buffer, spec, args );
943 /*********************************************************************
944 * system (CRTDLL.485)
946 INT __cdecl CRTDLL_system(LPSTR x)
948 #define SYSBUF_LENGTH 1500
949 char buffer[SYSBUF_LENGTH];
950 unsigned char *y = x;
951 unsigned char *bp;
952 int i;
954 sprintf( buffer, "%s \"", argv0 );
955 bp = buffer + strlen(buffer);
956 i = strlen(buffer) + strlen(x) +2;
958 /* Calculate needed buffer size to prevent overflow. */
959 while (*y) {
960 if (*y =='\\') i++;
961 y++;
963 /* If buffer too short, exit. */
964 if (i > SYSBUF_LENGTH) {
965 TRACE("_system buffer to small\n");
966 return 127;
969 y =x;
971 while (*y) {
972 *bp = *y;
973 bp++; y++;
974 if (*(y-1) =='\\') *bp++ = '\\';
976 /* Remove spaces from end of string. */
977 while (*(y-1) == ' ') {
978 bp--;y--;
980 *bp++ = '"';
981 *bp = 0;
982 TRACE("_system got '%s', executing '%s'\n",x,buffer);
984 return system(buffer);
987 /*********************************************************************
988 * longjmp (CRTDLL.426)
990 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
992 FIXME("CRTDLL_longjmp semistup, expect crash\n");
993 longjmp(env, val);
996 /*********************************************************************
997 * malloc (CRTDLL.427)
999 VOID* __cdecl CRTDLL_malloc(DWORD size)
1001 return HeapAlloc(GetProcessHeap(),0,size);
1004 /*********************************************************************
1005 * new (CRTDLL.001)
1007 VOID* __cdecl CRTDLL_new(DWORD size)
1009 VOID* result;
1010 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
1011 (*new_handler)();
1012 return result;
1015 /*********************************************************************
1016 * set_new_handler(CRTDLL.003)
1018 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
1020 new_handler_type old_handler = new_handler;
1021 new_handler = func;
1022 return old_handler;
1025 /*********************************************************************
1026 * calloc (CRTDLL.350)
1028 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
1030 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
1033 /*********************************************************************
1034 * realloc (CRTDLL.447)
1036 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
1038 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
1041 /*********************************************************************
1042 * free (CRTDLL.427)
1044 VOID __cdecl CRTDLL_free(LPVOID ptr)
1046 HeapFree(GetProcessHeap(),0,ptr);
1049 /*********************************************************************
1050 * delete (CRTDLL.002)
1052 VOID __cdecl CRTDLL_delete(VOID* ptr)
1054 HeapFree(GetProcessHeap(),0,ptr);
1057 /*********************************************************************
1058 * _strdup (CRTDLL.285)
1060 LPSTR __cdecl CRTDLL__strdup(LPCSTR ptr)
1062 return HEAP_strdupA(GetProcessHeap(),0,ptr);
1065 /*********************************************************************
1066 * fclose (CRTDLL.362)
1068 INT __cdecl CRTDLL_fclose( CRTDLL_FILE *file )
1070 TRACE("%p\n", file );
1071 if (!CloseHandle( file->handle )) return -1;
1072 HeapFree( GetProcessHeap(), 0, file );
1073 return 0;
1076 /*********************************************************************
1077 * _unlink (CRTDLL.315)
1079 INT __cdecl CRTDLL__unlink(LPCSTR pathname)
1081 return DeleteFileA( pathname ) ? 0 : -1;
1084 /*********************************************************************
1085 * rename (CRTDLL.449)
1087 INT __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
1089 BOOL ok = MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
1090 return ok ? 0 : -1;
1094 /*********************************************************************
1095 * _stat (CRTDLL.280)
1098 struct win_stat
1100 UINT16 win_st_dev;
1101 UINT16 win_st_ino;
1102 UINT16 win_st_mode;
1103 INT16 win_st_nlink;
1104 INT16 win_st_uid;
1105 INT16 win_st_gid;
1106 UINT win_st_rdev;
1107 INT win_st_size;
1108 INT win_st_atime;
1109 INT win_st_mtime;
1110 INT win_st_ctime;
1113 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
1115 int ret=0;
1116 DOS_FULL_NAME full_name;
1117 struct stat mystat;
1119 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1121 WARN("CRTDLL__stat filename %s bad name\n",filename);
1122 return -1;
1124 ret=stat(full_name.long_name,&mystat);
1125 TRACE("CRTDLL__stat %s\n", filename);
1126 if(ret)
1127 WARN(" Failed!\n");
1129 /* FIXME: should check what Windows returns */
1131 buf->win_st_dev = mystat.st_dev;
1132 buf->win_st_ino = mystat.st_ino;
1133 buf->win_st_mode = mystat.st_mode;
1134 buf->win_st_nlink = mystat.st_nlink;
1135 buf->win_st_uid = mystat.st_uid;
1136 buf->win_st_gid = mystat.st_gid;
1137 buf->win_st_rdev = mystat.st_rdev;
1138 buf->win_st_size = mystat.st_size;
1139 buf->win_st_atime = mystat.st_atime;
1140 buf->win_st_mtime = mystat.st_mtime;
1141 buf->win_st_ctime = mystat.st_ctime;
1142 return ret;
1145 /*********************************************************************
1146 * _open (CRTDLL.239)
1148 HFILE __cdecl CRTDLL__open(LPCSTR path,INT flags)
1150 DWORD access = 0, creation = 0;
1151 HFILE ret;
1153 /* FIXME:
1154 the flags in lcc's header differ from the ones in Linux, e.g.
1155 Linux: define O_APPEND 02000 (= 0x400)
1156 lcc: define _O_APPEND 0x0008
1157 so here a scheme to translate them
1158 Probably lcc is wrong here, but at least a hack to get is going
1160 switch(flags & 3)
1162 case O_RDONLY: access |= GENERIC_READ; break;
1163 case O_WRONLY: access |= GENERIC_WRITE; break;
1164 case O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break;
1167 if (flags & 0x0100) /* O_CREAT */
1169 if (flags & 0x0400) /* O_EXCL */
1170 creation = CREATE_NEW;
1171 else if (flags & 0x0200) /* O_TRUNC */
1172 creation = CREATE_ALWAYS;
1173 else
1174 creation = OPEN_ALWAYS;
1176 else /* no O_CREAT */
1178 if (flags & 0x0200) /* O_TRUNC */
1179 creation = TRUNCATE_EXISTING;
1180 else
1181 creation = OPEN_EXISTING;
1183 if (flags & 0x0008) /* O_APPEND */
1184 FIXME("O_APPEND not supported\n" );
1185 if (!(flags & 0x8000 /* O_BINARY */ ) || (flags & 0x4000 /* O_TEXT */))
1186 FIXME(":text mode not supported\n");
1187 if (flags & 0xf0f4)
1188 TRACE("CRTDLL_open file unsupported flags 0x%04x\n",flags);
1189 /* End Fixme */
1191 ret = CreateFileA( path, access, FILE_SHARE_READ | FILE_SHARE_WRITE,
1192 NULL, creation, FILE_ATTRIBUTE_NORMAL, -1 );
1193 TRACE("CRTDLL_open file %s mode 0x%04x got handle %d\n", path,flags,ret);
1194 return ret;
1197 /*********************************************************************
1198 * _close (CRTDLL.57)
1200 INT __cdecl CRTDLL__close(HFILE fd)
1202 int ret=_lclose(fd);
1204 TRACE("(%d)\n",fd);
1205 if(ret)
1206 WARN(" Failed!\n");
1208 return ret;
1211 /*********************************************************************
1212 * feof (CRTDLL.363)
1213 * FIXME: Care for large files
1214 * FIXME: Check errors
1216 INT __cdecl CRTDLL_feof( CRTDLL_FILE *file )
1218 DWORD curpos=SetFilePointer( file->handle, 0, NULL, SEEK_CUR );
1219 DWORD endpos=SetFilePointer( file->handle, 0, NULL, FILE_END );
1221 if (curpos==endpos)
1222 return TRUE;
1223 else
1224 SetFilePointer( file->handle, curpos,0,FILE_BEGIN);
1225 return FALSE;
1228 /*********************************************************************
1229 * setlocale (CRTDLL.453)
1231 LPSTR __cdecl CRTDLL_setlocale(INT category,LPCSTR locale)
1233 LPSTR categorystr;
1235 switch (category) {
1236 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1237 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1238 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1239 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1240 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1241 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1242 default: categorystr = "UNKNOWN?";break;
1244 FIXME("(%s,%s),stub!\n",categorystr,locale);
1245 return "C";
1248 /*********************************************************************
1249 * _setmode (CRTDLL.265)
1250 * FIXME: At present we ignore the request to translate CR/LF to LF.
1252 * We allways translate when we read with fgets, we never do with fread
1255 INT __cdecl CRTDLL__setmode( INT fh,INT mode)
1257 /* FIXME */
1258 #define O_TEXT 0x4000
1259 #define O_BINARY 0x8000
1261 FIXME("on fhandle %d mode %s, STUB.\n",
1262 fh,(mode=O_TEXT)?"O_TEXT":
1263 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1264 return -1;
1267 /*********************************************************************
1268 * _fpreset (CRTDLL.107)
1270 VOID __cdecl CRTDLL__fpreset(void)
1272 FIXME(" STUB.\n");
1275 /*********************************************************************
1276 * atexit (CRTDLL.345)
1278 INT __cdecl CRTDLL_atexit(LPVOID x)
1280 FIXME("(%p), STUB.\n",x);
1281 return 0; /* successful */
1284 /*********************************************************************
1285 * _isctype (CRTDLL.138)
1287 BOOL __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1289 if ((type & CRTDLL_SPACE) && isspace(x))
1290 return TRUE;
1291 if ((type & CRTDLL_PUNCT) && ispunct(x))
1292 return TRUE;
1293 if ((type & CRTDLL_LOWER) && islower(x))
1294 return TRUE;
1295 if ((type & CRTDLL_UPPER) && isupper(x))
1296 return TRUE;
1297 if ((type & CRTDLL_ALPHA) && isalpha(x))
1298 return TRUE;
1299 if ((type & CRTDLL_DIGIT) && isdigit(x))
1300 return TRUE;
1301 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1302 return TRUE;
1303 /* check CRTDLL_LEADBYTE */
1304 return FALSE;
1307 /*********************************************************************
1308 * _chdrive (CRTDLL.52)
1310 * newdir [I] drive to change to, A=1
1313 BOOL __cdecl CRTDLL__chdrive(INT newdrive)
1315 /* FIXME: generates errnos */
1316 return DRIVE_SetCurrentDrive(newdrive-1);
1319 /*********************************************************************
1320 * _chdir (CRTDLL.51)
1322 INT __cdecl CRTDLL__chdir(LPCSTR newdir)
1324 if (!SetCurrentDirectoryA(newdir))
1325 return 1;
1326 return 0;
1329 /*********************************************************************
1330 * _fullpath (CRTDLL.114)
1332 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT size)
1334 DOS_FULL_NAME full_name;
1336 if (!buf)
1338 size = 256;
1339 if(!(buf = CRTDLL_malloc(size))) return NULL;
1341 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1342 lstrcpynA(buf,full_name.short_name,size);
1343 TRACE("CRTDLL_fullpath got %s\n",buf);
1344 return buf;
1347 /*********************************************************************
1348 * _splitpath (CRTDLL.279)
1350 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1352 /* drive includes :
1353 directory includes leading and trailing (forward and backward slashes)
1354 filename without dot and slashes
1355 extension with leading dot
1357 char * drivechar,*dirchar,*namechar;
1359 TRACE("CRTDLL__splitpath got %s\n",path);
1361 drivechar = strchr(path,':');
1362 dirchar = strrchr(path,'/');
1363 namechar = strrchr(path,'\\');
1364 dirchar = max(dirchar,namechar);
1365 if (dirchar)
1366 namechar = strrchr(dirchar,'.');
1367 else
1368 namechar = strrchr(path,'.');
1371 if (drive)
1373 *drive = 0x00;
1374 if (drivechar)
1376 strncat(drive,path,drivechar-path+1);
1377 path = drivechar+1;
1380 if (directory)
1382 *directory = 0x00;
1383 if (dirchar)
1385 strncat(directory,path,dirchar-path+1);
1386 path = dirchar+1;
1389 if (filename)
1391 *filename = 0x00;
1392 if (namechar)
1394 strncat(filename,path,namechar-path);
1395 if (extension)
1397 *extension = 0x00;
1398 strcat(extension,namechar);
1403 TRACE("CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1408 /*********************************************************************
1409 * _makepath (CRTDLL.182)
1412 VOID __cdecl CRTDLL__makepath(LPSTR path, LPCSTR drive,
1413 LPCSTR directory, LPCSTR filename,
1414 LPCSTR extension )
1416 char ch;
1417 TRACE("CRTDLL__makepath got %s %s %s %s\n", drive, directory,
1418 filename, extension);
1420 if ( !path )
1421 return;
1423 path[0] = 0;
1424 if ( drive )
1425 if ( drive[0] ) {
1426 sprintf(path, "%c:", drive[0]);
1428 if ( directory )
1429 if ( directory[0] ) {
1430 strcat(path, directory);
1431 ch = path[strlen(path)-1];
1432 if (ch != '/' && ch != '\\')
1433 strcat(path,"\\");
1435 if ( filename )
1436 if ( filename[0] ) {
1437 strcat(path, filename);
1438 if ( extension ) {
1439 if ( extension[0] ) {
1440 if ( extension[0] != '.' ) {
1441 strcat(path,".");
1443 strcat(path,extension);
1448 TRACE("CRTDLL__makepath returns %s\n",path);
1451 /*********************************************************************
1452 * _getcwd (CRTDLL.120)
1454 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT size)
1456 char test[1];
1457 int len;
1459 len = size;
1460 if (!buf) {
1461 if (size < 0) /* allocate as big as nescessary */
1462 len =GetCurrentDirectoryA(1,test) + 1;
1463 if(!(buf = CRTDLL_malloc(len)))
1465 /* set error to OutOfRange */
1466 return( NULL );
1469 size = len;
1470 if(!(len =GetCurrentDirectoryA(len,buf)))
1472 return NULL;
1474 if (len > size)
1476 /* set error to ERANGE */
1477 TRACE("CRTDLL_getcwd buffer to small\n");
1478 return NULL;
1480 return buf;
1484 /*********************************************************************
1485 * _getdcwd (CRTDLL.121)
1487 CHAR* __cdecl CRTDLL__getdcwd(INT drive,LPSTR buf, INT size)
1489 char test[1];
1490 int len;
1492 FIXME("(\"%c:\",%s,%d)\n",drive+'A',buf,size);
1493 len = size;
1494 if (!buf) {
1495 if (size < 0) /* allocate as big as nescessary */
1496 len =GetCurrentDirectoryA(1,test) + 1;
1497 if(!(buf = CRTDLL_malloc(len)))
1499 /* set error to OutOfRange */
1500 return( NULL );
1503 size = len;
1504 if(!(len =GetCurrentDirectoryA(len,buf)))
1506 return NULL;
1508 if (len > size)
1510 /* set error to ERANGE */
1511 TRACE("buffer to small\n");
1512 return NULL;
1514 return buf;
1518 /*********************************************************************
1519 * _getdrive (CRTDLL.124)
1521 * Return current drive, 1 for A, 2 for B
1523 INT __cdecl CRTDLL__getdrive(VOID)
1525 return DRIVE_GetCurrentDrive() + 1;
1528 /*********************************************************************
1529 * _mkdir (CRTDLL.234)
1531 INT __cdecl CRTDLL__mkdir(LPCSTR newdir)
1533 if (!CreateDirectoryA(newdir,NULL))
1534 return -1;
1535 return 0;
1538 /*********************************************************************
1539 * remove (CRTDLL.448)
1541 INT __cdecl CRTDLL_remove(LPCSTR file)
1543 if (!DeleteFileA(file))
1544 return -1;
1545 return 0;
1548 /*********************************************************************
1549 * _errno (CRTDLL.52)
1550 * Yes, this is a function.
1552 LPINT __cdecl CRTDLL__errno()
1554 static int crtdllerrno;
1556 /* FIXME: we should set the error at the failing function call time */
1557 crtdllerrno = LastErrorToErrno(GetLastError());
1558 return &crtdllerrno;
1561 /*********************************************************************
1562 * _tempnam (CRTDLL.305)
1565 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1568 char *ret;
1569 DOS_FULL_NAME tempname;
1571 if ((ret = tempnam(dir,prefix))==NULL) {
1572 WARN("Unable to get unique filename\n");
1573 return NULL;
1575 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1577 TRACE("Wrong path?\n");
1578 return NULL;
1580 free(ret);
1581 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1582 WARN("CRTDL_malloc for shortname failed\n");
1583 return NULL;
1585 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1586 WARN("Malloc for shortname failed\n");
1587 return NULL;
1590 TRACE("dir %s prefix %s got %s\n",
1591 dir,prefix,ret);
1592 return ret;
1595 /*********************************************************************
1596 * tmpnam (CRTDLL.490)
1598 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1601 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1603 char *ret;
1605 if ((ret =tmpnam(s))== NULL) {
1606 WARN("Unable to get unique filename\n");
1607 return NULL;
1609 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1611 TRACE("Wrong path?\n");
1612 return NULL;
1614 strcat(CRTDLL_tmpname.short_name,".");
1615 TRACE("for buf %p got %s\n",
1616 s,CRTDLL_tmpname.short_name);
1617 TRACE("long got %s\n",
1618 CRTDLL_tmpname.long_name);
1619 if ( s != NULL)
1620 return strcpy(s,CRTDLL_tmpname.short_name);
1621 else
1622 return CRTDLL_tmpname.short_name;
1627 typedef VOID (*sig_handler_type)(VOID);
1629 /*********************************************************************
1630 * signal (CRTDLL.455)
1632 void * __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
1634 FIXME("(%d %p):stub.\n", sig, ptr);
1635 return (void*)-1;
1638 /*********************************************************************
1639 * _sleep (CRTDLL.267)
1641 VOID __cdecl CRTDLL__sleep(unsigned long timeout)
1643 TRACE("CRTDLL__sleep for %ld milliseconds\n",timeout);
1644 Sleep((timeout)?timeout:1);
1647 /*********************************************************************
1648 * getenv (CRTDLL.437)
1650 LPSTR __cdecl CRTDLL_getenv(const char *name)
1652 LPSTR environ = GetEnvironmentStringsA();
1653 LPSTR pp,pos = NULL;
1654 unsigned int length;
1656 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
1658 pos =strchr(pp,'=');
1659 if (pos)
1660 length = pos -pp;
1661 else
1662 length = strlen(pp);
1663 if (!strncmp(pp,name,length)) break;
1665 if ((pp)&& (pos))
1667 pp = pos+1;
1668 TRACE("got %s\n",pp);
1670 FreeEnvironmentStringsA( environ );
1671 return pp;
1674 /*********************************************************************
1675 * _mbsrchr (CRTDLL.223)
1677 LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x) {
1678 /* FIXME: handle multibyte strings */
1679 return strrchr(s,x);
1682 /*********************************************************************
1683 * __dllonexit (CRTDLL.25)
1685 VOID __cdecl CRTDLL___dllonexit ()
1687 FIXME("stub\n");
1690 /*********************************************************************
1691 * _strdate (CRTDLL.283)
1693 LPSTR __cdecl CRTDLL__strdate (LPSTR date)
1694 { FIXME("%p stub\n", date);
1695 return 0;
1698 /*********************************************************************
1699 * _strtime (CRTDLL.299)
1701 LPSTR __cdecl CRTDLL__strtime (LPSTR date)
1702 { FIXME("%p stub\n", date);
1703 return 0;
1706 /*********************************************************************
1707 * _except_handler2 (CRTDLL.78)
1709 INT __cdecl CRTDLL__except_handler2 (
1710 PEXCEPTION_RECORD rec,
1711 PEXCEPTION_FRAME frame,
1712 PCONTEXT context,
1713 PEXCEPTION_FRAME *dispatcher)
1715 FIXME ("exception %lx flags=%lx at %p handler=%p %p %p stub\n",
1716 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
1717 frame->Handler, context, dispatcher);
1718 return ExceptionContinueSearch;