Moved shared crtdll/ntdll functions into ntdll.
[wine.git] / dlls / crtdll / crtdll_main.c
blob0abc89a22160157b07aef60b3ee3c465e9a28684
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 * vsprintf (CRTDLL.500)
937 INT __cdecl CRTDLL_vsprintf( LPSTR buffer, LPCSTR spec, va_list args )
939 return wvsprintfA( buffer, spec, args );
942 /*********************************************************************
943 * vswprintf (CRTDLL.501)
945 INT __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args )
947 return wvsprintfW( buffer, spec, args );
951 /*********************************************************************
952 * system (CRTDLL.485)
954 INT __cdecl CRTDLL_system(LPSTR x)
956 #define SYSBUF_LENGTH 1500
957 char buffer[SYSBUF_LENGTH];
958 unsigned char *y = x;
959 unsigned char *bp;
960 int i;
962 sprintf( buffer, "%s \"", argv0 );
963 bp = buffer + strlen(buffer);
964 i = strlen(buffer) + strlen(x) +2;
966 /* Calculate needed buffer size to prevent overflow. */
967 while (*y) {
968 if (*y =='\\') i++;
969 y++;
971 /* If buffer too short, exit. */
972 if (i > SYSBUF_LENGTH) {
973 TRACE("_system buffer to small\n");
974 return 127;
977 y =x;
979 while (*y) {
980 *bp = *y;
981 bp++; y++;
982 if (*(y-1) =='\\') *bp++ = '\\';
984 /* Remove spaces from end of string. */
985 while (*(y-1) == ' ') {
986 bp--;y--;
988 *bp++ = '"';
989 *bp = 0;
990 TRACE("_system got '%s', executing '%s'\n",x,buffer);
992 return system(buffer);
995 /*********************************************************************
996 * longjmp (CRTDLL.426)
998 VOID __cdecl CRTDLL_longjmp(jmp_buf env, int val)
1000 FIXME("CRTDLL_longjmp semistup, expect crash\n");
1001 longjmp(env, val);
1004 /*********************************************************************
1005 * malloc (CRTDLL.427)
1007 VOID* __cdecl CRTDLL_malloc(DWORD size)
1009 return HeapAlloc(GetProcessHeap(),0,size);
1012 /*********************************************************************
1013 * new (CRTDLL.001)
1015 VOID* __cdecl CRTDLL_new(DWORD size)
1017 VOID* result;
1018 if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
1019 (*new_handler)();
1020 return result;
1023 /*********************************************************************
1024 * set_new_handler(CRTDLL.003)
1026 new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
1028 new_handler_type old_handler = new_handler;
1029 new_handler = func;
1030 return old_handler;
1033 /*********************************************************************
1034 * calloc (CRTDLL.350)
1036 VOID* __cdecl CRTDLL_calloc(DWORD size, DWORD count)
1038 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
1041 /*********************************************************************
1042 * realloc (CRTDLL.447)
1044 VOID* __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
1046 return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
1049 /*********************************************************************
1050 * free (CRTDLL.427)
1052 VOID __cdecl CRTDLL_free(LPVOID ptr)
1054 HeapFree(GetProcessHeap(),0,ptr);
1057 /*********************************************************************
1058 * delete (CRTDLL.002)
1060 VOID __cdecl CRTDLL_delete(VOID* ptr)
1062 HeapFree(GetProcessHeap(),0,ptr);
1065 /*********************************************************************
1066 * _strdup (CRTDLL.285)
1068 LPSTR __cdecl CRTDLL__strdup(LPCSTR ptr)
1070 return HEAP_strdupA(GetProcessHeap(),0,ptr);
1073 /*********************************************************************
1074 * fclose (CRTDLL.362)
1076 INT __cdecl CRTDLL_fclose( CRTDLL_FILE *file )
1078 TRACE("%p\n", file );
1079 if (!CloseHandle( file->handle )) return -1;
1080 HeapFree( GetProcessHeap(), 0, file );
1081 return 0;
1084 /*********************************************************************
1085 * _unlink (CRTDLL.315)
1087 INT __cdecl CRTDLL__unlink(LPCSTR pathname)
1089 return DeleteFileA( pathname ) ? 0 : -1;
1092 /*********************************************************************
1093 * rename (CRTDLL.449)
1095 INT __cdecl CRTDLL_rename(LPCSTR oldpath,LPCSTR newpath)
1097 BOOL ok = MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING );
1098 return ok ? 0 : -1;
1102 /*********************************************************************
1103 * _stat (CRTDLL.280)
1106 struct win_stat
1108 UINT16 win_st_dev;
1109 UINT16 win_st_ino;
1110 UINT16 win_st_mode;
1111 INT16 win_st_nlink;
1112 INT16 win_st_uid;
1113 INT16 win_st_gid;
1114 UINT win_st_rdev;
1115 INT win_st_size;
1116 INT win_st_atime;
1117 INT win_st_mtime;
1118 INT win_st_ctime;
1121 int __cdecl CRTDLL__stat(const char * filename, struct win_stat * buf)
1123 int ret=0;
1124 DOS_FULL_NAME full_name;
1125 struct stat mystat;
1127 if (!DOSFS_GetFullName( filename, TRUE, &full_name ))
1129 WARN("CRTDLL__stat filename %s bad name\n",filename);
1130 return -1;
1132 ret=stat(full_name.long_name,&mystat);
1133 TRACE("CRTDLL__stat %s\n", filename);
1134 if(ret)
1135 WARN(" Failed!\n");
1137 /* FIXME: should check what Windows returns */
1139 buf->win_st_dev = mystat.st_dev;
1140 buf->win_st_ino = mystat.st_ino;
1141 buf->win_st_mode = mystat.st_mode;
1142 buf->win_st_nlink = mystat.st_nlink;
1143 buf->win_st_uid = mystat.st_uid;
1144 buf->win_st_gid = mystat.st_gid;
1145 buf->win_st_rdev = mystat.st_rdev;
1146 buf->win_st_size = mystat.st_size;
1147 buf->win_st_atime = mystat.st_atime;
1148 buf->win_st_mtime = mystat.st_mtime;
1149 buf->win_st_ctime = mystat.st_ctime;
1150 return ret;
1153 /*********************************************************************
1154 * _open (CRTDLL.239)
1156 HFILE __cdecl CRTDLL__open(LPCSTR path,INT flags)
1158 DWORD access = 0, creation = 0;
1159 HFILE ret;
1161 /* FIXME:
1162 the flags in lcc's header differ from the ones in Linux, e.g.
1163 Linux: define O_APPEND 02000 (= 0x400)
1164 lcc: define _O_APPEND 0x0008
1165 so here a scheme to translate them
1166 Probably lcc is wrong here, but at least a hack to get is going
1168 switch(flags & 3)
1170 case O_RDONLY: access |= GENERIC_READ; break;
1171 case O_WRONLY: access |= GENERIC_WRITE; break;
1172 case O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break;
1175 if (flags & 0x0100) /* O_CREAT */
1177 if (flags & 0x0400) /* O_EXCL */
1178 creation = CREATE_NEW;
1179 else if (flags & 0x0200) /* O_TRUNC */
1180 creation = CREATE_ALWAYS;
1181 else
1182 creation = OPEN_ALWAYS;
1184 else /* no O_CREAT */
1186 if (flags & 0x0200) /* O_TRUNC */
1187 creation = TRUNCATE_EXISTING;
1188 else
1189 creation = OPEN_EXISTING;
1191 if (flags & 0x0008) /* O_APPEND */
1192 FIXME("O_APPEND not supported\n" );
1193 if (!(flags & 0x8000 /* O_BINARY */ ) || (flags & 0x4000 /* O_TEXT */))
1194 FIXME(":text mode not supported\n");
1195 if (flags & 0xf0f4)
1196 TRACE("CRTDLL_open file unsupported flags 0x%04x\n",flags);
1197 /* End Fixme */
1199 ret = CreateFileA( path, access, FILE_SHARE_READ | FILE_SHARE_WRITE,
1200 NULL, creation, FILE_ATTRIBUTE_NORMAL, -1 );
1201 TRACE("CRTDLL_open file %s mode 0x%04x got handle %d\n", path,flags,ret);
1202 return ret;
1205 /*********************************************************************
1206 * _close (CRTDLL.57)
1208 INT __cdecl CRTDLL__close(HFILE fd)
1210 int ret=_lclose(fd);
1212 TRACE("(%d)\n",fd);
1213 if(ret)
1214 WARN(" Failed!\n");
1216 return ret;
1219 /*********************************************************************
1220 * feof (CRTDLL.363)
1221 * FIXME: Care for large files
1222 * FIXME: Check errors
1224 INT __cdecl CRTDLL_feof( CRTDLL_FILE *file )
1226 DWORD curpos=SetFilePointer( file->handle, 0, NULL, SEEK_CUR );
1227 DWORD endpos=SetFilePointer( file->handle, 0, NULL, FILE_END );
1229 if (curpos==endpos)
1230 return TRUE;
1231 else
1232 SetFilePointer( file->handle, curpos,0,FILE_BEGIN);
1233 return FALSE;
1236 /*********************************************************************
1237 * setlocale (CRTDLL.453)
1239 LPSTR __cdecl CRTDLL_setlocale(INT category,LPCSTR locale)
1241 LPSTR categorystr;
1243 switch (category) {
1244 case CRTDLL_LC_ALL: categorystr="LC_ALL";break;
1245 case CRTDLL_LC_COLLATE: categorystr="LC_COLLATE";break;
1246 case CRTDLL_LC_CTYPE: categorystr="LC_CTYPE";break;
1247 case CRTDLL_LC_MONETARY: categorystr="LC_MONETARY";break;
1248 case CRTDLL_LC_NUMERIC: categorystr="LC_NUMERIC";break;
1249 case CRTDLL_LC_TIME: categorystr="LC_TIME";break;
1250 default: categorystr = "UNKNOWN?";break;
1252 FIXME("(%s,%s),stub!\n",categorystr,locale);
1253 return "C";
1256 /*********************************************************************
1257 * _setmode (CRTDLL.265)
1258 * FIXME: At present we ignore the request to translate CR/LF to LF.
1260 * We allways translate when we read with fgets, we never do with fread
1263 INT __cdecl CRTDLL__setmode( INT fh,INT mode)
1265 /* FIXME */
1266 #define O_TEXT 0x4000
1267 #define O_BINARY 0x8000
1269 FIXME("on fhandle %d mode %s, STUB.\n",
1270 fh,(mode=O_TEXT)?"O_TEXT":
1271 (mode=O_BINARY)?"O_BINARY":"UNKNOWN");
1272 return -1;
1275 /*********************************************************************
1276 * _fpreset (CRTDLL.107)
1278 VOID __cdecl CRTDLL__fpreset(void)
1280 FIXME(" STUB.\n");
1283 /*********************************************************************
1284 * atexit (CRTDLL.345)
1286 INT __cdecl CRTDLL_atexit(LPVOID x)
1288 FIXME("(%p), STUB.\n",x);
1289 return 0; /* successful */
1292 /*********************************************************************
1293 * _isctype (CRTDLL.138)
1295 BOOL __cdecl CRTDLL__isctype(CHAR x,CHAR type)
1297 if ((type & CRTDLL_SPACE) && isspace(x))
1298 return TRUE;
1299 if ((type & CRTDLL_PUNCT) && ispunct(x))
1300 return TRUE;
1301 if ((type & CRTDLL_LOWER) && islower(x))
1302 return TRUE;
1303 if ((type & CRTDLL_UPPER) && isupper(x))
1304 return TRUE;
1305 if ((type & CRTDLL_ALPHA) && isalpha(x))
1306 return TRUE;
1307 if ((type & CRTDLL_DIGIT) && isdigit(x))
1308 return TRUE;
1309 if ((type & CRTDLL_CONTROL) && iscntrl(x))
1310 return TRUE;
1311 /* check CRTDLL_LEADBYTE */
1312 return FALSE;
1315 /*********************************************************************
1316 * _chdrive (CRTDLL.52)
1318 * newdir [I] drive to change to, A=1
1321 BOOL __cdecl CRTDLL__chdrive(INT newdrive)
1323 /* FIXME: generates errnos */
1324 return DRIVE_SetCurrentDrive(newdrive-1);
1327 /*********************************************************************
1328 * _chdir (CRTDLL.51)
1330 INT __cdecl CRTDLL__chdir(LPCSTR newdir)
1332 if (!SetCurrentDirectoryA(newdir))
1333 return 1;
1334 return 0;
1337 /*********************************************************************
1338 * _fullpath (CRTDLL.114)
1340 LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT size)
1342 DOS_FULL_NAME full_name;
1344 if (!buf)
1346 size = 256;
1347 if(!(buf = CRTDLL_malloc(size))) return NULL;
1349 if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL;
1350 lstrcpynA(buf,full_name.short_name,size);
1351 TRACE("CRTDLL_fullpath got %s\n",buf);
1352 return buf;
1355 /*********************************************************************
1356 * _splitpath (CRTDLL.279)
1358 VOID __cdecl CRTDLL__splitpath(LPCSTR path, LPSTR drive, LPSTR directory, LPSTR filename, LPSTR extension )
1360 /* drive includes :
1361 directory includes leading and trailing (forward and backward slashes)
1362 filename without dot and slashes
1363 extension with leading dot
1365 char * drivechar,*dirchar,*namechar;
1367 TRACE("CRTDLL__splitpath got %s\n",path);
1369 drivechar = strchr(path,':');
1370 dirchar = strrchr(path,'/');
1371 namechar = strrchr(path,'\\');
1372 dirchar = max(dirchar,namechar);
1373 if (dirchar)
1374 namechar = strrchr(dirchar,'.');
1375 else
1376 namechar = strrchr(path,'.');
1379 if (drive)
1381 *drive = 0x00;
1382 if (drivechar)
1384 strncat(drive,path,drivechar-path+1);
1385 path = drivechar+1;
1388 if (directory)
1390 *directory = 0x00;
1391 if (dirchar)
1393 strncat(directory,path,dirchar-path+1);
1394 path = dirchar+1;
1397 if (filename)
1399 *filename = 0x00;
1400 if (namechar)
1402 strncat(filename,path,namechar-path);
1403 if (extension)
1405 *extension = 0x00;
1406 strcat(extension,namechar);
1411 TRACE("CRTDLL__splitpath found %s %s %s %s\n",drive,directory,filename,extension);
1416 /*********************************************************************
1417 * _makepath (CRTDLL.182)
1420 VOID __cdecl CRTDLL__makepath(LPSTR path, LPCSTR drive,
1421 LPCSTR directory, LPCSTR filename,
1422 LPCSTR extension )
1424 char ch;
1425 TRACE("CRTDLL__makepath got %s %s %s %s\n", drive, directory,
1426 filename, extension);
1428 if ( !path )
1429 return;
1431 path[0] = 0;
1432 if ( drive )
1433 if ( drive[0] ) {
1434 sprintf(path, "%c:", drive[0]);
1436 if ( directory )
1437 if ( directory[0] ) {
1438 strcat(path, directory);
1439 ch = path[strlen(path)-1];
1440 if (ch != '/' && ch != '\\')
1441 strcat(path,"\\");
1443 if ( filename )
1444 if ( filename[0] ) {
1445 strcat(path, filename);
1446 if ( extension ) {
1447 if ( extension[0] ) {
1448 if ( extension[0] != '.' ) {
1449 strcat(path,".");
1451 strcat(path,extension);
1456 TRACE("CRTDLL__makepath returns %s\n",path);
1459 /*********************************************************************
1460 * _getcwd (CRTDLL.120)
1462 CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT size)
1464 char test[1];
1465 int len;
1467 len = size;
1468 if (!buf) {
1469 if (size < 0) /* allocate as big as nescessary */
1470 len =GetCurrentDirectoryA(1,test) + 1;
1471 if(!(buf = CRTDLL_malloc(len)))
1473 /* set error to OutOfRange */
1474 return( NULL );
1477 size = len;
1478 if(!(len =GetCurrentDirectoryA(len,buf)))
1480 return NULL;
1482 if (len > size)
1484 /* set error to ERANGE */
1485 TRACE("CRTDLL_getcwd buffer to small\n");
1486 return NULL;
1488 return buf;
1492 /*********************************************************************
1493 * _getdcwd (CRTDLL.121)
1495 CHAR* __cdecl CRTDLL__getdcwd(INT drive,LPSTR buf, INT size)
1497 char test[1];
1498 int len;
1500 FIXME("(\"%c:\",%s,%d)\n",drive+'A',buf,size);
1501 len = size;
1502 if (!buf) {
1503 if (size < 0) /* allocate as big as nescessary */
1504 len =GetCurrentDirectoryA(1,test) + 1;
1505 if(!(buf = CRTDLL_malloc(len)))
1507 /* set error to OutOfRange */
1508 return( NULL );
1511 size = len;
1512 if(!(len =GetCurrentDirectoryA(len,buf)))
1514 return NULL;
1516 if (len > size)
1518 /* set error to ERANGE */
1519 TRACE("buffer to small\n");
1520 return NULL;
1522 return buf;
1526 /*********************************************************************
1527 * _getdrive (CRTDLL.124)
1529 * Return current drive, 1 for A, 2 for B
1531 INT __cdecl CRTDLL__getdrive(VOID)
1533 return DRIVE_GetCurrentDrive() + 1;
1536 /*********************************************************************
1537 * _mkdir (CRTDLL.234)
1539 INT __cdecl CRTDLL__mkdir(LPCSTR newdir)
1541 if (!CreateDirectoryA(newdir,NULL))
1542 return -1;
1543 return 0;
1546 /*********************************************************************
1547 * remove (CRTDLL.448)
1549 INT __cdecl CRTDLL_remove(LPCSTR file)
1551 if (!DeleteFileA(file))
1552 return -1;
1553 return 0;
1556 /*********************************************************************
1557 * _errno (CRTDLL.52)
1558 * Yes, this is a function.
1560 LPINT __cdecl CRTDLL__errno()
1562 static int crtdllerrno;
1564 /* FIXME: we should set the error at the failing function call time */
1565 crtdllerrno = LastErrorToErrno(GetLastError());
1566 return &crtdllerrno;
1569 /*********************************************************************
1570 * _tempnam (CRTDLL.305)
1573 LPSTR __cdecl CRTDLL__tempnam(LPCSTR dir, LPCSTR prefix)
1576 char *ret;
1577 DOS_FULL_NAME tempname;
1579 if ((ret = tempnam(dir,prefix))==NULL) {
1580 WARN("Unable to get unique filename\n");
1581 return NULL;
1583 if (!DOSFS_GetFullName(ret,FALSE,&tempname))
1585 TRACE("Wrong path?\n");
1586 return NULL;
1588 free(ret);
1589 if ((ret = CRTDLL_malloc(strlen(tempname.short_name)+1)) == NULL) {
1590 WARN("CRTDL_malloc for shortname failed\n");
1591 return NULL;
1593 if ((ret = strcpy(ret,tempname.short_name)) == NULL) {
1594 WARN("Malloc for shortname failed\n");
1595 return NULL;
1598 TRACE("dir %s prefix %s got %s\n",
1599 dir,prefix,ret);
1600 return ret;
1603 /*********************************************************************
1604 * tmpnam (CRTDLL.490)
1606 * lcclnk from lcc-win32 relies on a terminating dot in the name returned
1609 LPSTR __cdecl CRTDLL_tmpnam(LPSTR s)
1611 char *ret;
1613 if ((ret =tmpnam(s))== NULL) {
1614 WARN("Unable to get unique filename\n");
1615 return NULL;
1617 if (!DOSFS_GetFullName(ret,FALSE,&CRTDLL_tmpname))
1619 TRACE("Wrong path?\n");
1620 return NULL;
1622 strcat(CRTDLL_tmpname.short_name,".");
1623 TRACE("for buf %p got %s\n",
1624 s,CRTDLL_tmpname.short_name);
1625 TRACE("long got %s\n",
1626 CRTDLL_tmpname.long_name);
1627 if ( s != NULL)
1628 return strcpy(s,CRTDLL_tmpname.short_name);
1629 else
1630 return CRTDLL_tmpname.short_name;
1634 /*********************************************************************
1635 * _itoa (CRTDLL.165)
1637 LPSTR __cdecl CRTDLL__itoa(INT x,LPSTR buf,INT buflen)
1639 wsnprintfA(buf,buflen,"%d",x);
1640 return buf;
1644 typedef VOID (*sig_handler_type)(VOID);
1646 /*********************************************************************
1647 * signal (CRTDLL.455)
1649 void * __cdecl CRTDLL_signal(int sig, sig_handler_type ptr)
1651 FIXME("(%d %p):stub.\n", sig, ptr);
1652 return (void*)-1;
1655 /*********************************************************************
1656 * _sleep (CRTDLL.267)
1658 VOID __cdecl CRTDLL__sleep(unsigned long timeout)
1660 TRACE("CRTDLL__sleep for %ld milliseconds\n",timeout);
1661 Sleep((timeout)?timeout:1);
1664 /*********************************************************************
1665 * getenv (CRTDLL.437)
1667 LPSTR __cdecl CRTDLL_getenv(const char *name)
1669 LPSTR environ = GetEnvironmentStringsA();
1670 LPSTR pp,pos = NULL;
1671 unsigned int length;
1673 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
1675 pos =strchr(pp,'=');
1676 if (pos)
1677 length = pos -pp;
1678 else
1679 length = strlen(pp);
1680 if (!strncmp(pp,name,length)) break;
1682 if ((pp)&& (pos))
1684 pp = pos+1;
1685 TRACE("got %s\n",pp);
1687 FreeEnvironmentStringsA( environ );
1688 return pp;
1691 /*********************************************************************
1692 * _mbsrchr (CRTDLL.223)
1694 LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x) {
1695 /* FIXME: handle multibyte strings */
1696 return strrchr(s,x);
1699 /*********************************************************************
1700 * __dllonexit (CRTDLL.25)
1702 VOID __cdecl CRTDLL___dllonexit ()
1704 FIXME("stub\n");
1707 /*********************************************************************
1708 * _strdate (CRTDLL.283)
1710 LPSTR __cdecl CRTDLL__strdate (LPSTR date)
1711 { FIXME("%p stub\n", date);
1712 return 0;
1715 /*********************************************************************
1716 * _strtime (CRTDLL.299)
1718 LPSTR __cdecl CRTDLL__strtime (LPSTR date)
1719 { FIXME("%p stub\n", date);
1720 return 0;
1723 /*********************************************************************
1724 * _except_handler2 (CRTDLL.78)
1726 INT __cdecl CRTDLL__except_handler2 (
1727 PEXCEPTION_RECORD rec,
1728 PEXCEPTION_FRAME frame,
1729 PCONTEXT context,
1730 PEXCEPTION_FRAME *dispatcher)
1732 FIXME ("exception %lx flags=%lx at %p handler=%p %p %p stub\n",
1733 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
1734 frame->Handler, context, dispatcher);
1735 return ExceptionContinueSearch;