2 * msvcrt.dll file functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
35 #include "wine/unicode.h"
36 #include "msvcrt/direct.h"
37 #include "msvcrt/fcntl.h"
38 #include "msvcrt/io.h"
39 #include "msvcrt/sys/locking.h"
40 #include "msvcrt/stdio.h"
41 #include "msvcrt/stdlib.h"
42 #include "msvcrt/string.h"
43 #include "msvcrt/sys/stat.h"
44 #include "msvcrt/sys/utime.h"
45 #include "msvcrt/time.h"
46 #include "msvcrt/share.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
52 /* for stat mode, permissions apply to all,owner and group */
53 #define MSVCRT_S_IREAD (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
54 #define MSVCRT_S_IWRITE (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
55 #define MSVCRT_S_IEXEC (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))
57 /* _access() bit flags FIXME: incomplete */
58 #define MSVCRT_W_OK 0x02
61 /* FIXME: Make this dynamic */
62 #define MSVCRT_MAX_FILES 257
64 HANDLE MSVCRT_handles
[MSVCRT_MAX_FILES
];
65 MSVCRT_FILE
* MSVCRT_files
[MSVCRT_MAX_FILES
];
66 int MSVCRT_flags
[MSVCRT_MAX_FILES
];
67 char *MSVCRT_tempfiles
[MSVCRT_MAX_FILES
];
68 MSVCRT_FILE MSVCRT__iob
[3];
69 #define MSVCRT_stdin (MSVCRT__iob+STDIN_FILENO)
70 #define MSVCRT_stdout (MSVCRT__iob+STDOUT_FILENO)
71 #define MSVCRT_stderr (MSVCRT__iob+STDERR_FILENO)
73 static int MSVCRT_fdstart
= 3; /* first unallocated fd */
74 static int MSVCRT_fdend
= 3; /* highest allocated fd */
76 /* INTERNAL: process umask */
77 static int MSVCRT_umask
= 0;
79 /* INTERNAL: Static buffer for temp file name */
80 static char MSVCRT_tmpname
[MAX_PATH
];
82 static const unsigned int EXE
= 'e' << 16 | 'x' << 8 | 'e';
83 static const unsigned int BAT
= 'b' << 16 | 'a' << 8 | 't';
84 static const unsigned int CMD
= 'c' << 16 | 'm' << 8 | 'd';
85 static const unsigned int COM
= 'c' << 16 | 'o' << 8 | 'm';
87 #define TOUL(x) (ULONGLONG)((WCHAR)L##x)
88 static const ULONGLONG WCEXE
= TOUL('e') << 32 | TOUL('x') << 16 | TOUL('e');
89 static const ULONGLONG WCBAT
= TOUL('b') << 32 | TOUL('a') << 16 | TOUL('t');
90 static const ULONGLONG WCCMD
= TOUL('c') << 32 | TOUL('m') << 16 | TOUL('d');
91 static const ULONGLONG WCCOM
= TOUL('c') << 32 | TOUL('o') << 16 | TOUL('m');
93 extern CRITICAL_SECTION MSVCRT_file_cs
;
94 #define LOCK_FILES EnterCriticalSection(&MSVCRT_file_cs)
95 #define UNLOCK_FILES LeaveCriticalSection(&MSVCRT_file_cs)
98 /* INTERNAL: Get the HANDLE for a fd */
99 static HANDLE
msvcrt_fdtoh(int fd
)
101 if (fd
< 0 || fd
>= MSVCRT_fdend
||
102 MSVCRT_handles
[fd
] == INVALID_HANDLE_VALUE
)
104 WARN(":fd (%d) - no handle!\n",fd
);
105 SET_THREAD_VAR(doserrno
,0);
106 SET_THREAD_VAR(errno
,MSVCRT_EBADF
);
107 return INVALID_HANDLE_VALUE
;
109 return MSVCRT_handles
[fd
];
112 /* INTERNAL: free a file entry fd */
113 static void msvcrt_free_fd(int fd
)
115 MSVCRT_handles
[fd
] = INVALID_HANDLE_VALUE
;
116 MSVCRT_files
[fd
] = 0;
117 MSVCRT_flags
[fd
] = 0;
118 TRACE(":fd (%d) freed\n",fd
);
120 return; /* dont use 0,1,2 for user files */
121 if (fd
== MSVCRT_fdend
- 1)
123 if (fd
< MSVCRT_fdstart
)
127 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE */
128 static int msvcrt_alloc_fd(HANDLE hand
, int flag
)
130 int fd
= MSVCRT_fdstart
;
132 TRACE(":handle (%d) allocating fd (%d)\n",hand
,fd
);
133 if (fd
>= MSVCRT_MAX_FILES
)
135 WARN(":files exhausted!\n");
138 MSVCRT_handles
[fd
] = hand
;
139 MSVCRT_flags
[fd
] = flag
;
141 /* locate next free slot */
142 if (fd
== MSVCRT_fdend
)
143 MSVCRT_fdstart
= ++MSVCRT_fdend
;
145 while(MSVCRT_fdstart
< MSVCRT_fdend
&&
146 MSVCRT_handles
[MSVCRT_fdstart
] != INVALID_HANDLE_VALUE
)
152 /* INTERNAL: Allocate a FILE* for an fd slot
153 * This is done lazily to avoid memory wastage for low level open/write
154 * usage when a FILE* is not requested (but may be later).
156 static MSVCRT_FILE
* msvcrt_alloc_fp(int fd
)
158 TRACE(":fd (%d) allocating FILE*\n",fd
);
159 if (fd
< 0 || fd
>= MSVCRT_fdend
||
160 MSVCRT_handles
[fd
] == INVALID_HANDLE_VALUE
)
162 WARN(":invalid fd %d\n",fd
);
163 SET_THREAD_VAR(doserrno
,0);
164 SET_THREAD_VAR(errno
,MSVCRT_EBADF
);
167 if (!MSVCRT_files
[fd
])
169 if ((MSVCRT_files
[fd
] = MSVCRT_calloc(sizeof(MSVCRT_FILE
),1)))
171 MSVCRT_files
[fd
]->_file
= fd
;
172 MSVCRT_files
[fd
]->_flag
= MSVCRT_flags
[fd
];
173 MSVCRT_files
[fd
]->_flag
&= ~MSVCRT__IOAPPEND
; /* mask out, see above */
176 TRACE(":got FILE* (%p)\n",MSVCRT_files
[fd
]);
177 return MSVCRT_files
[fd
];
181 /* INTERNAL: Set up stdin, stderr and stdout */
182 void msvcrt_init_io(void)
185 memset(MSVCRT__iob
,0,3*sizeof(MSVCRT_FILE
));
186 MSVCRT_handles
[0] = GetStdHandle(STD_INPUT_HANDLE
);
187 MSVCRT_flags
[0] = MSVCRT__iob
[0]._flag
= MSVCRT__IOREAD
;
188 MSVCRT_handles
[1] = GetStdHandle(STD_OUTPUT_HANDLE
);
189 MSVCRT_flags
[1] = MSVCRT__iob
[1]._flag
= MSVCRT__IOWRT
;
190 MSVCRT_handles
[2] = GetStdHandle(STD_ERROR_HANDLE
);
191 MSVCRT_flags
[2] = MSVCRT__iob
[2]._flag
= MSVCRT__IOWRT
;
193 TRACE(":handles (%d)(%d)(%d)\n",MSVCRT_handles
[0],
194 MSVCRT_handles
[1],MSVCRT_handles
[2]);
196 for (i
= 0; i
< 3; i
++)
198 /* FILE structs for stdin/out/err are static and never deleted */
199 MSVCRT_files
[i
] = &MSVCRT__iob
[i
];
200 MSVCRT__iob
[i
]._file
= i
;
201 MSVCRT_tempfiles
[i
] = NULL
;
205 /* free everything on process exit */
206 void msvcrt_free_io(void)
214 /* INTERNAL: Flush stdio file buffer */
215 static int msvcrt_flush_buffer(MSVCRT_FILE
* file
)
218 int cnt
=file
->_ptr
-file
->_base
;
219 if(cnt
>0 && _write(file
->_file
, file
->_base
, cnt
) != cnt
) {
222 file
->_ptr
=file
->_base
;
223 file
->_cnt
=file
->_bufsiz
;
228 /* INTERNAL: Allocate stdio file buffer */
229 static void msvcrt_alloc_buffer(MSVCRT_FILE
* file
)
231 file
->_base
= MSVCRT_calloc(MSVCRT_BUFSIZ
,1);
233 file
->_bufsiz
= MSVCRT_BUFSIZ
;
234 file
->_flag
|= MSVCRT__IOMYBUF
;
236 file
->_base
= (unsigned char *)(&file
->_charbuf
);
238 file
->_bufsiz
= sizeof(file
->_charbuf
);
240 file
->_ptr
= file
->_base
;
244 /*********************************************************************
247 MSVCRT_FILE
*__p__iob(void)
249 return &MSVCRT__iob
[0];
252 /*********************************************************************
255 int _access(const char *filename
, int mode
)
257 DWORD attr
= GetFileAttributesA(filename
);
259 TRACE("(%s,%d) %ld\n",filename
,mode
,attr
);
261 if (!filename
|| attr
== 0xffffffff)
263 MSVCRT__set_errno(GetLastError());
266 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& MSVCRT_W_OK
))
268 MSVCRT__set_errno(ERROR_ACCESS_DENIED
);
274 /*********************************************************************
275 * _waccess (MSVCRT.@)
277 int _waccess(const WCHAR
*filename
, int mode
)
279 DWORD attr
= GetFileAttributesW(filename
);
281 TRACE("(%s,%d) %ld\n",debugstr_w(filename
),mode
,attr
);
283 if (!filename
|| attr
== 0xffffffff)
285 MSVCRT__set_errno(GetLastError());
288 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& MSVCRT_W_OK
))
290 MSVCRT__set_errno(ERROR_ACCESS_DENIED
);
296 /*********************************************************************
299 int _chmod(const char *path
, int flags
)
301 DWORD oldFlags
= GetFileAttributesA(path
);
303 if (oldFlags
!= 0x0FFFFFFFF)
305 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
306 oldFlags
| FILE_ATTRIBUTE_READONLY
;
308 if (newFlags
== oldFlags
|| SetFileAttributesA(path
, newFlags
))
311 MSVCRT__set_errno(GetLastError());
315 /*********************************************************************
318 int _wchmod(const WCHAR
*path
, int flags
)
320 DWORD oldFlags
= GetFileAttributesW(path
);
322 if (oldFlags
!= 0x0FFFFFFFF)
324 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
325 oldFlags
| FILE_ATTRIBUTE_READONLY
;
327 if (newFlags
== oldFlags
|| SetFileAttributesW(path
, newFlags
))
330 MSVCRT__set_errno(GetLastError());
334 /*********************************************************************
337 int _unlink(const char *path
)
339 TRACE("(%s)\n",path
);
340 if(DeleteFileA(path
))
342 TRACE("failed (%ld)\n",GetLastError());
343 MSVCRT__set_errno(GetLastError());
347 /*********************************************************************
348 * _wunlink (MSVCRT.@)
350 int _wunlink(const WCHAR
*path
)
352 TRACE("(%s)\n",debugstr_w(path
));
353 if(DeleteFileW(path
))
355 TRACE("failed (%ld)\n",GetLastError());
356 MSVCRT__set_errno(GetLastError());
360 /*********************************************************************
365 HANDLE hand
= msvcrt_fdtoh(fd
);
367 TRACE(":fd (%d) handle (%d)\n",fd
,hand
);
368 if (hand
== INVALID_HANDLE_VALUE
)
370 /* flush stdio buffers */
371 if(MSVCRT_files
[fd
]) {
372 if(MSVCRT_files
[fd
]->_flag
& MSVCRT__IOWRT
)
373 MSVCRT_fflush(MSVCRT_files
[fd
]);
375 if(MSVCRT_files
[fd
]->_flag
& MSVCRT__IOMYBUF
)
376 MSVCRT_free(MSVCRT_files
[fd
]->_base
);
379 /* Dont free std FILE*'s, they are not dynamic */
380 if (fd
> 2 && MSVCRT_files
[fd
])
381 MSVCRT_free(MSVCRT_files
[fd
]);
385 if (!CloseHandle(hand
))
387 WARN(":failed-last error (%ld)\n",GetLastError());
388 MSVCRT__set_errno(GetLastError());
391 if (MSVCRT_tempfiles
[fd
])
393 TRACE("deleting temporary file '%s'\n",MSVCRT_tempfiles
[fd
]);
394 _unlink(MSVCRT_tempfiles
[fd
]);
395 MSVCRT_free(MSVCRT_tempfiles
[fd
]);
396 MSVCRT_tempfiles
[fd
] = NULL
;
403 /*********************************************************************
408 HANDLE hand
= msvcrt_fdtoh(fd
);
410 TRACE(":fd (%d) handle (%d)\n",fd
,hand
);
411 if (hand
== INVALID_HANDLE_VALUE
)
414 if (!FlushFileBuffers(hand
))
416 if (GetLastError() == ERROR_INVALID_HANDLE
)
418 /* FlushFileBuffers fails for console handles
419 * so we ignore this error.
423 TRACE(":failed-last error (%ld)\n",GetLastError());
424 MSVCRT__set_errno(GetLastError());
431 /*********************************************************************
437 HANDLE hand
= msvcrt_fdtoh(fd
);
439 TRACE(":fd (%d) handle (%d)\n",fd
,hand
);
441 if (hand
== INVALID_HANDLE_VALUE
)
444 /* If we have a FILE* for this file, the EOF flag
445 * will be set by the read()/write() functions.
447 if (MSVCRT_files
[fd
])
448 return MSVCRT_flags
[fd
] & MSVCRT__IOEOF
;
450 /* Otherwise we do it the hard way */
451 curpos
= SetFilePointer(hand
, 0, NULL
, SEEK_CUR
);
452 endpos
= SetFilePointer(hand
, 0, NULL
, FILE_END
);
454 if (curpos
== endpos
)
457 SetFilePointer(hand
, curpos
, 0, FILE_BEGIN
);
461 /*********************************************************************
462 * _fcloseall (MSVCRT.@)
466 int num_closed
= 0, i
;
468 for (i
= 3; i
< MSVCRT_fdend
; i
++)
469 if (MSVCRT_handles
[i
] != INVALID_HANDLE_VALUE
)
475 TRACE(":closed (%d) handles\n",num_closed
);
479 /*********************************************************************
482 LONG
_lseek(int fd
, LONG offset
, int whence
)
485 HANDLE hand
= msvcrt_fdtoh(fd
);
487 TRACE(":fd (%d) handle (%d)\n",fd
,hand
);
488 if (hand
== INVALID_HANDLE_VALUE
)
491 if (whence
< 0 || whence
> 2)
493 SET_THREAD_VAR(errno
,MSVCRT_EINVAL
);
497 TRACE(":fd (%d) to 0x%08lx pos %s\n",
498 fd
,offset
,(whence
==SEEK_SET
)?"SEEK_SET":
499 (whence
==SEEK_CUR
)?"SEEK_CUR":
500 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
502 if ((ret
= SetFilePointer(hand
, offset
, NULL
, whence
)) != 0xffffffff)
504 if (MSVCRT_files
[fd
])
505 MSVCRT_files
[fd
]->_flag
&= ~MSVCRT__IOEOF
;
506 /* FIXME: What if we seek _to_ EOF - is EOF set? */
509 TRACE(":error-last error (%ld)\n",GetLastError());
510 if (MSVCRT_files
[fd
])
511 switch(GetLastError())
513 case ERROR_NEGATIVE_SEEK
:
514 case ERROR_SEEK_ON_DEVICE
:
515 MSVCRT__set_errno(GetLastError());
516 MSVCRT_files
[fd
]->_flag
|= MSVCRT__IOERR
;
524 /*********************************************************************
525 * _locking (MSVCRT.@)
527 * This is untested; the underlying LockFile doesn't work yet.
529 int _locking(int fd
, int mode
, LONG nbytes
)
533 HANDLE hand
= msvcrt_fdtoh(fd
);
535 TRACE(":fd (%d) handle (%d)\n",fd
,hand
);
536 if (hand
== INVALID_HANDLE_VALUE
)
539 if (mode
< 0 || mode
> 4)
541 SET_THREAD_VAR(errno
,MSVCRT_EINVAL
);
545 TRACE(":fd (%d) by 0x%08lx mode %s\n",
546 fd
,nbytes
,(mode
==_LK_UNLCK
)?"_LK_UNLCK":
547 (mode
==_LK_LOCK
)?"_LK_LOCK":
548 (mode
==_LK_NBLCK
)?"_LK_NBLCK":
549 (mode
==_LK_RLCK
)?"_LK_RLCK":
550 (mode
==_LK_NBRLCK
)?"_LK_NBRLCK":
553 if ((cur_locn
= SetFilePointer(hand
, 0L, NULL
, SEEK_CUR
)) == 0xffffffff)
555 FIXME ("Seek failed\n");
556 SET_THREAD_VAR(errno
,MSVCRT_EINVAL
); /* FIXME */
559 if (mode
== _LK_LOCK
|| mode
== _LK_RLCK
)
562 ret
= 1; /* just to satisfy gcc */
565 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
570 else if (mode
== _LK_UNLCK
)
571 ret
= UnlockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
573 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
574 /* FIXME - what about error settings? */
578 /*********************************************************************
581 void MSVCRT_rewind(MSVCRT_FILE
* file
)
583 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
584 MSVCRT_fseek(file
, 0L, SEEK_SET
);
585 MSVCRT_clearerr(file
);
588 /*********************************************************************
591 MSVCRT_FILE
* _fdopen(int fd
, const char *mode
)
593 MSVCRT_FILE
* file
= msvcrt_alloc_fp(fd
);
595 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
602 /*********************************************************************
603 * _wfdopen (MSVCRT.@)
605 MSVCRT_FILE
* _wfdopen(int fd
, const WCHAR
*mode
)
607 MSVCRT_FILE
* file
= msvcrt_alloc_fp(fd
);
609 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,debugstr_w(mode
),file
);
616 /*********************************************************************
617 * _filelength (MSVCRT.@)
619 LONG
_filelength(int fd
)
621 LONG curPos
= _lseek(fd
, 0, SEEK_CUR
);
624 LONG endPos
= _lseek(fd
, 0, SEEK_END
);
627 if (endPos
!= curPos
)
628 _lseek(fd
, curPos
, SEEK_SET
);
635 /*********************************************************************
638 int _fileno(MSVCRT_FILE
* file
)
640 TRACE(":FILE* (%p) fd (%d)\n",file
,file
->_file
);
644 /*********************************************************************
645 * _flushall (MSVCRT.@)
649 int num_flushed
= 0, i
= 3;
651 while(i
< MSVCRT_fdend
)
652 if (MSVCRT_handles
[i
] != INVALID_HANDLE_VALUE
)
655 /* FIXME: flush, do not commit */
656 if (_commit(i
) == -1)
658 MSVCRT_files
[i
]->_flag
|= MSVCRT__IOERR
;
660 if(MSVCRT_files
[i
] && MSVCRT_files
[i
]->_flag
& MSVCRT__IOWRT
) {
661 MSVCRT_fflush(MSVCRT_files
[i
]);
666 TRACE(":flushed (%d) handles\n",num_flushed
);
670 /*********************************************************************
673 int _fstat(int fd
, struct _stat
* buf
)
676 BY_HANDLE_FILE_INFORMATION hfi
;
677 HANDLE hand
= msvcrt_fdtoh(fd
);
679 TRACE(":fd (%d) stat (%p)\n",fd
,buf
);
680 if (hand
== INVALID_HANDLE_VALUE
)
685 WARN(":failed-NULL buf\n");
686 MSVCRT__set_errno(ERROR_INVALID_PARAMETER
);
690 memset(&hfi
, 0, sizeof(hfi
));
691 memset(buf
, 0, sizeof(struct _stat
));
692 if (!GetFileInformationByHandle(hand
, &hfi
))
694 WARN(":failed-last error (%ld)\n",GetLastError());
695 MSVCRT__set_errno(ERROR_INVALID_PARAMETER
);
698 FIXME(":dwFileAttributes = %ld, mode set to 0\n",hfi
.dwFileAttributes
);
699 buf
->st_nlink
= hfi
.nNumberOfLinks
;
700 buf
->st_size
= hfi
.nFileSizeLow
;
701 RtlTimeToSecondsSince1970(&hfi
.ftLastAccessTime
, &dw
);
703 RtlTimeToSecondsSince1970(&hfi
.ftLastWriteTime
, &dw
);
704 buf
->st_mtime
= buf
->st_ctime
= dw
;
708 /*********************************************************************
711 int _futime(int fd
, struct _utimbuf
*t
)
713 HANDLE hand
= msvcrt_fdtoh(fd
);
718 MSVCRT_time_t currTime
;
719 MSVCRT_time(&currTime
);
720 RtlSecondsSince1970ToTime(currTime
, &at
);
721 memcpy(&wt
, &at
, sizeof(wt
));
725 RtlSecondsSince1970ToTime(t
->actime
, &at
);
726 if (t
->actime
== t
->modtime
)
727 memcpy(&wt
, &at
, sizeof(wt
));
729 RtlSecondsSince1970ToTime(t
->modtime
, &wt
);
732 if (!SetFileTime(hand
, NULL
, &at
, &wt
))
734 MSVCRT__set_errno(GetLastError());
740 /*********************************************************************
741 * _get_osfhandle (MSVCRT.@)
743 long _get_osfhandle(int fd
)
745 HANDLE hand
= msvcrt_fdtoh(fd
);
746 HANDLE newhand
= hand
;
747 TRACE(":fd (%d) handle (%d)\n",fd
,hand
);
749 if (hand
!= INVALID_HANDLE_VALUE
)
751 /* FIXME: I'm not convinced that I should be copying the
752 * handle here - it may be leaked if the app doesn't
753 * close it (and the API docs dont say that it should)
754 * Not duplicating it means that it can't be inherited
755 * and so lcc's wedit doesn't cope when it passes it to
756 * child processes. I've an idea that it should either
757 * be copied by CreateProcess, or marked as inheritable
758 * when initialised, or maybe both? JG 21-9-00.
760 DuplicateHandle(GetCurrentProcess(),hand
,GetCurrentProcess(),
761 &newhand
,0,TRUE
,DUPLICATE_SAME_ACCESS
);
766 /*********************************************************************
771 HANDLE hand
= msvcrt_fdtoh(fd
);
773 TRACE(":fd (%d) handle (%d)\n",fd
,hand
);
774 if (hand
== INVALID_HANDLE_VALUE
)
777 return GetFileType(hand
) == FILE_TYPE_CHAR
? 1 : 0;
780 /*********************************************************************
783 char *_mktemp(char *pattern
)
786 char *retVal
= pattern
;
791 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
795 id
= GetCurrentProcessId();
799 int tempNum
= id
/ 10;
800 *pattern
-- = id
- (tempNum
* 10) + '0';
806 if (GetFileAttributesA(retVal
) == 0xFFFFFFFF &&
807 GetLastError() == ERROR_FILE_NOT_FOUND
)
810 } while(letter
!= '|');
814 /*********************************************************************
815 * _wmktemp (MSVCRT.@)
817 WCHAR
*_wmktemp(WCHAR
*pattern
)
820 WCHAR
*retVal
= pattern
;
822 WCHAR letter
= (WCHAR
)L
'a';
825 numX
= (*pattern
++ == (WCHAR
)L
'X')? numX
+ 1 : 0;
829 id
= GetCurrentProcessId();
833 int tempNum
= id
/ 10;
834 *pattern
-- = id
- (tempNum
* 10) + (WCHAR
)L
'0';
840 if (GetFileAttributesW(retVal
) == 0xFFFFFFFF &&
841 GetLastError() == ERROR_FILE_NOT_FOUND
)
844 } while(letter
!= (WCHAR
)L
'|');
848 /*********************************************************************
851 int MSVCRT__sopen( const char *path
, int oflags
, int shflags
, ... )
855 DWORD access
= 0, creation
= 0;
859 SECURITY_ATTRIBUTES sa
;
862 TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n",
863 path
, oflags
, shflags
);
865 switch(oflags
& (_O_RDONLY
| _O_WRONLY
| _O_RDWR
))
868 access
|= GENERIC_READ
;
869 ioflag
|= MSVCRT__IOREAD
;
872 access
|= GENERIC_WRITE
;
873 ioflag
|= MSVCRT__IOWRT
;
876 access
|= GENERIC_WRITE
| GENERIC_READ
;
877 ioflag
|= MSVCRT__IORW
;
881 if (oflags
& _O_CREAT
)
883 va_start(ap
, shflags
);
884 pmode
= va_arg(ap
, int);
887 FIXME(": pmode 0x%04x ignored\n", pmode
);
889 if (oflags
& _O_EXCL
)
890 creation
= CREATE_NEW
;
891 else if (oflags
& _O_TRUNC
)
892 creation
= CREATE_ALWAYS
;
894 creation
= OPEN_ALWAYS
;
896 else /* no _O_CREAT */
898 if (oflags
& _O_TRUNC
)
899 creation
= TRUNCATE_EXISTING
;
901 creation
= OPEN_EXISTING
;
903 if (oflags
& _O_APPEND
)
904 ioflag
|= MSVCRT__IOAPPEND
;
907 oflags
|= _O_BINARY
; /* FIXME: Default to text */
909 if (oflags
& _O_TEXT
)
911 /* Dont warn when writing */
912 if (ioflag
& GENERIC_READ
)
913 FIXME(":TEXT node not implemented\n");
923 sharing
= FILE_SHARE_READ
;
926 sharing
= FILE_SHARE_WRITE
;
929 sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
932 ERR( "Unhandled shflags 0x%x\n", shflags
);
936 if (oflags
& ~(_O_BINARY
|_O_TEXT
|_O_APPEND
|_O_TRUNC
|_O_EXCL
937 |_O_CREAT
|_O_RDWR
|_O_TEMPORARY
|_O_NOINHERIT
))
938 TRACE(":unsupported oflags 0x%04x\n",oflags
);
940 sa
.nLength
= sizeof( SECURITY_ATTRIBUTES
);
941 sa
.lpSecurityDescriptor
= NULL
;
942 sa
.bInheritHandle
= (oflags
& _O_NOINHERIT
) ? FALSE
: TRUE
;
944 hand
= CreateFileA(path
, access
, sharing
,
945 &sa
, creation
, FILE_ATTRIBUTE_NORMAL
, 0);
947 if (hand
== INVALID_HANDLE_VALUE
) {
948 WARN(":failed-last error (%ld)\n",GetLastError());
949 MSVCRT__set_errno(GetLastError());
953 fd
= msvcrt_alloc_fd(hand
, ioflag
);
955 TRACE(":fd (%d) handle (%d)\n",fd
, hand
);
959 if (oflags
& _O_TEMPORARY
)
960 MSVCRT_tempfiles
[fd
] = _strdup(path
);
961 if (ioflag
& MSVCRT__IOAPPEND
)
962 _lseek(fd
, 0, FILE_END
);
968 /*********************************************************************
971 int MSVCRT__wsopen( const WCHAR
* path
, int oflags
, int shflags
, ... )
973 const unsigned int len
= strlenW(path
);
974 char *patha
= MSVCRT_calloc(len
+ 1,1);
978 va_start(ap
, shflags
);
979 pmode
= va_arg(ap
, int);
982 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
984 int retval
= MSVCRT__sopen(patha
,oflags
,shflags
,pmode
);
989 MSVCRT__set_errno(GetLastError());
993 /*********************************************************************
996 int _open( const char *path
, int flags
, ... )
1001 va_start(ap
, flags
);
1002 pmode
= va_arg(ap
, int);
1005 return MSVCRT__sopen( path
, flags
, _SH_DENYNO
, pmode
);
1008 /*********************************************************************
1011 int _wopen(const WCHAR
*path
,int flags
,...)
1013 const unsigned int len
= strlenW(path
);
1014 char *patha
= MSVCRT_calloc(len
+ 1,1);
1018 va_start(ap
, flags
);
1019 pmode
= va_arg(ap
, int);
1022 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1024 int retval
= _open(patha
,flags
,pmode
);
1029 MSVCRT__set_errno(GetLastError());
1033 /*********************************************************************
1036 int _creat(const char *path
, int flags
)
1038 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1039 return _open(path
, usedFlags
);
1042 /*********************************************************************
1043 * _wcreat (MSVCRT.@)
1045 int _wcreat(const WCHAR
*path
, int flags
)
1047 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1048 return _wopen(path
, usedFlags
);
1051 /*********************************************************************
1052 * _open_osfhandle (MSVCRT.@)
1054 int _open_osfhandle(long hand
, int flags
)
1056 int fd
= msvcrt_alloc_fd(hand
,flags
);
1057 TRACE(":handle (%ld) fd (%d)\n",hand
,fd
);
1061 /*********************************************************************
1066 int num_removed
= 0, i
;
1068 for (i
= 3; i
< MSVCRT_fdend
; i
++)
1069 if (MSVCRT_tempfiles
[i
])
1076 TRACE(":removed (%d) temp files\n",num_removed
);
1080 /*********************************************************************
1083 int _read(int fd
, void *buf
, unsigned int count
)
1086 HANDLE hand
= msvcrt_fdtoh(fd
);
1088 /* Dont trace small reads, it gets *very* annoying */
1090 TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1091 if (hand
== INVALID_HANDLE_VALUE
)
1094 if (ReadFile(hand
, buf
, count
, &num_read
, NULL
))
1096 if (num_read
!= count
&& MSVCRT_files
[fd
])
1099 MSVCRT_flags
[fd
] |= MSVCRT__IOEOF
;
1101 MSVCRT_files[fd]->_flag |= MSVCRT__IOEOF;
1106 TRACE(":failed-last error (%ld)\n",GetLastError());
1107 if (MSVCRT_files
[fd
])
1108 MSVCRT_files
[fd
]->_flag
|= MSVCRT__IOERR
;
1112 /*********************************************************************
1115 int _getw(MSVCRT_FILE
* file
)
1118 if (_read(file
->_file
, &i
, sizeof(int)) != 1)
1123 /*********************************************************************
1124 * _setmode (MSVCRT.@)
1126 int _setmode(int fd
,int mode
)
1129 FIXME("fd (%d) mode (%d) TEXT not implemented\n",fd
,mode
);
1133 /*********************************************************************
1136 int _stat(const char* path
, struct _stat
* buf
)
1139 WIN32_FILE_ATTRIBUTE_DATA hfi
;
1140 unsigned short mode
= MSVCRT_S_IREAD
;
1143 TRACE(":file (%s) buf(%p)\n",path
,buf
);
1145 if (!GetFileAttributesExA(path
, GetFileExInfoStandard
, &hfi
))
1147 TRACE("failed (%ld)\n",GetLastError());
1148 MSVCRT__set_errno(ERROR_FILE_NOT_FOUND
);
1152 memset(buf
,0,sizeof(struct _stat
));
1154 /* FIXME: rdev isnt drive num,despite what the docs say-what is it?
1155 Bon 011120: This FIXME seems incorrect
1156 Also a letter as first char isn't enough to be classify
1159 if (isalpha(*path
)&& (*(path
+1)==':'))
1160 buf
->st_dev
= buf
->st_rdev
= toupper(*path
) - 'A'; /* drive num */
1162 buf
->st_dev
= buf
->st_rdev
= _getdrive() - 1;
1164 plen
= strlen(path
);
1166 /* Dir, or regular file? */
1167 if ((hfi
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1168 (path
[plen
-1] == '\\'))
1169 mode
|= (_S_IFDIR
| MSVCRT_S_IEXEC
);
1174 if (plen
> 6 && path
[plen
-4] == '.') /* shortest exe: "\x.exe" */
1176 unsigned int ext
= tolower(path
[plen
-1]) | (tolower(path
[plen
-2]) << 8) |
1177 (tolower(path
[plen
-3]) << 16);
1178 if (ext
== EXE
|| ext
== BAT
|| ext
== CMD
|| ext
== COM
)
1179 mode
|= MSVCRT_S_IEXEC
;
1183 if (!(hfi
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
))
1184 mode
|= MSVCRT_S_IWRITE
;
1186 buf
->st_mode
= mode
;
1188 buf
->st_size
= hfi
.nFileSizeLow
;
1189 RtlTimeToSecondsSince1970(&hfi
.ftLastAccessTime
, &dw
);
1191 RtlTimeToSecondsSince1970(&hfi
.ftLastWriteTime
, &dw
);
1192 buf
->st_mtime
= buf
->st_ctime
= dw
;
1193 TRACE("\n%d %d %d %ld %ld %ld\n", buf
->st_mode
,buf
->st_nlink
,buf
->st_size
,
1194 buf
->st_atime
,buf
->st_mtime
, buf
->st_ctime
);
1198 /*********************************************************************
1201 int _wstat(const WCHAR
* path
, struct _stat
* buf
)
1204 WIN32_FILE_ATTRIBUTE_DATA hfi
;
1205 unsigned short mode
= MSVCRT_S_IREAD
;
1208 TRACE(":file (%s) buf(%p)\n",debugstr_w(path
),buf
);
1210 if (!GetFileAttributesExW(path
, GetFileExInfoStandard
, &hfi
))
1212 TRACE("failed (%ld)\n",GetLastError());
1213 MSVCRT__set_errno(ERROR_FILE_NOT_FOUND
);
1217 memset(buf
,0,sizeof(struct _stat
));
1219 /* FIXME: rdev isn't drive num, despite what the docs says-what is it? */
1220 if (MSVCRT_iswalpha(*path
))
1221 buf
->st_dev
= buf
->st_rdev
= toupperW(*path
- (WCHAR
)L
'A'); /* drive num */
1223 buf
->st_dev
= buf
->st_rdev
= _getdrive() - 1;
1225 plen
= strlenW(path
);
1227 /* Dir, or regular file? */
1228 if ((hfi
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ||
1229 (path
[plen
-1] == (WCHAR
)L
'\\'))
1230 mode
|= (_S_IFDIR
| MSVCRT_S_IEXEC
);
1235 if (plen
> 6 && path
[plen
-4] == (WCHAR
)L
'.') /* shortest exe: "\x.exe" */
1237 ULONGLONG ext
= tolowerW(path
[plen
-1]) | (tolowerW(path
[plen
-2]) << 16) |
1238 ((ULONGLONG
)tolowerW(path
[plen
-3]) << 32);
1239 if (ext
== WCEXE
|| ext
== WCBAT
|| ext
== WCCMD
|| ext
== WCCOM
)
1240 mode
|= MSVCRT_S_IEXEC
;
1244 if (!(hfi
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
))
1245 mode
|= MSVCRT_S_IWRITE
;
1247 buf
->st_mode
= mode
;
1249 buf
->st_size
= hfi
.nFileSizeLow
;
1250 RtlTimeToSecondsSince1970(&hfi
.ftLastAccessTime
, &dw
);
1252 RtlTimeToSecondsSince1970(&hfi
.ftLastWriteTime
, &dw
);
1253 buf
->st_mtime
= buf
->st_ctime
= dw
;
1254 TRACE("\n%d %d %d %ld %ld %ld\n", buf
->st_mode
,buf
->st_nlink
,buf
->st_size
,
1255 buf
->st_atime
,buf
->st_mtime
, buf
->st_ctime
);
1259 /*********************************************************************
1264 return _lseek(fd
, 0, SEEK_CUR
);
1267 /*********************************************************************
1268 * _tempnam (MSVCRT.@)
1270 char *_tempnam(const char *dir
, const char *prefix
)
1272 char tmpbuf
[MAX_PATH
];
1274 TRACE("dir (%s) prefix (%s)\n",dir
,prefix
);
1275 if (GetTempFileNameA(dir
,prefix
,0,tmpbuf
))
1277 TRACE("got name (%s)\n",tmpbuf
);
1278 return _strdup(tmpbuf
);
1280 TRACE("failed (%ld)\n",GetLastError());
1284 /*********************************************************************
1285 * _wtempnam (MSVCRT.@)
1287 WCHAR
*_wtempnam(const WCHAR
*dir
, const WCHAR
*prefix
)
1289 WCHAR tmpbuf
[MAX_PATH
];
1291 TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir
),debugstr_w(prefix
));
1292 if (GetTempFileNameW(dir
,prefix
,0,tmpbuf
))
1294 TRACE("got name (%s)\n",debugstr_w(tmpbuf
));
1295 return _wcsdup(tmpbuf
);
1297 TRACE("failed (%ld)\n",GetLastError());
1301 /*********************************************************************
1304 int _umask(int umask
)
1306 int old_umask
= MSVCRT_umask
;
1307 TRACE("(%d)\n",umask
);
1308 MSVCRT_umask
= umask
;
1312 /*********************************************************************
1315 int _utime(const char* path
, struct _utimbuf
*t
)
1317 int fd
= _open(path
, _O_WRONLY
| _O_BINARY
);
1321 int retVal
= _futime(fd
, t
);
1328 /*********************************************************************
1329 * _wutime (MSVCRT.@)
1331 int _wutime(const WCHAR
* path
, struct _utimbuf
*t
)
1333 int fd
= _wopen(path
, _O_WRONLY
| _O_BINARY
);
1337 int retVal
= _futime(fd
, t
);
1344 /*********************************************************************
1347 int _write(int fd
, const void* buf
, unsigned int count
)
1350 HANDLE hand
= msvcrt_fdtoh(fd
);
1352 /* Dont trace small writes, it gets *very* annoying */
1355 TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1357 if (hand
== INVALID_HANDLE_VALUE
)
1360 /* If appending, go to EOF */
1361 if (MSVCRT_flags
[fd
] & MSVCRT__IOAPPEND
)
1362 _lseek(fd
, 0, FILE_END
);
1364 if (WriteFile(hand
, buf
, count
, &num_written
, NULL
)
1365 && (num_written
== count
))
1368 TRACE(":failed-last error (%ld)\n",GetLastError());
1369 if (MSVCRT_files
[fd
])
1370 MSVCRT_files
[fd
]->_flag
|= MSVCRT__IOERR
;
1375 /*********************************************************************
1378 int _putw(int val
, MSVCRT_FILE
* file
)
1380 return _write(file
->_file
, &val
, sizeof(val
)) == 1? val
: MSVCRT_EOF
;
1383 /*********************************************************************
1384 * clearerr (MSVCRT.@)
1386 void MSVCRT_clearerr(MSVCRT_FILE
* file
)
1388 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
1389 file
->_flag
&= ~(MSVCRT__IOERR
| MSVCRT__IOEOF
);
1392 /*********************************************************************
1395 int MSVCRT_fclose(MSVCRT_FILE
* file
)
1398 r
=_close(file
->_file
);
1399 return ((r
==MSVCRT_EOF
) || (file
->_flag
& MSVCRT__IOERR
) ? MSVCRT_EOF
: 0);
1402 /*********************************************************************
1405 int MSVCRT_feof(MSVCRT_FILE
* file
)
1407 return file
->_flag
& MSVCRT__IOEOF
;
1410 /*********************************************************************
1413 int MSVCRT_ferror(MSVCRT_FILE
* file
)
1415 return file
->_flag
& MSVCRT__IOERR
;
1418 /*********************************************************************
1421 int MSVCRT_fflush(MSVCRT_FILE
* file
)
1427 int res
=msvcrt_flush_buffer(file
);
1432 /*********************************************************************
1435 int MSVCRT_fgetc(MSVCRT_FILE
* file
)
1439 return *(unsigned char *)file
->_ptr
++;
1441 return _filbuf(file
);
1445 /*********************************************************************
1446 * _fgetchar (MSVCRT.@)
1450 return MSVCRT_fgetc(MSVCRT_stdin
);
1453 /*********************************************************************
1454 * _filbuf (MSVCRT.@)
1456 int _filbuf(MSVCRT_FILE
* file
)
1459 /* Allocate buffer if needed */
1460 if(file
->_bufsiz
== 0 && !(file
->_flag
& MSVCRT__IONBF
) ) {
1461 msvcrt_alloc_buffer(file
);
1463 if(!(file
->_flag
& MSVCRT__IOREAD
)) {
1464 if(file
->_flag
& MSVCRT__IORW
) {
1465 file
->_flag
|= MSVCRT__IOREAD
;
1470 if(file
->_flag
& MSVCRT__IONBF
) {
1472 if (_read(file
->_file
,&c
,1) != 1) {
1473 file
->_flag
|= MSVCRT__IOEOF
;
1478 file
->_cnt
= _read(file
->_file
, file
->_base
, file
->_bufsiz
);
1479 if(file
->_cnt
<0) file
->_cnt
= 0;
1481 file
->_flag
|= MSVCRT__IOEOF
;
1485 file
->_ptr
= file
->_base
+1;
1486 return *(unsigned char *)file
->_base
;
1490 /*********************************************************************
1491 * fgetpos (MSVCRT.@)
1493 int MSVCRT_fgetpos(MSVCRT_FILE
* file
, MSVCRT_fpos_t
*pos
)
1495 *pos
= MSVCRT_ftell(file
);
1496 return (*pos
== -1? -1 : 0);
1499 /*********************************************************************
1502 char *MSVCRT_fgets(char *s
, int size
, MSVCRT_FILE
* file
)
1505 char * buf_start
= s
;
1507 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
1508 file
,file
->_file
,s
,size
);
1510 for(cc
= MSVCRT_fgetc(file
); cc
!= MSVCRT_EOF
&& cc
!= '\n';
1511 cc
= MSVCRT_fgetc(file
))
1514 if (--size
<= 0) break;
1517 if ((cc
== MSVCRT_EOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
1519 TRACE(":nothing read\n");
1526 TRACE(":got '%s'\n", buf_start
);
1530 /*********************************************************************
1533 MSVCRT_wint_t
MSVCRT_fgetwc(MSVCRT_FILE
* file
)
1536 if (_read(file
->_file
, &wc
, sizeof(wc
)) != sizeof(wc
))
1541 /*********************************************************************
1544 MSVCRT_wint_t
MSVCRT_getwc(MSVCRT_FILE
* file
)
1546 return MSVCRT_fgetwc(file
);
1549 /*********************************************************************
1550 * _fgetwchar (MSVCRT.@)
1552 MSVCRT_wint_t
_fgetwchar(void)
1554 return MSVCRT_fgetwc(MSVCRT_stdin
);
1557 /*********************************************************************
1558 * getwchar (MSVCRT.@)
1560 MSVCRT_wint_t
MSVCRT_getwchar(void)
1562 return _fgetwchar();
1565 /*********************************************************************
1568 WCHAR
*MSVCRT_fgetws(WCHAR
*s
, int size
, MSVCRT_FILE
* file
)
1571 WCHAR
* buf_start
= s
;
1573 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
1574 file
,file
->_file
,s
,size
);
1576 for(cc
= MSVCRT_fgetwc(file
); cc
!= MSVCRT_WEOF
&& cc
!= L
'\n';
1577 cc
= MSVCRT_fgetwc(file
))
1580 if (--size
<= 0) break;
1583 if ((cc
== MSVCRT_EOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
1585 TRACE(":nothing read\n");
1592 /* TRACE(":got '%s'\n", buf_start); */
1597 /*********************************************************************
1600 MSVCRT_wint_t
MSVCRT_fputwc(MSVCRT_wint_t wc
, MSVCRT_FILE
* file
)
1603 if (MSVCRT_fwrite( &mwc
, sizeof(mwc
), 1, file
) != 1)
1608 /*********************************************************************
1609 * _fputwchar (MSVCRT.@)
1611 MSVCRT_wint_t
_fputwchar(MSVCRT_wint_t wc
)
1613 return MSVCRT_fputwc(wc
, MSVCRT_stdout
);
1616 /*********************************************************************
1619 MSVCRT_FILE
* MSVCRT_fopen(const char *path
, const char *mode
)
1622 int flags
= 0, plus
= 0, fd
;
1623 const char* search
= mode
;
1625 TRACE("(%s,%s)\n",path
,mode
);
1628 if (*search
++ == '+')
1631 /* map mode string to open() flags. "man fopen" for possibilities. */
1635 flags
= (plus
? _O_RDWR
: _O_RDONLY
);
1638 flags
= _O_CREAT
| _O_TRUNC
| (plus
? _O_RDWR
: _O_WRONLY
);
1641 flags
= _O_CREAT
| _O_APPEND
| (plus
? _O_RDWR
: _O_WRONLY
);
1656 flags
&= ~_O_BINARY
;
1661 FIXME(":unknown flag %c not supported\n",mode
[-1]);
1664 fd
= _open(path
, flags
);
1669 file
= msvcrt_alloc_fp(fd
);
1670 TRACE(":got (%p)\n",file
);
1677 /*********************************************************************
1678 * _wfopen (MSVCRT.@)
1680 MSVCRT_FILE
*_wfopen(const WCHAR
*path
, const WCHAR
*mode
)
1682 const unsigned int plen
= strlenW(path
), mlen
= strlenW(mode
);
1683 char *patha
= MSVCRT_calloc(plen
+ 1, 1);
1684 char *modea
= MSVCRT_calloc(mlen
+ 1, 1);
1686 TRACE("(%s,%s)\n",debugstr_w(path
),debugstr_w(mode
));
1688 if (patha
&& modea
&&
1689 WideCharToMultiByte(CP_ACP
,0,path
,plen
,patha
,plen
,NULL
,NULL
) &&
1690 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
1692 MSVCRT_FILE
*retval
= MSVCRT_fopen(patha
,modea
);
1698 MSVCRT__set_errno(GetLastError());
1702 /*********************************************************************
1703 * _fsopen (MSVCRT.@)
1705 MSVCRT_FILE
* _fsopen(const char *path
, const char *mode
, int share
)
1707 FIXME(":(%s,%s,%d),ignoring share mode!\n",path
,mode
,share
);
1708 return MSVCRT_fopen(path
,mode
);
1711 /*********************************************************************
1712 * _wfsopen (MSVCRT.@)
1714 MSVCRT_FILE
* _wfsopen(const WCHAR
*path
, const WCHAR
*mode
, int share
)
1716 FIXME(":(%s,%s,%d),ignoring share mode!\n",
1717 debugstr_w(path
),debugstr_w(mode
),share
);
1718 return _wfopen(path
,mode
);
1721 /*********************************************************************
1724 int MSVCRT_fputc(int c
, MSVCRT_FILE
* file
)
1731 return _flsbuf(c
, file
);
1735 /*********************************************************************
1736 * _flsbuf (MSVCRT.@)
1738 int _flsbuf(int c
, MSVCRT_FILE
* file
)
1740 /* Flush output buffer */
1741 if(file
->_bufsiz
== 0 && !(file
->_flag
& MSVCRT__IONBF
)) {
1742 msvcrt_alloc_buffer(file
);
1744 if(!(file
->_flag
& MSVCRT__IOWRT
)) {
1745 if(file
->_flag
& MSVCRT__IORW
) {
1746 file
->_flag
|= MSVCRT__IOWRT
;
1752 int res
=msvcrt_flush_buffer(file
);
1753 return res
?res
: MSVCRT_fputc(c
, file
);
1756 return _write(file
->_file
, &cc
, 1) == 1? c
: MSVCRT_EOF
;
1760 /*********************************************************************
1761 * _fputchar (MSVCRT.@)
1763 int _fputchar(int c
)
1765 return MSVCRT_fputc(c
, MSVCRT_stdout
);
1768 /*********************************************************************
1771 MSVCRT_size_t
MSVCRT_fread(void *ptr
, MSVCRT_size_t size
, MSVCRT_size_t nmemb
, MSVCRT_FILE
* file
)
1772 { MSVCRT_size_t rcnt
=size
* nmemb
;
1773 MSVCRT_size_t read
=0;
1775 /* first buffered data */
1777 int pcnt
= (rcnt
>file
->_cnt
)? file
->_cnt
:rcnt
;
1778 memcpy(ptr
, file
->_ptr
, pcnt
);
1783 ptr
= (char*)ptr
+ pcnt
;
1784 } else if(!(file
->_flag
& MSVCRT__IOREAD
)) {
1785 if(file
->_flag
& MSVCRT__IORW
) {
1786 file
->_flag
|= MSVCRT__IOREAD
;
1790 if(rcnt
) pread
= _read(file
->_file
,ptr
, rcnt
);
1791 if (MSVCRT_flags
[file
->_file
] & MSVCRT__IOEOF
)
1792 /* expose feof condition in the flags
1793 MFC tests file->_flag for feof, and doesn't not call feof())
1795 file
->_flag
|= MSVCRT__IOEOF
;
1802 /*********************************************************************
1803 * freopen (MSVCRT.@)
1806 MSVCRT_FILE
* MSVCRT_freopen(const char *path
, const char *mode
,MSVCRT_FILE
* file
)
1808 MSVCRT_FILE
* newfile
;
1811 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n",path
,mode
,file
,file
->_file
);
1812 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> MSVCRT_fdend
)
1818 FIXME(":reopen on user file not implemented!\n");
1819 MSVCRT__set_errno(ERROR_CALL_NOT_IMPLEMENTED
);
1822 if(MSVCRT_fclose(file
))
1824 return MSVCRT_fopen(path
, mode
);
1827 /* first, create the new file */
1828 if ((newfile
= MSVCRT_fopen(path
,mode
)) == NULL
)
1831 if (fd
< 3 && SetStdHandle(fd
== 0 ? STD_INPUT_HANDLE
:
1832 (fd
== 1? STD_OUTPUT_HANDLE
: STD_ERROR_HANDLE
),
1833 MSVCRT_handles
[newfile
->_file
]))
1835 /* Redirecting std handle to file , copy over.. */
1836 MSVCRT_handles
[fd
] = MSVCRT_handles
[newfile
->_file
];
1837 MSVCRT_flags
[fd
] = MSVCRT_flags
[newfile
->_file
];
1838 memcpy(&MSVCRT__iob
[fd
], newfile
, sizeof (MSVCRT_FILE
));
1839 MSVCRT__iob
[fd
]._file
= fd
;
1840 /* And free up the resources allocated by fopen, but
1841 * not the HANDLE we copied. */
1842 MSVCRT_free(MSVCRT_files
[fd
]);
1843 msvcrt_free_fd(newfile
->_file
);
1844 return &MSVCRT__iob
[fd
];
1847 WARN(":failed-last error (%ld)\n",GetLastError());
1848 MSVCRT_fclose(newfile
);
1849 MSVCRT__set_errno(GetLastError());
1853 /*********************************************************************
1854 * fsetpos (MSVCRT.@)
1856 int MSVCRT_fsetpos(MSVCRT_FILE
* file
, MSVCRT_fpos_t
*pos
)
1858 return _lseek(file
->_file
,*pos
,SEEK_SET
);
1861 /* helper function for fscanf. Returns the value of character c in the
1862 * given base, or -1 if the given character is not a digit of the base.
1864 static int char2digit(char c
, int base
) {
1865 if ((c
>='0') && (c
<='9') && (c
<='0'+base
-1)) return (c
-'0');
1866 if (base
<=10) return -1;
1867 if ((c
>='A') && (c
<='Z') && (c
<='A'+base
-11)) return (c
-'A'+10);
1868 if ((c
>='a') && (c
<='z') && (c
<='a'+base
-11)) return (c
-'a'+10);
1872 /*********************************************************************
1874 * Implemented based on
1875 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_format_specification_fields_.2d_.scanf_and_wscanf_functions.asp
1876 * Extended by C. Scott Ananian <cananian@alumni.princeton.edu> to handle
1877 * more types of format spec.
1879 int MSVCRT_fscanf(MSVCRT_FILE
* file
, const char *format
, ...)
1881 /* NOTE: If you extend this function, extend MSVCRT__cscanf in console.c too */
1885 if (!*format
) return 0;
1886 WARN("%p (\"%s\"): semi-stub\n", file
, format
);
1887 nch
= MSVCRT_fgetc(file
);
1888 va_start(ap
, format
);
1890 /* a whitespace character in the format string causes scanf to read,
1891 * but not store, all consecutive white-space characters in the input
1892 * up to the next non-white-space character. One white space character
1893 * in the input matches any number (including zero) and combination of
1894 * white-space characters in the input. */
1895 if (isspace(*format
)) {
1896 /* skip whitespace */
1897 while ((nch
!=MSVCRT_EOF
) && isspace(nch
))
1898 nch
= MSVCRT_fgetc(file
);
1900 /* a format specification causes scanf to read and convert characters
1901 * in the input into values of a specified type. The value is assigned
1902 * to an argument in the argument list. Format specifications have
1903 * the form %[*][width][{h | l | I64 | L}]type */
1904 /* FIXME: unimplemented: h/l/I64/L modifiers and some type specs. */
1905 else if (*format
== '%') {
1906 int st
= 0; int suppress
= 0; int width
= 0;
1907 int base
, number_signed
;
1909 /* look for leading asterisk, which means 'suppress assignment of
1915 /* look for width specification */
1916 while (isdigit(*format
)) {
1918 width
+=*format
++ - '0';
1920 if (width
==0) width
=-1; /* no width spec seen */
1922 case '%': /* read a percent symbol */
1923 if (nch
!='%') break;
1924 nch
= MSVCRT_fgetc(file
);
1927 case 'X': /* hexadecimal integer. */
1928 base
= 16; number_signed
= 0;
1930 case 'o': /* octal integer */
1931 base
= 8; number_signed
= 0;
1933 case 'u': /* unsigned decimal integer */
1934 base
= 10; number_signed
= 0;
1936 case 'd': /* signed decimal integer */
1937 base
= 10; number_signed
= 1;
1939 case 'i': /* generic integer */
1940 base
= 0; number_signed
= 1;
1942 /* read an integer */
1943 int*val
= suppress
? NULL
: va_arg(ap
, int*);
1944 int cur
= 0; int negative
= 0; int seendigit
=0;
1945 /* skip initial whitespace */
1946 while ((nch
!=MSVCRT_EOF
) && isspace(nch
))
1947 nch
= MSVCRT_fgetc(file
);
1949 if (number_signed
&& (nch
== '-' || nch
== '+')) {
1950 negative
= (nch
=='-');
1951 nch
= MSVCRT_fgetc(file
);
1952 if (width
>0) width
--;
1954 /* look for leading indication of base */
1955 if (width
!=0 && nch
== '0') {
1956 nch
= MSVCRT_fgetc(file
);
1957 if (width
>0) width
--;
1959 if (width
!=0 && (nch
=='x' || nch
=='X')) {
1963 nch
= MSVCRT_fgetc(file
);
1964 if (width
>0) width
--;
1972 /* throw away leading zeros */
1973 while (width
!=0 && nch
=='0') {
1974 nch
= MSVCRT_fgetc(file
);
1975 if (width
>0) width
--;
1978 /* get first digit. Keep working copy negative, as the
1979 * range of negative numbers in two's complement notation
1980 * is one larger than the range of positive numbers. */
1981 if (width
!=0 && char2digit(nch
, base
)!=-1) {
1982 cur
= -char2digit(nch
, base
);
1983 nch
= MSVCRT_fgetc(file
);
1984 if (width
>0) width
--;
1987 /* read until no more digits */
1988 while (width
!=0 && (nch
!=MSVCRT_EOF
) && isdigit(nch
)) {
1989 cur
= cur
*base
+ char2digit(nch
, base
);
1990 nch
= MSVCRT_fgetc(file
);
1991 if (width
>0) width
--;
1994 /* negate parsed number if non-negative */
1995 if (!negative
) cur
=-cur
;
1997 if (!seendigit
) break; /* not a valid number */
1999 if (!suppress
) *val
= cur
;
2006 case 'G': { /* read a float */
2007 float*val
= suppress
? NULL
: va_arg(ap
, float*);
2010 /* skip initial whitespace */
2011 while ((nch
!=MSVCRT_EOF
) && isspace(nch
))
2012 nch
= MSVCRT_fgetc(file
);
2014 if (nch
== '-' || nch
== '+') {
2015 negative
= (nch
=='-');
2016 if (width
>0) width
--;
2017 if (width
==0) break;
2018 nch
= MSVCRT_fgetc(file
);
2020 /* get first digit. */
2021 if (!isdigit(nch
)) break;
2022 cur
= (nch
- '0') * (negative
? -1 : 1);
2023 nch
= MSVCRT_fgetc(file
);
2024 if (width
>0) width
--;
2025 /* read until no more digits */
2026 while (width
!=0 && (nch
!=MSVCRT_EOF
) && isdigit(nch
)) {
2027 cur
= cur
*10 + (nch
- '0');
2028 nch
= MSVCRT_fgetc(file
);
2029 if (width
>0) width
--;
2031 /* handle decimals */
2032 if (width
!=0 && nch
== '.') {
2034 nch
= MSVCRT_fgetc(file
);
2035 if (width
>0) width
--;
2036 while (width
!=0 && (nch
!=MSVCRT_EOF
) && isdigit(nch
)) {
2038 cur
+= dec
* (nch
- '0');
2039 nch
= MSVCRT_fgetc(file
);
2040 if (width
>0) width
--;
2043 /* handle exponent */
2044 if (width
!=0 && (nch
== 'e' || nch
== 'E')) {
2045 int exponent
= 0, negexp
= 0;
2047 nch
= MSVCRT_fgetc(file
);
2048 if (width
>0) width
--;
2049 /* possible sign on the exponent */
2050 if (width
!=0 && (nch
=='+' || nch
=='-')) {
2051 negexp
= (nch
=='-');
2052 nch
= MSVCRT_fgetc(file
);
2053 if (width
>0) width
--;
2055 /* exponent digits */
2056 while (width
!=0 && (nch
!=MSVCRT_EOF
) && isdigit(nch
)) {
2058 exponent
+= (nch
- '0');
2059 nch
= MSVCRT_fgetc(file
);
2060 if (width
>0) width
--;
2062 /* update 'cur' with this exponent. */
2063 expcnt
= negexp
? .1 : 10;
2064 while (exponent
!=0) {
2068 expcnt
=expcnt
*expcnt
;
2072 if (!suppress
) *val
= cur
;
2075 case 's': { /* read a word */
2076 char*str
= suppress
? NULL
: va_arg(ap
, char*);
2078 /* skip initial whitespace */
2079 while ((nch
!=MSVCRT_EOF
) && isspace(nch
))
2080 nch
= MSVCRT_fgetc(file
);
2081 /* read until whitespace */
2082 while (width
!=0 && (nch
!=MSVCRT_EOF
) && !isspace(nch
)) {
2083 if (!suppress
) *sptr
++ = nch
;
2085 nch
= MSVCRT_fgetc(file
);
2086 if (width
>0) width
--;
2089 if (!suppress
) *sptr
= 0;
2090 TRACE("read word: %s\n", str
);
2093 default: FIXME("unhandled: %%%c\n", *format
);
2094 /* From spec: "if a percent sign is followed by a character
2095 * that has no meaning as a format-control character, that
2096 * character and the following characters are treated as
2097 * an ordinary sequence of characters, that is, a sequence
2098 * of characters that must match the input. For example,
2099 * to specify that a percent-sign character is to be input,
2101 * LEAVING AS-IS because we catch bugs better that way. */
2103 if (st
&& !suppress
) rd
++;
2106 /* a non-white-space character causes scanf to read, but not store,
2107 * a matching non-white-space character. */
2109 /* check for character match */
2111 nch
= MSVCRT_fgetc(file
);
2116 if (nch
!=MSVCRT_EOF
) {
2117 FIXME("need ungetch\n");
2120 TRACE("returning %d\n", rd
);
2124 /*********************************************************************
2127 int MSVCRT_fseek(MSVCRT_FILE
* file
, long offset
, int whence
)
2129 /* Flush output if needed */
2130 if(file
->_flag
& MSVCRT__IOWRT
)
2131 msvcrt_flush_buffer(file
);
2133 if(whence
== SEEK_CUR
&& file
->_flag
& MSVCRT__IOREAD
) {
2134 offset
-= file
->_cnt
;
2136 /* Discard buffered input */
2138 file
->_ptr
= file
->_base
;
2139 /* Reset direction of i/o */
2140 if(file
->_flag
& MSVCRT__IORW
) {
2141 file
->_flag
&= ~(MSVCRT__IOREAD
|MSVCRT__IOWRT
);
2143 return (_lseek(file
->_file
,offset
,whence
) == -1)?-1:0;
2146 /*********************************************************************
2149 LONG
MSVCRT_ftell(MSVCRT_FILE
* file
)
2154 if( file
->_flag
& MSVCRT__IOWRT
) {
2155 off
= file
->_ptr
- file
->_base
;
2160 pos
= _tell(file
->_file
);
2161 if(pos
== -1) return pos
;
2165 /*********************************************************************
2168 MSVCRT_size_t
MSVCRT_fwrite(const void *ptr
, MSVCRT_size_t size
, MSVCRT_size_t nmemb
, MSVCRT_FILE
* file
)
2170 MSVCRT_size_t wrcnt
=size
* nmemb
;
2175 int pcnt
=(file
->_cnt
>wrcnt
)? wrcnt
: file
->_cnt
;
2176 memcpy(file
->_ptr
, ptr
, pcnt
);
2181 ptr
= (char*)ptr
+ pcnt
;
2182 } else if(!(file
->_flag
& MSVCRT__IOWRT
)) {
2183 if(file
->_flag
& MSVCRT__IORW
) {
2184 file
->_flag
|= MSVCRT__IOWRT
;
2190 int res
=msvcrt_flush_buffer(file
);
2192 int pwritten
= _write(file
->_file
, ptr
, wrcnt
);
2193 if (pwritten
<= 0) pwritten
=0;
2194 written
+= pwritten
;
2197 return written
/ size
;
2200 /*********************************************************************
2203 int MSVCRT_fputs(const char *s
, MSVCRT_FILE
* file
)
2205 size_t len
= strlen(s
);
2206 return MSVCRT_fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : MSVCRT_EOF
;
2209 /*********************************************************************
2212 int MSVCRT_fputws(const WCHAR
*s
, MSVCRT_FILE
* file
)
2214 size_t len
= strlenW(s
);
2215 return MSVCRT_fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : MSVCRT_EOF
;
2218 /*********************************************************************
2219 * getchar (MSVCRT.@)
2221 int MSVCRT_getchar(void)
2223 return MSVCRT_fgetc(MSVCRT_stdin
);
2226 /*********************************************************************
2229 int MSVCRT_getc(MSVCRT_FILE
* file
)
2231 return MSVCRT_fgetc(file
);
2234 /*********************************************************************
2237 char *MSVCRT_gets(char *buf
)
2240 char * buf_start
= buf
;
2242 for(cc
= MSVCRT_fgetc(MSVCRT_stdin
); cc
!= MSVCRT_EOF
&& cc
!= '\n';
2243 cc
= MSVCRT_fgetc(MSVCRT_stdin
))
2244 if(cc
!= '\r') *buf
++ = (char)cc
;
2248 TRACE("got '%s'\n", buf_start
);
2252 /*********************************************************************
2255 WCHAR
* MSVCRT__getws(WCHAR
* buf
)
2260 for (cc
= MSVCRT_fgetwc(MSVCRT_stdin
); cc
!= MSVCRT_WEOF
&& cc
!= '\n';
2261 cc
= MSVCRT_fgetwc(MSVCRT_stdin
))
2268 TRACE("got '%s'\n", debugstr_w(ws
));
2272 /*********************************************************************
2275 int MSVCRT_putc(int c
, MSVCRT_FILE
* file
)
2277 return MSVCRT_fputc(c
, file
);
2280 /*********************************************************************
2281 * putchar (MSVCRT.@)
2283 int MSVCRT_putchar(int c
)
2285 return MSVCRT_fputc(c
, MSVCRT_stdout
);
2288 /*********************************************************************
2291 int MSVCRT_puts(const char *s
)
2293 size_t len
= strlen(s
);
2294 if (MSVCRT_fwrite(s
,sizeof(*s
),len
,MSVCRT_stdout
) != len
) return MSVCRT_EOF
;
2295 return MSVCRT_fwrite("\n",1,1,MSVCRT_stdout
) == 1 ? 0 : MSVCRT_EOF
;
2298 /*********************************************************************
2301 int _putws(const WCHAR
*s
)
2303 static const WCHAR nl
= '\n';
2304 size_t len
= strlenW(s
);
2305 if (MSVCRT_fwrite(s
,sizeof(*s
),len
,MSVCRT_stdout
) != len
) return MSVCRT_EOF
;
2306 return MSVCRT_fwrite(&nl
,sizeof(nl
),1,MSVCRT_stdout
) == 1 ? 0 : MSVCRT_EOF
;
2309 /*********************************************************************
2312 int MSVCRT_remove(const char *path
)
2314 TRACE("(%s)\n",path
);
2315 if (DeleteFileA(path
))
2317 TRACE(":failed (%ld)\n",GetLastError());
2318 MSVCRT__set_errno(GetLastError());
2322 /*********************************************************************
2323 * _wremove (MSVCRT.@)
2325 int _wremove(const WCHAR
*path
)
2327 TRACE("(%s)\n",debugstr_w(path
));
2328 if (DeleteFileW(path
))
2330 TRACE(":failed (%ld)\n",GetLastError());
2331 MSVCRT__set_errno(GetLastError());
2335 /*********************************************************************
2338 int MSVCRT_scanf(const char *format
, ...)
2343 va_start(valist
, format
);
2344 res
= MSVCRT_fscanf(MSVCRT_stdin
, format
, valist
);
2349 /*********************************************************************
2352 int MSVCRT_rename(const char *oldpath
,const char *newpath
)
2354 TRACE(":from %s to %s\n",oldpath
,newpath
);
2355 if (MoveFileExA(oldpath
, newpath
, MOVEFILE_REPLACE_EXISTING
))
2357 TRACE(":failed (%ld)\n",GetLastError());
2358 MSVCRT__set_errno(GetLastError());
2362 /*********************************************************************
2363 * _wrename (MSVCRT.@)
2365 int _wrename(const WCHAR
*oldpath
,const WCHAR
*newpath
)
2367 TRACE(":from %s to %s\n",debugstr_w(oldpath
),debugstr_w(newpath
));
2368 if (MoveFileExW(oldpath
, newpath
, MOVEFILE_REPLACE_EXISTING
))
2370 TRACE(":failed (%ld)\n",GetLastError());
2371 MSVCRT__set_errno(GetLastError());
2375 /*********************************************************************
2376 * setvbuf (MSVCRT.@)
2378 int MSVCRT_setvbuf(MSVCRT_FILE
* file
, char *buf
, int mode
, MSVCRT_size_t size
)
2380 /* TODO: Check if file busy */
2382 MSVCRT_free(file
->_base
);
2386 if(mode
== MSVCRT__IOFBF
) {
2387 file
->_flag
&= ~MSVCRT__IONBF
;
2388 file
->_base
= file
->_ptr
= buf
;
2390 file
->_bufsiz
= size
;
2393 file
->_flag
|= MSVCRT__IONBF
;
2398 /*********************************************************************
2401 void MSVCRT_setbuf(MSVCRT_FILE
* file
, char *buf
)
2403 MSVCRT_setvbuf(file
, buf
, buf
? MSVCRT__IOFBF
: MSVCRT__IONBF
, MSVCRT_BUFSIZ
);
2406 /*********************************************************************
2409 char *MSVCRT_tmpnam(char *s
)
2411 char tmpbuf
[MAX_PATH
];
2412 char* prefix
= "TMP";
2413 if (!GetTempPathA(MAX_PATH
,tmpbuf
) ||
2414 !GetTempFileNameA(tmpbuf
,prefix
,0,MSVCRT_tmpname
))
2416 TRACE(":failed-last error (%ld)\n",GetLastError());
2419 TRACE(":got tmpnam %s\n",MSVCRT_tmpname
);
2424 /*********************************************************************
2425 * tmpfile (MSVCRT.@)
2427 MSVCRT_FILE
* MSVCRT_tmpfile(void)
2429 char *filename
= MSVCRT_tmpnam(NULL
);
2431 fd
= _open(filename
, _O_CREAT
| _O_BINARY
| _O_RDWR
| _O_TEMPORARY
);
2433 return msvcrt_alloc_fp(fd
);
2437 /*********************************************************************
2438 * vfprintf (MSVCRT.@)
2440 int MSVCRT_vfprintf(MSVCRT_FILE
* file
, const char *format
, va_list valist
)
2442 char buf
[2048], *mem
= buf
;
2443 int written
, resize
= sizeof(buf
), retval
;
2444 /* There are two conventions for vsnprintf failing:
2445 * Return -1 if we truncated, or
2446 * Return the number of bytes that would have been written
2447 * The code below handles both cases
2449 while ((written
= vsnprintf(mem
, resize
, format
, valist
)) == -1 ||
2452 resize
= (written
== -1 ? resize
* 2 : written
+ 1);
2455 if (!(mem
= (char *)MSVCRT_malloc(resize
)))
2458 retval
= MSVCRT_fwrite(mem
, sizeof(*mem
), written
, file
);
2464 /*********************************************************************
2465 * vfwprintf (MSVCRT.@)
2467 * Is final char included in written (then resize is too big) or not
2468 * (then we must test for equality too)?
2470 int MSVCRT_vfwprintf(MSVCRT_FILE
* file
, const WCHAR
*format
, va_list valist
)
2472 WCHAR buf
[2048], *mem
= buf
;
2473 int written
, resize
= sizeof(buf
) / sizeof(WCHAR
), retval
;
2474 /* See vfprintf comments */
2475 while ((written
= _vsnwprintf(mem
, resize
, format
, valist
)) == -1 ||
2478 resize
= (written
== -1 ? resize
* 2 : written
+ sizeof(WCHAR
));
2481 if (!(mem
= (WCHAR
*)MSVCRT_malloc(resize
*sizeof(*mem
))))
2484 retval
= MSVCRT_fwrite(mem
, sizeof(*mem
), written
, file
);
2490 /*********************************************************************
2491 * vprintf (MSVCRT.@)
2493 int MSVCRT_vprintf(const char *format
, va_list valist
)
2495 return MSVCRT_vfprintf(MSVCRT_stdout
,format
,valist
);
2498 /*********************************************************************
2499 * vwprintf (MSVCRT.@)
2501 int MSVCRT_vwprintf(const WCHAR
*format
, va_list valist
)
2503 return MSVCRT_vfwprintf(MSVCRT_stdout
,format
,valist
);
2506 /*********************************************************************
2507 * fprintf (MSVCRT.@)
2509 int MSVCRT_fprintf(MSVCRT_FILE
* file
, const char *format
, ...)
2513 va_start(valist
, format
);
2514 res
= MSVCRT_vfprintf(file
, format
, valist
);
2519 /*********************************************************************
2520 * fwprintf (MSVCRT.@)
2522 int MSVCRT_fwprintf(MSVCRT_FILE
* file
, const WCHAR
*format
, ...)
2526 va_start(valist
, format
);
2527 res
= MSVCRT_vfwprintf(file
, format
, valist
);
2532 /*********************************************************************
2535 int MSVCRT_printf(const char *format
, ...)
2539 va_start(valist
, format
);
2540 res
= MSVCRT_vfprintf(MSVCRT_stdout
, format
, valist
);
2545 /*********************************************************************
2548 int MSVCRT_ungetc(int c
, MSVCRT_FILE
* file
)
2550 if(file
->_bufsiz
== 0 && !(file
->_flag
& MSVCRT__IONBF
)) {
2551 msvcrt_alloc_buffer(file
);
2554 if(file
->_ptr
>file
->_base
) {
2563 /*********************************************************************
2564 * ungetwc (MSVCRT.@)
2566 MSVCRT_wint_t
MSVCRT_ungetwc(MSVCRT_wint_t wc
, MSVCRT_FILE
* file
)
2569 char * pp
= (char *)&mwc
;
2571 for(i
=sizeof(WCHAR
)-1;i
>=0;i
--) {
2572 if(pp
[i
] != MSVCRT_ungetc(pp
[i
],file
))
2578 /*********************************************************************
2579 * wprintf (MSVCRT.@)
2581 int MSVCRT_wprintf(const WCHAR
*format
, ...)
2585 va_start(valist
, format
);
2586 res
= MSVCRT_vwprintf(format
, valist
);