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 FILE *__cdecl
__iob_func()
125 static inline BOOL
is_valid_fd(int fd
)
127 return fd
>= 0 && fd
< fdend
&& (fdesc
[fd
].wxflag
& WX_OPEN
);
130 /* INTERNAL: Get the HANDLE for a fd
131 * This doesn't lock the table, because a failure will result in
132 * INVALID_HANDLE_VALUE being returned, which should be handled correctly. If
133 * it returns a valid handle which is about to be closed, a subsequent call
134 * will fail, most likely in a sane way.
138 if (!is_valid_fd(fd
))
140 WARN(":fd (%d) - no handle!\n",fd
);
143 return INVALID_HANDLE_VALUE
;
145 //if (fdesc[fd].handle == INVALID_HANDLE_VALUE) FIXME("wtf\n");
146 return fdesc
[fd
].handle
;
149 /* INTERNAL: free a file entry fd */
150 static void free_fd(int fd
)
153 fdesc
[fd
].handle
= INVALID_HANDLE_VALUE
;
154 fdesc
[fd
].wxflag
= 0;
155 TRACE(":fd (%d) freed\n",fd
);
156 if (fd
< 3) /* don't use 0,1,2 for user files */
160 case 0: SetStdHandle(STD_INPUT_HANDLE
, NULL
); break;
161 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, NULL
); break;
162 case 2: SetStdHandle(STD_ERROR_HANDLE
, NULL
); break;
175 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE, starting from fd */
176 /* caller must hold the files lock */
177 static int alloc_fd_from(HANDLE hand
, int flag
, int fd
)
181 WARN(":files exhausted!\n");
184 fdesc
[fd
].handle
= hand
;
185 fdesc
[fd
].wxflag
= WX_OPEN
| (flag
& (WX_DONTINHERIT
| WX_APPEND
| WX_TEXT
));
187 /* locate next free slot */
188 if (fd
== fdstart
&& fd
== fdend
)
191 while (fdstart
< fdend
&&
192 fdesc
[fdstart
].handle
!= INVALID_HANDLE_VALUE
)
194 /* update last fd in use */
197 TRACE("fdstart is %d, fdend is %d\n", fdstart
, fdend
);
201 case 0: SetStdHandle(STD_INPUT_HANDLE
, hand
); break;
202 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, hand
); break;
203 case 2: SetStdHandle(STD_ERROR_HANDLE
, hand
); break;
209 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE */
210 /*static */int alloc_fd(HANDLE hand
, int flag
)
215 TRACE(":handle (%p) allocating fd (%d)\n",hand
,fdstart
);
216 ret
= alloc_fd_from(hand
, flag
, fdstart
);
221 /* INTERNAL: Allocate a FILE* for an fd slot */
222 /* caller must hold the files lock */
223 static FILE* alloc_fp(void)
227 for (i
= 3; i
< sizeof(fstreams
) / sizeof(fstreams
[0]); i
++)
229 if (!fstreams
[i
] || fstreams
[i
]->_flag
== 0)
233 if (!(fstreams
[i
] = calloc(sizeof(FILE),1)))
235 if (i
== stream_idx
) stream_idx
++;
243 /* INTERNAL: initialize a FILE* from an open fd */
244 static int init_fp(FILE* file
, int fd
, unsigned stream_flags
)
246 TRACE(":fd (%d) allocating FILE*\n",fd
);
247 if (!is_valid_fd(fd
))
249 WARN(":invalid fd %d\n",fd
);
254 memset(file
, 0, sizeof(*file
));
256 file
->_flag
= stream_flags
;
258 TRACE(":got FILE* (%p)\n",file
);
262 /* INTERNAL: Create an inheritance data block (for spawned process)
263 * The inheritance block is made of:
264 * 00 int nb of file descriptor (NBFD)
265 * 04 char file flags (wxflag): repeated for each fd
266 * 4+NBFD HANDLE file handle: repeated for each fd
268 unsigned create_io_inherit_block(WORD
*size
, BYTE
**block
)
274 *size
= sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE
)) * fdend
;
275 *block
= calloc(*size
, 1);
281 wxflag_ptr
= (char*)*block
+ sizeof(unsigned);
282 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ fdend
* sizeof(char));
284 *(unsigned*)*block
= fdend
;
285 for (fd
= 0; fd
< fdend
; fd
++)
287 /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
288 if ((fdesc
[fd
].wxflag
& (WX_OPEN
| WX_DONTINHERIT
)) == WX_OPEN
)
290 *wxflag_ptr
= fdesc
[fd
].wxflag
;
291 *handle_ptr
= fdesc
[fd
].handle
;
296 *handle_ptr
= INVALID_HANDLE_VALUE
;
298 wxflag_ptr
++; handle_ptr
++;
303 /* INTERNAL: Set up all file descriptors,
304 * as well as default streams (stdin, stderr and stdout)
306 void msvcrt_init_io(void)
311 InitializeCriticalSection(&FILE_cs
);
312 FILE_cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": FILE_cs");
313 GetStartupInfoA(&si
);
314 if (si
.cbReserved2
!= 0 && si
.lpReserved2
!= NULL
)
319 fdend
= *(unsigned*)si
.lpReserved2
;
321 wxflag_ptr
= (char*)(si
.lpReserved2
+ sizeof(unsigned));
322 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ fdend
* sizeof(char));
324 fdend
= min(fdend
, sizeof(fdesc
) / sizeof(fdesc
[0]));
325 for (i
= 0; i
< fdend
; i
++)
327 if ((*wxflag_ptr
& WX_OPEN
) && *handle_ptr
!= INVALID_HANDLE_VALUE
)
329 fdesc
[i
].wxflag
= *wxflag_ptr
;
330 fdesc
[i
].handle
= *handle_ptr
;
335 fdesc
[i
].handle
= INVALID_HANDLE_VALUE
;
337 wxflag_ptr
++; handle_ptr
++;
339 for (fdstart
= 3; fdstart
< fdend
; fdstart
++)
340 if (fdesc
[fdstart
].handle
== INVALID_HANDLE_VALUE
) break;
343 if (!(fdesc
[0].wxflag
& WX_OPEN
) || fdesc
[0].handle
== INVALID_HANDLE_VALUE
)
346 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE
),
347 GetCurrentProcess(), &fdesc
[0].handle
, 0, TRUE
,
348 DUPLICATE_SAME_ACCESS
);
350 fdesc
[0].handle
= GetStdHandle(STD_INPUT_HANDLE
);
351 if (fdesc
[0].handle
== NULL
)
352 fdesc
[0].handle
= INVALID_HANDLE_VALUE
;
354 fdesc
[0].wxflag
= WX_OPEN
| WX_TEXT
;
356 if (!(fdesc
[1].wxflag
& WX_OPEN
) || fdesc
[1].handle
== INVALID_HANDLE_VALUE
)
359 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE
),
360 GetCurrentProcess(), &fdesc
[1].handle
, 0, TRUE
,
361 DUPLICATE_SAME_ACCESS
);
363 fdesc
[1].handle
= GetStdHandle(STD_OUTPUT_HANDLE
);
364 if (fdesc
[1].handle
== NULL
)
365 fdesc
[1].handle
= INVALID_HANDLE_VALUE
;
367 fdesc
[1].wxflag
= WX_OPEN
| WX_TEXT
;
369 if (!(fdesc
[2].wxflag
& WX_OPEN
) || fdesc
[2].handle
== INVALID_HANDLE_VALUE
)
372 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE
),
373 GetCurrentProcess(), &fdesc
[2].handle
, 0, TRUE
,
374 DUPLICATE_SAME_ACCESS
);
376 fdesc
[2].handle
= GetStdHandle(STD_ERROR_HANDLE
);
377 if (fdesc
[2].handle
== NULL
)
378 fdesc
[2].handle
= INVALID_HANDLE_VALUE
;
380 fdesc
[2].wxflag
= WX_OPEN
| WX_TEXT
;
383 TRACE(":handles (%p)(%p)(%p)\n",fdesc
[0].handle
,
384 fdesc
[1].handle
,fdesc
[2].handle
);
386 memset(_iob
,0,3*sizeof(FILE));
387 for (i
= 0; i
< 3; i
++)
389 /* FILE structs for stdin/out/err are static and never deleted */
390 fstreams
[i
] = &_iob
[i
];
392 _iob
[i
]._tmpfname
= NULL
;
393 _iob
[i
]._flag
= (i
== 0) ? _IOREAD
: _IOWRT
;
398 /* INTERNAL: Flush stdio file buffer */
399 static int flush_buffer(FILE* file
)
402 int cnt
=file
->_ptr
-file
->_base
;
403 if(cnt
>0 && _write(file
->_file
, file
->_base
, cnt
) != cnt
) {
404 file
->_flag
|= _IOERR
;
407 file
->_ptr
=file
->_base
;
408 file
->_cnt
=file
->_bufsiz
;
413 /* INTERNAL: Allocate stdio file buffer */
414 static void alloc_buffer(FILE* file
)
416 file
->_base
= calloc(BUFSIZ
,1);
418 file
->_bufsiz
= BUFSIZ
;
419 file
->_flag
|= _IOMYBUF
;
421 file
->_base
= (char*)(&file
->_charbuf
);
423 file
->_bufsiz
= sizeof(file
->_charbuf
);
425 file
->_ptr
= file
->_base
;
429 /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */
430 static void int_to_base32(int num
, char *str
)
445 *p
= (num
& 31) + '0';
447 *p
+= ('a' - '0' - 10);
452 /*********************************************************************
455 FILE * CDECL
__p__iob(void)
460 /*********************************************************************
463 int CDECL
_access(const char *filename
, int mode
)
465 DWORD attr
= GetFileAttributesA(filename
);
467 TRACE("(%s,%d) %d\n",filename
,mode
,attr
);
469 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
471 _dosmaperr(GetLastError());
474 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
476 _dosmaperr(ERROR_ACCESS_DENIED
);
482 /*********************************************************************
483 * _waccess (MSVCRT.@)
485 int CDECL
_waccess(const wchar_t *filename
, int mode
)
487 DWORD attr
= GetFileAttributesW(filename
);
489 TRACE("(%s,%d) %d\n",debugstr_w(filename
),mode
,attr
);
491 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
493 _dosmaperr(GetLastError());
496 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
498 _dosmaperr(ERROR_ACCESS_DENIED
);
504 /*********************************************************************
507 int CDECL
_chmod(const char *path
, int flags
)
509 DWORD oldFlags
= GetFileAttributesA(path
);
511 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
513 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
514 oldFlags
| FILE_ATTRIBUTE_READONLY
;
516 if (newFlags
== oldFlags
|| SetFileAttributesA(path
, newFlags
))
519 _dosmaperr(GetLastError());
523 /*********************************************************************
526 int CDECL
_wchmod(const wchar_t *path
, int flags
)
528 DWORD oldFlags
= GetFileAttributesW(path
);
530 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
532 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
533 oldFlags
| FILE_ATTRIBUTE_READONLY
;
535 if (newFlags
== oldFlags
|| SetFileAttributesW(path
, newFlags
))
538 _dosmaperr(GetLastError());
542 /*********************************************************************
545 int CDECL
_unlink(const char *path
)
547 TRACE("%s\n",debugstr_a(path
));
548 if(DeleteFileA(path
))
550 TRACE("failed (%d)\n",GetLastError());
551 _dosmaperr(GetLastError());
555 /*********************************************************************
556 * _wunlink (MSVCRT.@)
558 int CDECL
_wunlink(const wchar_t *path
)
560 TRACE("(%s)\n",debugstr_w(path
));
561 if(DeleteFileW(path
))
563 TRACE("failed (%d)\n",GetLastError());
564 _dosmaperr(GetLastError());
568 /* _flushall calls fflush which calls _flushall */
569 int CDECL
fflush(FILE* file
);
571 /*********************************************************************
572 * _flushall (MSVCRT.@)
574 int CDECL
_flushall(void)
576 int i
, num_flushed
= 0;
579 for (i
= 3; i
< stream_idx
; i
++)
580 if (fstreams
[i
] && fstreams
[i
]->_flag
)
583 /* FIXME: flush, do not commit */
584 if (_commit(i
) == -1)
586 fstreams
[i
]->_flag
|= _IOERR
;
588 if(fstreams
[i
]->_flag
& _IOWRT
) {
595 TRACE(":flushed (%d) handles\n",num_flushed
);
599 /*********************************************************************
602 int CDECL
fflush(FILE* file
)
606 } else if(file
->_flag
& _IOWRT
) {
607 int res
=flush_buffer(file
);
613 /*********************************************************************
616 int CDECL
_close(int fd
)
623 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
624 if (hand
== INVALID_HANDLE_VALUE
)
626 else if (!CloseHandle(hand
))
628 WARN(":failed-last error (%d)\n",GetLastError());
629 _dosmaperr(GetLastError());
642 /*********************************************************************
645 int CDECL
_commit(int fd
)
647 HANDLE hand
= fdtoh(fd
);
649 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
650 if (hand
== INVALID_HANDLE_VALUE
)
653 if (!FlushFileBuffers(hand
))
655 if (GetLastError() == ERROR_INVALID_HANDLE
)
657 /* FlushFileBuffers fails for console handles
658 * so we ignore this error.
662 TRACE(":failed-last error (%d)\n",GetLastError());
663 _dosmaperr(GetLastError());
670 /*********************************************************************
673 * MSDN isn't clear on this point, but the remarks for _pipe
674 * indicate file descriptors duplicated with _dup and _dup2 are always
677 int CDECL
_dup2(int od
, int nd
)
681 TRACE("(od=%d, nd=%d)\n", od
, nd
);
683 if (nd
< MAX_FILES
&& is_valid_fd(od
))
687 if (DuplicateHandle(GetCurrentProcess(), fdesc
[od
].handle
,
688 GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
))
690 int wxflag
= fdesc
[od
].wxflag
& ~_O_NOINHERIT
;
694 ret
= alloc_fd_from(handle
, wxflag
, nd
);
702 /* _dup2 returns 0, not nd, on success */
709 _dosmaperr(GetLastError());
721 /*********************************************************************
724 int CDECL
_dup(int od
)
730 if (_dup2(od
, fd
) == 0)
738 /*********************************************************************
741 int CDECL
_eof(int fd
)
744 LONG hcurpos
,hendpos
;
745 HANDLE hand
= fdtoh(fd
);
747 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
749 if (hand
== INVALID_HANDLE_VALUE
)
752 if (fdesc
[fd
].wxflag
& WX_ATEOF
) return TRUE
;
754 /* Otherwise we do it the hard way */
755 hcurpos
= hendpos
= 0;
756 curpos
= SetFilePointer(hand
, 0, &hcurpos
, FILE_CURRENT
);
757 endpos
= SetFilePointer(hand
, 0, &hendpos
, FILE_END
);
759 if (curpos
== endpos
&& hcurpos
== hendpos
)
761 /* FIXME: shouldn't WX_ATEOF be set here? */
765 SetFilePointer(hand
, curpos
, &hcurpos
, FILE_BEGIN
);
769 /*********************************************************************
770 * _fcloseall (MSVCRT.@)
772 int CDECL
_fcloseall(void)
774 int num_closed
= 0, i
;
777 for (i
= 3; i
< stream_idx
; i
++)
778 if (fstreams
[i
] && fstreams
[i
]->_flag
&&
779 !fclose(fstreams
[i
]))
783 TRACE(":closed (%d) handles\n",num_closed
);
787 /* free everything on process exit */
788 void msvcrt_free_io(void)
791 /* The Win32 _fcloseall() function explicitly doesn't close stdin,
792 * stdout, and stderr (unlike GNU), so we need to fclose() them here
793 * or they won't get flushed.
798 FILE_cs
.DebugInfo
->Spare
[0] = 0;
799 DeleteCriticalSection(&FILE_cs
);
802 /*********************************************************************
803 * _lseeki64 (MSVCRT.@)
805 __int64 CDECL
_lseeki64(int fd
, __int64 offset
, int whence
)
807 HANDLE hand
= fdtoh(fd
);
808 LARGE_INTEGER ofs
, ret
;
810 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
811 if (hand
== INVALID_HANDLE_VALUE
)
814 if (whence
< 0 || whence
> 2)
820 TRACE(":fd (%d) to %s pos %s\n",
821 fd
,wine_dbgstr_longlong(offset
),
822 (whence
==SEEK_SET
)?"SEEK_SET":
823 (whence
==SEEK_CUR
)?"SEEK_CUR":
824 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
826 ofs
.QuadPart
= offset
;
827 if (SetFilePointerEx(hand
, ofs
, &ret
, whence
))
829 fdesc
[fd
].wxflag
&= ~(WX_ATEOF
|WX_READEOF
);
830 /* FIXME: What if we seek _to_ EOF - is EOF set? */
834 TRACE(":error-last error (%d)\n",GetLastError());
835 _dosmaperr(GetLastError());
839 /*********************************************************************
842 LONG CDECL
_lseek(int fd
, LONG offset
, int whence
)
844 return _lseeki64(fd
, offset
, whence
);
847 /*********************************************************************
848 * _locking (MSVCRT.@)
850 * This is untested; the underlying LockFile doesn't work yet.
852 int CDECL
_locking(int fd
, int mode
, LONG nbytes
)
856 HANDLE hand
= fdtoh(fd
);
858 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
859 if (hand
== INVALID_HANDLE_VALUE
)
862 if (mode
< 0 || mode
> 4)
868 TRACE(":fd (%d) by 0x%08x mode %s\n",
869 fd
,nbytes
,(mode
==_LK_UNLCK
)?"_LK_UNLCK":
870 (mode
==_LK_LOCK
)?"_LK_LOCK":
871 (mode
==_LK_NBLCK
)?"_LK_NBLCK":
872 (mode
==_LK_RLCK
)?"_LK_RLCK":
873 (mode
==_LK_NBRLCK
)?"_LK_NBRLCK":
876 if ((cur_locn
= SetFilePointer(hand
, 0L, NULL
, SEEK_CUR
)) == INVALID_SET_FILE_POINTER
)
878 FIXME ("Seek failed\n");
879 *_errno() = EINVAL
; /* FIXME */
882 if (mode
== _LK_LOCK
|| mode
== _LK_RLCK
)
885 ret
= 1; /* just to satisfy gcc */
888 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
893 else if (mode
== _LK_UNLCK
)
894 ret
= UnlockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
896 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
897 /* FIXME - what about error settings? */
901 /*********************************************************************
904 int CDECL
fseek(FILE* file
, long offset
, int whence
)
906 /* Flush output if needed */
907 if(file
->_flag
& _IOWRT
)
910 if(whence
== SEEK_CUR
&& file
->_flag
& _IOREAD
) {
911 offset
-= file
->_cnt
;
913 /* Discard buffered input */
915 file
->_ptr
= file
->_base
;
916 /* Reset direction of i/o */
917 if(file
->_flag
& _IORW
) {
918 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
920 /* Clear end of file flag */
921 file
->_flag
&= ~_IOEOF
;
922 return (_lseek(file
->_file
,offset
,whence
) == -1)?-1:0;
925 /*********************************************************************
928 int CDECL
_chsize(int fd
, long size
)
934 TRACE("(fd=%d, size=%ld)\n", fd
, size
);
939 if (handle
!= INVALID_HANDLE_VALUE
)
941 /* save the current file pointer */
942 cur
= _lseek(fd
, 0, SEEK_CUR
);
945 pos
= _lseek(fd
, size
, SEEK_SET
);
948 ret
= SetEndOfFile(handle
);
949 if (!ret
) _dosmaperr(GetLastError());
952 /* restore the file pointer */
953 _lseek(fd
, cur
, SEEK_SET
);
961 /*********************************************************************
962 * clearerr (MSVCRT.@)
964 void CDECL
clearerr(FILE* file
)
966 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
967 file
->_flag
&= ~(_IOERR
| _IOEOF
);
970 /*********************************************************************
973 void CDECL
rewind(FILE* file
)
975 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
976 fseek(file
, 0L, SEEK_SET
);
980 static int get_flags(const char* mode
, int *open_flags
, int* stream_flags
)
982 int plus
= strchr(mode
, '+') != NULL
;
987 *open_flags
= plus
? _O_RDWR
: _O_RDONLY
;
988 *stream_flags
= plus
? _IORW
: _IOREAD
;
991 *open_flags
= _O_CREAT
| _O_TRUNC
| (plus
? _O_RDWR
: _O_WRONLY
);
992 *stream_flags
= plus
? _IORW
: _IOWRT
;
995 *open_flags
= _O_CREAT
| _O_APPEND
| (plus
? _O_RDWR
: _O_WRONLY
);
996 *stream_flags
= plus
? _IORW
: _IOWRT
;
1006 *open_flags
|= _O_BINARY
;
1007 *open_flags
&= ~_O_TEXT
;
1010 *open_flags
|= _O_TEXT
;
1011 *open_flags
&= ~_O_BINARY
;
1016 FIXME(":unknown flag %c not supported\n",mode
[-1]);
1021 /*********************************************************************
1022 * _fdopen (MSVCRT.@)
1024 FILE* CDECL
_fdopen(int fd
, const char *mode
)
1026 int open_flags
, stream_flags
;
1029 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1) return NULL
;
1032 if (!(file
= alloc_fp()))
1034 else if (init_fp(file
, fd
, stream_flags
) == -1)
1039 else TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
1045 /*********************************************************************
1046 * _wfdopen (MSVCRT.@)
1048 FILE* CDECL
_wfdopen(int fd
, const wchar_t *mode
)
1050 unsigned mlen
= strlenW(mode
);
1051 char *modea
= calloc(mlen
+ 1, 1);
1053 int open_flags
, stream_flags
;
1056 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
1058 if (get_flags(modea
, &open_flags
, &stream_flags
) == -1)
1064 if (!(file
= alloc_fp()))
1066 else if (init_fp(file
, fd
, stream_flags
) == -1)
1074 rewind(file
); /* FIXME: is this needed ??? */
1075 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,debugstr_w(mode
),file
);
1083 /*********************************************************************
1084 * _filelength (MSVCRT.@)
1086 LONG CDECL
_filelength(int fd
)
1088 LONG curPos
= _lseek(fd
, 0, SEEK_CUR
);
1091 LONG endPos
= _lseek(fd
, 0, SEEK_END
);
1094 if (endPos
!= curPos
)
1095 _lseek(fd
, curPos
, SEEK_SET
);
1102 /*********************************************************************
1103 * _filelengthi64 (MSVCRT.@)
1105 __int64 CDECL
_filelengthi64(int fd
)
1107 __int64 curPos
= _lseeki64(fd
, 0, SEEK_CUR
);
1110 __int64 endPos
= _lseeki64(fd
, 0, SEEK_END
);
1113 if (endPos
!= curPos
)
1114 _lseeki64(fd
, curPos
, SEEK_SET
);
1121 /*********************************************************************
1122 * _fileno (MSVCRT.@)
1124 int CDECL
_fileno(FILE* file
)
1126 TRACE(":FILE* (%p) fd (%d)\n",file
,file
->_file
);
1130 /*********************************************************************
1131 * _futime (MSVCRT.@)
1133 int CDECL
_futime(int fd
, struct _utimbuf
*t
)
1135 HANDLE hand
= fdtoh(fd
);
1138 if (hand
== INVALID_HANDLE_VALUE
)
1145 RtlSecondsSince1970ToTime(currTime
, (LARGE_INTEGER
*)&at
);
1150 RtlSecondsSince1970ToTime(t
->actime
, (LARGE_INTEGER
*)&at
);
1151 if (t
->actime
== t
->modtime
)
1154 RtlSecondsSince1970ToTime(t
->modtime
, (LARGE_INTEGER
*)&wt
);
1157 if (!SetFileTime(hand
, NULL
, &at
, &wt
))
1159 _dosmaperr(GetLastError());
1165 /*********************************************************************
1166 * _get_osfhandle (MSVCRT.@)
1168 intptr_t CDECL
_get_osfhandle(int fd
)
1170 HANDLE hand
= fdtoh(fd
);
1171 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1173 return (long)(LONG_PTR
)hand
;
1176 /*********************************************************************
1177 * _isatty (MSVCRT.@)
1179 int CDECL
_isatty(int fd
)
1181 HANDLE hand
= fdtoh(fd
);
1183 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1184 if (hand
== INVALID_HANDLE_VALUE
)
1187 return GetFileType(hand
) == FILE_TYPE_CHAR
? 1 : 0;
1190 /*********************************************************************
1191 * _mktemp (MSVCRT.@)
1193 char * CDECL
_mktemp(char *pattern
)
1196 char *retVal
= pattern
;
1201 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1205 id
= GetCurrentProcessId();
1209 int tempNum
= id
/ 10;
1210 *pattern
-- = id
- (tempNum
* 10) + '0';
1216 *pattern
= letter
++;
1217 if (GetFileAttributesA(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1218 GetLastError() == ERROR_FILE_NOT_FOUND
)
1220 } while(letter
<= 'z');
1224 /*********************************************************************
1225 * _wmktemp (MSVCRT.@)
1227 wchar_t * CDECL
_wmktemp(wchar_t *pattern
)
1230 wchar_t *retVal
= pattern
;
1232 wchar_t letter
= 'a';
1235 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1239 id
= GetCurrentProcessId();
1243 int tempNum
= id
/ 10;
1244 *pattern
-- = id
- (tempNum
* 10) + '0';
1250 if (GetFileAttributesW(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1251 GetLastError() == ERROR_FILE_NOT_FOUND
)
1253 *pattern
= letter
++;
1254 } while(letter
!= '|');
1258 /*static */unsigned split_oflags(unsigned oflags
)
1261 unsigned unsupp
; /* until we support everything */
1263 if (oflags
& _O_APPEND
) wxflags
|= WX_APPEND
;
1264 if (oflags
& _O_BINARY
) {/* Nothing to do */}
1265 else if (oflags
& _O_TEXT
) wxflags
|= WX_TEXT
;
1266 else if (*__p__fmode() & _O_BINARY
) {/* Nothing to do */}
1267 else wxflags
|= WX_TEXT
; /* default to TEXT*/
1268 if (oflags
& _O_NOINHERIT
) wxflags
|= WX_DONTINHERIT
;
1270 if ((unsupp
= oflags
& ~(
1271 _O_BINARY
|_O_TEXT
|_O_APPEND
|
1272 _O_TRUNC
|_O_EXCL
|_O_CREAT
|
1273 _O_RDWR
|_O_WRONLY
|_O_TEMPORARY
|
1275 _O_SEQUENTIAL
|_O_RANDOM
|_O_SHORT_LIVED
1277 ERR(":unsupported oflags 0x%04x\n",unsupp
);
1282 /*********************************************************************
1285 int CDECL
_pipe(int *pfds
, unsigned int psize
, int textmode
)
1288 SECURITY_ATTRIBUTES sa
;
1289 HANDLE readHandle
, writeHandle
;
1297 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
1298 sa
.bInheritHandle
= !(textmode
& _O_NOINHERIT
);
1299 sa
.lpSecurityDescriptor
= NULL
;
1300 if (CreatePipe(&readHandle
, &writeHandle
, &sa
, psize
))
1302 unsigned int wxflags
= split_oflags(textmode
);
1306 fd
= alloc_fd(readHandle
, wxflags
);
1310 fd
= alloc_fd(writeHandle
, wxflags
);
1319 CloseHandle(writeHandle
);
1325 CloseHandle(readHandle
);
1326 CloseHandle(writeHandle
);
1332 _dosmaperr(GetLastError());
1337 /*********************************************************************
1340 int CDECL
_sopen( const char *path
, int oflags
, int shflags
, ... )
1344 DWORD access
= 0, creation
= 0, attrib
;
1348 SECURITY_ATTRIBUTES sa
;
1351 TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n",
1352 path
, oflags
, shflags
);
1354 wxflag
= split_oflags(oflags
);
1355 switch (oflags
& (_O_RDONLY
| _O_WRONLY
| _O_RDWR
))
1357 case _O_RDONLY
: access
|= GENERIC_READ
; break;
1358 case _O_WRONLY
: access
|= GENERIC_WRITE
; break;
1359 case _O_RDWR
: access
|= GENERIC_WRITE
| GENERIC_READ
; break;
1362 if (oflags
& _O_CREAT
)
1364 va_start(ap
, shflags
);
1365 pmode
= va_arg(ap
, int);
1368 if(pmode
& ~(_S_IREAD
| _S_IWRITE
))
1369 FIXME(": pmode 0x%04x ignored\n", pmode
);
1371 WARN(": pmode 0x%04x ignored\n", pmode
);
1373 if (oflags
& _O_EXCL
)
1374 creation
= CREATE_NEW
;
1375 else if (oflags
& _O_TRUNC
)
1376 creation
= CREATE_ALWAYS
;
1378 creation
= OPEN_ALWAYS
;
1380 else /* no _O_CREAT */
1382 if (oflags
& _O_TRUNC
)
1383 creation
= TRUNCATE_EXISTING
;
1385 creation
= OPEN_EXISTING
;
1394 sharing
= FILE_SHARE_READ
;
1397 sharing
= FILE_SHARE_WRITE
;
1400 sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1403 ERR( "Unhandled shflags 0x%x\n", shflags
);
1406 attrib
= FILE_ATTRIBUTE_NORMAL
;
1408 if (oflags
& _O_TEMPORARY
)
1410 attrib
|= FILE_FLAG_DELETE_ON_CLOSE
;
1412 sharing
|= FILE_SHARE_DELETE
;
1415 sa
.nLength
= sizeof( SECURITY_ATTRIBUTES
);
1416 sa
.lpSecurityDescriptor
= NULL
;
1417 sa
.bInheritHandle
= (oflags
& _O_NOINHERIT
) ? FALSE
: TRUE
;
1419 hand
= CreateFileA(path
, access
, sharing
, &sa
, creation
, attrib
, 0);
1421 if (hand
== INVALID_HANDLE_VALUE
) {
1422 WARN(":failed-last error (%d)\n",GetLastError());
1423 _dosmaperr(GetLastError());
1427 fd
= alloc_fd(hand
, wxflag
);
1429 TRACE(":fd (%d) handle (%p)\n",fd
, hand
);
1433 /*********************************************************************
1434 * _wsopen (MSVCRT.@)
1436 int CDECL
_wsopen( const wchar_t* path
, int oflags
, int shflags
, ... )
1438 const unsigned int len
= strlenW(path
);
1439 char *patha
= calloc(len
+ 1,1);
1443 va_start(ap
, shflags
);
1444 pmode
= va_arg(ap
, int);
1447 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1449 int retval
= _sopen(patha
,oflags
,shflags
,pmode
);
1453 _dosmaperr(GetLastError());
1458 /*********************************************************************
1461 int CDECL
_open( const char *path
, int flags
, ... )
1465 if (flags
& _O_CREAT
)
1468 va_start(ap
, flags
);
1469 pmode
= va_arg(ap
, int);
1471 return _sopen( path
, flags
, _SH_DENYNO
, pmode
);
1474 return _sopen( path
, flags
, _SH_DENYNO
);
1477 /*********************************************************************
1480 int CDECL
_wopen(const wchar_t *path
,int flags
,...)
1482 const unsigned int len
= strlenW(path
);
1483 char *patha
= calloc(len
+ 1,1);
1487 va_start(ap
, flags
);
1488 pmode
= va_arg(ap
, int);
1491 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1493 int retval
= _open(patha
,flags
,pmode
);
1498 _dosmaperr(GetLastError());
1502 /*********************************************************************
1505 int CDECL
_creat(const char *path
, int flags
)
1507 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1508 return _open(path
, usedFlags
);
1511 /*********************************************************************
1512 * _wcreat (MSVCRT.@)
1514 int CDECL
_wcreat(const wchar_t *path
, int flags
)
1516 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1517 return _wopen(path
, usedFlags
);
1520 /*********************************************************************
1521 * _open_osfhandle (MSVCRT.@)
1523 int CDECL
_open_osfhandle(intptr_t handle
, int oflags
)
1527 /* _O_RDONLY (0) always matches, so set the read flag
1528 * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
1529 * file, so set the write flag. It also only sets _O_TEXT if it wants
1530 * text - it never sets _O_BINARY.
1532 /* don't let split_oflags() decide the mode if no mode is passed */
1533 if (!(oflags
& (_O_BINARY
| _O_TEXT
)))
1534 oflags
|= _O_BINARY
;
1536 fd
= alloc_fd((HANDLE
)(LONG_PTR
)handle
, split_oflags(oflags
));
1537 TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle
, fd
, oflags
);
1541 /*********************************************************************
1544 int CDECL
_rmtmp(void)
1546 int num_removed
= 0, i
;
1549 for (i
= 3; i
< stream_idx
; i
++)
1550 if (fstreams
[i
] && fstreams
[i
]->_tmpfname
)
1552 fclose(fstreams
[i
]);
1558 TRACE(":removed (%d) temp files\n",num_removed
);
1562 /*********************************************************************
1563 * (internal) remove_cr
1565 * Translate all \r\n to \n inplace.
1566 * return the number of \r removed
1567 * Corner cases required by some apps:
1569 * BUG: should save state across calls somehow, so CR LF that
1570 * straddles buffer boundary gets recognized properly?
1572 static unsigned int remove_cr(char *buf
, unsigned int count
)
1576 for (i
=0, j
=0; j
< count
; j
++)
1577 if ((buf
[j
] != '\r') || ((j
+1) < count
&& buf
[j
+1] != '\n'))
1583 /*********************************************************************
1586 static int read_i(int fd
, void *buf
, unsigned int count
)
1589 char *bufstart
= buf
;
1590 HANDLE hand
= fdtoh(fd
);
1592 if (fdesc
[fd
].wxflag
& WX_READEOF
) {
1593 fdesc
[fd
].wxflag
|= WX_ATEOF
;
1594 TRACE("already at EOF, returning 0\n");
1597 /* Don't trace small reads, it gets *very* annoying */
1599 TRACE(":fd (%d) handle (%p) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1600 if (hand
== INVALID_HANDLE_VALUE
)
1603 /* Reading single bytes in O_TEXT mode makes things slow
1604 * So read big chunks
1606 if (ReadFile(hand
, bufstart
, count
, &num_read
, NULL
))
1608 if (fdesc
[fd
].wxflag
& WX_TEXT
)
1611 /* in text mode, a ctrl-z signals EOF */
1612 for (i
=0; i
<num_read
; i
++)
1614 if (bufstart
[i
] == 0x1a)
1617 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1618 TRACE(":^Z EOF %s\n",debugstr_an(buf
,num_read
));
1623 if (count
!= 0 && num_read
== 0)
1625 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1626 TRACE(":EOF %s\n",debugstr_an(buf
,num_read
));
1631 if (GetLastError() == ERROR_BROKEN_PIPE
)
1633 TRACE(":end-of-pipe\n");
1634 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1639 TRACE(":failed-last error (%d)\n",GetLastError());
1645 TRACE("(%u), %s\n",num_read
,debugstr_an(buf
, num_read
));
1649 /*********************************************************************
1652 int CDECL
_read(int fd
, void *buf
, unsigned int count
)
1655 num_read
= read_i(fd
, buf
, count
);
1656 if (num_read
>0 && fdesc
[fd
].wxflag
& WX_TEXT
)
1658 num_read
-= remove_cr(buf
,num_read
);
1663 /*********************************************************************
1664 * _setmode (MSVCRT.@)
1666 int CDECL
_setmode(int fd
,int mode
)
1668 int ret
= fdesc
[fd
].wxflag
& WX_TEXT
? _O_TEXT
: _O_BINARY
;
1669 if (mode
& (~(_O_TEXT
|_O_BINARY
)))
1670 FIXME("fd (%d) mode (0x%08x) unknown\n",fd
,mode
);
1671 if ((mode
& _O_TEXT
) == _O_TEXT
)
1672 fdesc
[fd
].wxflag
|= WX_TEXT
;
1674 fdesc
[fd
].wxflag
&= ~WX_TEXT
;
1678 /*********************************************************************
1681 long CDECL
_tell(int fd
)
1683 return _lseek(fd
, 0, SEEK_CUR
);
1686 /*********************************************************************
1687 * _telli64 (MSVCRT.@)
1689 __int64 CDECL
_telli64(int fd
)
1691 return _lseeki64(fd
, 0, SEEK_CUR
);
1694 /*********************************************************************
1695 * _tempnam (MSVCRT.@)
1697 char * CDECL
_tempnam(const char *dir
, const char *prefix
)
1699 char tmpbuf
[MAX_PATH
];
1700 const char *tmp_dir
= getenv("TMP");
1702 if (tmp_dir
) dir
= tmp_dir
;
1704 TRACE("dir (%s) prefix (%s)\n",dir
,prefix
);
1705 if (GetTempFileNameA(dir
,prefix
,0,tmpbuf
))
1707 TRACE("got name (%s)\n",tmpbuf
);
1708 DeleteFileA(tmpbuf
);
1709 return _strdup(tmpbuf
);
1711 TRACE("failed (%d)\n",GetLastError());
1715 /*********************************************************************
1716 * _wtempnam (MSVCRT.@)
1718 wchar_t * CDECL
_wtempnam(const wchar_t *dir
, const wchar_t *prefix
)
1720 wchar_t tmpbuf
[MAX_PATH
];
1722 TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir
),debugstr_w(prefix
));
1723 if (GetTempFileNameW(dir
,prefix
,0,tmpbuf
))
1725 TRACE("got name (%s)\n",debugstr_w(tmpbuf
));
1726 DeleteFileW(tmpbuf
);
1727 return _wcsdup(tmpbuf
);
1729 TRACE("failed (%d)\n",GetLastError());
1733 /*********************************************************************
1736 int CDECL
_umask(int umask
)
1738 int old_umask
= umask
;
1739 TRACE("(%d)\n",umask
);
1740 MSVCRT_umask
= umask
;
1744 /*********************************************************************
1747 int CDECL
_utime(const char* path
, struct _utimbuf
*t
)
1749 int fd
= _open(path
, _O_WRONLY
| _O_BINARY
);
1753 int retVal
= _futime(fd
, t
);
1760 /*********************************************************************
1761 * _wutime (MSVCRT.@)
1763 int CDECL
_wutime(const wchar_t* path
, struct _utimbuf
*t
)
1765 int fd
= _wopen(path
, _O_WRONLY
| _O_BINARY
);
1769 int retVal
= _futime(fd
, t
);
1776 /*********************************************************************
1779 int CDECL
_write(int fd
, const void* buf
, unsigned int count
)
1782 HANDLE hand
= fdtoh(fd
);
1784 /* Don't trace small writes, it gets *very* annoying */
1787 TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1789 if (hand
== INVALID_HANDLE_VALUE
)
1795 /* If appending, go to EOF */
1796 if (fdesc
[fd
].wxflag
& WX_APPEND
)
1797 _lseek(fd
, 0, FILE_END
);
1799 if (!(fdesc
[fd
].wxflag
& WX_TEXT
))
1801 if (WriteFile(hand
, buf
, count
, &num_written
, NULL
)
1802 && (num_written
== count
))
1804 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd
,
1805 hand
, GetLastError());
1810 unsigned int i
, j
, nr_lf
;
1813 const char *s
= (const char *)buf
, *buf_start
= (const char *)buf
;
1814 /* find number of \n ( without preceding \r ) */
1815 for ( nr_lf
=0,i
= 0; i
<count
; i
++)
1820 /*if ((i >1) && (s[i-1] == '\r')) nr_lf--; */
1825 if ((q
= p
= malloc(count
+ nr_lf
)))
1827 for (s
= (const char *)buf
, i
= 0, j
= 0; i
< count
; i
++)
1832 /*if ((i >1) && (s[i-1] == '\r'))j--;*/
1839 FIXME("Malloc failed\n");
1847 if ((WriteFile(hand
, q
, count
+nr_lf
, &num_written
, NULL
) == 0 ) || (num_written
!= count
+nr_lf
))
1849 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
1850 fd
, hand
, GetLastError(), num_written
);
1854 return s
- buf_start
;
1866 /*********************************************************************
1869 int CDECL
_putw(int val
, FILE* file
)
1872 len
= _write(file
->_file
, &val
, sizeof(val
));
1873 if (len
== sizeof(val
)) return val
;
1874 file
->_flag
|= _IOERR
;
1878 /*********************************************************************
1881 int CDECL
fclose(FILE* file
)
1886 free(file
->_tmpfname
);
1887 file
->_tmpfname
= NULL
;
1888 /* flush stdio buffers */
1889 if(file
->_flag
& _IOWRT
)
1891 if(file
->_flag
& _IOMYBUF
)
1894 r
=_close(file
->_file
);
1898 return ((r
== -1) || (flag
& _IOERR
) ? EOF
: 0);
1901 /*********************************************************************
1904 int CDECL
feof(FILE* file
)
1906 return file
->_flag
& _IOEOF
;
1909 /*********************************************************************
1912 int CDECL
ferror(FILE* file
)
1914 return file
->_flag
& _IOERR
;
1917 /*********************************************************************
1918 * _filbuf (MSVCRT.@)
1920 int CDECL
_filbuf(FILE* file
)
1922 /* Allocate buffer if needed */
1923 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
) ) {
1926 if(!(file
->_flag
& _IOREAD
)) {
1927 if(file
->_flag
& _IORW
) {
1928 file
->_flag
|= _IOREAD
;
1933 if(file
->_flag
& _IONBF
) {
1936 if ((r
= read_i(file
->_file
,&c
,1)) != 1) {
1937 file
->_flag
|= (r
== 0) ? _IOEOF
: _IOERR
;
1942 file
->_cnt
= read_i(file
->_file
, file
->_base
, file
->_bufsiz
);
1944 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
1949 file
->_ptr
= file
->_base
+1;
1950 return *(unsigned char *)file
->_base
;
1954 /*********************************************************************
1957 int CDECL
fgetc(FILE* file
)
1964 i
= (unsigned char *)file
->_ptr
++;
1968 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
)
1969 || ((j
!= '\r') || (file
->_cnt
&& file
->_ptr
[0] != '\n')))
1974 /*********************************************************************
1975 * _fgetchar (MSVCRT.@)
1977 int CDECL
_fgetchar(void)
1979 return fgetc(stdin
);
1982 /*********************************************************************
1985 char * CDECL
fgets(char *s
, int size
, FILE* file
)
1988 char * buf_start
= s
;
1990 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
1991 file
,file
->_file
,s
,size
);
1993 while ((size
>1) && (cc
= fgetc(file
)) != EOF
&& cc
!= '\n')
1998 if ((cc
== EOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
2000 TRACE(":nothing read\n");
2003 if ((cc
!= EOF
) && (size
> 1))
2006 TRACE(":got %s\n", debugstr_a(buf_start
));
2010 /*********************************************************************
2013 * In _O_TEXT mode, multibyte characters are read from the file, dropping
2014 * the CR from CR/LF combinations
2016 wint_t CDECL
fgetwc(FILE* file
)
2020 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2026 for(i
=0; i
<sizeof(wc
); i
++)
2039 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
2050 if ((*__p___mb_cur_max() > 1) && isleadbyte(c
))
2052 FIXME("Treat Multibyte characters\n");
2060 /*********************************************************************
2063 int CDECL
_getw(FILE* file
)
2068 for (j
=0; j
<sizeof(int); j
++) {
2071 file
->_flag
|= _IOEOF
;
2079 /*********************************************************************
2082 wint_t CDECL
getwc(FILE* file
)
2084 return fgetwc(file
);
2087 /*********************************************************************
2088 * _fgetwchar (MSVCRT.@)
2090 wint_t CDECL
_fgetwchar(void)
2092 return fgetwc(stdin
);
2095 /*********************************************************************
2096 * getwchar (MSVCRT.@)
2098 wint_t CDECL
getwchar(void)
2100 return _fgetwchar();
2103 /*********************************************************************
2106 wchar_t * CDECL
fgetws(wchar_t *s
, int size
, FILE* file
)
2109 wchar_t * buf_start
= s
;
2111 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
2112 file
,file
->_file
,s
,size
);
2114 while ((size
>1) && (cc
= fgetwc(file
)) != WEOF
&& cc
!= '\n')
2119 if ((cc
== WEOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
2121 TRACE(":nothing read\n");
2124 if ((cc
!= WEOF
) && (size
> 1))
2127 TRACE(":got %s\n", debugstr_w(buf_start
));
2131 /*********************************************************************
2134 size_t CDECL
fwrite(const void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2136 size_t wrcnt
=size
* nmemb
;
2141 int pcnt
=(file
->_cnt
>wrcnt
)? wrcnt
: file
->_cnt
;
2142 memcpy(file
->_ptr
, ptr
, pcnt
);
2147 ptr
= (const char*)ptr
+ pcnt
;
2148 } else if(!(file
->_flag
& _IOWRT
)) {
2149 if(file
->_flag
& _IORW
) {
2150 file
->_flag
|= _IOWRT
;
2156 int res
=flush_buffer(file
);
2158 int pwritten
= _write(file
->_file
, ptr
, wrcnt
);
2161 file
->_flag
|= _IOERR
;
2164 written
+= pwritten
;
2167 return written
/ size
;
2170 /*********************************************************************
2173 wint_t CDECL
fputwc(wint_t wc
, FILE* file
)
2176 if (fwrite( &mwc
, sizeof(mwc
), 1, file
) != 1)
2181 /*********************************************************************
2182 * _fputwchar (MSVCRT.@)
2184 wint_t CDECL
_fputwchar(wint_t wc
)
2186 return fputwc(wc
, stdout
);
2189 /*********************************************************************
2190 * _fsopen (MSVCRT.@)
2192 FILE * CDECL
_fsopen(const char *path
, const char *mode
, int share
)
2195 int open_flags
, stream_flags
, fd
;
2197 TRACE("(%s,%s)\n",path
,mode
);
2199 /* map mode string to open() flags. "man fopen" for possibilities. */
2200 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2204 fd
= _sopen(path
, open_flags
, share
, _S_IREAD
| _S_IWRITE
);
2207 else if ((file
= alloc_fp()) && init_fp(file
, fd
, stream_flags
)
2209 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
2216 TRACE(":got (%p)\n",file
);
2217 if (fd
>= 0 && !file
)
2223 /*********************************************************************
2224 * _wfsopen (MSVCRT.@)
2226 FILE * CDECL
_wfsopen(const wchar_t *path
, const wchar_t *mode
, int share
)
2228 const unsigned int plen
= strlenW(path
), mlen
= strlenW(mode
);
2229 char *patha
= calloc(plen
+ 1, 1);
2230 char *modea
= calloc(mlen
+ 1, 1);
2232 TRACE("(%s,%s)\n",debugstr_w(path
),debugstr_w(mode
));
2234 if (patha
&& modea
&&
2235 WideCharToMultiByte(CP_ACP
,0,path
,plen
,patha
,plen
,NULL
,NULL
) &&
2236 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
2238 FILE *retval
= _fsopen(patha
,modea
,share
);
2245 _dosmaperr(GetLastError());
2249 /*********************************************************************
2252 FILE * CDECL
fopen(const char *path
, const char *mode
)
2254 return _fsopen( path
, mode
, _SH_DENYNO
);
2257 /*********************************************************************
2258 * _wfopen (MSVCRT.@)
2260 FILE * CDECL
_wfopen(const wchar_t *path
, const wchar_t *mode
)
2262 return _wfsopen( path
, mode
, _SH_DENYNO
);
2265 /* fputc calls _flsbuf which calls fputc */
2266 int CDECL
_flsbuf(int c
, FILE* file
);
2268 /*********************************************************************
2271 int CDECL
fputc(int c
, FILE* file
)
2278 int res
= flush_buffer(file
);
2279 return res
? res
: c
;
2284 return _flsbuf(c
, file
);
2288 /*********************************************************************
2289 * _flsbuf (MSVCRT.@)
2291 int CDECL
_flsbuf(int c
, FILE* file
)
2293 /* Flush output buffer */
2294 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2297 if(!(file
->_flag
& _IOWRT
)) {
2298 if(file
->_flag
& _IORW
) {
2299 file
->_flag
|= _IOWRT
;
2305 int res
=flush_buffer(file
);
2306 return res
?res
: fputc(c
, file
);
2310 len
= _write(file
->_file
, &cc
, 1);
2311 if (len
== 1) return c
& 0xff;
2312 file
->_flag
|= _IOERR
;
2317 /*********************************************************************
2318 * _fputchar (MSVCRT.@)
2320 int CDECL
_fputchar(int c
)
2322 return fputc(c
, stdout
);
2325 /*********************************************************************
2328 size_t CDECL
fread(void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2329 { size_t rcnt
=size
* nmemb
;
2336 /* first buffered data */
2338 int pcnt
= (rcnt
>file
->_cnt
)? file
->_cnt
:rcnt
;
2339 memcpy(ptr
, file
->_ptr
, pcnt
);
2342 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
)
2343 pcnt
-= remove_cr(ptr
,pcnt
);
2346 ptr
= (char*)ptr
+ pcnt
;
2347 } else if(!(file
->_flag
& _IOREAD
)) {
2348 if(file
->_flag
& _IORW
) {
2349 file
->_flag
|= _IOREAD
;
2356 /* Fill the buffer on small reads.
2357 * TODO: Use a better buffering strategy.
2359 if (!file
->_cnt
&& size
*nmemb
<= BUFSIZ
/2 && !(file
->_flag
& _IONBF
)) {
2360 if (file
->_bufsiz
== 0) {
2363 file
->_cnt
= _read(file
->_file
, file
->_base
, file
->_bufsiz
);
2364 file
->_ptr
= file
->_base
;
2365 i
= (file
->_cnt
<rcnt
) ? file
->_cnt
: rcnt
;
2366 /* If the buffer fill reaches eof but fread wouldn't, clear eof. */
2367 if (i
> 0 && i
< file
->_cnt
) {
2368 fdesc
[file
->_file
].wxflag
&= ~WX_ATEOF
;
2369 file
->_flag
&= ~_IOEOF
;
2372 memcpy(ptr
, file
->_ptr
, i
);
2377 i
= _read(file
->_file
,ptr
, rcnt
);
2381 ptr
= (char *)ptr
+i
;
2382 /* expose feof condition in the flags
2383 * MFC tests file->_flag for feof, and doesn't call feof())
2385 if ( fdesc
[file
->_file
].wxflag
& WX_ATEOF
)
2386 file
->_flag
|= _IOEOF
;
2389 file
->_flag
|= _IOERR
;
2399 /*********************************************************************
2400 * freopen (MSVCRT.@)
2403 FILE* CDECL
freopen(const char *path
, const char *mode
,FILE* file
)
2405 int open_flags
, stream_flags
, fd
;
2407 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n",path
,mode
,file
,file
->_file
);
2410 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2415 /* map mode string to open() flags. "man fopen" for possibilities. */
2416 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2420 fd
= _open(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2423 else if (init_fp(file
, fd
, stream_flags
) == -1)
2426 WARN(":failed-last error (%d)\n",GetLastError());
2427 _dosmaperr(GetLastError());
2436 /*********************************************************************
2437 * wfreopen (MSVCRT.@)
2440 FILE* CDECL
_wfreopen(const wchar_t *path
, const wchar_t *mode
,FILE* file
)
2442 int open_flags
, stream_flags
, fd
;
2444 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path
), debugstr_w(mode
), file
, file
->_file
);
2447 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2452 /* map mode string to open() flags. "man fopen" for possibilities. */
2453 if (get_flags((char*)mode
, &open_flags
, &stream_flags
) == -1)
2457 fd
= _wopen(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2460 else if (init_fp(file
, fd
, stream_flags
) == -1)
2463 WARN(":failed-last error (%d)\n",GetLastError());
2464 _dosmaperr(GetLastError());
2473 /*********************************************************************
2474 * fsetpos (MSVCRT.@)
2476 int CDECL
fsetpos(FILE* file
, const fpos_t *pos
)
2478 /* Note that all this has been lifted 'as is' from fseek */
2479 if(file
->_flag
& _IOWRT
)
2482 /* Discard buffered input */
2484 file
->_ptr
= file
->_base
;
2486 /* Reset direction of i/o */
2487 if(file
->_flag
& _IORW
) {
2488 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
2491 return (_lseeki64(file
->_file
,*pos
,SEEK_SET
) == -1) ? -1 : 0;
2494 /*********************************************************************
2497 LONG CDECL
ftell(FILE* file
)
2502 if( file
->_flag
& _IOWRT
) {
2503 off
= file
->_ptr
- file
->_base
;
2508 pos
= _tell(file
->_file
);
2509 if(pos
== -1) return pos
;
2513 /*********************************************************************
2514 * fgetpos (MSVCRT.@)
2516 int CDECL
fgetpos(FILE* file
, fpos_t *pos
)
2518 /* This code has been lifted form the ftell function */
2521 *pos
= _lseeki64(file
->_file
,0,SEEK_CUR
);
2523 if (*pos
== -1) return -1;
2526 if( file
->_flag
& _IOWRT
) {
2527 off
= file
->_ptr
- file
->_base
;
2537 /*********************************************************************
2540 int CDECL
fputs(const char *s
, FILE* file
)
2542 size_t i
, len
= strlen(s
);
2543 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2544 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2545 for (i
=0; i
<len
; i
++)
2546 if (fputc(s
[i
], file
) == EOF
)
2551 /*********************************************************************
2554 int CDECL
fputws(const wchar_t *s
, FILE* file
)
2556 size_t i
, len
= strlenW(s
);
2557 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2558 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2559 for (i
=0; i
<len
; i
++)
2561 if ((s
[i
] == '\n') && (fputc('\r', file
) == EOF
))
2563 if (fputwc(s
[i
], file
) == WEOF
)
2569 /*********************************************************************
2570 * getchar (MSVCRT.@)
2572 int CDECL
getchar(void)
2574 return fgetc(stdin
);
2577 /*********************************************************************
2580 int CDECL
getc(FILE* file
)
2585 /*********************************************************************
2588 char * CDECL
gets(char *buf
)
2591 char * buf_start
= buf
;
2593 for(cc
= fgetc(stdin
); cc
!= EOF
&& cc
!= '\n';
2595 if(cc
!= '\r') *buf
++ = (char)cc
;
2599 TRACE("got '%s'\n", buf_start
);
2603 /*********************************************************************
2606 wchar_t* CDECL
_getws(wchar_t* buf
)
2611 for (cc
= fgetwc(stdin
); cc
!= WEOF
&& cc
!= '\n';
2615 *buf
++ = (wchar_t)cc
;
2619 TRACE("got %s\n", debugstr_w(ws
));
2623 /*********************************************************************
2626 int CDECL
putc(int c
, FILE* file
)
2628 return fputc(c
, file
);
2631 /*********************************************************************
2632 * putchar (MSVCRT.@)
2634 int CDECL
putchar(int c
)
2636 return fputc(c
, stdout
);
2639 /*********************************************************************
2642 int CDECL
puts(const char *s
)
2644 size_t len
= strlen(s
);
2645 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2646 return fwrite("\n",1,1,stdout
) == 1 ? 0 : EOF
;
2649 /*********************************************************************
2652 int CDECL
_putws(const wchar_t *s
)
2654 static const wchar_t nl
= '\n';
2655 size_t len
= strlenW(s
);
2656 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2657 return fwrite(&nl
,sizeof(nl
),1,stdout
) == 1 ? 0 : EOF
;
2660 /*********************************************************************
2663 int CDECL
remove(const char *path
)
2665 TRACE("(%s)\n",path
);
2666 if (DeleteFileA(path
))
2668 TRACE(":failed (%d)\n",GetLastError());
2669 _dosmaperr(GetLastError());
2673 /*********************************************************************
2674 * _wremove (MSVCRT.@)
2676 int CDECL
_wremove(const wchar_t *path
)
2678 TRACE("(%s)\n",debugstr_w(path
));
2679 if (DeleteFileW(path
))
2681 TRACE(":failed (%d)\n",GetLastError());
2682 _dosmaperr(GetLastError());
2686 /*********************************************************************
2689 int CDECL
rename(const char *oldpath
,const char *newpath
)
2691 TRACE(":from %s to %s\n",oldpath
,newpath
);
2692 if (MoveFileExA(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2694 TRACE(":failed (%d)\n",GetLastError());
2695 _dosmaperr(GetLastError());
2699 /*********************************************************************
2700 * _wrename (MSVCRT.@)
2702 int CDECL
_wrename(const wchar_t *oldpath
,const wchar_t *newpath
)
2704 TRACE(":from %s to %s\n",debugstr_w(oldpath
),debugstr_w(newpath
));
2705 if (MoveFileExW(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2707 TRACE(":failed (%d)\n",GetLastError());
2708 _dosmaperr(GetLastError());
2712 /*********************************************************************
2713 * setvbuf (MSVCRT.@)
2715 int CDECL
setvbuf(FILE* file
, char *buf
, int mode
, size_t size
)
2717 /* TODO: Check if file busy */
2723 if(mode
== _IOFBF
) {
2724 file
->_flag
&= ~_IONBF
;
2725 file
->_base
= file
->_ptr
= buf
;
2727 file
->_bufsiz
= size
;
2730 file
->_flag
|= _IONBF
;
2735 /*********************************************************************
2738 void CDECL
setbuf(FILE* file
, char *buf
)
2740 setvbuf(file
, buf
, buf
? _IOFBF
: _IONBF
, BUFSIZ
);
2743 /*********************************************************************
2746 char * CDECL
tmpnam(char *s
)
2754 int_to_base32(GetCurrentProcessId(), tmpstr
);
2755 p
= s
+ sprintf(s
, "\\s%s.", tmpstr
);
2756 for (count
= 0; count
< TMP_MAX
; count
++)
2758 int_to_base32(unique
++, tmpstr
);
2760 if (GetFileAttributesA(s
) == INVALID_FILE_ATTRIBUTES
&&
2761 GetLastError() == ERROR_FILE_NOT_FOUND
)
2767 /*********************************************************************
2768 * wtmpnam (MSVCRT.@)
2770 wchar_t * CDECL
_wtmpnam(wchar_t *s
)
2772 ERR("UNIMPLEMENTED!\n");
2776 /*********************************************************************
2777 * tmpfile (MSVCRT.@)
2779 FILE* CDECL
tmpfile(void)
2781 char *filename
= tmpnam(NULL
);
2786 fd
= _open(filename
, _O_CREAT
| _O_BINARY
| _O_RDWR
| _O_TEMPORARY
);
2787 if (fd
!= -1 && (file
= alloc_fp()))
2789 if (init_fp(file
, fd
, _O_RDWR
) == -1)
2794 else file
->_tmpfname
= _strdup(filename
);
2800 /*********************************************************************
2801 * vfprintf (MSVCRT.@)
2803 int CDECL
vfprintf(FILE* file
, const char *format
, va_list valist
)
2805 char buf
[2048], *mem
= buf
;
2806 int written
, resize
= sizeof(buf
), retval
;
2807 /* There are two conventions for vsnprintf failing:
2808 * Return -1 if we truncated, or
2809 * Return the number of bytes that would have been written
2810 * The code below handles both cases
2812 while ((written
= _vsnprintf(mem
, resize
, format
, valist
)) == -1 ||
2815 resize
= (written
== -1 ? resize
* 2 : written
+ 1);
2818 if (!(mem
= malloc(resize
)))
2821 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2827 /*********************************************************************
2828 * vfwprintf (MSVCRT.@)
2830 * Is final char included in written (then resize is too big) or not
2831 * (then we must test for equality too)?
2833 int CDECL
vfwprintf(FILE* file
, const wchar_t *format
, va_list valist
)
2835 wchar_t buf
[2048], *mem
= buf
;
2836 int written
, resize
= sizeof(buf
) / sizeof(wchar_t), retval
;
2837 /* See vfprintf comments */
2838 while ((written
= _vsnwprintf(mem
, resize
, format
, valist
)) == -1 ||
2841 resize
= (written
== -1 ? resize
* 2 : written
+ sizeof(wchar_t));
2844 if (!(mem
= malloc(resize
*sizeof(*mem
))))
2848 /* Check if outputting to a text-file */
2849 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
)
2851 /* Convert each character and stop at the first invalid character. Behavior verified by tests under WinXP SP2 */
2852 char chMultiByte
[MB_LEN_MAX
];
2858 for (p
= mem
; *p
; p
++)
2860 nReturn
= wctomb(chMultiByte
, *p
);
2865 retval
+= fwrite(chMultiByte
, 1, nReturn
, file
);
2870 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2879 /*********************************************************************
2880 * vprintf (MSVCRT.@)
2882 int CDECL
vprintf(const char *format
, va_list valist
)
2884 return vfprintf(stdout
,format
,valist
);
2887 /*********************************************************************
2888 * vwprintf (MSVCRT.@)
2890 int CDECL
vwprintf(const wchar_t *format
, va_list valist
)
2892 return vfwprintf(stdout
,format
,valist
);
2895 /*********************************************************************
2896 * fprintf (MSVCRT.@)
2898 int CDECL
fprintf(FILE* file
, const char *format
, ...)
2902 va_start(valist
, format
);
2903 res
= vfprintf(file
, format
, valist
);
2908 /*********************************************************************
2909 * fwprintf (MSVCRT.@)
2911 int CDECL
fwprintf(FILE* file
, const wchar_t *format
, ...)
2915 va_start(valist
, format
);
2916 res
= vfwprintf(file
, format
, valist
);
2921 /*********************************************************************
2924 int CDECL
printf(const char *format
, ...)
2928 va_start(valist
, format
);
2929 res
= vfprintf(stdout
, format
, valist
);
2934 /*********************************************************************
2937 int CDECL
ungetc(int c
, FILE * file
)
2941 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2945 if(file
->_ptr
>file
->_base
) {
2955 /*********************************************************************
2956 * ungetwc (MSVCRT.@)
2958 wint_t CDECL
ungetwc(wint_t wc
, FILE * file
)
2961 char * pp
= (char *)&mwc
;
2963 for(i
=sizeof(wchar_t)-1;i
>=0;i
--) {
2964 if(pp
[i
] != ungetc(pp
[i
],file
))
2970 /*********************************************************************
2971 * wprintf (MSVCRT.@)
2973 int CDECL
wprintf(const wchar_t *format
, ...)
2977 va_start(valist
, format
);
2978 res
= vwprintf(format
, valist
);
2983 /*********************************************************************
2984 * _getmaxstdio (MSVCRT.@)
2986 int CDECL
_getmaxstdio(void)
2988 FIXME("stub, always returns 512\n");
2992 /*********************************************************************
2993 * _setmaxstdio_ (MSVCRT.@)
2995 int CDECL
_setmaxstdio(int newmax
)
3002 FIXME("stub: setting new maximum for number of simultaneously open files not implemented,returning %d\n",res
);
3006 /*********************************************************************
3007 * __pioinfo (MSVCRT.@)
3008 * FIXME: see MAX_FILES define.
3010 ioinfo
* __pioinfo
[] = { /* array of pointers to ioinfo arrays [64] */
3011 &fdesc
[0 * 64], &fdesc
[1 * 64], &fdesc
[2 * 64],
3012 &fdesc
[3 * 64], &fdesc
[4 * 64], &fdesc
[5 * 64],
3013 &fdesc
[6 * 64], &fdesc
[7 * 64], &fdesc
[8 * 64],
3014 &fdesc
[9 * 64], &fdesc
[10 * 64], &fdesc
[11 * 64],
3015 &fdesc
[12 * 64], &fdesc
[13 * 64], &fdesc
[14 * 64],
3016 &fdesc
[15 * 64], &fdesc
[16 * 64], &fdesc
[17 * 64],
3017 &fdesc
[18 * 64], &fdesc
[19 * 64], &fdesc
[20 * 64],
3018 &fdesc
[21 * 64], &fdesc
[22 * 64], &fdesc
[23 * 64],
3019 &fdesc
[24 * 64], &fdesc
[25 * 64], &fdesc
[26 * 64],
3020 &fdesc
[27 * 64], &fdesc
[28 * 64], &fdesc
[29 * 64],
3021 &fdesc
[30 * 64], &fdesc
[31 * 64]
3024 /*********************************************************************
3025 * __badioinfo (MSVCRT.@)
3027 ioinfo __badioinfo
= { INVALID_HANDLE_VALUE
, WX_TEXT
, { 0, } };