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
>= sizeof(unsigned int) && si
.lpReserved2
!= NULL
)
320 count
= *(unsigned*)si
.lpReserved2
;
321 wxflag_ptr
= si
.lpReserved2
+ sizeof(unsigned);
322 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ count
);
324 count
= min(count
, (si
.cbReserved2
- sizeof(unsigned)) / (sizeof(HANDLE
) + 1));
325 count
= min(count
, sizeof(fdesc
) / sizeof(fdesc
[0]));
326 for (i
= 0; i
< count
; i
++)
328 if ((*wxflag_ptr
& WX_OPEN
) && *handle_ptr
!= INVALID_HANDLE_VALUE
)
330 fdesc
[i
].wxflag
= *wxflag_ptr
;
331 fdesc
[i
].handle
= *handle_ptr
;
336 fdesc
[i
].handle
= INVALID_HANDLE_VALUE
;
338 wxflag_ptr
++; handle_ptr
++;
340 fdend
= max( 3, count
);
341 for (fdstart
= 3; fdstart
< fdend
; fdstart
++)
342 if (fdesc
[fdstart
].handle
== INVALID_HANDLE_VALUE
) break;
345 if (!(fdesc
[0].wxflag
& WX_OPEN
) || fdesc
[0].handle
== INVALID_HANDLE_VALUE
)
348 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE
),
349 GetCurrentProcess(), &fdesc
[0].handle
, 0, TRUE
,
350 DUPLICATE_SAME_ACCESS
);
352 fdesc
[0].handle
= GetStdHandle(STD_INPUT_HANDLE
);
353 if (fdesc
[0].handle
== NULL
)
354 fdesc
[0].handle
= INVALID_HANDLE_VALUE
;
356 fdesc
[0].wxflag
= WX_OPEN
| WX_TEXT
;
358 if (!(fdesc
[1].wxflag
& WX_OPEN
) || fdesc
[1].handle
== INVALID_HANDLE_VALUE
)
361 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE
),
362 GetCurrentProcess(), &fdesc
[1].handle
, 0, TRUE
,
363 DUPLICATE_SAME_ACCESS
);
365 fdesc
[1].handle
= GetStdHandle(STD_OUTPUT_HANDLE
);
366 if (fdesc
[1].handle
== NULL
)
367 fdesc
[1].handle
= INVALID_HANDLE_VALUE
;
369 fdesc
[1].wxflag
= WX_OPEN
| WX_TEXT
;
371 if (!(fdesc
[2].wxflag
& WX_OPEN
) || fdesc
[2].handle
== INVALID_HANDLE_VALUE
)
374 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE
),
375 GetCurrentProcess(), &fdesc
[2].handle
, 0, TRUE
,
376 DUPLICATE_SAME_ACCESS
);
378 fdesc
[2].handle
= GetStdHandle(STD_ERROR_HANDLE
);
379 if (fdesc
[2].handle
== NULL
)
380 fdesc
[2].handle
= INVALID_HANDLE_VALUE
;
382 fdesc
[2].wxflag
= WX_OPEN
| WX_TEXT
;
385 TRACE(":handles (%p)(%p)(%p)\n",fdesc
[0].handle
,
386 fdesc
[1].handle
,fdesc
[2].handle
);
388 memset(_iob
,0,3*sizeof(FILE));
389 for (i
= 0; i
< 3; i
++)
391 /* FILE structs for stdin/out/err are static and never deleted */
392 fstreams
[i
] = &_iob
[i
];
394 _iob
[i
]._tmpfname
= NULL
;
395 _iob
[i
]._flag
= (i
== 0) ? _IOREAD
: _IOWRT
;
400 /* INTERNAL: Flush stdio file buffer */
401 static int flush_buffer(FILE* file
)
404 int cnt
=file
->_ptr
-file
->_base
;
405 if(cnt
>0 && _write(file
->_file
, file
->_base
, cnt
) != cnt
) {
406 file
->_flag
|= _IOERR
;
409 file
->_ptr
=file
->_base
;
410 file
->_cnt
=file
->_bufsiz
;
415 /* INTERNAL: Allocate stdio file buffer */
416 static void alloc_buffer(FILE* file
)
418 file
->_base
= calloc(BUFSIZ
,1);
420 file
->_bufsiz
= BUFSIZ
;
421 file
->_flag
|= _IOMYBUF
;
423 file
->_base
= (char*)(&file
->_charbuf
);
425 file
->_bufsiz
= sizeof(file
->_charbuf
);
427 file
->_ptr
= file
->_base
;
431 /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */
432 static void int_to_base32(int num
, char *str
)
447 *p
= (num
& 31) + '0';
449 *p
+= ('a' - '0' - 10);
454 /*********************************************************************
457 FILE * CDECL
__p__iob(void)
462 /*********************************************************************
465 int CDECL
_access(const char *filename
, int mode
)
467 DWORD attr
= GetFileAttributesA(filename
);
469 TRACE("(%s,%d) %d\n",filename
,mode
,attr
);
471 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
473 _dosmaperr(GetLastError());
476 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
478 _dosmaperr(ERROR_ACCESS_DENIED
);
484 /*********************************************************************
485 * _waccess (MSVCRT.@)
487 int CDECL
_waccess(const wchar_t *filename
, int mode
)
489 DWORD attr
= GetFileAttributesW(filename
);
491 TRACE("(%s,%d) %d\n",debugstr_w(filename
),mode
,attr
);
493 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
495 _dosmaperr(GetLastError());
498 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
500 _dosmaperr(ERROR_ACCESS_DENIED
);
506 /*********************************************************************
509 int CDECL
_chmod(const char *path
, int flags
)
511 DWORD oldFlags
= GetFileAttributesA(path
);
513 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
515 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
516 oldFlags
| FILE_ATTRIBUTE_READONLY
;
518 if (newFlags
== oldFlags
|| SetFileAttributesA(path
, newFlags
))
521 _dosmaperr(GetLastError());
525 /*********************************************************************
528 int CDECL
_wchmod(const wchar_t *path
, int flags
)
530 DWORD oldFlags
= GetFileAttributesW(path
);
532 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
534 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
535 oldFlags
| FILE_ATTRIBUTE_READONLY
;
537 if (newFlags
== oldFlags
|| SetFileAttributesW(path
, newFlags
))
540 _dosmaperr(GetLastError());
544 /*********************************************************************
547 int CDECL
_unlink(const char *path
)
549 TRACE("%s\n",debugstr_a(path
));
550 if(DeleteFileA(path
))
552 TRACE("failed (%d)\n",GetLastError());
553 _dosmaperr(GetLastError());
557 /*********************************************************************
558 * _wunlink (MSVCRT.@)
560 int CDECL
_wunlink(const wchar_t *path
)
562 TRACE("(%s)\n",debugstr_w(path
));
563 if(DeleteFileW(path
))
565 TRACE("failed (%d)\n",GetLastError());
566 _dosmaperr(GetLastError());
570 /* _flushall calls fflush which calls _flushall */
571 int CDECL
fflush(FILE* file
);
573 /*********************************************************************
574 * _flushall (MSVCRT.@)
576 int CDECL
_flushall(void)
578 int i
, num_flushed
= 0;
581 for (i
= 3; i
< stream_idx
; i
++)
582 if (fstreams
[i
] && fstreams
[i
]->_flag
)
585 /* FIXME: flush, do not commit */
586 if (_commit(i
) == -1)
588 fstreams
[i
]->_flag
|= _IOERR
;
590 if(fstreams
[i
]->_flag
& _IOWRT
) {
597 TRACE(":flushed (%d) handles\n",num_flushed
);
601 /*********************************************************************
604 int CDECL
fflush(FILE* file
)
608 } else if(file
->_flag
& _IOWRT
) {
609 int res
=flush_buffer(file
);
615 /*********************************************************************
618 int CDECL
_close(int fd
)
625 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
626 if (hand
== INVALID_HANDLE_VALUE
)
628 else if (!CloseHandle(hand
))
630 WARN(":failed-last error (%d)\n",GetLastError());
631 _dosmaperr(GetLastError());
644 /*********************************************************************
647 int CDECL
_commit(int fd
)
649 HANDLE hand
= fdtoh(fd
);
651 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
652 if (hand
== INVALID_HANDLE_VALUE
)
655 if (!FlushFileBuffers(hand
))
657 if (GetLastError() == ERROR_INVALID_HANDLE
)
659 /* FlushFileBuffers fails for console handles
660 * so we ignore this error.
664 TRACE(":failed-last error (%d)\n",GetLastError());
665 _dosmaperr(GetLastError());
672 /*********************************************************************
675 * MSDN isn't clear on this point, but the remarks for _pipe
676 * indicate file descriptors duplicated with _dup and _dup2 are always
679 int CDECL
_dup2(int od
, int nd
)
683 TRACE("(od=%d, nd=%d)\n", od
, nd
);
685 if (nd
< MAX_FILES
&& is_valid_fd(od
))
689 if (DuplicateHandle(GetCurrentProcess(), fdesc
[od
].handle
,
690 GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
))
692 int wxflag
= fdesc
[od
].wxflag
& ~_O_NOINHERIT
;
696 ret
= alloc_fd_from(handle
, wxflag
, nd
);
704 /* _dup2 returns 0, not nd, on success */
711 _dosmaperr(GetLastError());
723 /*********************************************************************
726 int CDECL
_dup(int od
)
732 if (_dup2(od
, fd
) == 0)
740 /*********************************************************************
743 int CDECL
_eof(int fd
)
746 LONG hcurpos
,hendpos
;
747 HANDLE hand
= fdtoh(fd
);
749 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
751 if (hand
== INVALID_HANDLE_VALUE
)
754 if (fdesc
[fd
].wxflag
& WX_ATEOF
) return TRUE
;
756 /* Otherwise we do it the hard way */
757 hcurpos
= hendpos
= 0;
758 curpos
= SetFilePointer(hand
, 0, &hcurpos
, FILE_CURRENT
);
759 endpos
= SetFilePointer(hand
, 0, &hendpos
, FILE_END
);
761 if (curpos
== endpos
&& hcurpos
== hendpos
)
763 /* FIXME: shouldn't WX_ATEOF be set here? */
767 SetFilePointer(hand
, curpos
, &hcurpos
, FILE_BEGIN
);
771 /*********************************************************************
772 * _fcloseall (MSVCRT.@)
774 int CDECL
_fcloseall(void)
776 int num_closed
= 0, i
;
779 for (i
= 3; i
< stream_idx
; i
++)
780 if (fstreams
[i
] && fstreams
[i
]->_flag
&&
781 !fclose(fstreams
[i
]))
785 TRACE(":closed (%d) handles\n",num_closed
);
789 /* free everything on process exit */
790 void msvcrt_free_io(void)
793 /* The Win32 _fcloseall() function explicitly doesn't close stdin,
794 * stdout, and stderr (unlike GNU), so we need to fclose() them here
795 * or they won't get flushed.
800 FILE_cs
.DebugInfo
->Spare
[0] = 0;
801 DeleteCriticalSection(&FILE_cs
);
804 /*********************************************************************
805 * _lseeki64 (MSVCRT.@)
807 __int64 CDECL
_lseeki64(int fd
, __int64 offset
, int whence
)
809 HANDLE hand
= fdtoh(fd
);
810 LARGE_INTEGER ofs
, ret
;
812 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
813 if (hand
== INVALID_HANDLE_VALUE
)
816 if (whence
< 0 || whence
> 2)
822 TRACE(":fd (%d) to %s pos %s\n",
823 fd
,wine_dbgstr_longlong(offset
),
824 (whence
==SEEK_SET
)?"SEEK_SET":
825 (whence
==SEEK_CUR
)?"SEEK_CUR":
826 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
828 ofs
.QuadPart
= offset
;
829 if (SetFilePointerEx(hand
, ofs
, &ret
, whence
))
831 fdesc
[fd
].wxflag
&= ~(WX_ATEOF
|WX_READEOF
);
832 /* FIXME: What if we seek _to_ EOF - is EOF set? */
836 TRACE(":error-last error (%d)\n",GetLastError());
837 _dosmaperr(GetLastError());
841 /*********************************************************************
844 LONG CDECL
_lseek(int fd
, LONG offset
, int whence
)
846 return _lseeki64(fd
, offset
, whence
);
849 /*********************************************************************
850 * _locking (MSVCRT.@)
852 * This is untested; the underlying LockFile doesn't work yet.
854 int CDECL
_locking(int fd
, int mode
, LONG nbytes
)
858 HANDLE hand
= fdtoh(fd
);
860 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
861 if (hand
== INVALID_HANDLE_VALUE
)
864 if (mode
< 0 || mode
> 4)
870 TRACE(":fd (%d) by 0x%08x mode %s\n",
871 fd
,nbytes
,(mode
==_LK_UNLCK
)?"_LK_UNLCK":
872 (mode
==_LK_LOCK
)?"_LK_LOCK":
873 (mode
==_LK_NBLCK
)?"_LK_NBLCK":
874 (mode
==_LK_RLCK
)?"_LK_RLCK":
875 (mode
==_LK_NBRLCK
)?"_LK_NBRLCK":
878 if ((cur_locn
= SetFilePointer(hand
, 0L, NULL
, SEEK_CUR
)) == INVALID_SET_FILE_POINTER
)
880 FIXME ("Seek failed\n");
881 *_errno() = EINVAL
; /* FIXME */
884 if (mode
== _LK_LOCK
|| mode
== _LK_RLCK
)
887 ret
= 1; /* just to satisfy gcc */
890 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
895 else if (mode
== _LK_UNLCK
)
896 ret
= UnlockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
898 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
899 /* FIXME - what about error settings? */
903 /*********************************************************************
906 int CDECL
fseek(FILE* file
, long offset
, int whence
)
908 /* Flush output if needed */
909 if(file
->_flag
& _IOWRT
)
912 if(whence
== SEEK_CUR
&& file
->_flag
& _IOREAD
) {
913 offset
-= file
->_cnt
;
914 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
) {
915 /* Black magic correction for CR removal */
917 for (i
=0; i
<file
->_cnt
; i
++) {
918 if (file
->_ptr
[i
] == '\n')
923 /* Discard buffered input */
925 file
->_ptr
= file
->_base
;
926 /* Reset direction of i/o */
927 if(file
->_flag
& _IORW
) {
928 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
930 /* Clear end of file flag */
931 file
->_flag
&= ~_IOEOF
;
932 return (_lseek(file
->_file
,offset
,whence
) == -1)?-1:0;
935 /*********************************************************************
938 int CDECL
_chsize(int fd
, long size
)
944 TRACE("(fd=%d, size=%ld)\n", fd
, size
);
949 if (handle
!= INVALID_HANDLE_VALUE
)
951 /* save the current file pointer */
952 cur
= _lseek(fd
, 0, SEEK_CUR
);
955 pos
= _lseek(fd
, size
, SEEK_SET
);
958 ret
= SetEndOfFile(handle
);
959 if (!ret
) _dosmaperr(GetLastError());
962 /* restore the file pointer */
963 _lseek(fd
, cur
, SEEK_SET
);
971 /*********************************************************************
972 * clearerr (MSVCRT.@)
974 void CDECL
clearerr(FILE* file
)
976 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
977 file
->_flag
&= ~(_IOERR
| _IOEOF
);
980 /*********************************************************************
983 void CDECL
rewind(FILE* file
)
985 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
986 fseek(file
, 0L, SEEK_SET
);
990 static int get_flags(const char* mode
, int *open_flags
, int* stream_flags
)
992 int plus
= strchr(mode
, '+') != NULL
;
997 *open_flags
= plus
? _O_RDWR
: _O_RDONLY
;
998 *stream_flags
= plus
? _IORW
: _IOREAD
;
1001 *open_flags
= _O_CREAT
| _O_TRUNC
| (plus
? _O_RDWR
: _O_WRONLY
);
1002 *stream_flags
= plus
? _IORW
: _IOWRT
;
1005 *open_flags
= _O_CREAT
| _O_APPEND
| (plus
? _O_RDWR
: _O_WRONLY
);
1006 *stream_flags
= plus
? _IORW
: _IOWRT
;
1016 *open_flags
|= _O_BINARY
;
1017 *open_flags
&= ~_O_TEXT
;
1020 *open_flags
|= _O_TEXT
;
1021 *open_flags
&= ~_O_BINARY
;
1026 FIXME(":unknown flag %c not supported\n",mode
[-1]);
1031 /*********************************************************************
1032 * _fdopen (MSVCRT.@)
1034 FILE* CDECL
_fdopen(int fd
, const char *mode
)
1036 int open_flags
, stream_flags
;
1039 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1) return NULL
;
1042 if (!(file
= alloc_fp()))
1044 else if (init_fp(file
, fd
, stream_flags
) == -1)
1049 else TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
1055 /*********************************************************************
1056 * _wfdopen (MSVCRT.@)
1058 FILE* CDECL
_wfdopen(int fd
, const wchar_t *mode
)
1060 unsigned mlen
= strlenW(mode
);
1061 char *modea
= calloc(mlen
+ 1, 1);
1063 int open_flags
, stream_flags
;
1066 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
1068 if (get_flags(modea
, &open_flags
, &stream_flags
) == -1)
1074 if (!(file
= alloc_fp()))
1076 else if (init_fp(file
, fd
, stream_flags
) == -1)
1084 rewind(file
); /* FIXME: is this needed ??? */
1085 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,debugstr_w(mode
),file
);
1093 /*********************************************************************
1094 * _filelength (MSVCRT.@)
1096 LONG CDECL
_filelength(int fd
)
1098 LONG curPos
= _lseek(fd
, 0, SEEK_CUR
);
1101 LONG endPos
= _lseek(fd
, 0, SEEK_END
);
1104 if (endPos
!= curPos
)
1105 _lseek(fd
, curPos
, SEEK_SET
);
1112 /*********************************************************************
1113 * _filelengthi64 (MSVCRT.@)
1115 __int64 CDECL
_filelengthi64(int fd
)
1117 __int64 curPos
= _lseeki64(fd
, 0, SEEK_CUR
);
1120 __int64 endPos
= _lseeki64(fd
, 0, SEEK_END
);
1123 if (endPos
!= curPos
)
1124 _lseeki64(fd
, curPos
, SEEK_SET
);
1131 /*********************************************************************
1132 * _fileno (MSVCRT.@)
1134 int CDECL
_fileno(FILE* file
)
1136 TRACE(":FILE* (%p) fd (%d)\n",file
,file
->_file
);
1140 /*********************************************************************
1141 * _futime (MSVCRT.@)
1143 int CDECL
_futime(int fd
, struct _utimbuf
*t
)
1145 HANDLE hand
= fdtoh(fd
);
1148 if (hand
== INVALID_HANDLE_VALUE
)
1155 RtlSecondsSince1970ToTime(currTime
, (LARGE_INTEGER
*)&at
);
1160 RtlSecondsSince1970ToTime(t
->actime
, (LARGE_INTEGER
*)&at
);
1161 if (t
->actime
== t
->modtime
)
1164 RtlSecondsSince1970ToTime(t
->modtime
, (LARGE_INTEGER
*)&wt
);
1167 if (!SetFileTime(hand
, NULL
, &at
, &wt
))
1169 _dosmaperr(GetLastError());
1175 /*********************************************************************
1176 * _get_osfhandle (MSVCRT.@)
1178 intptr_t CDECL
_get_osfhandle(int fd
)
1180 HANDLE hand
= fdtoh(fd
);
1181 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1183 return (long)(LONG_PTR
)hand
;
1186 /*********************************************************************
1187 * _isatty (MSVCRT.@)
1189 int CDECL
_isatty(int fd
)
1191 HANDLE hand
= fdtoh(fd
);
1193 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1194 if (hand
== INVALID_HANDLE_VALUE
)
1197 return GetFileType(hand
) == FILE_TYPE_CHAR
? 1 : 0;
1200 /*********************************************************************
1201 * _mktemp (MSVCRT.@)
1203 char * CDECL
_mktemp(char *pattern
)
1206 char *retVal
= pattern
;
1211 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1215 id
= GetCurrentProcessId();
1219 int tempNum
= id
/ 10;
1220 *pattern
-- = id
- (tempNum
* 10) + '0';
1226 *pattern
= letter
++;
1227 if (GetFileAttributesA(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1228 GetLastError() == ERROR_FILE_NOT_FOUND
)
1230 } while(letter
<= 'z');
1234 /*********************************************************************
1235 * _wmktemp (MSVCRT.@)
1237 wchar_t * CDECL
_wmktemp(wchar_t *pattern
)
1240 wchar_t *retVal
= pattern
;
1242 wchar_t letter
= 'a';
1245 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1249 id
= GetCurrentProcessId();
1253 int tempNum
= id
/ 10;
1254 *pattern
-- = id
- (tempNum
* 10) + '0';
1260 if (GetFileAttributesW(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1261 GetLastError() == ERROR_FILE_NOT_FOUND
)
1263 *pattern
= letter
++;
1264 } while(letter
!= '|');
1268 /*static */unsigned split_oflags(unsigned oflags
)
1271 unsigned unsupp
; /* until we support everything */
1273 if (oflags
& _O_APPEND
) wxflags
|= WX_APPEND
;
1274 if (oflags
& _O_BINARY
) {/* Nothing to do */}
1275 else if (oflags
& _O_TEXT
) wxflags
|= WX_TEXT
;
1276 else if (*__p__fmode() & _O_BINARY
) {/* Nothing to do */}
1277 else wxflags
|= WX_TEXT
; /* default to TEXT*/
1278 if (oflags
& _O_NOINHERIT
) wxflags
|= WX_DONTINHERIT
;
1280 if ((unsupp
= oflags
& ~(
1281 _O_BINARY
|_O_TEXT
|_O_APPEND
|
1282 _O_TRUNC
|_O_EXCL
|_O_CREAT
|
1283 _O_RDWR
|_O_WRONLY
|_O_TEMPORARY
|
1285 _O_SEQUENTIAL
|_O_RANDOM
|_O_SHORT_LIVED
1287 ERR(":unsupported oflags 0x%04x\n",unsupp
);
1292 /*********************************************************************
1295 int CDECL
_pipe(int *pfds
, unsigned int psize
, int textmode
)
1298 SECURITY_ATTRIBUTES sa
;
1299 HANDLE readHandle
, writeHandle
;
1307 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
1308 sa
.bInheritHandle
= !(textmode
& _O_NOINHERIT
);
1309 sa
.lpSecurityDescriptor
= NULL
;
1310 if (CreatePipe(&readHandle
, &writeHandle
, &sa
, psize
))
1312 unsigned int wxflags
= split_oflags(textmode
);
1316 fd
= alloc_fd(readHandle
, wxflags
);
1320 fd
= alloc_fd(writeHandle
, wxflags
);
1329 CloseHandle(writeHandle
);
1335 CloseHandle(readHandle
);
1336 CloseHandle(writeHandle
);
1342 _dosmaperr(GetLastError());
1347 /*********************************************************************
1350 int CDECL
_sopen( const char *path
, int oflags
, int shflags
, ... )
1354 DWORD access
= 0, creation
= 0, attrib
;
1358 SECURITY_ATTRIBUTES sa
;
1361 TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n",
1362 path
, oflags
, shflags
);
1364 wxflag
= split_oflags(oflags
);
1365 switch (oflags
& (_O_RDONLY
| _O_WRONLY
| _O_RDWR
))
1367 case _O_RDONLY
: access
|= GENERIC_READ
; break;
1368 case _O_WRONLY
: access
|= GENERIC_WRITE
; break;
1369 case _O_RDWR
: access
|= GENERIC_WRITE
| GENERIC_READ
; break;
1372 if (oflags
& _O_CREAT
)
1374 va_start(ap
, shflags
);
1375 pmode
= va_arg(ap
, int);
1378 if(pmode
& ~(_S_IREAD
| _S_IWRITE
))
1379 FIXME(": pmode 0x%04x ignored\n", pmode
);
1381 WARN(": pmode 0x%04x ignored\n", pmode
);
1383 if (oflags
& _O_EXCL
)
1384 creation
= CREATE_NEW
;
1385 else if (oflags
& _O_TRUNC
)
1386 creation
= CREATE_ALWAYS
;
1388 creation
= OPEN_ALWAYS
;
1390 else /* no _O_CREAT */
1392 if (oflags
& _O_TRUNC
)
1393 creation
= TRUNCATE_EXISTING
;
1395 creation
= OPEN_EXISTING
;
1404 sharing
= FILE_SHARE_READ
;
1407 sharing
= FILE_SHARE_WRITE
;
1410 sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1413 ERR( "Unhandled shflags 0x%x\n", shflags
);
1416 attrib
= FILE_ATTRIBUTE_NORMAL
;
1418 if (oflags
& _O_TEMPORARY
)
1420 attrib
|= FILE_FLAG_DELETE_ON_CLOSE
;
1422 sharing
|= FILE_SHARE_DELETE
;
1425 sa
.nLength
= sizeof( SECURITY_ATTRIBUTES
);
1426 sa
.lpSecurityDescriptor
= NULL
;
1427 sa
.bInheritHandle
= (oflags
& _O_NOINHERIT
) ? FALSE
: TRUE
;
1429 hand
= CreateFileA(path
, access
, sharing
, &sa
, creation
, attrib
, 0);
1431 if (hand
== INVALID_HANDLE_VALUE
) {
1432 WARN(":failed-last error (%d)\n",GetLastError());
1433 _dosmaperr(GetLastError());
1437 fd
= alloc_fd(hand
, wxflag
);
1439 TRACE(":fd (%d) handle (%p)\n",fd
, hand
);
1443 /*********************************************************************
1444 * _wsopen (MSVCRT.@)
1446 int CDECL
_wsopen( const wchar_t* path
, int oflags
, int shflags
, ... )
1448 const unsigned int len
= strlenW(path
);
1449 char *patha
= calloc(len
+ 1,1);
1453 va_start(ap
, shflags
);
1454 pmode
= va_arg(ap
, int);
1457 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1459 int retval
= _sopen(patha
,oflags
,shflags
,pmode
);
1463 _dosmaperr(GetLastError());
1468 /*********************************************************************
1471 int CDECL
_open( const char *path
, int flags
, ... )
1475 if (flags
& _O_CREAT
)
1478 va_start(ap
, flags
);
1479 pmode
= va_arg(ap
, int);
1481 return _sopen( path
, flags
, _SH_DENYNO
, pmode
);
1484 return _sopen( path
, flags
, _SH_DENYNO
);
1487 /*********************************************************************
1490 int CDECL
_wopen(const wchar_t *path
,int flags
,...)
1492 const unsigned int len
= strlenW(path
);
1493 char *patha
= calloc(len
+ 1,1);
1497 va_start(ap
, flags
);
1498 pmode
= va_arg(ap
, int);
1501 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1503 int retval
= _open(patha
,flags
,pmode
);
1508 _dosmaperr(GetLastError());
1512 /*********************************************************************
1515 int CDECL
_creat(const char *path
, int flags
)
1517 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1518 return _open(path
, usedFlags
);
1521 /*********************************************************************
1522 * _wcreat (MSVCRT.@)
1524 int CDECL
_wcreat(const wchar_t *path
, int flags
)
1526 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1527 return _wopen(path
, usedFlags
);
1530 /*********************************************************************
1531 * _open_osfhandle (MSVCRT.@)
1533 int CDECL
_open_osfhandle(intptr_t handle
, int oflags
)
1537 /* _O_RDONLY (0) always matches, so set the read flag
1538 * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
1539 * file, so set the write flag. It also only sets _O_TEXT if it wants
1540 * text - it never sets _O_BINARY.
1542 /* don't let split_oflags() decide the mode if no mode is passed */
1543 if (!(oflags
& (_O_BINARY
| _O_TEXT
)))
1544 oflags
|= _O_BINARY
;
1546 fd
= alloc_fd((HANDLE
)(LONG_PTR
)handle
, split_oflags(oflags
));
1547 TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle
, fd
, oflags
);
1551 /*********************************************************************
1554 int CDECL
_rmtmp(void)
1556 int num_removed
= 0, i
;
1559 for (i
= 3; i
< stream_idx
; i
++)
1560 if (fstreams
[i
] && fstreams
[i
]->_tmpfname
)
1562 fclose(fstreams
[i
]);
1568 TRACE(":removed (%d) temp files\n",num_removed
);
1572 /*********************************************************************
1575 static int read_i(int fd
, void *buf
, unsigned int count
)
1578 char *bufstart
= buf
;
1579 HANDLE hand
= fdtoh(fd
);
1581 if (fdesc
[fd
].wxflag
& WX_READEOF
) {
1582 fdesc
[fd
].wxflag
|= WX_ATEOF
;
1583 TRACE("already at EOF, returning 0\n");
1586 /* Don't trace small reads, it gets *very* annoying */
1588 TRACE(":fd (%d) handle (%p) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1589 if (hand
== INVALID_HANDLE_VALUE
)
1592 /* Reading single bytes in O_TEXT mode makes things slow
1593 * So read big chunks
1595 if (ReadFile(hand
, bufstart
, count
, &num_read
, NULL
))
1597 if (fdesc
[fd
].wxflag
& WX_TEXT
)
1600 for (i
=0, j
=0; i
<num_read
; i
++)
1602 /* in text mode, a ctrl-z signals EOF */
1603 if (bufstart
[i
] == 0x1a)
1605 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1606 TRACE(":^Z EOF %s\n",debugstr_an(buf
,num_read
));
1609 /* in text mode, strip \r if followed by \n.
1610 * BUG: should save state across calls somehow, so CR LF that
1611 * straddles buffer boundary gets recognized properly?
1613 if ((bufstart
[i
] != '\r')
1614 || ((i
+1) < num_read
&& bufstart
[i
+1] != '\n'))
1615 bufstart
[j
++] = bufstart
[i
];
1619 if (count
!= 0 && num_read
== 0)
1621 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1622 TRACE(":EOF %s\n",debugstr_an(buf
,num_read
));
1627 if (GetLastError() == ERROR_BROKEN_PIPE
)
1629 TRACE(":end-of-pipe\n");
1630 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1635 TRACE(":failed-last error (%d)\n",GetLastError());
1641 TRACE("(%u), %s\n",num_read
,debugstr_an(buf
, num_read
));
1645 /*********************************************************************
1648 int CDECL
_read(int fd
, void *buf
, unsigned int count
)
1651 num_read
= read_i(fd
, buf
, count
);
1655 /*********************************************************************
1656 * _setmode (MSVCRT.@)
1658 int CDECL
_setmode(int fd
,int mode
)
1660 int ret
= fdesc
[fd
].wxflag
& WX_TEXT
? _O_TEXT
: _O_BINARY
;
1661 if (mode
& (~(_O_TEXT
|_O_BINARY
)))
1662 FIXME("fd (%d) mode (0x%08x) unknown\n",fd
,mode
);
1663 if ((mode
& _O_TEXT
) == _O_TEXT
)
1664 fdesc
[fd
].wxflag
|= WX_TEXT
;
1666 fdesc
[fd
].wxflag
&= ~WX_TEXT
;
1670 /*********************************************************************
1673 long CDECL
_tell(int fd
)
1675 return _lseek(fd
, 0, SEEK_CUR
);
1678 /*********************************************************************
1679 * _telli64 (MSVCRT.@)
1681 __int64 CDECL
_telli64(int fd
)
1683 return _lseeki64(fd
, 0, SEEK_CUR
);
1686 /*********************************************************************
1687 * _tempnam (MSVCRT.@)
1689 char * CDECL
_tempnam(const char *dir
, const char *prefix
)
1691 char tmpbuf
[MAX_PATH
];
1692 const char *tmp_dir
= getenv("TMP");
1694 if (tmp_dir
) dir
= tmp_dir
;
1696 TRACE("dir (%s) prefix (%s)\n",dir
,prefix
);
1697 if (GetTempFileNameA(dir
,prefix
,0,tmpbuf
))
1699 TRACE("got name (%s)\n",tmpbuf
);
1700 DeleteFileA(tmpbuf
);
1701 return _strdup(tmpbuf
);
1703 TRACE("failed (%d)\n",GetLastError());
1707 /*********************************************************************
1708 * _wtempnam (MSVCRT.@)
1710 wchar_t * CDECL
_wtempnam(const wchar_t *dir
, const wchar_t *prefix
)
1712 wchar_t tmpbuf
[MAX_PATH
];
1714 TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir
),debugstr_w(prefix
));
1715 if (GetTempFileNameW(dir
,prefix
,0,tmpbuf
))
1717 TRACE("got name (%s)\n",debugstr_w(tmpbuf
));
1718 DeleteFileW(tmpbuf
);
1719 return _wcsdup(tmpbuf
);
1721 TRACE("failed (%d)\n",GetLastError());
1725 /*********************************************************************
1728 int CDECL
_umask(int umask
)
1730 int old_umask
= umask
;
1731 TRACE("(%d)\n",umask
);
1732 MSVCRT_umask
= umask
;
1736 /*********************************************************************
1739 int CDECL
_utime(const char* path
, struct _utimbuf
*t
)
1741 int fd
= _open(path
, _O_WRONLY
| _O_BINARY
);
1745 int retVal
= _futime(fd
, t
);
1752 /*********************************************************************
1753 * _wutime (MSVCRT.@)
1755 int CDECL
_wutime(const wchar_t* path
, struct _utimbuf
*t
)
1757 int fd
= _wopen(path
, _O_WRONLY
| _O_BINARY
);
1761 int retVal
= _futime(fd
, t
);
1768 /*********************************************************************
1771 int CDECL
_write(int fd
, const void* buf
, unsigned int count
)
1774 HANDLE hand
= fdtoh(fd
);
1776 /* Don't trace small writes, it gets *very* annoying */
1779 TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1781 if (hand
== INVALID_HANDLE_VALUE
)
1787 /* If appending, go to EOF */
1788 if (fdesc
[fd
].wxflag
& WX_APPEND
)
1789 _lseek(fd
, 0, FILE_END
);
1791 if (!(fdesc
[fd
].wxflag
& WX_TEXT
))
1793 if (WriteFile(hand
, buf
, count
, &num_written
, NULL
)
1794 && (num_written
== count
))
1796 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd
,
1797 hand
, GetLastError());
1802 unsigned int i
, j
, nr_lf
;
1805 const char *s
= (const char *)buf
, *buf_start
= (const char *)buf
;
1806 /* find number of \n ( without preceding \r ) */
1807 for ( nr_lf
=0,i
= 0; i
<count
; i
++)
1812 /*if ((i >1) && (s[i-1] == '\r')) nr_lf--; */
1817 if ((q
= p
= malloc(count
+ nr_lf
)))
1819 for (s
= (const char *)buf
, i
= 0, j
= 0; i
< count
; i
++)
1824 /*if ((i >1) && (s[i-1] == '\r'))j--;*/
1831 FIXME("Malloc failed\n");
1839 if ((WriteFile(hand
, q
, count
+nr_lf
, &num_written
, NULL
) == 0 ) || (num_written
!= count
+nr_lf
))
1841 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
1842 fd
, hand
, GetLastError(), num_written
);
1846 return s
- buf_start
;
1858 /*********************************************************************
1861 int CDECL
_putw(int val
, FILE* file
)
1864 len
= _write(file
->_file
, &val
, sizeof(val
));
1865 if (len
== sizeof(val
)) return val
;
1866 file
->_flag
|= _IOERR
;
1870 /*********************************************************************
1873 int CDECL
fclose(FILE* file
)
1878 free(file
->_tmpfname
);
1879 file
->_tmpfname
= NULL
;
1880 /* flush stdio buffers */
1881 if(file
->_flag
& _IOWRT
)
1883 if(file
->_flag
& _IOMYBUF
)
1886 r
=_close(file
->_file
);
1890 return ((r
== -1) || (flag
& _IOERR
) ? EOF
: 0);
1893 /*********************************************************************
1896 int CDECL
feof(FILE* file
)
1898 return file
->_flag
& _IOEOF
;
1901 /*********************************************************************
1904 int CDECL
ferror(FILE* file
)
1906 return file
->_flag
& _IOERR
;
1909 /*********************************************************************
1910 * _filbuf (MSVCRT.@)
1912 int CDECL
_filbuf(FILE* file
)
1914 /* Allocate buffer if needed */
1915 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
) ) {
1918 if(!(file
->_flag
& _IOREAD
)) {
1919 if(file
->_flag
& _IORW
) {
1920 file
->_flag
|= _IOREAD
;
1925 if(file
->_flag
& _IONBF
) {
1928 if ((r
= read_i(file
->_file
,&c
,1)) != 1) {
1929 file
->_flag
|= (r
== 0) ? _IOEOF
: _IOERR
;
1934 file
->_cnt
= read_i(file
->_file
, file
->_base
, file
->_bufsiz
);
1936 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
1941 file
->_ptr
= file
->_base
+1;
1942 return *(unsigned char *)file
->_base
;
1946 /*********************************************************************
1949 int CDECL
fgetc(FILE* file
)
1955 i
= (unsigned char *)file
->_ptr
++;
1962 /*********************************************************************
1963 * _fgetchar (MSVCRT.@)
1965 int CDECL
_fgetchar(void)
1967 return fgetc(stdin
);
1970 /*********************************************************************
1973 char * CDECL
fgets(char *s
, int size
, FILE* file
)
1976 char * buf_start
= s
;
1978 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
1979 file
,file
->_file
,s
,size
);
1981 while ((size
>1) && (cc
= fgetc(file
)) != EOF
&& cc
!= '\n')
1986 if ((cc
== EOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
1988 TRACE(":nothing read\n");
1991 if ((cc
!= EOF
) && (size
> 1))
1994 TRACE(":got %s\n", debugstr_a(buf_start
));
1998 /*********************************************************************
2001 * In _O_TEXT mode, multibyte characters are read from the file, dropping
2002 * the CR from CR/LF combinations
2004 wint_t CDECL
fgetwc(FILE* file
)
2008 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2014 for(i
=0; i
<sizeof(wc
); i
++)
2027 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
2038 if ((*__p___mb_cur_max() > 1) && isleadbyte(c
))
2040 FIXME("Treat Multibyte characters\n");
2048 /*********************************************************************
2051 int CDECL
_getw(FILE* file
)
2056 for (j
=0; j
<sizeof(int); j
++) {
2059 file
->_flag
|= _IOEOF
;
2067 /*********************************************************************
2070 wint_t CDECL
getwc(FILE* file
)
2072 return fgetwc(file
);
2075 /*********************************************************************
2076 * _fgetwchar (MSVCRT.@)
2078 wint_t CDECL
_fgetwchar(void)
2080 return fgetwc(stdin
);
2083 /*********************************************************************
2084 * getwchar (MSVCRT.@)
2086 wint_t CDECL
getwchar(void)
2088 return _fgetwchar();
2091 /*********************************************************************
2094 wchar_t * CDECL
fgetws(wchar_t *s
, int size
, FILE* file
)
2097 wchar_t * buf_start
= s
;
2099 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
2100 file
,file
->_file
,s
,size
);
2102 while ((size
>1) && (cc
= fgetwc(file
)) != WEOF
&& cc
!= '\n')
2107 if ((cc
== WEOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
2109 TRACE(":nothing read\n");
2112 if ((cc
!= WEOF
) && (size
> 1))
2115 TRACE(":got %s\n", debugstr_w(buf_start
));
2119 /*********************************************************************
2122 size_t CDECL
fwrite(const void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2124 size_t wrcnt
=size
* nmemb
;
2129 int pcnt
=(file
->_cnt
>wrcnt
)? wrcnt
: file
->_cnt
;
2130 memcpy(file
->_ptr
, ptr
, pcnt
);
2135 ptr
= (const char*)ptr
+ pcnt
;
2136 } else if(!(file
->_flag
& _IOWRT
)) {
2137 if(file
->_flag
& _IORW
) {
2138 file
->_flag
|= _IOWRT
;
2144 int res
=flush_buffer(file
);
2146 int pwritten
= _write(file
->_file
, ptr
, wrcnt
);
2149 file
->_flag
|= _IOERR
;
2152 written
+= pwritten
;
2155 return written
/ size
;
2158 /*********************************************************************
2161 wint_t CDECL
fputwc(wint_t wc
, FILE* file
)
2164 if (fwrite( &mwc
, sizeof(mwc
), 1, file
) != 1)
2169 /*********************************************************************
2170 * _fputwchar (MSVCRT.@)
2172 wint_t CDECL
_fputwchar(wint_t wc
)
2174 return fputwc(wc
, stdout
);
2177 /*********************************************************************
2178 * _fsopen (MSVCRT.@)
2180 FILE * CDECL
_fsopen(const char *path
, const char *mode
, int share
)
2183 int open_flags
, stream_flags
, fd
;
2185 TRACE("(%s,%s)\n",path
,mode
);
2187 /* map mode string to open() flags. "man fopen" for possibilities. */
2188 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2192 fd
= _sopen(path
, open_flags
, share
, _S_IREAD
| _S_IWRITE
);
2195 else if ((file
= alloc_fp()) && init_fp(file
, fd
, stream_flags
)
2197 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
2204 TRACE(":got (%p)\n",file
);
2205 if (fd
>= 0 && !file
)
2211 /*********************************************************************
2212 * _wfsopen (MSVCRT.@)
2214 FILE * CDECL
_wfsopen(const wchar_t *path
, const wchar_t *mode
, int share
)
2216 const unsigned int plen
= strlenW(path
), mlen
= strlenW(mode
);
2217 char *patha
= calloc(plen
+ 1, 1);
2218 char *modea
= calloc(mlen
+ 1, 1);
2220 TRACE("(%s,%s)\n",debugstr_w(path
),debugstr_w(mode
));
2222 if (patha
&& modea
&&
2223 WideCharToMultiByte(CP_ACP
,0,path
,plen
,patha
,plen
,NULL
,NULL
) &&
2224 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
2226 FILE *retval
= _fsopen(patha
,modea
,share
);
2233 _dosmaperr(GetLastError());
2237 /*********************************************************************
2240 FILE * CDECL
fopen(const char *path
, const char *mode
)
2242 return _fsopen( path
, mode
, _SH_DENYNO
);
2245 /*********************************************************************
2246 * _wfopen (MSVCRT.@)
2248 FILE * CDECL
_wfopen(const wchar_t *path
, const wchar_t *mode
)
2250 return _wfsopen( path
, mode
, _SH_DENYNO
);
2253 /* fputc calls _flsbuf which calls fputc */
2254 int CDECL
_flsbuf(int c
, FILE* file
);
2256 /*********************************************************************
2259 int CDECL
fputc(int c
, FILE* file
)
2266 int res
= flush_buffer(file
);
2267 return res
? res
: c
;
2272 return _flsbuf(c
, file
);
2276 /*********************************************************************
2277 * _flsbuf (MSVCRT.@)
2279 int CDECL
_flsbuf(int c
, FILE* file
)
2281 /* Flush output buffer */
2282 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2285 if(!(file
->_flag
& _IOWRT
)) {
2286 if(file
->_flag
& _IORW
) {
2287 file
->_flag
|= _IOWRT
;
2293 int res
=flush_buffer(file
);
2294 return res
?res
: fputc(c
, file
);
2298 /* set _cnt to 0 for unbuffered FILEs */
2300 len
= _write(file
->_file
, &cc
, 1);
2301 if (len
== 1) return c
& 0xff;
2302 file
->_flag
|= _IOERR
;
2307 /*********************************************************************
2308 * _fputchar (MSVCRT.@)
2310 int CDECL
_fputchar(int c
)
2312 return fputc(c
, stdout
);
2315 /*********************************************************************
2318 size_t CDECL
fread(void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2319 { size_t rcnt
=size
* nmemb
;
2326 /* first buffered data */
2328 int pcnt
= (rcnt
>file
->_cnt
)? file
->_cnt
:rcnt
;
2329 memcpy(ptr
, file
->_ptr
, pcnt
);
2334 ptr
= (char*)ptr
+ pcnt
;
2335 } else if(!(file
->_flag
& _IOREAD
)) {
2336 if(file
->_flag
& _IORW
) {
2337 file
->_flag
|= _IOREAD
;
2344 /* Fill the buffer on small reads.
2345 * TODO: Use a better buffering strategy.
2347 if (!file
->_cnt
&& size
*nmemb
<= BUFSIZ
/2 && !(file
->_flag
& _IONBF
)) {
2348 if (file
->_bufsiz
== 0) {
2351 file
->_cnt
= _read(file
->_file
, file
->_base
, file
->_bufsiz
);
2352 file
->_ptr
= file
->_base
;
2353 i
= (file
->_cnt
<rcnt
) ? file
->_cnt
: rcnt
;
2354 /* If the buffer fill reaches eof but fread wouldn't, clear eof. */
2355 if (i
> 0 && i
< file
->_cnt
) {
2356 fdesc
[file
->_file
].wxflag
&= ~WX_ATEOF
;
2357 file
->_flag
&= ~_IOEOF
;
2360 memcpy(ptr
, file
->_ptr
, i
);
2365 i
= _read(file
->_file
,ptr
, rcnt
);
2369 ptr
= (char *)ptr
+i
;
2370 /* expose feof condition in the flags
2371 * MFC tests file->_flag for feof, and doesn't call feof())
2373 if ( fdesc
[file
->_file
].wxflag
& WX_ATEOF
)
2374 file
->_flag
|= _IOEOF
;
2377 file
->_flag
|= _IOERR
;
2387 /*********************************************************************
2388 * freopen (MSVCRT.@)
2391 FILE* CDECL
freopen(const char *path
, const char *mode
,FILE* file
)
2393 int open_flags
, stream_flags
, fd
;
2395 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n",path
,mode
,file
,file
->_file
);
2398 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2403 /* map mode string to open() flags. "man fopen" for possibilities. */
2404 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2408 fd
= _open(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2411 else if (init_fp(file
, fd
, stream_flags
) == -1)
2414 WARN(":failed-last error (%d)\n",GetLastError());
2415 _dosmaperr(GetLastError());
2424 /*********************************************************************
2425 * wfreopen (MSVCRT.@)
2428 FILE* CDECL
_wfreopen(const wchar_t *path
, const wchar_t *mode
,FILE* file
)
2430 int open_flags
, stream_flags
, fd
;
2432 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path
), debugstr_w(mode
), file
, file
->_file
);
2435 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2440 /* map mode string to open() flags. "man fopen" for possibilities. */
2441 if (get_flags((char*)mode
, &open_flags
, &stream_flags
) == -1)
2445 fd
= _wopen(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2448 else if (init_fp(file
, fd
, stream_flags
) == -1)
2451 WARN(":failed-last error (%d)\n",GetLastError());
2452 _dosmaperr(GetLastError());
2461 /*********************************************************************
2462 * fsetpos (MSVCRT.@)
2464 int CDECL
fsetpos(FILE* file
, const fpos_t *pos
)
2466 /* Note that all this has been lifted 'as is' from fseek */
2467 if(file
->_flag
& _IOWRT
)
2470 /* Discard buffered input */
2472 file
->_ptr
= file
->_base
;
2474 /* Reset direction of i/o */
2475 if(file
->_flag
& _IORW
) {
2476 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
2479 return (_lseeki64(file
->_file
,*pos
,SEEK_SET
) == -1) ? -1 : 0;
2482 /*********************************************************************
2485 LONG CDECL
ftell(FILE* file
)
2487 /* TODO: just call fgetpos and return lower half of result */
2490 pos
= _tell(file
->_file
);
2491 if(pos
== -1) return -1;
2493 if( file
->_flag
& _IOWRT
) {
2494 off
= file
->_ptr
- file
->_base
;
2497 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
) {
2498 /* Black magic correction for CR removal */
2500 for (i
=0; i
<file
->_cnt
; i
++) {
2501 if (file
->_ptr
[i
] == '\n')
2510 /*********************************************************************
2511 * fgetpos (MSVCRT.@)
2513 int CDECL
fgetpos(FILE* file
, fpos_t *pos
)
2516 *pos
= _lseeki64(file
->_file
,0,SEEK_CUR
);
2517 if(*pos
== -1) return -1;
2519 if( file
->_flag
& _IOWRT
) {
2520 off
= file
->_ptr
- file
->_base
;
2523 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
) {
2524 /* Black magic correction for CR removal */
2526 for (i
=0; i
<file
->_cnt
; i
++) {
2527 if (file
->_ptr
[i
] == '\n')
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, } };