2 * PROJECT: ReactOS CRT library
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: lib/sdk/crt/stdio/file.c
5 * PURPOSE: File CRT functions
6 * PROGRAMMERS: Wine team
7 * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org)
11 * msvcrt.dll file functions
13 * Copyright 1996,1998 Marcus Meissner
14 * Copyright 1996 Jukka Iivonen
15 * Copyright 1997,2000 Uwe Bonnes
16 * Copyright 2000 Jon Griffiths
17 * Copyright 2004 Eric Pouech
18 * Copyright 2004 Juan Lang
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED
39 #include "wine/unicode.h"
41 #include <sys/utime.h>
44 int *__p__fmode(void);
45 int *__p___mb_cur_max(void);
72 /* _access() bit flags FIXME: incomplete */
73 /* defined in crt/io.h */
75 /* values for wxflag in file descriptor */
78 #define WX_READEOF 0x04 /* like ATEOF, but for underlying file rather than buffer */
79 #define WX_DONTINHERIT 0x10
80 #define WX_APPEND 0x20
83 /* FIXME: this should be allocated dynamically */
84 #define MAX_FILES 2048
86 /* ReactOS: Use _FDINFO instead! */
90 DWORD unkn
[7]; /* critical section and init flag */
93 ioinfo fdesc
[MAX_FILES
];
95 FILE _iob
[3] = { { 0 } };
97 static int fdstart
= 3; /* first unallocated fd */
98 static int fdend
= 3; /* highest allocated fd */
100 static FILE* fstreams
[2048];
101 static int stream_idx
;
103 /* INTERNAL: process umask */
104 static int MSVCRT_umask
= 0;
106 /* INTERNAL: Static buffer for temp file name */
107 static char tmpname
[MAX_PATH
];
109 /* This critical section protects the tables fdesc and fstreams,
110 * and their related indexes, fdstart, fdend,
111 * and stream_idx, from race conditions.
112 * It doesn't protect against race conditions manipulating the underlying files
113 * or flags; doing so would probably be better accomplished with per-file
114 * protection, rather than locking the whole table for every change.
116 static CRITICAL_SECTION FILE_cs
;
117 #define LOCK_FILES() do { EnterCriticalSection(&FILE_cs); } while (0)
118 #define UNLOCK_FILES() do { LeaveCriticalSection(&FILE_cs); } while (0)
120 static inline BOOL
is_valid_fd(int fd
)
122 return fd
>= 0 && fd
< fdend
&& (fdesc
[fd
].wxflag
& WX_OPEN
);
125 /* INTERNAL: Get the HANDLE for a fd
126 * This doesn't lock the table, because a failure will result in
127 * INVALID_HANDLE_VALUE being returned, which should be handled correctly. If
128 * it returns a valid handle which is about to be closed, a subsequent call
129 * will fail, most likely in a sane way.
133 if (!is_valid_fd(fd
))
135 WARN(":fd (%d) - no handle!\n",fd
);
138 return INVALID_HANDLE_VALUE
;
140 //if (fdesc[fd].handle == INVALID_HANDLE_VALUE) FIXME("wtf\n");
141 return fdesc
[fd
].handle
;
144 /* INTERNAL: free a file entry fd */
145 static void free_fd(int fd
)
148 fdesc
[fd
].handle
= INVALID_HANDLE_VALUE
;
149 fdesc
[fd
].wxflag
= 0;
150 TRACE(":fd (%d) freed\n",fd
);
151 if (fd
< 3) /* don't use 0,1,2 for user files */
155 case 0: SetStdHandle(STD_INPUT_HANDLE
, NULL
); break;
156 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, NULL
); break;
157 case 2: SetStdHandle(STD_ERROR_HANDLE
, NULL
); break;
170 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE, starting from fd */
171 /* caller must hold the files lock */
172 static int alloc_fd_from(HANDLE hand
, int flag
, int fd
)
176 WARN(":files exhausted!\n");
179 fdesc
[fd
].handle
= hand
;
180 fdesc
[fd
].wxflag
= WX_OPEN
| (flag
& (WX_DONTINHERIT
| WX_APPEND
| WX_TEXT
));
182 /* locate next free slot */
183 if (fd
== fdstart
&& fd
== fdend
)
186 while (fdstart
< fdend
&&
187 fdesc
[fdstart
].handle
!= INVALID_HANDLE_VALUE
)
189 /* update last fd in use */
192 TRACE("fdstart is %d, fdend is %d\n", fdstart
, fdend
);
196 case 0: SetStdHandle(STD_INPUT_HANDLE
, hand
); break;
197 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, hand
); break;
198 case 2: SetStdHandle(STD_ERROR_HANDLE
, hand
); break;
204 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE */
205 /*static */int alloc_fd(HANDLE hand
, int flag
)
210 TRACE(":handle (%p) allocating fd (%d)\n",hand
,fdstart
);
211 ret
= alloc_fd_from(hand
, flag
, fdstart
);
216 /* INTERNAL: Allocate a FILE* for an fd slot */
217 /* caller must hold the files lock */
218 static FILE* alloc_fp(void)
222 for (i
= 3; i
< sizeof(fstreams
) / sizeof(fstreams
[0]); i
++)
224 if (!fstreams
[i
] || fstreams
[i
]->_flag
== 0)
228 if (!(fstreams
[i
] = calloc(sizeof(FILE),1)))
230 if (i
== stream_idx
) stream_idx
++;
238 /* INTERNAL: initialize a FILE* from an open fd */
239 static int init_fp(FILE* file
, int fd
, unsigned stream_flags
)
241 TRACE(":fd (%d) allocating FILE*\n",fd
);
242 if (!is_valid_fd(fd
))
244 WARN(":invalid fd %d\n",fd
);
249 memset(file
, 0, sizeof(*file
));
251 file
->_flag
= stream_flags
;
253 TRACE(":got FILE* (%p)\n",file
);
257 /* INTERNAL: Create an inheritance data block (for spawned process)
258 * The inheritance block is made of:
259 * 00 int nb of file descriptor (NBFD)
260 * 04 char file flags (wxflag): repeated for each fd
261 * 4+NBFD HANDLE file handle: repeated for each fd
263 unsigned create_io_inherit_block(WORD
*size
, BYTE
**block
)
269 *size
= sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE
)) * fdend
;
270 *block
= calloc(*size
, 1);
276 wxflag_ptr
= (char*)*block
+ sizeof(unsigned);
277 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ fdend
* sizeof(char));
279 *(unsigned*)*block
= fdend
;
280 for (fd
= 0; fd
< fdend
; fd
++)
282 /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
283 if ((fdesc
[fd
].wxflag
& (WX_OPEN
| WX_DONTINHERIT
)) == WX_OPEN
)
285 *wxflag_ptr
= fdesc
[fd
].wxflag
;
286 *handle_ptr
= fdesc
[fd
].handle
;
291 *handle_ptr
= INVALID_HANDLE_VALUE
;
293 wxflag_ptr
++; handle_ptr
++;
298 /* INTERNAL: Set up all file descriptors,
299 * as well as default streams (stdin, stderr and stdout)
301 void msvcrt_init_io(void)
306 InitializeCriticalSection(&FILE_cs
);
307 FILE_cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": FILE_cs");
308 GetStartupInfoA(&si
);
309 if (si
.cbReserved2
!= 0 && si
.lpReserved2
!= NULL
)
314 fdend
= *(unsigned*)si
.lpReserved2
;
316 wxflag_ptr
= (char*)(si
.lpReserved2
+ sizeof(unsigned));
317 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ fdend
* sizeof(char));
319 fdend
= min(fdend
, sizeof(fdesc
) / sizeof(fdesc
[0]));
320 for (i
= 0; i
< fdend
; i
++)
322 if ((*wxflag_ptr
& WX_OPEN
) && *handle_ptr
!= INVALID_HANDLE_VALUE
)
324 fdesc
[i
].wxflag
= *wxflag_ptr
;
325 fdesc
[i
].handle
= *handle_ptr
;
330 fdesc
[i
].handle
= INVALID_HANDLE_VALUE
;
332 wxflag_ptr
++; handle_ptr
++;
334 for (fdstart
= 3; fdstart
< fdend
; fdstart
++)
335 if (fdesc
[fdstart
].handle
== INVALID_HANDLE_VALUE
) break;
338 if (!(fdesc
[0].wxflag
& WX_OPEN
) || fdesc
[0].handle
== INVALID_HANDLE_VALUE
)
341 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE
),
342 GetCurrentProcess(), &fdesc
[0].handle
, 0, TRUE
,
343 DUPLICATE_SAME_ACCESS
);
345 fdesc
[0].handle
= GetStdHandle(STD_INPUT_HANDLE
);
346 if (fdesc
[0].handle
== NULL
)
347 fdesc
[0].handle
= INVALID_HANDLE_VALUE
;
349 fdesc
[0].wxflag
= WX_OPEN
| WX_TEXT
;
351 if (!(fdesc
[1].wxflag
& WX_OPEN
) || fdesc
[1].handle
== INVALID_HANDLE_VALUE
)
354 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE
),
355 GetCurrentProcess(), &fdesc
[1].handle
, 0, TRUE
,
356 DUPLICATE_SAME_ACCESS
);
358 fdesc
[1].handle
= GetStdHandle(STD_OUTPUT_HANDLE
);
359 if (fdesc
[1].handle
== NULL
)
360 fdesc
[1].handle
= INVALID_HANDLE_VALUE
;
362 fdesc
[1].wxflag
= WX_OPEN
| WX_TEXT
;
364 if (!(fdesc
[2].wxflag
& WX_OPEN
) || fdesc
[2].handle
== INVALID_HANDLE_VALUE
)
367 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE
),
368 GetCurrentProcess(), &fdesc
[2].handle
, 0, TRUE
,
369 DUPLICATE_SAME_ACCESS
);
371 fdesc
[2].handle
= GetStdHandle(STD_ERROR_HANDLE
);
372 if (fdesc
[2].handle
== NULL
)
373 fdesc
[2].handle
= INVALID_HANDLE_VALUE
;
375 fdesc
[2].wxflag
= WX_OPEN
| WX_TEXT
;
378 TRACE(":handles (%p)(%p)(%p)\n",fdesc
[0].handle
,
379 fdesc
[1].handle
,fdesc
[2].handle
);
381 memset(_iob
,0,3*sizeof(FILE));
382 for (i
= 0; i
< 3; i
++)
384 /* FILE structs for stdin/out/err are static and never deleted */
385 fstreams
[i
] = &_iob
[i
];
387 _iob
[i
]._tmpfname
= NULL
;
388 _iob
[i
]._flag
= (i
== 0) ? _IOREAD
: _IOWRT
;
393 /* INTERNAL: Flush stdio file buffer */
394 static int flush_buffer(FILE* file
)
397 int cnt
=file
->_ptr
-file
->_base
;
398 if(cnt
>0 && _write(file
->_file
, file
->_base
, cnt
) != cnt
) {
399 file
->_flag
|= _IOERR
;
402 file
->_ptr
=file
->_base
;
403 file
->_cnt
=file
->_bufsiz
;
408 /* INTERNAL: Allocate stdio file buffer */
409 static void alloc_buffer(FILE* file
)
411 file
->_base
= calloc(BUFSIZ
,1);
413 file
->_bufsiz
= BUFSIZ
;
414 file
->_flag
|= _IOMYBUF
;
416 file
->_base
= (char*)(&file
->_charbuf
);
418 file
->_bufsiz
= sizeof(file
->_charbuf
);
420 file
->_ptr
= file
->_base
;
424 /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */
425 static void int_to_base32(int num
, char *str
)
440 *p
= (num
& 31) + '0';
442 *p
+= ('a' - '0' - 10);
447 /*********************************************************************
450 FILE * CDECL
__p__iob(void)
455 /*********************************************************************
458 int CDECL
_access(const char *filename
, int mode
)
460 DWORD attr
= GetFileAttributesA(filename
);
462 TRACE("(%s,%d) %d\n",filename
,mode
,attr
);
464 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
466 _dosmaperr(GetLastError());
469 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
471 _dosmaperr(ERROR_ACCESS_DENIED
);
477 /*********************************************************************
478 * _waccess (MSVCRT.@)
480 int CDECL
_waccess(const wchar_t *filename
, int mode
)
482 DWORD attr
= GetFileAttributesW(filename
);
484 TRACE("(%s,%d) %d\n",debugstr_w(filename
),mode
,attr
);
486 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
488 _dosmaperr(GetLastError());
491 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
493 _dosmaperr(ERROR_ACCESS_DENIED
);
499 /*********************************************************************
502 int CDECL
_chmod(const char *path
, int flags
)
504 DWORD oldFlags
= GetFileAttributesA(path
);
506 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
508 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
509 oldFlags
| FILE_ATTRIBUTE_READONLY
;
511 if (newFlags
== oldFlags
|| SetFileAttributesA(path
, newFlags
))
514 _dosmaperr(GetLastError());
518 /*********************************************************************
521 int CDECL
_wchmod(const wchar_t *path
, int flags
)
523 DWORD oldFlags
= GetFileAttributesW(path
);
525 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
527 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
528 oldFlags
| FILE_ATTRIBUTE_READONLY
;
530 if (newFlags
== oldFlags
|| SetFileAttributesW(path
, newFlags
))
533 _dosmaperr(GetLastError());
537 /*********************************************************************
540 int CDECL
_unlink(const char *path
)
542 TRACE("%s\n",debugstr_a(path
));
543 if(DeleteFileA(path
))
545 TRACE("failed (%d)\n",GetLastError());
546 _dosmaperr(GetLastError());
550 /*********************************************************************
551 * _wunlink (MSVCRT.@)
553 int CDECL
_wunlink(const wchar_t *path
)
555 TRACE("(%s)\n",debugstr_w(path
));
556 if(DeleteFileW(path
))
558 TRACE("failed (%d)\n",GetLastError());
559 _dosmaperr(GetLastError());
563 /* _flushall calls fflush which calls _flushall */
564 int CDECL
fflush(FILE* file
);
566 /*********************************************************************
567 * _flushall (MSVCRT.@)
569 int CDECL
_flushall(void)
571 int i
, num_flushed
= 0;
574 for (i
= 3; i
< stream_idx
; i
++)
575 if (fstreams
[i
] && fstreams
[i
]->_flag
)
578 /* FIXME: flush, do not commit */
579 if (_commit(i
) == -1)
581 fstreams
[i
]->_flag
|= _IOERR
;
583 if(fstreams
[i
]->_flag
& _IOWRT
) {
590 TRACE(":flushed (%d) handles\n",num_flushed
);
594 /*********************************************************************
597 int CDECL
fflush(FILE* file
)
601 } else if(file
->_flag
& _IOWRT
) {
602 int res
=flush_buffer(file
);
608 /*********************************************************************
611 int CDECL
_close(int fd
)
618 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
619 if (hand
== INVALID_HANDLE_VALUE
)
621 else if (!CloseHandle(hand
))
623 WARN(":failed-last error (%d)\n",GetLastError());
624 _dosmaperr(GetLastError());
637 /*********************************************************************
640 int CDECL
_commit(int fd
)
642 HANDLE hand
= fdtoh(fd
);
644 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
645 if (hand
== INVALID_HANDLE_VALUE
)
648 if (!FlushFileBuffers(hand
))
650 if (GetLastError() == ERROR_INVALID_HANDLE
)
652 /* FlushFileBuffers fails for console handles
653 * so we ignore this error.
657 TRACE(":failed-last error (%d)\n",GetLastError());
658 _dosmaperr(GetLastError());
665 /*********************************************************************
668 * MSDN isn't clear on this point, but the remarks for _pipe
669 * indicate file descriptors duplicated with _dup and _dup2 are always
672 int CDECL
_dup2(int od
, int nd
)
676 TRACE("(od=%d, nd=%d)\n", od
, nd
);
678 if (nd
< MAX_FILES
&& is_valid_fd(od
))
682 if (DuplicateHandle(GetCurrentProcess(), fdesc
[od
].handle
,
683 GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
))
685 int wxflag
= fdesc
[od
].wxflag
& ~_O_NOINHERIT
;
689 ret
= alloc_fd_from(handle
, wxflag
, nd
);
697 /* _dup2 returns 0, not nd, on success */
704 _dosmaperr(GetLastError());
716 /*********************************************************************
719 int CDECL
_dup(int od
)
725 if (_dup2(od
, fd
) == 0)
733 /*********************************************************************
736 int CDECL
_eof(int fd
)
739 LONG hcurpos
,hendpos
;
740 HANDLE hand
= fdtoh(fd
);
742 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
744 if (hand
== INVALID_HANDLE_VALUE
)
747 if (fdesc
[fd
].wxflag
& WX_ATEOF
) return TRUE
;
749 /* Otherwise we do it the hard way */
750 hcurpos
= hendpos
= 0;
751 curpos
= SetFilePointer(hand
, 0, &hcurpos
, FILE_CURRENT
);
752 endpos
= SetFilePointer(hand
, 0, &hendpos
, FILE_END
);
754 if (curpos
== endpos
&& hcurpos
== hendpos
)
756 /* FIXME: shouldn't WX_ATEOF be set here? */
760 SetFilePointer(hand
, curpos
, &hcurpos
, FILE_BEGIN
);
764 /*********************************************************************
765 * _fcloseall (MSVCRT.@)
767 int CDECL
_fcloseall(void)
769 int num_closed
= 0, i
;
772 for (i
= 3; i
< stream_idx
; i
++)
773 if (fstreams
[i
] && fstreams
[i
]->_flag
&&
774 !fclose(fstreams
[i
]))
778 TRACE(":closed (%d) handles\n",num_closed
);
782 /* free everything on process exit */
783 void msvcrt_free_io(void)
786 /* The Win32 _fcloseall() function explicitly doesn't close stdin,
787 * stdout, and stderr (unlike GNU), so we need to fclose() them here
788 * or they won't get flushed.
793 FILE_cs
.DebugInfo
->Spare
[0] = 0;
794 DeleteCriticalSection(&FILE_cs
);
797 /*********************************************************************
798 * _lseeki64 (MSVCRT.@)
800 __int64 CDECL
_lseeki64(int fd
, __int64 offset
, int whence
)
802 HANDLE hand
= fdtoh(fd
);
803 LARGE_INTEGER ofs
, ret
;
805 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
806 if (hand
== INVALID_HANDLE_VALUE
)
809 if (whence
< 0 || whence
> 2)
815 TRACE(":fd (%d) to %s pos %s\n",
816 fd
,wine_dbgstr_longlong(offset
),
817 (whence
==SEEK_SET
)?"SEEK_SET":
818 (whence
==SEEK_CUR
)?"SEEK_CUR":
819 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
821 ofs
.QuadPart
= offset
;
822 if (SetFilePointerEx(hand
, ofs
, &ret
, whence
))
824 fdesc
[fd
].wxflag
&= ~(WX_ATEOF
|WX_READEOF
);
825 /* FIXME: What if we seek _to_ EOF - is EOF set? */
829 TRACE(":error-last error (%d)\n",GetLastError());
830 _dosmaperr(GetLastError());
834 /*********************************************************************
837 LONG CDECL
_lseek(int fd
, LONG offset
, int whence
)
839 return _lseeki64(fd
, offset
, whence
);
842 /*********************************************************************
843 * _locking (MSVCRT.@)
845 * This is untested; the underlying LockFile doesn't work yet.
847 int CDECL
_locking(int fd
, int mode
, LONG nbytes
)
851 HANDLE hand
= fdtoh(fd
);
853 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
854 if (hand
== INVALID_HANDLE_VALUE
)
857 if (mode
< 0 || mode
> 4)
863 TRACE(":fd (%d) by 0x%08x mode %s\n",
864 fd
,nbytes
,(mode
==_LK_UNLCK
)?"_LK_UNLCK":
865 (mode
==_LK_LOCK
)?"_LK_LOCK":
866 (mode
==_LK_NBLCK
)?"_LK_NBLCK":
867 (mode
==_LK_RLCK
)?"_LK_RLCK":
868 (mode
==_LK_NBRLCK
)?"_LK_NBRLCK":
871 if ((cur_locn
= SetFilePointer(hand
, 0L, NULL
, SEEK_CUR
)) == INVALID_SET_FILE_POINTER
)
873 FIXME ("Seek failed\n");
874 *_errno() = EINVAL
; /* FIXME */
877 if (mode
== _LK_LOCK
|| mode
== _LK_RLCK
)
880 ret
= 1; /* just to satisfy gcc */
883 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
888 else if (mode
== _LK_UNLCK
)
889 ret
= UnlockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
891 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
892 /* FIXME - what about error settings? */
896 /*********************************************************************
899 int CDECL
fseek(FILE* file
, long offset
, int whence
)
901 /* Flush output if needed */
902 if(file
->_flag
& _IOWRT
)
905 if(whence
== SEEK_CUR
&& file
->_flag
& _IOREAD
) {
906 offset
-= file
->_cnt
;
908 /* Discard buffered input */
910 file
->_ptr
= file
->_base
;
911 /* Reset direction of i/o */
912 if(file
->_flag
& _IORW
) {
913 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
915 /* Clear end of file flag */
916 file
->_flag
&= ~_IOEOF
;
917 return (_lseek(file
->_file
,offset
,whence
) == -1)?-1:0;
920 /*********************************************************************
923 int CDECL
_chsize(int fd
, long size
)
929 TRACE("(fd=%d, size=%ld)\n", fd
, size
);
934 if (handle
!= INVALID_HANDLE_VALUE
)
936 /* save the current file pointer */
937 cur
= _lseek(fd
, 0, SEEK_CUR
);
940 pos
= _lseek(fd
, size
, SEEK_SET
);
943 ret
= SetEndOfFile(handle
);
944 if (!ret
) _dosmaperr(GetLastError());
947 /* restore the file pointer */
948 _lseek(fd
, cur
, SEEK_SET
);
956 /*********************************************************************
957 * clearerr (MSVCRT.@)
959 void CDECL
clearerr(FILE* file
)
961 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
962 file
->_flag
&= ~(_IOERR
| _IOEOF
);
965 /*********************************************************************
968 void CDECL
rewind(FILE* file
)
970 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
971 fseek(file
, 0L, SEEK_SET
);
975 static int get_flags(const char* mode
, int *open_flags
, int* stream_flags
)
977 int plus
= strchr(mode
, '+') != NULL
;
982 *open_flags
= plus
? _O_RDWR
: _O_RDONLY
;
983 *stream_flags
= plus
? _IORW
: _IOREAD
;
986 *open_flags
= _O_CREAT
| _O_TRUNC
| (plus
? _O_RDWR
: _O_WRONLY
);
987 *stream_flags
= plus
? _IORW
: _IOWRT
;
990 *open_flags
= _O_CREAT
| _O_APPEND
| (plus
? _O_RDWR
: _O_WRONLY
);
991 *stream_flags
= plus
? _IORW
: _IOWRT
;
1001 *open_flags
|= _O_BINARY
;
1002 *open_flags
&= ~_O_TEXT
;
1005 *open_flags
|= _O_TEXT
;
1006 *open_flags
&= ~_O_BINARY
;
1011 FIXME(":unknown flag %c not supported\n",mode
[-1]);
1016 /*********************************************************************
1017 * _fdopen (MSVCRT.@)
1019 FILE* CDECL
_fdopen(int fd
, const char *mode
)
1021 int open_flags
, stream_flags
;
1024 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1) return NULL
;
1027 if (!(file
= alloc_fp()))
1029 else if (init_fp(file
, fd
, stream_flags
) == -1)
1034 else TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
1040 /*********************************************************************
1041 * _wfdopen (MSVCRT.@)
1043 FILE* CDECL
_wfdopen(int fd
, const wchar_t *mode
)
1045 unsigned mlen
= strlenW(mode
);
1046 char *modea
= calloc(mlen
+ 1, 1);
1048 int open_flags
, stream_flags
;
1051 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
1053 if (get_flags(modea
, &open_flags
, &stream_flags
) == -1)
1059 if (!(file
= alloc_fp()))
1061 else if (init_fp(file
, fd
, stream_flags
) == -1)
1069 rewind(file
); /* FIXME: is this needed ??? */
1070 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,debugstr_w(mode
),file
);
1078 /*********************************************************************
1079 * _filelength (MSVCRT.@)
1081 LONG CDECL
_filelength(int fd
)
1083 LONG curPos
= _lseek(fd
, 0, SEEK_CUR
);
1086 LONG endPos
= _lseek(fd
, 0, SEEK_END
);
1089 if (endPos
!= curPos
)
1090 _lseek(fd
, curPos
, SEEK_SET
);
1097 /*********************************************************************
1098 * _filelengthi64 (MSVCRT.@)
1100 __int64 CDECL
_filelengthi64(int fd
)
1102 __int64 curPos
= _lseeki64(fd
, 0, SEEK_CUR
);
1105 __int64 endPos
= _lseeki64(fd
, 0, SEEK_END
);
1108 if (endPos
!= curPos
)
1109 _lseeki64(fd
, curPos
, SEEK_SET
);
1116 /*********************************************************************
1117 * _fileno (MSVCRT.@)
1119 int CDECL
_fileno(FILE* file
)
1121 TRACE(":FILE* (%p) fd (%d)\n",file
,file
->_file
);
1125 /*********************************************************************
1126 * _futime (MSVCRT.@)
1128 int CDECL
_futime(int fd
, struct _utimbuf
*t
)
1130 HANDLE hand
= fdtoh(fd
);
1133 if (hand
== INVALID_HANDLE_VALUE
)
1140 RtlSecondsSince1970ToTime(currTime
, (LARGE_INTEGER
*)&at
);
1145 RtlSecondsSince1970ToTime(t
->actime
, (LARGE_INTEGER
*)&at
);
1146 if (t
->actime
== t
->modtime
)
1149 RtlSecondsSince1970ToTime(t
->modtime
, (LARGE_INTEGER
*)&wt
);
1152 if (!SetFileTime(hand
, NULL
, &at
, &wt
))
1154 _dosmaperr(GetLastError());
1160 /*********************************************************************
1161 * _get_osfhandle (MSVCRT.@)
1163 intptr_t CDECL
_get_osfhandle(int fd
)
1165 HANDLE hand
= fdtoh(fd
);
1166 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1168 return (long)(LONG_PTR
)hand
;
1171 /*********************************************************************
1172 * _isatty (MSVCRT.@)
1174 int CDECL
_isatty(int fd
)
1176 HANDLE hand
= fdtoh(fd
);
1178 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1179 if (hand
== INVALID_HANDLE_VALUE
)
1182 return GetFileType(hand
) == FILE_TYPE_CHAR
? 1 : 0;
1185 /*********************************************************************
1186 * _mktemp (MSVCRT.@)
1188 char * CDECL
_mktemp(char *pattern
)
1191 char *retVal
= pattern
;
1196 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1200 id
= GetCurrentProcessId();
1204 int tempNum
= id
/ 10;
1205 *pattern
-- = id
- (tempNum
* 10) + '0';
1211 *pattern
= letter
++;
1212 if (GetFileAttributesA(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1213 GetLastError() == ERROR_FILE_NOT_FOUND
)
1215 } while(letter
<= 'z');
1219 /*********************************************************************
1220 * _wmktemp (MSVCRT.@)
1222 wchar_t * CDECL
_wmktemp(wchar_t *pattern
)
1225 wchar_t *retVal
= pattern
;
1227 wchar_t letter
= 'a';
1230 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1234 id
= GetCurrentProcessId();
1238 int tempNum
= id
/ 10;
1239 *pattern
-- = id
- (tempNum
* 10) + '0';
1245 if (GetFileAttributesW(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1246 GetLastError() == ERROR_FILE_NOT_FOUND
)
1248 *pattern
= letter
++;
1249 } while(letter
!= '|');
1253 /*static */unsigned split_oflags(unsigned oflags
)
1256 unsigned unsupp
; /* until we support everything */
1258 if (oflags
& _O_APPEND
) wxflags
|= WX_APPEND
;
1259 if (oflags
& _O_BINARY
) {/* Nothing to do */}
1260 else if (oflags
& _O_TEXT
) wxflags
|= WX_TEXT
;
1261 else if (*__p__fmode() & _O_BINARY
) {/* Nothing to do */}
1262 else wxflags
|= WX_TEXT
; /* default to TEXT*/
1263 if (oflags
& _O_NOINHERIT
) wxflags
|= WX_DONTINHERIT
;
1265 if ((unsupp
= oflags
& ~(
1266 _O_BINARY
|_O_TEXT
|_O_APPEND
|
1267 _O_TRUNC
|_O_EXCL
|_O_CREAT
|
1268 _O_RDWR
|_O_WRONLY
|_O_TEMPORARY
|
1270 _O_SEQUENTIAL
|_O_RANDOM
|_O_SHORT_LIVED
1272 ERR(":unsupported oflags 0x%04x\n",unsupp
);
1277 /*********************************************************************
1280 int CDECL
_pipe(int *pfds
, unsigned int psize
, int textmode
)
1283 SECURITY_ATTRIBUTES sa
;
1284 HANDLE readHandle
, writeHandle
;
1292 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
1293 sa
.bInheritHandle
= !(textmode
& _O_NOINHERIT
);
1294 sa
.lpSecurityDescriptor
= NULL
;
1295 if (CreatePipe(&readHandle
, &writeHandle
, &sa
, psize
))
1297 unsigned int wxflags
= split_oflags(textmode
);
1301 fd
= alloc_fd(readHandle
, wxflags
);
1305 fd
= alloc_fd(writeHandle
, wxflags
);
1314 CloseHandle(writeHandle
);
1320 CloseHandle(readHandle
);
1321 CloseHandle(writeHandle
);
1327 _dosmaperr(GetLastError());
1332 /*********************************************************************
1335 int CDECL
_sopen( const char *path
, int oflags
, int shflags
, ... )
1339 DWORD access
= 0, creation
= 0, attrib
;
1343 SECURITY_ATTRIBUTES sa
;
1346 TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n",
1347 path
, oflags
, shflags
);
1349 wxflag
= split_oflags(oflags
);
1350 switch (oflags
& (_O_RDONLY
| _O_WRONLY
| _O_RDWR
))
1352 case _O_RDONLY
: access
|= GENERIC_READ
; break;
1353 case _O_WRONLY
: access
|= GENERIC_WRITE
; break;
1354 case _O_RDWR
: access
|= GENERIC_WRITE
| GENERIC_READ
; break;
1357 if (oflags
& _O_CREAT
)
1359 va_start(ap
, shflags
);
1360 pmode
= va_arg(ap
, int);
1363 if(pmode
& ~(_S_IREAD
| _S_IWRITE
))
1364 FIXME(": pmode 0x%04x ignored\n", pmode
);
1366 WARN(": pmode 0x%04x ignored\n", pmode
);
1368 if (oflags
& _O_EXCL
)
1369 creation
= CREATE_NEW
;
1370 else if (oflags
& _O_TRUNC
)
1371 creation
= CREATE_ALWAYS
;
1373 creation
= OPEN_ALWAYS
;
1375 else /* no _O_CREAT */
1377 if (oflags
& _O_TRUNC
)
1378 creation
= TRUNCATE_EXISTING
;
1380 creation
= OPEN_EXISTING
;
1389 sharing
= FILE_SHARE_READ
;
1392 sharing
= FILE_SHARE_WRITE
;
1395 sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1398 ERR( "Unhandled shflags 0x%x\n", shflags
);
1401 attrib
= FILE_ATTRIBUTE_NORMAL
;
1403 if (oflags
& _O_TEMPORARY
)
1405 attrib
|= FILE_FLAG_DELETE_ON_CLOSE
;
1407 sharing
|= FILE_SHARE_DELETE
;
1410 sa
.nLength
= sizeof( SECURITY_ATTRIBUTES
);
1411 sa
.lpSecurityDescriptor
= NULL
;
1412 sa
.bInheritHandle
= (oflags
& _O_NOINHERIT
) ? FALSE
: TRUE
;
1414 hand
= CreateFileA(path
, access
, sharing
, &sa
, creation
, attrib
, 0);
1416 if (hand
== INVALID_HANDLE_VALUE
) {
1417 WARN(":failed-last error (%d)\n",GetLastError());
1418 _dosmaperr(GetLastError());
1422 fd
= alloc_fd(hand
, wxflag
);
1424 TRACE(":fd (%d) handle (%p)\n",fd
, hand
);
1428 /*********************************************************************
1429 * _wsopen (MSVCRT.@)
1431 int CDECL
_wsopen( const wchar_t* path
, int oflags
, int shflags
, ... )
1433 const unsigned int len
= strlenW(path
);
1434 char *patha
= calloc(len
+ 1,1);
1438 va_start(ap
, shflags
);
1439 pmode
= va_arg(ap
, int);
1442 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1444 int retval
= _sopen(patha
,oflags
,shflags
,pmode
);
1448 _dosmaperr(GetLastError());
1453 /*********************************************************************
1456 int CDECL
_open( const char *path
, int flags
, ... )
1460 if (flags
& _O_CREAT
)
1463 va_start(ap
, flags
);
1464 pmode
= va_arg(ap
, int);
1466 return _sopen( path
, flags
, _SH_DENYNO
, pmode
);
1469 return _sopen( path
, flags
, _SH_DENYNO
);
1472 /*********************************************************************
1475 int CDECL
_wopen(const wchar_t *path
,int flags
,...)
1477 const unsigned int len
= strlenW(path
);
1478 char *patha
= calloc(len
+ 1,1);
1482 va_start(ap
, flags
);
1483 pmode
= va_arg(ap
, int);
1486 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1488 int retval
= _open(patha
,flags
,pmode
);
1493 _dosmaperr(GetLastError());
1497 /*********************************************************************
1500 int CDECL
_creat(const char *path
, int flags
)
1502 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1503 return _open(path
, usedFlags
);
1506 /*********************************************************************
1507 * _wcreat (MSVCRT.@)
1509 int CDECL
_wcreat(const wchar_t *path
, int flags
)
1511 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1512 return _wopen(path
, usedFlags
);
1515 /*********************************************************************
1516 * _open_osfhandle (MSVCRT.@)
1518 int CDECL
_open_osfhandle(intptr_t handle
, int oflags
)
1522 /* _O_RDONLY (0) always matches, so set the read flag
1523 * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
1524 * file, so set the write flag. It also only sets _O_TEXT if it wants
1525 * text - it never sets _O_BINARY.
1527 /* don't let split_oflags() decide the mode if no mode is passed */
1528 if (!(oflags
& (_O_BINARY
| _O_TEXT
)))
1529 oflags
|= _O_BINARY
;
1531 fd
= alloc_fd((HANDLE
)(LONG_PTR
)handle
, split_oflags(oflags
));
1532 TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle
, fd
, oflags
);
1536 /*********************************************************************
1539 int CDECL
_rmtmp(void)
1541 int num_removed
= 0, i
;
1544 for (i
= 3; i
< stream_idx
; i
++)
1545 if (fstreams
[i
] && fstreams
[i
]->_tmpfname
)
1547 fclose(fstreams
[i
]);
1553 TRACE(":removed (%d) temp files\n",num_removed
);
1557 /*********************************************************************
1558 * (internal) remove_cr
1560 * Translate all \r\n to \n inplace.
1561 * return the number of \r removed
1562 * Corner cases required by some apps:
1564 * BUG: should save state across calls somehow, so CR LF that
1565 * straddles buffer boundary gets recognized properly?
1567 static unsigned int remove_cr(char *buf
, unsigned int count
)
1571 for (i
=0, j
=0; j
< count
; j
++)
1572 if ((buf
[j
] != '\r') || ((j
+1) < count
&& buf
[j
+1] != '\n'))
1578 /*********************************************************************
1581 static int read_i(int fd
, void *buf
, unsigned int count
)
1584 char *bufstart
= buf
;
1585 HANDLE hand
= fdtoh(fd
);
1587 if (fdesc
[fd
].wxflag
& WX_READEOF
) {
1588 fdesc
[fd
].wxflag
|= WX_ATEOF
;
1589 TRACE("already at EOF, returning 0\n");
1592 /* Don't trace small reads, it gets *very* annoying */
1594 TRACE(":fd (%d) handle (%p) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1595 if (hand
== INVALID_HANDLE_VALUE
)
1598 /* Reading single bytes in O_TEXT mode makes things slow
1599 * So read big chunks
1601 if (ReadFile(hand
, bufstart
, count
, &num_read
, NULL
))
1603 if (fdesc
[fd
].wxflag
& WX_TEXT
)
1606 /* in text mode, a ctrl-z signals EOF */
1607 for (i
=0; i
<num_read
; i
++)
1609 if (bufstart
[i
] == 0x1a)
1612 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1613 TRACE(":^Z EOF %s\n",debugstr_an(buf
,num_read
));
1618 if (count
!= 0 && num_read
== 0)
1620 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1621 TRACE(":EOF %s\n",debugstr_an(buf
,num_read
));
1626 if (GetLastError() == ERROR_BROKEN_PIPE
)
1628 TRACE(":end-of-pipe\n");
1629 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1634 TRACE(":failed-last error (%d)\n",GetLastError());
1640 TRACE("(%u), %s\n",num_read
,debugstr_an(buf
, num_read
));
1644 /*********************************************************************
1647 int CDECL
_read(int fd
, void *buf
, unsigned int count
)
1650 num_read
= read_i(fd
, buf
, count
);
1651 if (num_read
>0 && fdesc
[fd
].wxflag
& WX_TEXT
)
1653 num_read
-= remove_cr(buf
,num_read
);
1658 /*********************************************************************
1659 * _setmode (MSVCRT.@)
1661 int CDECL
_setmode(int fd
,int mode
)
1663 int ret
= fdesc
[fd
].wxflag
& WX_TEXT
? _O_TEXT
: _O_BINARY
;
1664 if (mode
& (~(_O_TEXT
|_O_BINARY
)))
1665 FIXME("fd (%d) mode (0x%08x) unknown\n",fd
,mode
);
1666 if ((mode
& _O_TEXT
) == _O_TEXT
)
1667 fdesc
[fd
].wxflag
|= WX_TEXT
;
1669 fdesc
[fd
].wxflag
&= ~WX_TEXT
;
1673 /*********************************************************************
1676 long CDECL
_tell(int fd
)
1678 return _lseek(fd
, 0, SEEK_CUR
);
1681 /*********************************************************************
1682 * _telli64 (MSVCRT.@)
1684 __int64 CDECL
_telli64(int fd
)
1686 return _lseeki64(fd
, 0, SEEK_CUR
);
1689 /*********************************************************************
1690 * _tempnam (MSVCRT.@)
1692 char * CDECL
_tempnam(const char *dir
, const char *prefix
)
1694 char tmpbuf
[MAX_PATH
];
1695 const char *tmp_dir
= getenv("TMP");
1697 if (tmp_dir
) dir
= tmp_dir
;
1699 TRACE("dir (%s) prefix (%s)\n",dir
,prefix
);
1700 if (GetTempFileNameA(dir
,prefix
,0,tmpbuf
))
1702 TRACE("got name (%s)\n",tmpbuf
);
1703 DeleteFileA(tmpbuf
);
1704 return _strdup(tmpbuf
);
1706 TRACE("failed (%d)\n",GetLastError());
1710 /*********************************************************************
1711 * _wtempnam (MSVCRT.@)
1713 wchar_t * CDECL
_wtempnam(const wchar_t *dir
, const wchar_t *prefix
)
1715 wchar_t tmpbuf
[MAX_PATH
];
1717 TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir
),debugstr_w(prefix
));
1718 if (GetTempFileNameW(dir
,prefix
,0,tmpbuf
))
1720 TRACE("got name (%s)\n",debugstr_w(tmpbuf
));
1721 DeleteFileW(tmpbuf
);
1722 return _wcsdup(tmpbuf
);
1724 TRACE("failed (%d)\n",GetLastError());
1728 /*********************************************************************
1731 int CDECL
_umask(int umask
)
1733 int old_umask
= umask
;
1734 TRACE("(%d)\n",umask
);
1735 MSVCRT_umask
= umask
;
1739 /*********************************************************************
1742 int CDECL
_utime(const char* path
, struct _utimbuf
*t
)
1744 int fd
= _open(path
, _O_WRONLY
| _O_BINARY
);
1748 int retVal
= _futime(fd
, t
);
1755 /*********************************************************************
1756 * _wutime (MSVCRT.@)
1758 int CDECL
_wutime(const wchar_t* path
, struct _utimbuf
*t
)
1760 int fd
= _wopen(path
, _O_WRONLY
| _O_BINARY
);
1764 int retVal
= _futime(fd
, t
);
1771 /*********************************************************************
1774 int CDECL
_write(int fd
, const void* buf
, unsigned int count
)
1777 HANDLE hand
= fdtoh(fd
);
1779 /* Don't trace small writes, it gets *very* annoying */
1782 TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1784 if (hand
== INVALID_HANDLE_VALUE
)
1790 /* If appending, go to EOF */
1791 if (fdesc
[fd
].wxflag
& WX_APPEND
)
1792 _lseek(fd
, 0, FILE_END
);
1794 if (!(fdesc
[fd
].wxflag
& WX_TEXT
))
1796 if (WriteFile(hand
, buf
, count
, &num_written
, NULL
)
1797 && (num_written
== count
))
1799 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd
,
1800 hand
, GetLastError());
1805 unsigned int i
, j
, nr_lf
;
1808 const char *s
= (const char *)buf
, *buf_start
= (const char *)buf
;
1809 /* find number of \n ( without preceding \r ) */
1810 for ( nr_lf
=0,i
= 0; i
<count
; i
++)
1815 /*if ((i >1) && (s[i-1] == '\r')) nr_lf--; */
1820 if ((q
= p
= malloc(count
+ nr_lf
)))
1822 for (s
= (const char *)buf
, i
= 0, j
= 0; i
< count
; i
++)
1827 /*if ((i >1) && (s[i-1] == '\r'))j--;*/
1834 FIXME("Malloc failed\n");
1842 if ((WriteFile(hand
, q
, count
+nr_lf
, &num_written
, NULL
) == 0 ) || (num_written
!= count
+nr_lf
))
1844 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
1845 fd
, hand
, GetLastError(), num_written
);
1849 return s
- buf_start
;
1861 /*********************************************************************
1864 int CDECL
_putw(int val
, FILE* file
)
1867 len
= _write(file
->_file
, &val
, sizeof(val
));
1868 if (len
== sizeof(val
)) return val
;
1869 file
->_flag
|= _IOERR
;
1873 /*********************************************************************
1876 int CDECL
fclose(FILE* file
)
1881 free(file
->_tmpfname
);
1882 file
->_tmpfname
= NULL
;
1883 /* flush stdio buffers */
1884 if(file
->_flag
& _IOWRT
)
1886 if(file
->_flag
& _IOMYBUF
)
1889 r
=_close(file
->_file
);
1893 return ((r
== -1) || (flag
& _IOERR
) ? EOF
: 0);
1896 /*********************************************************************
1899 int CDECL
feof(FILE* file
)
1901 return file
->_flag
& _IOEOF
;
1904 /*********************************************************************
1907 int CDECL
ferror(FILE* file
)
1909 return file
->_flag
& _IOERR
;
1912 /*********************************************************************
1913 * _filbuf (MSVCRT.@)
1915 int CDECL
_filbuf(FILE* file
)
1917 /* Allocate buffer if needed */
1918 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
) ) {
1921 if(!(file
->_flag
& _IOREAD
)) {
1922 if(file
->_flag
& _IORW
) {
1923 file
->_flag
|= _IOREAD
;
1928 if(file
->_flag
& _IONBF
) {
1931 if ((r
= read_i(file
->_file
,&c
,1)) != 1) {
1932 file
->_flag
|= (r
== 0) ? _IOEOF
: _IOERR
;
1937 file
->_cnt
= read_i(file
->_file
, file
->_base
, file
->_bufsiz
);
1939 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
1944 file
->_ptr
= file
->_base
+1;
1945 return *(unsigned char *)file
->_base
;
1949 /*********************************************************************
1952 int CDECL
fgetc(FILE* file
)
1959 i
= (unsigned char *)file
->_ptr
++;
1963 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
)
1964 || ((j
!= '\r') || (file
->_cnt
&& file
->_ptr
[0] != '\n')))
1969 /*********************************************************************
1970 * _fgetchar (MSVCRT.@)
1972 int CDECL
_fgetchar(void)
1974 return fgetc(stdin
);
1977 /*********************************************************************
1980 char * CDECL
fgets(char *s
, int size
, FILE* file
)
1983 char * buf_start
= s
;
1985 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
1986 file
,file
->_file
,s
,size
);
1988 while ((size
>1) && (cc
= fgetc(file
)) != EOF
&& cc
!= '\n')
1993 if ((cc
== EOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
1995 TRACE(":nothing read\n");
1998 if ((cc
!= EOF
) && (size
> 1))
2001 TRACE(":got %s\n", debugstr_a(buf_start
));
2005 /*********************************************************************
2008 * In _O_TEXT mode, multibyte characters are read from the file, dropping
2009 * the CR from CR/LF combinations
2011 wint_t CDECL
fgetwc(FILE* file
)
2015 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2021 for(i
=0; i
<sizeof(wc
); i
++)
2034 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
2045 if ((*__p___mb_cur_max() > 1) && isleadbyte(c
))
2047 FIXME("Treat Multibyte characters\n");
2055 /*********************************************************************
2058 int CDECL
_getw(FILE* file
)
2063 for (j
=0; j
<sizeof(int); j
++) {
2066 file
->_flag
|= _IOEOF
;
2074 /*********************************************************************
2077 wint_t CDECL
getwc(FILE* file
)
2079 return fgetwc(file
);
2082 /*********************************************************************
2083 * _fgetwchar (MSVCRT.@)
2085 wint_t CDECL
_fgetwchar(void)
2087 return fgetwc(stdin
);
2090 /*********************************************************************
2091 * getwchar (MSVCRT.@)
2093 wint_t CDECL
getwchar(void)
2095 return _fgetwchar();
2098 /*********************************************************************
2101 wchar_t * CDECL
fgetws(wchar_t *s
, int size
, FILE* file
)
2104 wchar_t * buf_start
= s
;
2106 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
2107 file
,file
->_file
,s
,size
);
2109 while ((size
>1) && (cc
= fgetwc(file
)) != WEOF
&& cc
!= '\n')
2114 if ((cc
== WEOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
2116 TRACE(":nothing read\n");
2119 if ((cc
!= WEOF
) && (size
> 1))
2122 TRACE(":got %s\n", debugstr_w(buf_start
));
2126 /*********************************************************************
2129 size_t CDECL
fwrite(const void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2131 size_t wrcnt
=size
* nmemb
;
2136 int pcnt
=(file
->_cnt
>wrcnt
)? wrcnt
: file
->_cnt
;
2137 memcpy(file
->_ptr
, ptr
, pcnt
);
2142 ptr
= (const char*)ptr
+ pcnt
;
2143 } else if(!(file
->_flag
& _IOWRT
)) {
2144 if(file
->_flag
& _IORW
) {
2145 file
->_flag
|= _IOWRT
;
2151 int res
=flush_buffer(file
);
2153 int pwritten
= _write(file
->_file
, ptr
, wrcnt
);
2156 file
->_flag
|= _IOERR
;
2159 written
+= pwritten
;
2162 return written
/ size
;
2165 /*********************************************************************
2168 wint_t CDECL
fputwc(wint_t wc
, FILE* file
)
2171 if (fwrite( &mwc
, sizeof(mwc
), 1, file
) != 1)
2176 /*********************************************************************
2177 * _fputwchar (MSVCRT.@)
2179 wint_t CDECL
_fputwchar(wint_t wc
)
2181 return fputwc(wc
, stdout
);
2184 /*********************************************************************
2185 * _fsopen (MSVCRT.@)
2187 FILE * CDECL
_fsopen(const char *path
, const char *mode
, int share
)
2190 int open_flags
, stream_flags
, fd
;
2192 TRACE("(%s,%s)\n",path
,mode
);
2194 /* map mode string to open() flags. "man fopen" for possibilities. */
2195 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2199 fd
= _sopen(path
, open_flags
, share
, _S_IREAD
| _S_IWRITE
);
2202 else if ((file
= alloc_fp()) && init_fp(file
, fd
, stream_flags
)
2204 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
2211 TRACE(":got (%p)\n",file
);
2212 if (fd
>= 0 && !file
)
2218 /*********************************************************************
2219 * _wfsopen (MSVCRT.@)
2221 FILE * CDECL
_wfsopen(const wchar_t *path
, const wchar_t *mode
, int share
)
2223 const unsigned int plen
= strlenW(path
), mlen
= strlenW(mode
);
2224 char *patha
= calloc(plen
+ 1, 1);
2225 char *modea
= calloc(mlen
+ 1, 1);
2227 TRACE("(%s,%s)\n",debugstr_w(path
),debugstr_w(mode
));
2229 if (patha
&& modea
&&
2230 WideCharToMultiByte(CP_ACP
,0,path
,plen
,patha
,plen
,NULL
,NULL
) &&
2231 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
2233 FILE *retval
= _fsopen(patha
,modea
,share
);
2240 _dosmaperr(GetLastError());
2244 /*********************************************************************
2247 FILE * CDECL
fopen(const char *path
, const char *mode
)
2249 return _fsopen( path
, mode
, _SH_DENYNO
);
2252 /*********************************************************************
2253 * _wfopen (MSVCRT.@)
2255 FILE * CDECL
_wfopen(const wchar_t *path
, const wchar_t *mode
)
2257 return _wfsopen( path
, mode
, _SH_DENYNO
);
2260 /* fputc calls _flsbuf which calls fputc */
2261 int CDECL
_flsbuf(int c
, FILE* file
);
2263 /*********************************************************************
2266 int CDECL
fputc(int c
, FILE* file
)
2273 int res
= flush_buffer(file
);
2274 return res
? res
: c
;
2279 return _flsbuf(c
, file
);
2283 /*********************************************************************
2284 * _flsbuf (MSVCRT.@)
2286 int CDECL
_flsbuf(int c
, FILE* file
)
2288 /* Flush output buffer */
2289 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2292 if(!(file
->_flag
& _IOWRT
)) {
2293 if(file
->_flag
& _IORW
) {
2294 file
->_flag
|= _IOWRT
;
2300 int res
=flush_buffer(file
);
2301 return res
?res
: fputc(c
, file
);
2305 len
= _write(file
->_file
, &cc
, 1);
2306 if (len
== 1) return c
& 0xff;
2307 file
->_flag
|= _IOERR
;
2312 /*********************************************************************
2313 * _fputchar (MSVCRT.@)
2315 int CDECL
_fputchar(int c
)
2317 return fputc(c
, stdout
);
2320 /*********************************************************************
2323 size_t CDECL
fread(void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2324 { size_t rcnt
=size
* nmemb
;
2331 /* first buffered data */
2333 int pcnt
= (rcnt
>file
->_cnt
)? file
->_cnt
:rcnt
;
2334 memcpy(ptr
, file
->_ptr
, pcnt
);
2337 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
)
2338 pcnt
-= remove_cr(ptr
,pcnt
);
2341 ptr
= (char*)ptr
+ pcnt
;
2342 } else if(!(file
->_flag
& _IOREAD
)) {
2343 if(file
->_flag
& _IORW
) {
2344 file
->_flag
|= _IOREAD
;
2351 /* Fill the buffer on small reads.
2352 * TODO: Use a better buffering strategy.
2354 if (!file
->_cnt
&& size
*nmemb
<= BUFSIZ
/2 && !(file
->_flag
& _IONBF
)) {
2355 if (file
->_bufsiz
== 0) {
2358 file
->_cnt
= _read(file
->_file
, file
->_base
, file
->_bufsiz
);
2359 file
->_ptr
= file
->_base
;
2360 i
= (file
->_cnt
<rcnt
) ? file
->_cnt
: rcnt
;
2361 /* If the buffer fill reaches eof but fread wouldn't, clear eof. */
2362 if (i
> 0 && i
< file
->_cnt
) {
2363 fdesc
[file
->_file
].wxflag
&= ~WX_ATEOF
;
2364 file
->_flag
&= ~_IOEOF
;
2367 memcpy(ptr
, file
->_ptr
, i
);
2372 i
= _read(file
->_file
,ptr
, rcnt
);
2376 ptr
= (char *)ptr
+i
;
2377 /* expose feof condition in the flags
2378 * MFC tests file->_flag for feof, and doesn't call feof())
2380 if ( fdesc
[file
->_file
].wxflag
& WX_ATEOF
)
2381 file
->_flag
|= _IOEOF
;
2384 file
->_flag
|= _IOERR
;
2394 /*********************************************************************
2395 * freopen (MSVCRT.@)
2398 FILE* CDECL
freopen(const char *path
, const char *mode
,FILE* file
)
2400 int open_flags
, stream_flags
, fd
;
2402 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n",path
,mode
,file
,file
->_file
);
2405 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2410 /* map mode string to open() flags. "man fopen" for possibilities. */
2411 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2415 fd
= _open(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2418 else if (init_fp(file
, fd
, stream_flags
) == -1)
2421 WARN(":failed-last error (%d)\n",GetLastError());
2422 _dosmaperr(GetLastError());
2431 /*********************************************************************
2432 * wfreopen (MSVCRT.@)
2435 FILE* CDECL
_wfreopen(const wchar_t *path
, const wchar_t *mode
,FILE* file
)
2437 int open_flags
, stream_flags
, fd
;
2439 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path
), debugstr_w(mode
), file
, file
->_file
);
2442 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2447 /* map mode string to open() flags. "man fopen" for possibilities. */
2448 if (get_flags((char*)mode
, &open_flags
, &stream_flags
) == -1)
2452 fd
= _wopen(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2455 else if (init_fp(file
, fd
, stream_flags
) == -1)
2458 WARN(":failed-last error (%d)\n",GetLastError());
2459 _dosmaperr(GetLastError());
2468 /*********************************************************************
2469 * fsetpos (MSVCRT.@)
2471 int CDECL
fsetpos(FILE* file
, const fpos_t *pos
)
2473 /* Note that all this has been lifted 'as is' from fseek */
2474 if(file
->_flag
& _IOWRT
)
2477 /* Discard buffered input */
2479 file
->_ptr
= file
->_base
;
2481 /* Reset direction of i/o */
2482 if(file
->_flag
& _IORW
) {
2483 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
2486 return (_lseeki64(file
->_file
,*pos
,SEEK_SET
) == -1) ? -1 : 0;
2489 /*********************************************************************
2492 LONG CDECL
ftell(FILE* file
)
2497 if( file
->_flag
& _IOWRT
) {
2498 off
= file
->_ptr
- file
->_base
;
2503 pos
= _tell(file
->_file
);
2504 if(pos
== -1) return pos
;
2508 /*********************************************************************
2509 * fgetpos (MSVCRT.@)
2511 int CDECL
fgetpos(FILE* file
, fpos_t *pos
)
2513 /* This code has been lifted form the ftell function */
2516 *pos
= _lseeki64(file
->_file
,0,SEEK_CUR
);
2518 if (*pos
== -1) return -1;
2521 if( file
->_flag
& _IOWRT
) {
2522 off
= file
->_ptr
- file
->_base
;
2532 /*********************************************************************
2535 int CDECL
fputs(const char *s
, FILE* file
)
2537 size_t i
, len
= strlen(s
);
2538 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2539 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2540 for (i
=0; i
<len
; i
++)
2541 if (fputc(s
[i
], file
) == EOF
)
2546 /*********************************************************************
2549 int CDECL
fputws(const wchar_t *s
, FILE* file
)
2551 size_t i
, len
= strlenW(s
);
2552 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2553 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2554 for (i
=0; i
<len
; i
++)
2556 if ((s
[i
] == '\n') && (fputc('\r', file
) == EOF
))
2558 if (fputwc(s
[i
], file
) == WEOF
)
2564 /*********************************************************************
2565 * getchar (MSVCRT.@)
2567 int CDECL
getchar(void)
2569 return fgetc(stdin
);
2572 /*********************************************************************
2575 int CDECL
getc(FILE* file
)
2580 /*********************************************************************
2583 char * CDECL
gets(char *buf
)
2586 char * buf_start
= buf
;
2588 for(cc
= fgetc(stdin
); cc
!= EOF
&& cc
!= '\n';
2590 if(cc
!= '\r') *buf
++ = (char)cc
;
2594 TRACE("got '%s'\n", buf_start
);
2598 /*********************************************************************
2601 wchar_t* CDECL
_getws(wchar_t* buf
)
2606 for (cc
= fgetwc(stdin
); cc
!= WEOF
&& cc
!= '\n';
2610 *buf
++ = (wchar_t)cc
;
2614 TRACE("got %s\n", debugstr_w(ws
));
2618 /*********************************************************************
2621 int CDECL
putc(int c
, FILE* file
)
2623 return fputc(c
, file
);
2626 /*********************************************************************
2627 * putchar (MSVCRT.@)
2629 int CDECL
putchar(int c
)
2631 return fputc(c
, stdout
);
2634 /*********************************************************************
2637 int CDECL
puts(const char *s
)
2639 size_t len
= strlen(s
);
2640 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2641 return fwrite("\n",1,1,stdout
) == 1 ? 0 : EOF
;
2644 /*********************************************************************
2647 int CDECL
_putws(const wchar_t *s
)
2649 static const wchar_t nl
= '\n';
2650 size_t len
= strlenW(s
);
2651 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2652 return fwrite(&nl
,sizeof(nl
),1,stdout
) == 1 ? 0 : EOF
;
2655 /*********************************************************************
2658 int CDECL
remove(const char *path
)
2660 TRACE("(%s)\n",path
);
2661 if (DeleteFileA(path
))
2663 TRACE(":failed (%d)\n",GetLastError());
2664 _dosmaperr(GetLastError());
2668 /*********************************************************************
2669 * _wremove (MSVCRT.@)
2671 int CDECL
_wremove(const wchar_t *path
)
2673 TRACE("(%s)\n",debugstr_w(path
));
2674 if (DeleteFileW(path
))
2676 TRACE(":failed (%d)\n",GetLastError());
2677 _dosmaperr(GetLastError());
2681 /*********************************************************************
2684 int CDECL
rename(const char *oldpath
,const char *newpath
)
2686 TRACE(":from %s to %s\n",oldpath
,newpath
);
2687 if (MoveFileExA(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2689 TRACE(":failed (%d)\n",GetLastError());
2690 _dosmaperr(GetLastError());
2694 /*********************************************************************
2695 * _wrename (MSVCRT.@)
2697 int CDECL
_wrename(const wchar_t *oldpath
,const wchar_t *newpath
)
2699 TRACE(":from %s to %s\n",debugstr_w(oldpath
),debugstr_w(newpath
));
2700 if (MoveFileExW(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2702 TRACE(":failed (%d)\n",GetLastError());
2703 _dosmaperr(GetLastError());
2707 /*********************************************************************
2708 * setvbuf (MSVCRT.@)
2710 int CDECL
setvbuf(FILE* file
, char *buf
, int mode
, size_t size
)
2712 /* TODO: Check if file busy */
2718 if(mode
== _IOFBF
) {
2719 file
->_flag
&= ~_IONBF
;
2720 file
->_base
= file
->_ptr
= buf
;
2722 file
->_bufsiz
= size
;
2725 file
->_flag
|= _IONBF
;
2730 /*********************************************************************
2733 void CDECL
setbuf(FILE* file
, char *buf
)
2735 setvbuf(file
, buf
, buf
? _IOFBF
: _IONBF
, BUFSIZ
);
2738 /*********************************************************************
2741 char * CDECL
tmpnam(char *s
)
2749 int_to_base32(GetCurrentProcessId(), tmpstr
);
2750 p
= s
+ sprintf(s
, "\\s%s.", tmpstr
);
2751 for (count
= 0; count
< TMP_MAX
; count
++)
2753 int_to_base32(unique
++, tmpstr
);
2755 if (GetFileAttributesA(s
) == INVALID_FILE_ATTRIBUTES
&&
2756 GetLastError() == ERROR_FILE_NOT_FOUND
)
2762 /*********************************************************************
2763 * wtmpnam (MSVCRT.@)
2765 wchar_t * CDECL
_wtmpnam(wchar_t *s
)
2767 ERR("UNIMPLEMENTED!\n");
2771 /*********************************************************************
2772 * tmpfile (MSVCRT.@)
2774 FILE* CDECL
tmpfile(void)
2776 char *filename
= tmpnam(NULL
);
2781 fd
= _open(filename
, _O_CREAT
| _O_BINARY
| _O_RDWR
| _O_TEMPORARY
);
2782 if (fd
!= -1 && (file
= alloc_fp()))
2784 if (init_fp(file
, fd
, _O_RDWR
) == -1)
2789 else file
->_tmpfname
= _strdup(filename
);
2795 /*********************************************************************
2796 * vfprintf (MSVCRT.@)
2798 int CDECL
vfprintf(FILE* file
, const char *format
, va_list valist
)
2800 char buf
[2048], *mem
= buf
;
2801 int written
, resize
= sizeof(buf
), retval
;
2802 /* There are two conventions for vsnprintf failing:
2803 * Return -1 if we truncated, or
2804 * Return the number of bytes that would have been written
2805 * The code below handles both cases
2807 while ((written
= _vsnprintf(mem
, resize
, format
, valist
)) == -1 ||
2810 resize
= (written
== -1 ? resize
* 2 : written
+ 1);
2813 if (!(mem
= malloc(resize
)))
2816 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2822 /*********************************************************************
2823 * vfwprintf (MSVCRT.@)
2825 * Is final char included in written (then resize is too big) or not
2826 * (then we must test for equality too)?
2828 int CDECL
vfwprintf(FILE* file
, const wchar_t *format
, va_list valist
)
2830 wchar_t buf
[2048], *mem
= buf
;
2831 int written
, resize
= sizeof(buf
) / sizeof(wchar_t), retval
;
2832 /* See vfprintf comments */
2833 while ((written
= _vsnwprintf(mem
, resize
, format
, valist
)) == -1 ||
2836 resize
= (written
== -1 ? resize
* 2 : written
+ sizeof(wchar_t));
2839 if (!(mem
= malloc(resize
*sizeof(*mem
))))
2843 /* Check if outputting to a text-file */
2844 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
)
2846 /* Convert each character and stop at the first invalid character. Behavior verified by tests under WinXP SP2 */
2847 char chMultiByte
[MB_LEN_MAX
];
2853 for (p
= mem
; *p
; p
++)
2855 nReturn
= wctomb(chMultiByte
, *p
);
2860 retval
+= fwrite(chMultiByte
, 1, nReturn
, file
);
2865 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2874 /*********************************************************************
2875 * vprintf (MSVCRT.@)
2877 int CDECL
vprintf(const char *format
, va_list valist
)
2879 return vfprintf(stdout
,format
,valist
);
2882 /*********************************************************************
2883 * vwprintf (MSVCRT.@)
2885 int CDECL
vwprintf(const wchar_t *format
, va_list valist
)
2887 return vfwprintf(stdout
,format
,valist
);
2890 /*********************************************************************
2891 * fprintf (MSVCRT.@)
2893 int CDECL
fprintf(FILE* file
, const char *format
, ...)
2897 va_start(valist
, format
);
2898 res
= vfprintf(file
, format
, valist
);
2903 /*********************************************************************
2904 * fwprintf (MSVCRT.@)
2906 int CDECL
fwprintf(FILE* file
, const wchar_t *format
, ...)
2910 va_start(valist
, format
);
2911 res
= vfwprintf(file
, format
, valist
);
2916 /*********************************************************************
2919 int CDECL
printf(const char *format
, ...)
2923 va_start(valist
, format
);
2924 res
= vfprintf(stdout
, format
, valist
);
2929 /*********************************************************************
2932 int CDECL
ungetc(int c
, FILE * file
)
2936 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2940 if(file
->_ptr
>file
->_base
) {
2950 /*********************************************************************
2951 * ungetwc (MSVCRT.@)
2953 wint_t CDECL
ungetwc(wint_t wc
, FILE * file
)
2956 char * pp
= (char *)&mwc
;
2958 for(i
=sizeof(wchar_t)-1;i
>=0;i
--) {
2959 if(pp
[i
] != ungetc(pp
[i
],file
))
2965 /*********************************************************************
2966 * wprintf (MSVCRT.@)
2968 int CDECL
wprintf(const wchar_t *format
, ...)
2972 va_start(valist
, format
);
2973 res
= vwprintf(format
, valist
);
2978 /*********************************************************************
2979 * _getmaxstdio (MSVCRT.@)
2981 int CDECL
_getmaxstdio(void)
2983 FIXME("stub, always returns 512\n");
2987 /*********************************************************************
2988 * _setmaxstdio_ (MSVCRT.@)
2990 int CDECL
_setmaxstdio(int newmax
)
2997 FIXME("stub: setting new maximum for number of simultaneously open files not implemented,returning %d\n",res
);
3001 /*********************************************************************
3002 * __pioinfo (MSVCRT.@)
3003 * FIXME: see MAX_FILES define.
3005 ioinfo
* __pioinfo
[] = { /* array of pointers to ioinfo arrays [64] */
3006 &fdesc
[0 * 64], &fdesc
[1 * 64], &fdesc
[2 * 64],
3007 &fdesc
[3 * 64], &fdesc
[4 * 64], &fdesc
[5 * 64],
3008 &fdesc
[6 * 64], &fdesc
[7 * 64], &fdesc
[8 * 64],
3009 &fdesc
[9 * 64], &fdesc
[10 * 64], &fdesc
[11 * 64],
3010 &fdesc
[12 * 64], &fdesc
[13 * 64], &fdesc
[14 * 64],
3011 &fdesc
[15 * 64], &fdesc
[16 * 64], &fdesc
[17 * 64],
3012 &fdesc
[18 * 64], &fdesc
[19 * 64], &fdesc
[20 * 64],
3013 &fdesc
[21 * 64], &fdesc
[22 * 64], &fdesc
[23 * 64],
3014 &fdesc
[24 * 64], &fdesc
[25 * 64], &fdesc
[26 * 64],
3015 &fdesc
[27 * 64], &fdesc
[28 * 64], &fdesc
[29 * 64],
3016 &fdesc
[30 * 64], &fdesc
[31 * 64]
3019 /*********************************************************************
3020 * __badioinfo (MSVCRT.@)
3022 ioinfo __badioinfo
= { INVALID_HANDLE_VALUE
, WX_TEXT
, { 0, } };