2 * PROJECT: ReactOS CRT library
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: lib/sdk/crt/stdio/file.c
5 * PURPOSE: File CRT functions
6 * PROGRAMMERS: Wine team
7 * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org)
11 * msvcrt.dll file functions
13 * Copyright 1996,1998 Marcus Meissner
14 * Copyright 1996 Jukka Iivonen
15 * Copyright 1997,2000 Uwe Bonnes
16 * Copyright 2000 Jon Griffiths
17 * Copyright 2004 Eric Pouech
18 * Copyright 2004 Juan Lang
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED
39 #include "wine/unicode.h"
41 #include <sys/utime.h>
44 int *__p__fmode(void);
45 int *__p___mb_cur_max(void);
72 /* _access() bit flags FIXME: incomplete */
73 /* defined in crt/io.h */
75 /* values for wxflag in file descriptor */
78 #define WX_READEOF 0x04 /* like ATEOF, but for underlying file rather than buffer */
79 #define WX_DONTINHERIT 0x10
80 #define WX_APPEND 0x20
83 /* FIXME: this should be allocated dynamically */
84 #define MAX_FILES 2048
86 /* ReactOS: Use _FDINFO instead! */
90 DWORD unkn
[7]; /* critical section and init flag */
93 ioinfo fdesc
[MAX_FILES
];
95 FILE _iob
[3] = { { 0 } };
97 static int fdstart
= 3; /* first unallocated fd */
98 static int fdend
= 3; /* highest allocated fd */
100 static FILE* fstreams
[2048];
101 static int stream_idx
;
103 /* INTERNAL: process umask */
104 static int MSVCRT_umask
= 0;
106 /* INTERNAL: Static buffer for temp file name */
107 static char tmpname
[MAX_PATH
];
109 /* This critical section protects the tables fdesc and fstreams,
110 * and their related indexes, fdstart, fdend,
111 * and stream_idx, from race conditions.
112 * It doesn't protect against race conditions manipulating the underlying files
113 * or flags; doing so would probably be better accomplished with per-file
114 * protection, rather than locking the whole table for every change.
116 static CRITICAL_SECTION FILE_cs
;
117 #define LOCK_FILES() do { EnterCriticalSection(&FILE_cs); } while (0)
118 #define UNLOCK_FILES() do { LeaveCriticalSection(&FILE_cs); } while (0)
120 static inline BOOL
is_valid_fd(int fd
)
122 return fd
>= 0 && fd
< fdend
&& (fdesc
[fd
].wxflag
& WX_OPEN
);
125 /* INTERNAL: Get the HANDLE for a fd
126 * This doesn't lock the table, because a failure will result in
127 * INVALID_HANDLE_VALUE being returned, which should be handled correctly. If
128 * it returns a valid handle which is about to be closed, a subsequent call
129 * will fail, most likely in a sane way.
133 if (!is_valid_fd(fd
))
135 WARN(":fd (%d) - no handle!\n",fd
);
138 return INVALID_HANDLE_VALUE
;
140 //if (fdesc[fd].handle == INVALID_HANDLE_VALUE) FIXME("wtf\n");
141 return fdesc
[fd
].handle
;
144 /* INTERNAL: free a file entry fd */
145 static void free_fd(int fd
)
148 fdesc
[fd
].handle
= INVALID_HANDLE_VALUE
;
149 fdesc
[fd
].wxflag
= 0;
150 TRACE(":fd (%d) freed\n",fd
);
151 if (fd
< 3) /* don't use 0,1,2 for user files */
155 case 0: SetStdHandle(STD_INPUT_HANDLE
, NULL
); break;
156 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, NULL
); break;
157 case 2: SetStdHandle(STD_ERROR_HANDLE
, NULL
); break;
170 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE, starting from fd */
171 /* caller must hold the files lock */
172 static int alloc_fd_from(HANDLE hand
, int flag
, int fd
)
176 WARN(":files exhausted!\n");
179 fdesc
[fd
].handle
= hand
;
180 fdesc
[fd
].wxflag
= WX_OPEN
| (flag
& (WX_DONTINHERIT
| WX_APPEND
| WX_TEXT
));
182 /* locate next free slot */
183 if (fd
== fdstart
&& fd
== fdend
)
186 while (fdstart
< fdend
&&
187 fdesc
[fdstart
].handle
!= INVALID_HANDLE_VALUE
)
189 /* update last fd in use */
192 TRACE("fdstart is %d, fdend is %d\n", fdstart
, fdend
);
196 case 0: SetStdHandle(STD_INPUT_HANDLE
, hand
); break;
197 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, hand
); break;
198 case 2: SetStdHandle(STD_ERROR_HANDLE
, hand
); break;
204 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE */
205 /*static */int alloc_fd(HANDLE hand
, int flag
)
210 TRACE(":handle (%p) allocating fd (%d)\n",hand
,fdstart
);
211 ret
= alloc_fd_from(hand
, flag
, fdstart
);
216 /* INTERNAL: Allocate a FILE* for an fd slot */
217 /* caller must hold the files lock */
218 static FILE* alloc_fp(void)
222 for (i
= 3; i
< sizeof(fstreams
) / sizeof(fstreams
[0]); i
++)
224 if (!fstreams
[i
] || fstreams
[i
]->_flag
== 0)
228 if (!(fstreams
[i
] = calloc(sizeof(FILE),1)))
230 if (i
== stream_idx
) stream_idx
++;
238 /* INTERNAL: initialize a FILE* from an open fd */
239 static int init_fp(FILE* file
, int fd
, unsigned stream_flags
)
241 TRACE(":fd (%d) allocating FILE*\n",fd
);
242 if (!is_valid_fd(fd
))
244 WARN(":invalid fd %d\n",fd
);
249 memset(file
, 0, sizeof(*file
));
251 file
->_flag
= stream_flags
;
253 TRACE(":got FILE* (%p)\n",file
);
257 /* INTERNAL: Create an inheritance data block (for spawned process)
258 * The inheritance block is made of:
259 * 00 int nb of file descriptor (NBFD)
260 * 04 char file flags (wxflag): repeated for each fd
261 * 4+NBFD HANDLE file handle: repeated for each fd
263 unsigned create_io_inherit_block(WORD
*size
, BYTE
**block
)
269 *size
= sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE
)) * fdend
;
270 *block
= calloc(*size
, 1);
276 wxflag_ptr
= (char*)*block
+ sizeof(unsigned);
277 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ fdend
* sizeof(char));
279 *(unsigned*)*block
= fdend
;
280 for (fd
= 0; fd
< fdend
; fd
++)
282 /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
283 if ((fdesc
[fd
].wxflag
& (WX_OPEN
| WX_DONTINHERIT
)) == WX_OPEN
)
285 *wxflag_ptr
= fdesc
[fd
].wxflag
;
286 *handle_ptr
= fdesc
[fd
].handle
;
291 *handle_ptr
= INVALID_HANDLE_VALUE
;
293 wxflag_ptr
++; handle_ptr
++;
298 /* INTERNAL: Set up all file descriptors,
299 * as well as default streams (stdin, stderr and stdout)
301 void msvcrt_init_io(void)
306 InitializeCriticalSection(&FILE_cs
);
307 FILE_cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": FILE_cs");
308 GetStartupInfoA(&si
);
309 if (si
.cbReserved2
>= sizeof(unsigned int) && si
.lpReserved2
!= NULL
)
315 count
= *(unsigned*)si
.lpReserved2
;
316 wxflag_ptr
= si
.lpReserved2
+ sizeof(unsigned);
317 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ count
);
319 count
= min(count
, (si
.cbReserved2
- sizeof(unsigned)) / (sizeof(HANDLE
) + 1));
320 count
= min(count
, sizeof(fdesc
) / sizeof(fdesc
[0]));
321 for (i
= 0; i
< count
; i
++)
323 if ((*wxflag_ptr
& WX_OPEN
) && *handle_ptr
!= INVALID_HANDLE_VALUE
)
325 fdesc
[i
].wxflag
= *wxflag_ptr
;
326 fdesc
[i
].handle
= *handle_ptr
;
331 fdesc
[i
].handle
= INVALID_HANDLE_VALUE
;
333 wxflag_ptr
++; handle_ptr
++;
335 fdend
= max( 3, count
);
336 for (fdstart
= 3; fdstart
< fdend
; fdstart
++)
337 if (fdesc
[fdstart
].handle
== INVALID_HANDLE_VALUE
) break;
340 if (!(fdesc
[0].wxflag
& WX_OPEN
) || fdesc
[0].handle
== INVALID_HANDLE_VALUE
)
343 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE
),
344 GetCurrentProcess(), &fdesc
[0].handle
, 0, TRUE
,
345 DUPLICATE_SAME_ACCESS
);
347 fdesc
[0].handle
= GetStdHandle(STD_INPUT_HANDLE
);
348 if (fdesc
[0].handle
== NULL
)
349 fdesc
[0].handle
= INVALID_HANDLE_VALUE
;
351 fdesc
[0].wxflag
= WX_OPEN
| WX_TEXT
;
353 if (!(fdesc
[1].wxflag
& WX_OPEN
) || fdesc
[1].handle
== INVALID_HANDLE_VALUE
)
356 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE
),
357 GetCurrentProcess(), &fdesc
[1].handle
, 0, TRUE
,
358 DUPLICATE_SAME_ACCESS
);
360 fdesc
[1].handle
= GetStdHandle(STD_OUTPUT_HANDLE
);
361 if (fdesc
[1].handle
== NULL
)
362 fdesc
[1].handle
= INVALID_HANDLE_VALUE
;
364 fdesc
[1].wxflag
= WX_OPEN
| WX_TEXT
;
366 if (!(fdesc
[2].wxflag
& WX_OPEN
) || fdesc
[2].handle
== INVALID_HANDLE_VALUE
)
369 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE
),
370 GetCurrentProcess(), &fdesc
[2].handle
, 0, TRUE
,
371 DUPLICATE_SAME_ACCESS
);
373 fdesc
[2].handle
= GetStdHandle(STD_ERROR_HANDLE
);
374 if (fdesc
[2].handle
== NULL
)
375 fdesc
[2].handle
= INVALID_HANDLE_VALUE
;
377 fdesc
[2].wxflag
= WX_OPEN
| WX_TEXT
;
380 TRACE(":handles (%p)(%p)(%p)\n",fdesc
[0].handle
,
381 fdesc
[1].handle
,fdesc
[2].handle
);
383 memset(_iob
,0,3*sizeof(FILE));
384 for (i
= 0; i
< 3; i
++)
386 /* FILE structs for stdin/out/err are static and never deleted */
387 fstreams
[i
] = &_iob
[i
];
389 _iob
[i
]._tmpfname
= NULL
;
390 _iob
[i
]._flag
= (i
== 0) ? _IOREAD
: _IOWRT
;
395 /* INTERNAL: Flush stdio file buffer */
396 static int flush_buffer(FILE* file
)
399 int cnt
=file
->_ptr
-file
->_base
;
400 if(cnt
>0 && _write(file
->_file
, file
->_base
, cnt
) != cnt
) {
401 file
->_flag
|= _IOERR
;
404 file
->_ptr
=file
->_base
;
405 file
->_cnt
=file
->_bufsiz
;
410 /* INTERNAL: Allocate stdio file buffer */
411 static void alloc_buffer(FILE* file
)
413 file
->_base
= calloc(BUFSIZ
,1);
415 file
->_bufsiz
= BUFSIZ
;
416 file
->_flag
|= _IOMYBUF
;
418 file
->_base
= (char*)(&file
->_charbuf
);
420 file
->_bufsiz
= sizeof(file
->_charbuf
);
422 file
->_ptr
= file
->_base
;
426 /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */
427 static void int_to_base32(int num
, char *str
)
442 *p
= (num
& 31) + '0';
444 *p
+= ('a' - '0' - 10);
449 /*********************************************************************
452 FILE * CDECL
__p__iob(void)
457 /*********************************************************************
460 int CDECL
_access(const char *filename
, int mode
)
462 DWORD attr
= GetFileAttributesA(filename
);
464 TRACE("(%s,%d) %d\n",filename
,mode
,attr
);
466 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
468 _dosmaperr(GetLastError());
471 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
473 _dosmaperr(ERROR_ACCESS_DENIED
);
479 /*********************************************************************
480 * _waccess (MSVCRT.@)
482 int CDECL
_waccess(const wchar_t *filename
, int mode
)
484 DWORD attr
= GetFileAttributesW(filename
);
486 TRACE("(%s,%d) %d\n",debugstr_w(filename
),mode
,attr
);
488 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
490 _dosmaperr(GetLastError());
493 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
495 _dosmaperr(ERROR_ACCESS_DENIED
);
501 /*********************************************************************
504 int CDECL
_chmod(const char *path
, int flags
)
506 DWORD oldFlags
= GetFileAttributesA(path
);
508 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
510 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
511 oldFlags
| FILE_ATTRIBUTE_READONLY
;
513 if (newFlags
== oldFlags
|| SetFileAttributesA(path
, newFlags
))
516 _dosmaperr(GetLastError());
520 /*********************************************************************
523 int CDECL
_wchmod(const wchar_t *path
, int flags
)
525 DWORD oldFlags
= GetFileAttributesW(path
);
527 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
529 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
530 oldFlags
| FILE_ATTRIBUTE_READONLY
;
532 if (newFlags
== oldFlags
|| SetFileAttributesW(path
, newFlags
))
535 _dosmaperr(GetLastError());
539 /*********************************************************************
542 int CDECL
_unlink(const char *path
)
544 TRACE("%s\n",debugstr_a(path
));
545 if(DeleteFileA(path
))
547 TRACE("failed (%d)\n",GetLastError());
548 _dosmaperr(GetLastError());
552 /*********************************************************************
553 * _wunlink (MSVCRT.@)
555 int CDECL
_wunlink(const wchar_t *path
)
557 TRACE("(%s)\n",debugstr_w(path
));
558 if(DeleteFileW(path
))
560 TRACE("failed (%d)\n",GetLastError());
561 _dosmaperr(GetLastError());
565 /* _flushall calls fflush which calls _flushall */
566 int CDECL
fflush(FILE* file
);
568 /*********************************************************************
569 * _flushall (MSVCRT.@)
571 int CDECL
_flushall(void)
573 int i
, num_flushed
= 0;
576 for (i
= 3; i
< stream_idx
; i
++)
577 if (fstreams
[i
] && fstreams
[i
]->_flag
)
580 /* FIXME: flush, do not commit */
581 if (_commit(i
) == -1)
583 fstreams
[i
]->_flag
|= _IOERR
;
585 if(fstreams
[i
]->_flag
& _IOWRT
) {
592 TRACE(":flushed (%d) handles\n",num_flushed
);
596 /*********************************************************************
599 int CDECL
fflush(FILE* file
)
603 } else if(file
->_flag
& _IOWRT
) {
604 int res
=flush_buffer(file
);
610 /*********************************************************************
613 int CDECL
_close(int fd
)
620 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
621 if (hand
== INVALID_HANDLE_VALUE
)
623 else if (!CloseHandle(hand
))
625 WARN(":failed-last error (%d)\n",GetLastError());
626 _dosmaperr(GetLastError());
639 /*********************************************************************
642 int CDECL
_commit(int fd
)
644 HANDLE hand
= fdtoh(fd
);
646 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
647 if (hand
== INVALID_HANDLE_VALUE
)
650 if (!FlushFileBuffers(hand
))
652 if (GetLastError() == ERROR_INVALID_HANDLE
)
654 /* FlushFileBuffers fails for console handles
655 * so we ignore this error.
659 TRACE(":failed-last error (%d)\n",GetLastError());
660 _dosmaperr(GetLastError());
667 /*********************************************************************
670 * MSDN isn't clear on this point, but the remarks for _pipe
671 * indicate file descriptors duplicated with _dup and _dup2 are always
674 int CDECL
_dup2(int od
, int nd
)
678 TRACE("(od=%d, nd=%d)\n", od
, nd
);
680 if (nd
< MAX_FILES
&& is_valid_fd(od
))
684 if (DuplicateHandle(GetCurrentProcess(), fdesc
[od
].handle
,
685 GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
))
687 int wxflag
= fdesc
[od
].wxflag
& ~_O_NOINHERIT
;
691 ret
= alloc_fd_from(handle
, wxflag
, nd
);
699 /* _dup2 returns 0, not nd, on success */
706 _dosmaperr(GetLastError());
718 /*********************************************************************
721 int CDECL
_dup(int od
)
727 if (_dup2(od
, fd
) == 0)
735 /*********************************************************************
738 int CDECL
_eof(int fd
)
741 LONG hcurpos
,hendpos
;
742 HANDLE hand
= fdtoh(fd
);
744 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
746 if (hand
== INVALID_HANDLE_VALUE
)
749 if (fdesc
[fd
].wxflag
& WX_ATEOF
) return TRUE
;
751 /* Otherwise we do it the hard way */
752 hcurpos
= hendpos
= 0;
753 curpos
= SetFilePointer(hand
, 0, &hcurpos
, FILE_CURRENT
);
754 endpos
= SetFilePointer(hand
, 0, &hendpos
, FILE_END
);
756 if (curpos
== endpos
&& hcurpos
== hendpos
)
758 /* FIXME: shouldn't WX_ATEOF be set here? */
762 SetFilePointer(hand
, curpos
, &hcurpos
, FILE_BEGIN
);
766 /*********************************************************************
767 * _fcloseall (MSVCRT.@)
769 int CDECL
_fcloseall(void)
771 int num_closed
= 0, i
;
774 for (i
= 3; i
< stream_idx
; i
++)
775 if (fstreams
[i
] && fstreams
[i
]->_flag
&&
776 !fclose(fstreams
[i
]))
780 TRACE(":closed (%d) handles\n",num_closed
);
784 /* free everything on process exit */
785 void msvcrt_free_io(void)
788 /* The Win32 _fcloseall() function explicitly doesn't close stdin,
789 * stdout, and stderr (unlike GNU), so we need to fclose() them here
790 * or they won't get flushed.
795 FILE_cs
.DebugInfo
->Spare
[0] = 0;
796 DeleteCriticalSection(&FILE_cs
);
799 /*********************************************************************
800 * _lseeki64 (MSVCRT.@)
802 __int64 CDECL
_lseeki64(int fd
, __int64 offset
, int whence
)
804 HANDLE hand
= fdtoh(fd
);
805 LARGE_INTEGER ofs
, ret
;
807 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
808 if (hand
== INVALID_HANDLE_VALUE
)
811 if (whence
< 0 || whence
> 2)
817 TRACE(":fd (%d) to %s pos %s\n",
818 fd
,wine_dbgstr_longlong(offset
),
819 (whence
==SEEK_SET
)?"SEEK_SET":
820 (whence
==SEEK_CUR
)?"SEEK_CUR":
821 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
823 ofs
.QuadPart
= offset
;
824 if (SetFilePointerEx(hand
, ofs
, &ret
, whence
))
826 fdesc
[fd
].wxflag
&= ~(WX_ATEOF
|WX_READEOF
);
827 /* FIXME: What if we seek _to_ EOF - is EOF set? */
831 TRACE(":error-last error (%d)\n",GetLastError());
832 _dosmaperr(GetLastError());
836 /*********************************************************************
839 LONG CDECL
_lseek(int fd
, LONG offset
, int whence
)
841 return _lseeki64(fd
, offset
, whence
);
844 /*********************************************************************
845 * _locking (MSVCRT.@)
847 * This is untested; the underlying LockFile doesn't work yet.
849 int CDECL
_locking(int fd
, int mode
, LONG nbytes
)
853 HANDLE hand
= fdtoh(fd
);
855 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
856 if (hand
== INVALID_HANDLE_VALUE
)
859 if (mode
< 0 || mode
> 4)
865 TRACE(":fd (%d) by 0x%08x mode %s\n",
866 fd
,nbytes
,(mode
==_LK_UNLCK
)?"_LK_UNLCK":
867 (mode
==_LK_LOCK
)?"_LK_LOCK":
868 (mode
==_LK_NBLCK
)?"_LK_NBLCK":
869 (mode
==_LK_RLCK
)?"_LK_RLCK":
870 (mode
==_LK_NBRLCK
)?"_LK_NBRLCK":
873 if ((cur_locn
= SetFilePointer(hand
, 0L, NULL
, SEEK_CUR
)) == INVALID_SET_FILE_POINTER
)
875 FIXME ("Seek failed\n");
876 *_errno() = EINVAL
; /* FIXME */
879 if (mode
== _LK_LOCK
|| mode
== _LK_RLCK
)
882 ret
= 1; /* just to satisfy gcc */
885 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
890 else if (mode
== _LK_UNLCK
)
891 ret
= UnlockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
893 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
894 /* FIXME - what about error settings? */
898 /*********************************************************************
901 int CDECL
fseek(FILE* file
, long offset
, int whence
)
903 /* Flush output if needed */
904 if(file
->_flag
& _IOWRT
)
907 if(whence
== SEEK_CUR
&& file
->_flag
& _IOREAD
) {
908 offset
-= file
->_cnt
;
910 /* Discard buffered input */
912 file
->_ptr
= file
->_base
;
913 /* Reset direction of i/o */
914 if(file
->_flag
& _IORW
) {
915 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
917 /* Clear end of file flag */
918 file
->_flag
&= ~_IOEOF
;
919 return (_lseek(file
->_file
,offset
,whence
) == -1)?-1:0;
922 /*********************************************************************
925 int CDECL
_chsize(int fd
, long size
)
931 TRACE("(fd=%d, size=%ld)\n", fd
, size
);
936 if (handle
!= INVALID_HANDLE_VALUE
)
938 /* save the current file pointer */
939 cur
= _lseek(fd
, 0, SEEK_CUR
);
942 pos
= _lseek(fd
, size
, SEEK_SET
);
945 ret
= SetEndOfFile(handle
);
946 if (!ret
) _dosmaperr(GetLastError());
949 /* restore the file pointer */
950 _lseek(fd
, cur
, SEEK_SET
);
958 /*********************************************************************
959 * clearerr (MSVCRT.@)
961 void CDECL
clearerr(FILE* file
)
963 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
964 file
->_flag
&= ~(_IOERR
| _IOEOF
);
967 /*********************************************************************
970 void CDECL
rewind(FILE* file
)
972 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
973 fseek(file
, 0L, SEEK_SET
);
977 static int get_flags(const char* mode
, int *open_flags
, int* stream_flags
)
979 int plus
= strchr(mode
, '+') != NULL
;
984 *open_flags
= plus
? _O_RDWR
: _O_RDONLY
;
985 *stream_flags
= plus
? _IORW
: _IOREAD
;
988 *open_flags
= _O_CREAT
| _O_TRUNC
| (plus
? _O_RDWR
: _O_WRONLY
);
989 *stream_flags
= plus
? _IORW
: _IOWRT
;
992 *open_flags
= _O_CREAT
| _O_APPEND
| (plus
? _O_RDWR
: _O_WRONLY
);
993 *stream_flags
= plus
? _IORW
: _IOWRT
;
1003 *open_flags
|= _O_BINARY
;
1004 *open_flags
&= ~_O_TEXT
;
1007 *open_flags
|= _O_TEXT
;
1008 *open_flags
&= ~_O_BINARY
;
1013 FIXME(":unknown flag %c not supported\n",mode
[-1]);
1018 /*********************************************************************
1019 * _fdopen (MSVCRT.@)
1021 FILE* CDECL
_fdopen(int fd
, const char *mode
)
1023 int open_flags
, stream_flags
;
1026 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1) return NULL
;
1029 if (!(file
= alloc_fp()))
1031 else if (init_fp(file
, fd
, stream_flags
) == -1)
1036 else TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
1042 /*********************************************************************
1043 * _wfdopen (MSVCRT.@)
1045 FILE* CDECL
_wfdopen(int fd
, const wchar_t *mode
)
1047 unsigned mlen
= strlenW(mode
);
1048 char *modea
= calloc(mlen
+ 1, 1);
1050 int open_flags
, stream_flags
;
1053 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
1055 if (get_flags(modea
, &open_flags
, &stream_flags
) == -1)
1061 if (!(file
= alloc_fp()))
1063 else if (init_fp(file
, fd
, stream_flags
) == -1)
1071 rewind(file
); /* FIXME: is this needed ??? */
1072 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,debugstr_w(mode
),file
);
1080 /*********************************************************************
1081 * _filelength (MSVCRT.@)
1083 LONG CDECL
_filelength(int fd
)
1085 LONG curPos
= _lseek(fd
, 0, SEEK_CUR
);
1088 LONG endPos
= _lseek(fd
, 0, SEEK_END
);
1091 if (endPos
!= curPos
)
1092 _lseek(fd
, curPos
, SEEK_SET
);
1099 /*********************************************************************
1100 * _filelengthi64 (MSVCRT.@)
1102 __int64 CDECL
_filelengthi64(int fd
)
1104 __int64 curPos
= _lseeki64(fd
, 0, SEEK_CUR
);
1107 __int64 endPos
= _lseeki64(fd
, 0, SEEK_END
);
1110 if (endPos
!= curPos
)
1111 _lseeki64(fd
, curPos
, SEEK_SET
);
1118 /*********************************************************************
1119 * _fileno (MSVCRT.@)
1121 int CDECL
_fileno(FILE* file
)
1123 TRACE(":FILE* (%p) fd (%d)\n",file
,file
->_file
);
1127 /*********************************************************************
1128 * _futime (MSVCRT.@)
1130 int CDECL
_futime(int fd
, struct _utimbuf
*t
)
1132 HANDLE hand
= fdtoh(fd
);
1135 if (hand
== INVALID_HANDLE_VALUE
)
1142 RtlSecondsSince1970ToTime(currTime
, (LARGE_INTEGER
*)&at
);
1147 RtlSecondsSince1970ToTime(t
->actime
, (LARGE_INTEGER
*)&at
);
1148 if (t
->actime
== t
->modtime
)
1151 RtlSecondsSince1970ToTime(t
->modtime
, (LARGE_INTEGER
*)&wt
);
1154 if (!SetFileTime(hand
, NULL
, &at
, &wt
))
1156 _dosmaperr(GetLastError());
1162 /*********************************************************************
1163 * _get_osfhandle (MSVCRT.@)
1165 intptr_t CDECL
_get_osfhandle(int fd
)
1167 HANDLE hand
= fdtoh(fd
);
1168 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1170 return (long)(LONG_PTR
)hand
;
1173 /*********************************************************************
1174 * _isatty (MSVCRT.@)
1176 int CDECL
_isatty(int fd
)
1178 HANDLE hand
= fdtoh(fd
);
1180 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1181 if (hand
== INVALID_HANDLE_VALUE
)
1184 return GetFileType(hand
) == FILE_TYPE_CHAR
? 1 : 0;
1187 /*********************************************************************
1188 * _mktemp (MSVCRT.@)
1190 char * CDECL
_mktemp(char *pattern
)
1193 char *retVal
= pattern
;
1198 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1202 id
= GetCurrentProcessId();
1206 int tempNum
= id
/ 10;
1207 *pattern
-- = id
- (tempNum
* 10) + '0';
1213 *pattern
= letter
++;
1214 if (GetFileAttributesA(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1215 GetLastError() == ERROR_FILE_NOT_FOUND
)
1217 } while(letter
<= 'z');
1221 /*********************************************************************
1222 * _wmktemp (MSVCRT.@)
1224 wchar_t * CDECL
_wmktemp(wchar_t *pattern
)
1227 wchar_t *retVal
= pattern
;
1229 wchar_t letter
= 'a';
1232 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1236 id
= GetCurrentProcessId();
1240 int tempNum
= id
/ 10;
1241 *pattern
-- = id
- (tempNum
* 10) + '0';
1247 if (GetFileAttributesW(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1248 GetLastError() == ERROR_FILE_NOT_FOUND
)
1250 *pattern
= letter
++;
1251 } while(letter
!= '|');
1255 /*static */unsigned split_oflags(unsigned oflags
)
1258 unsigned unsupp
; /* until we support everything */
1260 if (oflags
& _O_APPEND
) wxflags
|= WX_APPEND
;
1261 if (oflags
& _O_BINARY
) {/* Nothing to do */}
1262 else if (oflags
& _O_TEXT
) wxflags
|= WX_TEXT
;
1263 else if (*__p__fmode() & _O_BINARY
) {/* Nothing to do */}
1264 else wxflags
|= WX_TEXT
; /* default to TEXT*/
1265 if (oflags
& _O_NOINHERIT
) wxflags
|= WX_DONTINHERIT
;
1267 if ((unsupp
= oflags
& ~(
1268 _O_BINARY
|_O_TEXT
|_O_APPEND
|
1269 _O_TRUNC
|_O_EXCL
|_O_CREAT
|
1270 _O_RDWR
|_O_WRONLY
|_O_TEMPORARY
|
1272 _O_SEQUENTIAL
|_O_RANDOM
|_O_SHORT_LIVED
1274 ERR(":unsupported oflags 0x%04x\n",unsupp
);
1279 /*********************************************************************
1282 int CDECL
_pipe(int *pfds
, unsigned int psize
, int textmode
)
1285 SECURITY_ATTRIBUTES sa
;
1286 HANDLE readHandle
, writeHandle
;
1294 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
1295 sa
.bInheritHandle
= !(textmode
& _O_NOINHERIT
);
1296 sa
.lpSecurityDescriptor
= NULL
;
1297 if (CreatePipe(&readHandle
, &writeHandle
, &sa
, psize
))
1299 unsigned int wxflags
= split_oflags(textmode
);
1303 fd
= alloc_fd(readHandle
, wxflags
);
1307 fd
= alloc_fd(writeHandle
, wxflags
);
1316 CloseHandle(writeHandle
);
1322 CloseHandle(readHandle
);
1323 CloseHandle(writeHandle
);
1329 _dosmaperr(GetLastError());
1334 /*********************************************************************
1337 int CDECL
_sopen( const char *path
, int oflags
, int shflags
, ... )
1341 DWORD access
= 0, creation
= 0, attrib
;
1345 SECURITY_ATTRIBUTES sa
;
1348 TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n",
1349 path
, oflags
, shflags
);
1351 wxflag
= split_oflags(oflags
);
1352 switch (oflags
& (_O_RDONLY
| _O_WRONLY
| _O_RDWR
))
1354 case _O_RDONLY
: access
|= GENERIC_READ
; break;
1355 case _O_WRONLY
: access
|= GENERIC_WRITE
; break;
1356 case _O_RDWR
: access
|= GENERIC_WRITE
| GENERIC_READ
; break;
1359 if (oflags
& _O_CREAT
)
1361 va_start(ap
, shflags
);
1362 pmode
= va_arg(ap
, int);
1365 if(pmode
& ~(_S_IREAD
| _S_IWRITE
))
1366 FIXME(": pmode 0x%04x ignored\n", pmode
);
1368 WARN(": pmode 0x%04x ignored\n", pmode
);
1370 if (oflags
& _O_EXCL
)
1371 creation
= CREATE_NEW
;
1372 else if (oflags
& _O_TRUNC
)
1373 creation
= CREATE_ALWAYS
;
1375 creation
= OPEN_ALWAYS
;
1377 else /* no _O_CREAT */
1379 if (oflags
& _O_TRUNC
)
1380 creation
= TRUNCATE_EXISTING
;
1382 creation
= OPEN_EXISTING
;
1391 sharing
= FILE_SHARE_READ
;
1394 sharing
= FILE_SHARE_WRITE
;
1397 sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1400 ERR( "Unhandled shflags 0x%x\n", shflags
);
1403 attrib
= FILE_ATTRIBUTE_NORMAL
;
1405 if (oflags
& _O_TEMPORARY
)
1407 attrib
|= FILE_FLAG_DELETE_ON_CLOSE
;
1409 sharing
|= FILE_SHARE_DELETE
;
1412 sa
.nLength
= sizeof( SECURITY_ATTRIBUTES
);
1413 sa
.lpSecurityDescriptor
= NULL
;
1414 sa
.bInheritHandle
= (oflags
& _O_NOINHERIT
) ? FALSE
: TRUE
;
1416 hand
= CreateFileA(path
, access
, sharing
, &sa
, creation
, attrib
, 0);
1418 if (hand
== INVALID_HANDLE_VALUE
) {
1419 WARN(":failed-last error (%d)\n",GetLastError());
1420 _dosmaperr(GetLastError());
1424 fd
= alloc_fd(hand
, wxflag
);
1426 TRACE(":fd (%d) handle (%p)\n",fd
, hand
);
1430 /*********************************************************************
1431 * _wsopen (MSVCRT.@)
1433 int CDECL
_wsopen( const wchar_t* path
, int oflags
, int shflags
, ... )
1435 const unsigned int len
= strlenW(path
);
1436 char *patha
= calloc(len
+ 1,1);
1440 va_start(ap
, shflags
);
1441 pmode
= va_arg(ap
, int);
1444 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1446 int retval
= _sopen(patha
,oflags
,shflags
,pmode
);
1450 _dosmaperr(GetLastError());
1455 /*********************************************************************
1458 int CDECL
_open( const char *path
, int flags
, ... )
1462 if (flags
& _O_CREAT
)
1465 va_start(ap
, flags
);
1466 pmode
= va_arg(ap
, int);
1468 return _sopen( path
, flags
, _SH_DENYNO
, pmode
);
1471 return _sopen( path
, flags
, _SH_DENYNO
);
1474 /*********************************************************************
1477 int CDECL
_wopen(const wchar_t *path
,int flags
,...)
1479 const unsigned int len
= strlenW(path
);
1480 char *patha
= calloc(len
+ 1,1);
1484 va_start(ap
, flags
);
1485 pmode
= va_arg(ap
, int);
1488 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1490 int retval
= _open(patha
,flags
,pmode
);
1495 _dosmaperr(GetLastError());
1499 /*********************************************************************
1502 int CDECL
_creat(const char *path
, int flags
)
1504 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1505 return _open(path
, usedFlags
);
1508 /*********************************************************************
1509 * _wcreat (MSVCRT.@)
1511 int CDECL
_wcreat(const wchar_t *path
, int flags
)
1513 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1514 return _wopen(path
, usedFlags
);
1517 /*********************************************************************
1518 * _open_osfhandle (MSVCRT.@)
1520 int CDECL
_open_osfhandle(intptr_t handle
, int oflags
)
1524 /* _O_RDONLY (0) always matches, so set the read flag
1525 * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
1526 * file, so set the write flag. It also only sets _O_TEXT if it wants
1527 * text - it never sets _O_BINARY.
1529 /* don't let split_oflags() decide the mode if no mode is passed */
1530 if (!(oflags
& (_O_BINARY
| _O_TEXT
)))
1531 oflags
|= _O_BINARY
;
1533 fd
= alloc_fd((HANDLE
)(LONG_PTR
)handle
, split_oflags(oflags
));
1534 TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle
, fd
, oflags
);
1538 /*********************************************************************
1541 int CDECL
_rmtmp(void)
1543 int num_removed
= 0, i
;
1546 for (i
= 3; i
< stream_idx
; i
++)
1547 if (fstreams
[i
] && fstreams
[i
]->_tmpfname
)
1549 fclose(fstreams
[i
]);
1555 TRACE(":removed (%d) temp files\n",num_removed
);
1559 /*********************************************************************
1560 * (internal) remove_cr
1562 * Translate all \r\n to \n inplace.
1563 * return the number of \r removed
1564 * Corner cases required by some apps:
1566 * BUG: should save state across calls somehow, so CR LF that
1567 * straddles buffer boundary gets recognized properly?
1569 static unsigned int remove_cr(char *buf
, unsigned int count
)
1573 for (i
=0, j
=0; j
< count
; j
++)
1574 if ((buf
[j
] != '\r') || ((j
+1) < count
&& buf
[j
+1] != '\n'))
1580 /*********************************************************************
1583 static int read_i(int fd
, void *buf
, unsigned int count
)
1586 char *bufstart
= buf
;
1587 HANDLE hand
= fdtoh(fd
);
1589 if (fdesc
[fd
].wxflag
& WX_READEOF
) {
1590 fdesc
[fd
].wxflag
|= WX_ATEOF
;
1591 TRACE("already at EOF, returning 0\n");
1594 /* Don't trace small reads, it gets *very* annoying */
1596 TRACE(":fd (%d) handle (%p) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1597 if (hand
== INVALID_HANDLE_VALUE
)
1600 /* Reading single bytes in O_TEXT mode makes things slow
1601 * So read big chunks
1603 if (ReadFile(hand
, bufstart
, count
, &num_read
, NULL
))
1605 if (fdesc
[fd
].wxflag
& WX_TEXT
)
1608 /* in text mode, a ctrl-z signals EOF */
1609 for (i
=0; i
<num_read
; i
++)
1611 if (bufstart
[i
] == 0x1a)
1614 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1615 TRACE(":^Z EOF %s\n",debugstr_an(buf
,num_read
));
1620 if (count
!= 0 && num_read
== 0)
1622 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1623 TRACE(":EOF %s\n",debugstr_an(buf
,num_read
));
1628 if (GetLastError() == ERROR_BROKEN_PIPE
)
1630 TRACE(":end-of-pipe\n");
1631 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1636 TRACE(":failed-last error (%d)\n",GetLastError());
1642 TRACE("(%u), %s\n",num_read
,debugstr_an(buf
, num_read
));
1646 /*********************************************************************
1649 int CDECL
_read(int fd
, void *buf
, unsigned int count
)
1652 num_read
= read_i(fd
, buf
, count
);
1653 if (num_read
>0 && fdesc
[fd
].wxflag
& WX_TEXT
)
1655 num_read
-= remove_cr(buf
,num_read
);
1660 /*********************************************************************
1661 * _setmode (MSVCRT.@)
1663 int CDECL
_setmode(int fd
,int mode
)
1665 int ret
= fdesc
[fd
].wxflag
& WX_TEXT
? _O_TEXT
: _O_BINARY
;
1666 if (mode
& (~(_O_TEXT
|_O_BINARY
)))
1667 FIXME("fd (%d) mode (0x%08x) unknown\n",fd
,mode
);
1668 if ((mode
& _O_TEXT
) == _O_TEXT
)
1669 fdesc
[fd
].wxflag
|= WX_TEXT
;
1671 fdesc
[fd
].wxflag
&= ~WX_TEXT
;
1675 /*********************************************************************
1678 long CDECL
_tell(int fd
)
1680 return _lseek(fd
, 0, SEEK_CUR
);
1683 /*********************************************************************
1684 * _telli64 (MSVCRT.@)
1686 __int64 CDECL
_telli64(int fd
)
1688 return _lseeki64(fd
, 0, SEEK_CUR
);
1691 /*********************************************************************
1692 * _tempnam (MSVCRT.@)
1694 char * CDECL
_tempnam(const char *dir
, const char *prefix
)
1696 char tmpbuf
[MAX_PATH
];
1697 const char *tmp_dir
= getenv("TMP");
1699 if (tmp_dir
) dir
= tmp_dir
;
1701 TRACE("dir (%s) prefix (%s)\n",dir
,prefix
);
1702 if (GetTempFileNameA(dir
,prefix
,0,tmpbuf
))
1704 TRACE("got name (%s)\n",tmpbuf
);
1705 DeleteFileA(tmpbuf
);
1706 return _strdup(tmpbuf
);
1708 TRACE("failed (%d)\n",GetLastError());
1712 /*********************************************************************
1713 * _wtempnam (MSVCRT.@)
1715 wchar_t * CDECL
_wtempnam(const wchar_t *dir
, const wchar_t *prefix
)
1717 wchar_t tmpbuf
[MAX_PATH
];
1719 TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir
),debugstr_w(prefix
));
1720 if (GetTempFileNameW(dir
,prefix
,0,tmpbuf
))
1722 TRACE("got name (%s)\n",debugstr_w(tmpbuf
));
1723 DeleteFileW(tmpbuf
);
1724 return _wcsdup(tmpbuf
);
1726 TRACE("failed (%d)\n",GetLastError());
1730 /*********************************************************************
1733 int CDECL
_umask(int umask
)
1735 int old_umask
= umask
;
1736 TRACE("(%d)\n",umask
);
1737 MSVCRT_umask
= umask
;
1741 /*********************************************************************
1744 int CDECL
_utime(const char* path
, struct _utimbuf
*t
)
1746 int fd
= _open(path
, _O_WRONLY
| _O_BINARY
);
1750 int retVal
= _futime(fd
, t
);
1757 /*********************************************************************
1758 * _wutime (MSVCRT.@)
1760 int CDECL
_wutime(const wchar_t* path
, struct _utimbuf
*t
)
1762 int fd
= _wopen(path
, _O_WRONLY
| _O_BINARY
);
1766 int retVal
= _futime(fd
, t
);
1773 /*********************************************************************
1776 int CDECL
_write(int fd
, const void* buf
, unsigned int count
)
1779 HANDLE hand
= fdtoh(fd
);
1781 /* Don't trace small writes, it gets *very* annoying */
1784 TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1786 if (hand
== INVALID_HANDLE_VALUE
)
1792 /* If appending, go to EOF */
1793 if (fdesc
[fd
].wxflag
& WX_APPEND
)
1794 _lseek(fd
, 0, FILE_END
);
1796 if (!(fdesc
[fd
].wxflag
& WX_TEXT
))
1798 if (WriteFile(hand
, buf
, count
, &num_written
, NULL
)
1799 && (num_written
== count
))
1801 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd
,
1802 hand
, GetLastError());
1807 unsigned int i
, j
, nr_lf
;
1810 const char *s
= (const char *)buf
, *buf_start
= (const char *)buf
;
1811 /* find number of \n ( without preceding \r ) */
1812 for ( nr_lf
=0,i
= 0; i
<count
; i
++)
1817 /*if ((i >1) && (s[i-1] == '\r')) nr_lf--; */
1822 if ((q
= p
= malloc(count
+ nr_lf
)))
1824 for (s
= (const char *)buf
, i
= 0, j
= 0; i
< count
; i
++)
1829 /*if ((i >1) && (s[i-1] == '\r'))j--;*/
1836 FIXME("Malloc failed\n");
1844 if ((WriteFile(hand
, q
, count
+nr_lf
, &num_written
, NULL
) == 0 ) || (num_written
!= count
+nr_lf
))
1846 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
1847 fd
, hand
, GetLastError(), num_written
);
1851 return s
- buf_start
;
1863 /*********************************************************************
1866 int CDECL
_putw(int val
, FILE* file
)
1869 len
= _write(file
->_file
, &val
, sizeof(val
));
1870 if (len
== sizeof(val
)) return val
;
1871 file
->_flag
|= _IOERR
;
1875 /*********************************************************************
1878 int CDECL
fclose(FILE* file
)
1883 free(file
->_tmpfname
);
1884 file
->_tmpfname
= NULL
;
1885 /* flush stdio buffers */
1886 if(file
->_flag
& _IOWRT
)
1888 if(file
->_flag
& _IOMYBUF
)
1891 r
=_close(file
->_file
);
1895 return ((r
== -1) || (flag
& _IOERR
) ? EOF
: 0);
1898 /*********************************************************************
1901 int CDECL
feof(FILE* file
)
1903 return file
->_flag
& _IOEOF
;
1906 /*********************************************************************
1909 int CDECL
ferror(FILE* file
)
1911 return file
->_flag
& _IOERR
;
1914 /*********************************************************************
1915 * _filbuf (MSVCRT.@)
1917 int CDECL
_filbuf(FILE* file
)
1919 /* Allocate buffer if needed */
1920 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
) ) {
1923 if(!(file
->_flag
& _IOREAD
)) {
1924 if(file
->_flag
& _IORW
) {
1925 file
->_flag
|= _IOREAD
;
1930 if(file
->_flag
& _IONBF
) {
1933 if ((r
= read_i(file
->_file
,&c
,1)) != 1) {
1934 file
->_flag
|= (r
== 0) ? _IOEOF
: _IOERR
;
1939 file
->_cnt
= read_i(file
->_file
, file
->_base
, file
->_bufsiz
);
1941 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
1946 file
->_ptr
= file
->_base
+1;
1947 return *(unsigned char *)file
->_base
;
1951 /*********************************************************************
1954 int CDECL
fgetc(FILE* file
)
1961 i
= (unsigned char *)file
->_ptr
++;
1965 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
)
1966 || ((j
!= '\r') || (file
->_cnt
&& file
->_ptr
[0] != '\n')))
1971 /*********************************************************************
1972 * _fgetchar (MSVCRT.@)
1974 int CDECL
_fgetchar(void)
1976 return fgetc(stdin
);
1979 /*********************************************************************
1982 char * CDECL
fgets(char *s
, int size
, FILE* file
)
1985 char * buf_start
= s
;
1987 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
1988 file
,file
->_file
,s
,size
);
1990 while ((size
>1) && (cc
= fgetc(file
)) != EOF
&& cc
!= '\n')
1995 if ((cc
== EOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
1997 TRACE(":nothing read\n");
2000 if ((cc
!= EOF
) && (size
> 1))
2003 TRACE(":got %s\n", debugstr_a(buf_start
));
2007 /*********************************************************************
2010 * In _O_TEXT mode, multibyte characters are read from the file, dropping
2011 * the CR from CR/LF combinations
2013 wint_t CDECL
fgetwc(FILE* file
)
2017 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2023 for(i
=0; i
<sizeof(wc
); i
++)
2036 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
2047 if ((*__p___mb_cur_max() > 1) && isleadbyte(c
))
2049 FIXME("Treat Multibyte characters\n");
2057 /*********************************************************************
2060 int CDECL
_getw(FILE* file
)
2065 for (j
=0; j
<sizeof(int); j
++) {
2068 file
->_flag
|= _IOEOF
;
2076 /*********************************************************************
2079 wint_t CDECL
getwc(FILE* file
)
2081 return fgetwc(file
);
2084 /*********************************************************************
2085 * _fgetwchar (MSVCRT.@)
2087 wint_t CDECL
_fgetwchar(void)
2089 return fgetwc(stdin
);
2092 /*********************************************************************
2093 * getwchar (MSVCRT.@)
2095 wint_t CDECL
getwchar(void)
2097 return _fgetwchar();
2100 /*********************************************************************
2103 wchar_t * CDECL
fgetws(wchar_t *s
, int size
, FILE* file
)
2106 wchar_t * buf_start
= s
;
2108 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
2109 file
,file
->_file
,s
,size
);
2111 while ((size
>1) && (cc
= fgetwc(file
)) != WEOF
&& cc
!= '\n')
2116 if ((cc
== WEOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
2118 TRACE(":nothing read\n");
2121 if ((cc
!= WEOF
) && (size
> 1))
2124 TRACE(":got %s\n", debugstr_w(buf_start
));
2128 /*********************************************************************
2131 size_t CDECL
fwrite(const void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2133 size_t wrcnt
=size
* nmemb
;
2138 int pcnt
=(file
->_cnt
>wrcnt
)? wrcnt
: file
->_cnt
;
2139 memcpy(file
->_ptr
, ptr
, pcnt
);
2144 ptr
= (const char*)ptr
+ pcnt
;
2145 } else if(!(file
->_flag
& _IOWRT
)) {
2146 if(file
->_flag
& _IORW
) {
2147 file
->_flag
|= _IOWRT
;
2153 int res
=flush_buffer(file
);
2155 int pwritten
= _write(file
->_file
, ptr
, wrcnt
);
2158 file
->_flag
|= _IOERR
;
2161 written
+= pwritten
;
2164 return written
/ size
;
2167 /*********************************************************************
2170 wint_t CDECL
fputwc(wint_t wc
, FILE* file
)
2173 if (fwrite( &mwc
, sizeof(mwc
), 1, file
) != 1)
2178 /*********************************************************************
2179 * _fputwchar (MSVCRT.@)
2181 wint_t CDECL
_fputwchar(wint_t wc
)
2183 return fputwc(wc
, stdout
);
2186 /*********************************************************************
2187 * _fsopen (MSVCRT.@)
2189 FILE * CDECL
_fsopen(const char *path
, const char *mode
, int share
)
2192 int open_flags
, stream_flags
, fd
;
2194 TRACE("(%s,%s)\n",path
,mode
);
2196 /* map mode string to open() flags. "man fopen" for possibilities. */
2197 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2201 fd
= _sopen(path
, open_flags
, share
, _S_IREAD
| _S_IWRITE
);
2204 else if ((file
= alloc_fp()) && init_fp(file
, fd
, stream_flags
)
2206 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
2213 TRACE(":got (%p)\n",file
);
2214 if (fd
>= 0 && !file
)
2220 /*********************************************************************
2221 * _wfsopen (MSVCRT.@)
2223 FILE * CDECL
_wfsopen(const wchar_t *path
, const wchar_t *mode
, int share
)
2225 const unsigned int plen
= strlenW(path
), mlen
= strlenW(mode
);
2226 char *patha
= calloc(plen
+ 1, 1);
2227 char *modea
= calloc(mlen
+ 1, 1);
2229 TRACE("(%s,%s)\n",debugstr_w(path
),debugstr_w(mode
));
2231 if (patha
&& modea
&&
2232 WideCharToMultiByte(CP_ACP
,0,path
,plen
,patha
,plen
,NULL
,NULL
) &&
2233 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
2235 FILE *retval
= _fsopen(patha
,modea
,share
);
2242 _dosmaperr(GetLastError());
2246 /*********************************************************************
2249 FILE * CDECL
fopen(const char *path
, const char *mode
)
2251 return _fsopen( path
, mode
, _SH_DENYNO
);
2254 /*********************************************************************
2255 * _wfopen (MSVCRT.@)
2257 FILE * CDECL
_wfopen(const wchar_t *path
, const wchar_t *mode
)
2259 return _wfsopen( path
, mode
, _SH_DENYNO
);
2262 /* fputc calls _flsbuf which calls fputc */
2263 int CDECL
_flsbuf(int c
, FILE* file
);
2265 /*********************************************************************
2268 int CDECL
fputc(int c
, FILE* file
)
2275 int res
= flush_buffer(file
);
2276 return res
? res
: c
;
2281 return _flsbuf(c
, file
);
2285 /*********************************************************************
2286 * _flsbuf (MSVCRT.@)
2288 int CDECL
_flsbuf(int c
, FILE* file
)
2290 /* Flush output buffer */
2291 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2294 if(!(file
->_flag
& _IOWRT
)) {
2295 if(file
->_flag
& _IORW
) {
2296 file
->_flag
|= _IOWRT
;
2302 int res
=flush_buffer(file
);
2303 return res
?res
: fputc(c
, file
);
2307 len
= _write(file
->_file
, &cc
, 1);
2308 if (len
== 1) return c
& 0xff;
2309 file
->_flag
|= _IOERR
;
2314 /*********************************************************************
2315 * _fputchar (MSVCRT.@)
2317 int CDECL
_fputchar(int c
)
2319 return fputc(c
, stdout
);
2322 /*********************************************************************
2325 size_t CDECL
fread(void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2326 { size_t rcnt
=size
* nmemb
;
2333 /* first buffered data */
2335 int pcnt
= (rcnt
>file
->_cnt
)? file
->_cnt
:rcnt
;
2336 memcpy(ptr
, file
->_ptr
, pcnt
);
2339 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
)
2340 pcnt
-= remove_cr(ptr
,pcnt
);
2343 ptr
= (char*)ptr
+ pcnt
;
2344 } else if(!(file
->_flag
& _IOREAD
)) {
2345 if(file
->_flag
& _IORW
) {
2346 file
->_flag
|= _IOREAD
;
2353 /* Fill the buffer on small reads.
2354 * TODO: Use a better buffering strategy.
2356 if (!file
->_cnt
&& size
*nmemb
<= BUFSIZ
/2 && !(file
->_flag
& _IONBF
)) {
2357 if (file
->_bufsiz
== 0) {
2360 file
->_cnt
= _read(file
->_file
, file
->_base
, file
->_bufsiz
);
2361 file
->_ptr
= file
->_base
;
2362 i
= (file
->_cnt
<rcnt
) ? file
->_cnt
: rcnt
;
2363 /* If the buffer fill reaches eof but fread wouldn't, clear eof. */
2364 if (i
> 0 && i
< file
->_cnt
) {
2365 fdesc
[file
->_file
].wxflag
&= ~WX_ATEOF
;
2366 file
->_flag
&= ~_IOEOF
;
2369 memcpy(ptr
, file
->_ptr
, i
);
2374 i
= _read(file
->_file
,ptr
, rcnt
);
2378 ptr
= (char *)ptr
+i
;
2379 /* expose feof condition in the flags
2380 * MFC tests file->_flag for feof, and doesn't call feof())
2382 if ( fdesc
[file
->_file
].wxflag
& WX_ATEOF
)
2383 file
->_flag
|= _IOEOF
;
2386 file
->_flag
|= _IOERR
;
2396 /*********************************************************************
2397 * freopen (MSVCRT.@)
2400 FILE* CDECL
freopen(const char *path
, const char *mode
,FILE* file
)
2402 int open_flags
, stream_flags
, fd
;
2404 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n",path
,mode
,file
,file
->_file
);
2407 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2412 /* map mode string to open() flags. "man fopen" for possibilities. */
2413 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2417 fd
= _open(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2420 else if (init_fp(file
, fd
, stream_flags
) == -1)
2423 WARN(":failed-last error (%d)\n",GetLastError());
2424 _dosmaperr(GetLastError());
2433 /*********************************************************************
2434 * wfreopen (MSVCRT.@)
2437 FILE* CDECL
_wfreopen(const wchar_t *path
, const wchar_t *mode
,FILE* file
)
2439 int open_flags
, stream_flags
, fd
;
2441 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path
), debugstr_w(mode
), file
, file
->_file
);
2444 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2449 /* map mode string to open() flags. "man fopen" for possibilities. */
2450 if (get_flags((char*)mode
, &open_flags
, &stream_flags
) == -1)
2454 fd
= _wopen(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2457 else if (init_fp(file
, fd
, stream_flags
) == -1)
2460 WARN(":failed-last error (%d)\n",GetLastError());
2461 _dosmaperr(GetLastError());
2470 /*********************************************************************
2471 * fsetpos (MSVCRT.@)
2473 int CDECL
fsetpos(FILE* file
, const fpos_t *pos
)
2475 /* Note that all this has been lifted 'as is' from fseek */
2476 if(file
->_flag
& _IOWRT
)
2479 /* Discard buffered input */
2481 file
->_ptr
= file
->_base
;
2483 /* Reset direction of i/o */
2484 if(file
->_flag
& _IORW
) {
2485 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
2488 return (_lseeki64(file
->_file
,*pos
,SEEK_SET
) == -1) ? -1 : 0;
2491 /*********************************************************************
2494 LONG CDECL
ftell(FILE* file
)
2499 if( file
->_flag
& _IOWRT
) {
2500 off
= file
->_ptr
- file
->_base
;
2505 pos
= _tell(file
->_file
);
2506 if(pos
== -1) return pos
;
2510 /*********************************************************************
2511 * fgetpos (MSVCRT.@)
2513 int CDECL
fgetpos(FILE* file
, fpos_t *pos
)
2515 /* This code has been lifted form the ftell function */
2518 *pos
= _lseeki64(file
->_file
,0,SEEK_CUR
);
2520 if (*pos
== -1) return -1;
2523 if( file
->_flag
& _IOWRT
) {
2524 off
= file
->_ptr
- file
->_base
;
2534 /*********************************************************************
2537 int CDECL
fputs(const char *s
, FILE* file
)
2539 size_t i
, len
= strlen(s
);
2540 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2541 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2542 for (i
=0; i
<len
; i
++)
2543 if (fputc(s
[i
], file
) == EOF
)
2548 /*********************************************************************
2551 int CDECL
fputws(const wchar_t *s
, FILE* file
)
2553 size_t i
, len
= strlenW(s
);
2554 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2555 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2556 for (i
=0; i
<len
; i
++)
2558 if ((s
[i
] == '\n') && (fputc('\r', file
) == EOF
))
2560 if (fputwc(s
[i
], file
) == WEOF
)
2566 /*********************************************************************
2567 * getchar (MSVCRT.@)
2569 int CDECL
getchar(void)
2571 return fgetc(stdin
);
2574 /*********************************************************************
2577 int CDECL
getc(FILE* file
)
2582 /*********************************************************************
2585 char * CDECL
gets(char *buf
)
2588 char * buf_start
= buf
;
2590 for(cc
= fgetc(stdin
); cc
!= EOF
&& cc
!= '\n';
2592 if(cc
!= '\r') *buf
++ = (char)cc
;
2596 TRACE("got '%s'\n", buf_start
);
2600 /*********************************************************************
2603 wchar_t* CDECL
_getws(wchar_t* buf
)
2608 for (cc
= fgetwc(stdin
); cc
!= WEOF
&& cc
!= '\n';
2612 *buf
++ = (wchar_t)cc
;
2616 TRACE("got %s\n", debugstr_w(ws
));
2620 /*********************************************************************
2623 int CDECL
putc(int c
, FILE* file
)
2625 return fputc(c
, file
);
2628 /*********************************************************************
2629 * putchar (MSVCRT.@)
2631 int CDECL
putchar(int c
)
2633 return fputc(c
, stdout
);
2636 /*********************************************************************
2639 int CDECL
puts(const char *s
)
2641 size_t len
= strlen(s
);
2642 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2643 return fwrite("\n",1,1,stdout
) == 1 ? 0 : EOF
;
2646 /*********************************************************************
2649 int CDECL
_putws(const wchar_t *s
)
2651 static const wchar_t nl
= '\n';
2652 size_t len
= strlenW(s
);
2653 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2654 return fwrite(&nl
,sizeof(nl
),1,stdout
) == 1 ? 0 : EOF
;
2657 /*********************************************************************
2660 int CDECL
remove(const char *path
)
2662 TRACE("(%s)\n",path
);
2663 if (DeleteFileA(path
))
2665 TRACE(":failed (%d)\n",GetLastError());
2666 _dosmaperr(GetLastError());
2670 /*********************************************************************
2671 * _wremove (MSVCRT.@)
2673 int CDECL
_wremove(const wchar_t *path
)
2675 TRACE("(%s)\n",debugstr_w(path
));
2676 if (DeleteFileW(path
))
2678 TRACE(":failed (%d)\n",GetLastError());
2679 _dosmaperr(GetLastError());
2683 /*********************************************************************
2686 int CDECL
rename(const char *oldpath
,const char *newpath
)
2688 TRACE(":from %s to %s\n",oldpath
,newpath
);
2689 if (MoveFileExA(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2691 TRACE(":failed (%d)\n",GetLastError());
2692 _dosmaperr(GetLastError());
2696 /*********************************************************************
2697 * _wrename (MSVCRT.@)
2699 int CDECL
_wrename(const wchar_t *oldpath
,const wchar_t *newpath
)
2701 TRACE(":from %s to %s\n",debugstr_w(oldpath
),debugstr_w(newpath
));
2702 if (MoveFileExW(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2704 TRACE(":failed (%d)\n",GetLastError());
2705 _dosmaperr(GetLastError());
2709 /*********************************************************************
2710 * setvbuf (MSVCRT.@)
2712 int CDECL
setvbuf(FILE* file
, char *buf
, int mode
, size_t size
)
2714 /* TODO: Check if file busy */
2720 if(mode
== _IOFBF
) {
2721 file
->_flag
&= ~_IONBF
;
2722 file
->_base
= file
->_ptr
= buf
;
2724 file
->_bufsiz
= size
;
2727 file
->_flag
|= _IONBF
;
2732 /*********************************************************************
2735 void CDECL
setbuf(FILE* file
, char *buf
)
2737 setvbuf(file
, buf
, buf
? _IOFBF
: _IONBF
, BUFSIZ
);
2740 /*********************************************************************
2743 char * CDECL
tmpnam(char *s
)
2751 int_to_base32(GetCurrentProcessId(), tmpstr
);
2752 p
= s
+ sprintf(s
, "\\s%s.", tmpstr
);
2753 for (count
= 0; count
< TMP_MAX
; count
++)
2755 int_to_base32(unique
++, tmpstr
);
2757 if (GetFileAttributesA(s
) == INVALID_FILE_ATTRIBUTES
&&
2758 GetLastError() == ERROR_FILE_NOT_FOUND
)
2764 /*********************************************************************
2765 * wtmpnam (MSVCRT.@)
2767 wchar_t * CDECL
_wtmpnam(wchar_t *s
)
2769 ERR("UNIMPLEMENTED!\n");
2773 /*********************************************************************
2774 * tmpfile (MSVCRT.@)
2776 FILE* CDECL
tmpfile(void)
2778 char *filename
= tmpnam(NULL
);
2783 fd
= _open(filename
, _O_CREAT
| _O_BINARY
| _O_RDWR
| _O_TEMPORARY
);
2784 if (fd
!= -1 && (file
= alloc_fp()))
2786 if (init_fp(file
, fd
, _O_RDWR
) == -1)
2791 else file
->_tmpfname
= _strdup(filename
);
2797 /*********************************************************************
2798 * vfprintf (MSVCRT.@)
2800 int CDECL
vfprintf(FILE* file
, const char *format
, va_list valist
)
2802 char buf
[2048], *mem
= buf
;
2803 int written
, resize
= sizeof(buf
), retval
;
2804 /* There are two conventions for vsnprintf failing:
2805 * Return -1 if we truncated, or
2806 * Return the number of bytes that would have been written
2807 * The code below handles both cases
2809 while ((written
= _vsnprintf(mem
, resize
, format
, valist
)) == -1 ||
2812 resize
= (written
== -1 ? resize
* 2 : written
+ 1);
2815 if (!(mem
= malloc(resize
)))
2818 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2824 /*********************************************************************
2825 * vfwprintf (MSVCRT.@)
2827 * Is final char included in written (then resize is too big) or not
2828 * (then we must test for equality too)?
2830 int CDECL
vfwprintf(FILE* file
, const wchar_t *format
, va_list valist
)
2832 wchar_t buf
[2048], *mem
= buf
;
2833 int written
, resize
= sizeof(buf
) / sizeof(wchar_t), retval
;
2834 /* See vfprintf comments */
2835 while ((written
= _vsnwprintf(mem
, resize
, format
, valist
)) == -1 ||
2838 resize
= (written
== -1 ? resize
* 2 : written
+ sizeof(wchar_t));
2841 if (!(mem
= malloc(resize
*sizeof(*mem
))))
2845 /* Check if outputting to a text-file */
2846 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
)
2848 /* Convert each character and stop at the first invalid character. Behavior verified by tests under WinXP SP2 */
2849 char chMultiByte
[MB_LEN_MAX
];
2855 for (p
= mem
; *p
; p
++)
2857 nReturn
= wctomb(chMultiByte
, *p
);
2862 retval
+= fwrite(chMultiByte
, 1, nReturn
, file
);
2867 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2876 /*********************************************************************
2877 * vprintf (MSVCRT.@)
2879 int CDECL
vprintf(const char *format
, va_list valist
)
2881 return vfprintf(stdout
,format
,valist
);
2884 /*********************************************************************
2885 * vwprintf (MSVCRT.@)
2887 int CDECL
vwprintf(const wchar_t *format
, va_list valist
)
2889 return vfwprintf(stdout
,format
,valist
);
2892 /*********************************************************************
2893 * fprintf (MSVCRT.@)
2895 int CDECL
fprintf(FILE* file
, const char *format
, ...)
2899 va_start(valist
, format
);
2900 res
= vfprintf(file
, format
, valist
);
2905 /*********************************************************************
2906 * fwprintf (MSVCRT.@)
2908 int CDECL
fwprintf(FILE* file
, const wchar_t *format
, ...)
2912 va_start(valist
, format
);
2913 res
= vfwprintf(file
, format
, valist
);
2918 /*********************************************************************
2921 int CDECL
printf(const char *format
, ...)
2925 va_start(valist
, format
);
2926 res
= vfprintf(stdout
, format
, valist
);
2931 /*********************************************************************
2934 int CDECL
ungetc(int c
, FILE * file
)
2938 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2942 if(file
->_ptr
>file
->_base
) {
2952 /*********************************************************************
2953 * ungetwc (MSVCRT.@)
2955 wint_t CDECL
ungetwc(wint_t wc
, FILE * file
)
2958 char * pp
= (char *)&mwc
;
2960 for(i
=sizeof(wchar_t)-1;i
>=0;i
--) {
2961 if(pp
[i
] != ungetc(pp
[i
],file
))
2967 /*********************************************************************
2968 * wprintf (MSVCRT.@)
2970 int CDECL
wprintf(const wchar_t *format
, ...)
2974 va_start(valist
, format
);
2975 res
= vwprintf(format
, valist
);
2980 /*********************************************************************
2981 * _getmaxstdio (MSVCRT.@)
2983 int CDECL
_getmaxstdio(void)
2985 FIXME("stub, always returns 512\n");
2989 /*********************************************************************
2990 * _setmaxstdio_ (MSVCRT.@)
2992 int CDECL
_setmaxstdio(int newmax
)
2999 FIXME("stub: setting new maximum for number of simultaneously open files not implemented,returning %d\n",res
);
3003 /*********************************************************************
3004 * __pioinfo (MSVCRT.@)
3005 * FIXME: see MAX_FILES define.
3007 ioinfo
* __pioinfo
[] = { /* array of pointers to ioinfo arrays [64] */
3008 &fdesc
[0 * 64], &fdesc
[1 * 64], &fdesc
[2 * 64],
3009 &fdesc
[3 * 64], &fdesc
[4 * 64], &fdesc
[5 * 64],
3010 &fdesc
[6 * 64], &fdesc
[7 * 64], &fdesc
[8 * 64],
3011 &fdesc
[9 * 64], &fdesc
[10 * 64], &fdesc
[11 * 64],
3012 &fdesc
[12 * 64], &fdesc
[13 * 64], &fdesc
[14 * 64],
3013 &fdesc
[15 * 64], &fdesc
[16 * 64], &fdesc
[17 * 64],
3014 &fdesc
[18 * 64], &fdesc
[19 * 64], &fdesc
[20 * 64],
3015 &fdesc
[21 * 64], &fdesc
[22 * 64], &fdesc
[23 * 64],
3016 &fdesc
[24 * 64], &fdesc
[25 * 64], &fdesc
[26 * 64],
3017 &fdesc
[27 * 64], &fdesc
[28 * 64], &fdesc
[29 * 64],
3018 &fdesc
[30 * 64], &fdesc
[31 * 64]
3021 /*********************************************************************
3022 * __badioinfo (MSVCRT.@)
3024 ioinfo __badioinfo
= { INVALID_HANDLE_VALUE
, WX_TEXT
, { 0, } };