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_READCR 0x08 /* underlying file is at \r */
80 #define WX_DONTINHERIT 0x10
81 #define WX_APPEND 0x20
84 /* FIXME: this should be allocated dynamically */
85 #define MAX_FILES 2048
87 /* ReactOS: Use _FDINFO instead! */
91 DWORD unkn
[7]; /* critical section and init flag */
94 ioinfo fdesc
[MAX_FILES
];
96 FILE _iob
[3] = { { 0 } };
98 static int fdstart
= 3; /* first unallocated fd */
99 static int fdend
= 3; /* highest allocated fd */
101 static FILE* fstreams
[2048];
102 static int stream_idx
;
104 /* INTERNAL: process umask */
105 static int MSVCRT_umask
= 0;
107 /* INTERNAL: Static buffer for temp file name */
108 static char tmpname
[MAX_PATH
];
110 /* This critical section protects the tables fdesc and fstreams,
111 * and their related indexes, fdstart, fdend,
112 * and stream_idx, from race conditions.
113 * It doesn't protect against race conditions manipulating the underlying files
114 * or flags; doing so would probably be better accomplished with per-file
115 * protection, rather than locking the whole table for every change.
117 static CRITICAL_SECTION FILE_cs
;
118 #define LOCK_FILES() do { EnterCriticalSection(&FILE_cs); } while (0)
119 #define UNLOCK_FILES() do { LeaveCriticalSection(&FILE_cs); } while (0)
121 FILE *__cdecl
__iob_func()
126 static inline BOOL
is_valid_fd(int fd
)
128 return fd
>= 0 && fd
< fdend
&& (fdesc
[fd
].wxflag
& WX_OPEN
);
131 /* INTERNAL: Get the HANDLE for a fd
132 * This doesn't lock the table, because a failure will result in
133 * INVALID_HANDLE_VALUE being returned, which should be handled correctly. If
134 * it returns a valid handle which is about to be closed, a subsequent call
135 * will fail, most likely in a sane way.
139 if (!is_valid_fd(fd
))
141 WARN(":fd (%d) - no handle!\n",fd
);
144 return INVALID_HANDLE_VALUE
;
146 //if (fdesc[fd].handle == INVALID_HANDLE_VALUE) FIXME("wtf\n");
147 return fdesc
[fd
].handle
;
150 /* INTERNAL: free a file entry fd */
151 static void free_fd(int fd
)
154 fdesc
[fd
].handle
= INVALID_HANDLE_VALUE
;
155 fdesc
[fd
].wxflag
= 0;
156 TRACE(":fd (%d) freed\n",fd
);
157 if (fd
< 3) /* don't use 0,1,2 for user files */
161 case 0: SetStdHandle(STD_INPUT_HANDLE
, NULL
); break;
162 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, NULL
); break;
163 case 2: SetStdHandle(STD_ERROR_HANDLE
, NULL
); break;
176 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE, starting from fd */
177 /* caller must hold the files lock */
178 static int alloc_fd_from(HANDLE hand
, int flag
, int fd
)
182 WARN(":files exhausted!\n");
185 fdesc
[fd
].handle
= hand
;
186 fdesc
[fd
].wxflag
= WX_OPEN
| (flag
& (WX_DONTINHERIT
| WX_APPEND
| WX_TEXT
));
188 /* locate next free slot */
189 if (fd
== fdstart
&& fd
== fdend
)
192 while (fdstart
< fdend
&&
193 fdesc
[fdstart
].handle
!= INVALID_HANDLE_VALUE
)
195 /* update last fd in use */
198 TRACE("fdstart is %d, fdend is %d\n", fdstart
, fdend
);
202 case 0: SetStdHandle(STD_INPUT_HANDLE
, hand
); break;
203 case 1: SetStdHandle(STD_OUTPUT_HANDLE
, hand
); break;
204 case 2: SetStdHandle(STD_ERROR_HANDLE
, hand
); break;
210 /* INTERNAL: Allocate an fd slot from a Win32 HANDLE */
211 /*static */int alloc_fd(HANDLE hand
, int flag
)
216 TRACE(":handle (%p) allocating fd (%d)\n",hand
,fdstart
);
217 ret
= alloc_fd_from(hand
, flag
, fdstart
);
222 /* INTERNAL: Allocate a FILE* for an fd slot */
223 /* caller must hold the files lock */
224 static FILE* alloc_fp(void)
228 for (i
= 3; i
< sizeof(fstreams
) / sizeof(fstreams
[0]); i
++)
230 if (!fstreams
[i
] || fstreams
[i
]->_flag
== 0)
234 if (!(fstreams
[i
] = calloc(sizeof(FILE),1)))
236 if (i
== stream_idx
) stream_idx
++;
244 /* INTERNAL: initialize a FILE* from an open fd */
245 static int init_fp(FILE* file
, int fd
, unsigned stream_flags
)
247 TRACE(":fd (%d) allocating FILE*\n",fd
);
248 if (!is_valid_fd(fd
))
250 WARN(":invalid fd %d\n",fd
);
255 memset(file
, 0, sizeof(*file
));
257 file
->_flag
= stream_flags
;
259 TRACE(":got FILE* (%p)\n",file
);
263 /* INTERNAL: Create an inheritance data block (for spawned process)
264 * The inheritance block is made of:
265 * 00 int nb of file descriptor (NBFD)
266 * 04 char file flags (wxflag): repeated for each fd
267 * 4+NBFD HANDLE file handle: repeated for each fd
269 unsigned create_io_inherit_block(WORD
*size
, BYTE
**block
)
275 *size
= sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE
)) * fdend
;
276 *block
= calloc(*size
, 1);
282 wxflag_ptr
= (char*)*block
+ sizeof(unsigned);
283 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ fdend
* sizeof(char));
285 *(unsigned*)*block
= fdend
;
286 for (fd
= 0; fd
< fdend
; fd
++)
288 /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
289 if ((fdesc
[fd
].wxflag
& (WX_OPEN
| WX_DONTINHERIT
)) == WX_OPEN
)
291 *wxflag_ptr
= fdesc
[fd
].wxflag
;
292 *handle_ptr
= fdesc
[fd
].handle
;
297 *handle_ptr
= INVALID_HANDLE_VALUE
;
299 wxflag_ptr
++; handle_ptr
++;
304 /* INTERNAL: Set up all file descriptors,
305 * as well as default streams (stdin, stderr and stdout)
307 void msvcrt_init_io(void)
312 InitializeCriticalSection(&FILE_cs
);
313 FILE_cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": FILE_cs");
314 GetStartupInfoA(&si
);
315 if (si
.cbReserved2
>= sizeof(unsigned int) && si
.lpReserved2
!= NULL
)
321 count
= *(unsigned*)si
.lpReserved2
;
322 wxflag_ptr
= si
.lpReserved2
+ sizeof(unsigned);
323 handle_ptr
= (HANDLE
*)(wxflag_ptr
+ count
);
325 count
= min(count
, (si
.cbReserved2
- sizeof(unsigned)) / (sizeof(HANDLE
) + 1));
326 count
= min(count
, sizeof(fdesc
) / sizeof(fdesc
[0]));
327 for (i
= 0; i
< count
; i
++)
329 if ((*wxflag_ptr
& WX_OPEN
) && *handle_ptr
!= INVALID_HANDLE_VALUE
)
331 fdesc
[i
].wxflag
= *wxflag_ptr
;
332 fdesc
[i
].handle
= *handle_ptr
;
337 fdesc
[i
].handle
= INVALID_HANDLE_VALUE
;
339 wxflag_ptr
++; handle_ptr
++;
341 fdend
= max( 3, count
);
342 for (fdstart
= 3; fdstart
< fdend
; fdstart
++)
343 if (fdesc
[fdstart
].handle
== INVALID_HANDLE_VALUE
) break;
346 if (!(fdesc
[0].wxflag
& WX_OPEN
) || fdesc
[0].handle
== INVALID_HANDLE_VALUE
)
349 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE
),
350 GetCurrentProcess(), &fdesc
[0].handle
, 0, TRUE
,
351 DUPLICATE_SAME_ACCESS
);
353 fdesc
[0].handle
= GetStdHandle(STD_INPUT_HANDLE
);
354 if (fdesc
[0].handle
== NULL
)
355 fdesc
[0].handle
= INVALID_HANDLE_VALUE
;
357 fdesc
[0].wxflag
= WX_OPEN
| WX_TEXT
;
359 if (!(fdesc
[1].wxflag
& WX_OPEN
) || fdesc
[1].handle
== INVALID_HANDLE_VALUE
)
362 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE
),
363 GetCurrentProcess(), &fdesc
[1].handle
, 0, TRUE
,
364 DUPLICATE_SAME_ACCESS
);
366 fdesc
[1].handle
= GetStdHandle(STD_OUTPUT_HANDLE
);
367 if (fdesc
[1].handle
== NULL
)
368 fdesc
[1].handle
= INVALID_HANDLE_VALUE
;
370 fdesc
[1].wxflag
= WX_OPEN
| WX_TEXT
;
372 if (!(fdesc
[2].wxflag
& WX_OPEN
) || fdesc
[2].handle
== INVALID_HANDLE_VALUE
)
375 DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE
),
376 GetCurrentProcess(), &fdesc
[2].handle
, 0, TRUE
,
377 DUPLICATE_SAME_ACCESS
);
379 fdesc
[2].handle
= GetStdHandle(STD_ERROR_HANDLE
);
380 if (fdesc
[2].handle
== NULL
)
381 fdesc
[2].handle
= INVALID_HANDLE_VALUE
;
383 fdesc
[2].wxflag
= WX_OPEN
| WX_TEXT
;
386 TRACE(":handles (%p)(%p)(%p)\n",fdesc
[0].handle
,
387 fdesc
[1].handle
,fdesc
[2].handle
);
389 memset(_iob
,0,3*sizeof(FILE));
390 for (i
= 0; i
< 3; i
++)
392 /* FILE structs for stdin/out/err are static and never deleted */
393 fstreams
[i
] = &_iob
[i
];
395 _iob
[i
]._tmpfname
= NULL
;
396 _iob
[i
]._flag
= (i
== 0) ? _IOREAD
: _IOWRT
;
401 /* INTERNAL: Flush stdio file buffer */
402 static int flush_buffer(FILE* file
)
405 int cnt
=file
->_ptr
-file
->_base
;
406 if(cnt
>0 && _write(file
->_file
, file
->_base
, cnt
) != cnt
) {
407 file
->_flag
|= _IOERR
;
410 file
->_ptr
=file
->_base
;
411 file
->_cnt
=file
->_bufsiz
;
416 /* INTERNAL: Allocate stdio file buffer */
417 static void alloc_buffer(FILE* file
)
419 file
->_base
= calloc(BUFSIZ
,1);
421 file
->_bufsiz
= BUFSIZ
;
422 file
->_flag
|= _IOMYBUF
;
424 file
->_base
= (char*)(&file
->_charbuf
);
426 file
->_bufsiz
= sizeof(file
->_charbuf
);
428 file
->_ptr
= file
->_base
;
432 /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */
433 static void int_to_base32(int num
, char *str
)
448 *p
= (num
& 31) + '0';
450 *p
+= ('a' - '0' - 10);
455 /*********************************************************************
458 FILE * CDECL
__p__iob(void)
463 /*********************************************************************
466 int CDECL
_access(const char *filename
, int mode
)
468 DWORD attr
= GetFileAttributesA(filename
);
470 TRACE("(%s,%d) %d\n",filename
,mode
,attr
);
472 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
474 _dosmaperr(GetLastError());
477 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
479 _dosmaperr(ERROR_ACCESS_DENIED
);
485 /*********************************************************************
486 * _waccess (MSVCRT.@)
488 int CDECL
_waccess(const wchar_t *filename
, int mode
)
490 DWORD attr
= GetFileAttributesW(filename
);
492 TRACE("(%s,%d) %d\n",debugstr_w(filename
),mode
,attr
);
494 if (!filename
|| attr
== INVALID_FILE_ATTRIBUTES
)
496 _dosmaperr(GetLastError());
499 if ((attr
& FILE_ATTRIBUTE_READONLY
) && (mode
& W_OK
))
501 _dosmaperr(ERROR_ACCESS_DENIED
);
507 /*********************************************************************
510 int CDECL
_chmod(const char *path
, int flags
)
512 DWORD oldFlags
= GetFileAttributesA(path
);
514 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
516 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
517 oldFlags
| FILE_ATTRIBUTE_READONLY
;
519 if (newFlags
== oldFlags
|| SetFileAttributesA(path
, newFlags
))
522 _dosmaperr(GetLastError());
526 /*********************************************************************
529 int CDECL
_wchmod(const wchar_t *path
, int flags
)
531 DWORD oldFlags
= GetFileAttributesW(path
);
533 if (oldFlags
!= INVALID_FILE_ATTRIBUTES
)
535 DWORD newFlags
= (flags
& _S_IWRITE
)? oldFlags
& ~FILE_ATTRIBUTE_READONLY
:
536 oldFlags
| FILE_ATTRIBUTE_READONLY
;
538 if (newFlags
== oldFlags
|| SetFileAttributesW(path
, newFlags
))
541 _dosmaperr(GetLastError());
545 /*********************************************************************
548 int CDECL
_unlink(const char *path
)
550 TRACE("%s\n",debugstr_a(path
));
551 if(DeleteFileA(path
))
553 TRACE("failed (%d)\n",GetLastError());
554 _dosmaperr(GetLastError());
558 /*********************************************************************
559 * _wunlink (MSVCRT.@)
561 int CDECL
_wunlink(const wchar_t *path
)
563 TRACE("(%s)\n",debugstr_w(path
));
564 if(DeleteFileW(path
))
566 TRACE("failed (%d)\n",GetLastError());
567 _dosmaperr(GetLastError());
571 /* _flushall calls fflush which calls _flushall */
572 int CDECL
fflush(FILE* file
);
574 /*********************************************************************
575 * _flushall (MSVCRT.@)
577 int CDECL
_flushall(void)
579 int i
, num_flushed
= 0;
582 for (i
= 3; i
< stream_idx
; i
++)
583 if (fstreams
[i
] && fstreams
[i
]->_flag
)
586 /* FIXME: flush, do not commit */
587 if (_commit(i
) == -1)
589 fstreams
[i
]->_flag
|= _IOERR
;
591 if(fstreams
[i
]->_flag
& _IOWRT
) {
598 TRACE(":flushed (%d) handles\n",num_flushed
);
602 /*********************************************************************
605 int CDECL
fflush(FILE* file
)
609 } else if(file
->_flag
& _IOWRT
) {
610 int res
=flush_buffer(file
);
616 /*********************************************************************
619 int CDECL
_close(int fd
)
626 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
627 if (hand
== INVALID_HANDLE_VALUE
)
629 else if (!CloseHandle(hand
))
631 WARN(":failed-last error (%d)\n",GetLastError());
632 _dosmaperr(GetLastError());
645 /*********************************************************************
648 int CDECL
_commit(int fd
)
650 HANDLE hand
= fdtoh(fd
);
652 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
653 if (hand
== INVALID_HANDLE_VALUE
)
656 if (!FlushFileBuffers(hand
))
658 if (GetLastError() == ERROR_INVALID_HANDLE
)
660 /* FlushFileBuffers fails for console handles
661 * so we ignore this error.
665 TRACE(":failed-last error (%d)\n",GetLastError());
666 _dosmaperr(GetLastError());
673 /*********************************************************************
676 * MSDN isn't clear on this point, but the remarks for _pipe
677 * indicate file descriptors duplicated with _dup and _dup2 are always
680 int CDECL
_dup2(int od
, int nd
)
684 TRACE("(od=%d, nd=%d)\n", od
, nd
);
686 if (nd
< MAX_FILES
&& is_valid_fd(od
))
690 if (DuplicateHandle(GetCurrentProcess(), fdesc
[od
].handle
,
691 GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
))
693 int wxflag
= fdesc
[od
].wxflag
& ~_O_NOINHERIT
;
697 ret
= alloc_fd_from(handle
, wxflag
, nd
);
705 /* _dup2 returns 0, not nd, on success */
712 _dosmaperr(GetLastError());
724 /*********************************************************************
727 int CDECL
_dup(int od
)
733 if (_dup2(od
, fd
) == 0)
741 /*********************************************************************
744 int CDECL
_eof(int fd
)
747 LONG hcurpos
,hendpos
;
748 HANDLE hand
= fdtoh(fd
);
750 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
752 if (hand
== INVALID_HANDLE_VALUE
)
755 if (fdesc
[fd
].wxflag
& WX_ATEOF
) return TRUE
;
757 /* Otherwise we do it the hard way */
758 hcurpos
= hendpos
= 0;
759 curpos
= SetFilePointer(hand
, 0, &hcurpos
, FILE_CURRENT
);
760 endpos
= SetFilePointer(hand
, 0, &hendpos
, FILE_END
);
762 if (curpos
== endpos
&& hcurpos
== hendpos
)
764 /* FIXME: shouldn't WX_ATEOF be set here? */
768 SetFilePointer(hand
, curpos
, &hcurpos
, FILE_BEGIN
);
772 /*********************************************************************
773 * _fcloseall (MSVCRT.@)
775 int CDECL
_fcloseall(void)
777 int num_closed
= 0, i
;
780 for (i
= 3; i
< stream_idx
; i
++)
781 if (fstreams
[i
] && fstreams
[i
]->_flag
&&
782 !fclose(fstreams
[i
]))
786 TRACE(":closed (%d) handles\n",num_closed
);
790 /* free everything on process exit */
791 void msvcrt_free_io(void)
794 /* The Win32 _fcloseall() function explicitly doesn't close stdin,
795 * stdout, and stderr (unlike GNU), so we need to fclose() them here
796 * or they won't get flushed.
801 FILE_cs
.DebugInfo
->Spare
[0] = 0;
802 DeleteCriticalSection(&FILE_cs
);
805 /*********************************************************************
806 * _lseeki64 (MSVCRT.@)
808 __int64 CDECL
_lseeki64(int fd
, __int64 offset
, int whence
)
810 HANDLE hand
= fdtoh(fd
);
811 LARGE_INTEGER ofs
, ret
;
813 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
814 if (hand
== INVALID_HANDLE_VALUE
)
817 if (whence
< 0 || whence
> 2)
823 TRACE(":fd (%d) to %s pos %s\n",
824 fd
,wine_dbgstr_longlong(offset
),
825 (whence
==SEEK_SET
)?"SEEK_SET":
826 (whence
==SEEK_CUR
)?"SEEK_CUR":
827 (whence
==SEEK_END
)?"SEEK_END":"UNKNOWN");
829 ofs
.QuadPart
= offset
;
830 if (SetFilePointerEx(hand
, ofs
, &ret
, whence
))
832 fdesc
[fd
].wxflag
&= ~(WX_ATEOF
|WX_READEOF
);
833 /* FIXME: What if we seek _to_ EOF - is EOF set? */
837 TRACE(":error-last error (%d)\n",GetLastError());
838 _dosmaperr(GetLastError());
842 /*********************************************************************
845 LONG CDECL
_lseek(int fd
, LONG offset
, int whence
)
847 return _lseeki64(fd
, offset
, whence
);
850 /*********************************************************************
851 * _locking (MSVCRT.@)
853 * This is untested; the underlying LockFile doesn't work yet.
855 int CDECL
_locking(int fd
, int mode
, LONG nbytes
)
859 HANDLE hand
= fdtoh(fd
);
861 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
862 if (hand
== INVALID_HANDLE_VALUE
)
865 if (mode
< 0 || mode
> 4)
871 TRACE(":fd (%d) by 0x%08x mode %s\n",
872 fd
,nbytes
,(mode
==_LK_UNLCK
)?"_LK_UNLCK":
873 (mode
==_LK_LOCK
)?"_LK_LOCK":
874 (mode
==_LK_NBLCK
)?"_LK_NBLCK":
875 (mode
==_LK_RLCK
)?"_LK_RLCK":
876 (mode
==_LK_NBRLCK
)?"_LK_NBRLCK":
879 if ((cur_locn
= SetFilePointer(hand
, 0L, NULL
, SEEK_CUR
)) == INVALID_SET_FILE_POINTER
)
881 FIXME ("Seek failed\n");
882 *_errno() = EINVAL
; /* FIXME */
885 if (mode
== _LK_LOCK
|| mode
== _LK_RLCK
)
888 ret
= 1; /* just to satisfy gcc */
891 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
896 else if (mode
== _LK_UNLCK
)
897 ret
= UnlockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
899 ret
= LockFile(hand
, cur_locn
, 0L, nbytes
, 0L);
900 /* FIXME - what about error settings? */
904 /*********************************************************************
907 int CDECL
fseek(FILE* file
, long offset
, int whence
)
909 /* Flush output if needed */
910 if(file
->_flag
& _IOWRT
)
913 if(whence
== SEEK_CUR
&& file
->_flag
& _IOREAD
) {
914 offset
-= file
->_cnt
;
915 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
) {
916 /* Black magic correction for CR removal */
918 for (i
=0; i
<file
->_cnt
; i
++) {
919 if (file
->_ptr
[i
] == '\n')
922 /* Black magic when reading CR at buffer boundary*/
923 if(fdesc
[file
->_file
].wxflag
& WX_READCR
)
927 /* Discard buffered input */
929 file
->_ptr
= file
->_base
;
930 /* Reset direction of i/o */
931 if(file
->_flag
& _IORW
) {
932 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
934 /* Clear end of file flag */
935 file
->_flag
&= ~_IOEOF
;
936 return (_lseek(file
->_file
,offset
,whence
) == -1)?-1:0;
939 /*********************************************************************
942 int CDECL
_chsize(int fd
, long size
)
948 TRACE("(fd=%d, size=%ld)\n", fd
, size
);
953 if (handle
!= INVALID_HANDLE_VALUE
)
955 /* save the current file pointer */
956 cur
= _lseek(fd
, 0, SEEK_CUR
);
959 pos
= _lseek(fd
, size
, SEEK_SET
);
962 ret
= SetEndOfFile(handle
);
963 if (!ret
) _dosmaperr(GetLastError());
966 /* restore the file pointer */
967 _lseek(fd
, cur
, SEEK_SET
);
975 /*********************************************************************
976 * clearerr (MSVCRT.@)
978 void CDECL
clearerr(FILE* file
)
980 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
981 file
->_flag
&= ~(_IOERR
| _IOEOF
);
984 /*********************************************************************
987 void CDECL
rewind(FILE* file
)
989 TRACE(":file (%p) fd (%d)\n",file
,file
->_file
);
990 fseek(file
, 0L, SEEK_SET
);
994 static int get_flags(const char* mode
, int *open_flags
, int* stream_flags
)
996 int plus
= strchr(mode
, '+') != NULL
;
1001 *open_flags
= plus
? _O_RDWR
: _O_RDONLY
;
1002 *stream_flags
= plus
? _IORW
: _IOREAD
;
1005 *open_flags
= _O_CREAT
| _O_TRUNC
| (plus
? _O_RDWR
: _O_WRONLY
);
1006 *stream_flags
= plus
? _IORW
: _IOWRT
;
1009 *open_flags
= _O_CREAT
| _O_APPEND
| (plus
? _O_RDWR
: _O_WRONLY
);
1010 *stream_flags
= plus
? _IORW
: _IOWRT
;
1020 *open_flags
|= _O_BINARY
;
1021 *open_flags
&= ~_O_TEXT
;
1024 *open_flags
|= _O_TEXT
;
1025 *open_flags
&= ~_O_BINARY
;
1030 FIXME(":unknown flag %c not supported\n",mode
[-1]);
1035 /*********************************************************************
1036 * _fdopen (MSVCRT.@)
1038 FILE* CDECL
_fdopen(int fd
, const char *mode
)
1040 int open_flags
, stream_flags
;
1043 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1) return NULL
;
1046 if (!(file
= alloc_fp()))
1048 else if (init_fp(file
, fd
, stream_flags
) == -1)
1053 else TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
1059 /*********************************************************************
1060 * _wfdopen (MSVCRT.@)
1062 FILE* CDECL
_wfdopen(int fd
, const wchar_t *mode
)
1064 unsigned mlen
= strlenW(mode
);
1065 char *modea
= calloc(mlen
+ 1, 1);
1067 int open_flags
, stream_flags
;
1070 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
1072 if (get_flags(modea
, &open_flags
, &stream_flags
) == -1)
1078 if (!(file
= alloc_fp()))
1080 else if (init_fp(file
, fd
, stream_flags
) == -1)
1088 rewind(file
); /* FIXME: is this needed ??? */
1089 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,debugstr_w(mode
),file
);
1097 /*********************************************************************
1098 * _filelength (MSVCRT.@)
1100 LONG CDECL
_filelength(int fd
)
1102 LONG curPos
= _lseek(fd
, 0, SEEK_CUR
);
1105 LONG endPos
= _lseek(fd
, 0, SEEK_END
);
1108 if (endPos
!= curPos
)
1109 _lseek(fd
, curPos
, SEEK_SET
);
1116 /*********************************************************************
1117 * _filelengthi64 (MSVCRT.@)
1119 __int64 CDECL
_filelengthi64(int fd
)
1121 __int64 curPos
= _lseeki64(fd
, 0, SEEK_CUR
);
1124 __int64 endPos
= _lseeki64(fd
, 0, SEEK_END
);
1127 if (endPos
!= curPos
)
1128 _lseeki64(fd
, curPos
, SEEK_SET
);
1135 /*********************************************************************
1136 * _fileno (MSVCRT.@)
1138 int CDECL
_fileno(FILE* file
)
1140 TRACE(":FILE* (%p) fd (%d)\n",file
,file
->_file
);
1144 /*********************************************************************
1145 * _futime (MSVCRT.@)
1147 int CDECL
_futime(int fd
, struct _utimbuf
*t
)
1149 HANDLE hand
= fdtoh(fd
);
1152 if (hand
== INVALID_HANDLE_VALUE
)
1159 RtlSecondsSince1970ToTime(currTime
, (LARGE_INTEGER
*)&at
);
1164 RtlSecondsSince1970ToTime(t
->actime
, (LARGE_INTEGER
*)&at
);
1165 if (t
->actime
== t
->modtime
)
1168 RtlSecondsSince1970ToTime(t
->modtime
, (LARGE_INTEGER
*)&wt
);
1171 if (!SetFileTime(hand
, NULL
, &at
, &wt
))
1173 _dosmaperr(GetLastError());
1179 /*********************************************************************
1180 * _get_osfhandle (MSVCRT.@)
1182 intptr_t CDECL
_get_osfhandle(int fd
)
1184 HANDLE hand
= fdtoh(fd
);
1185 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1187 return (long)(LONG_PTR
)hand
;
1190 /*********************************************************************
1191 * _isatty (MSVCRT.@)
1193 int CDECL
_isatty(int fd
)
1195 HANDLE hand
= fdtoh(fd
);
1197 TRACE(":fd (%d) handle (%p)\n",fd
,hand
);
1198 if (hand
== INVALID_HANDLE_VALUE
)
1201 return GetFileType(hand
) == FILE_TYPE_CHAR
? 1 : 0;
1204 /*********************************************************************
1205 * _mktemp (MSVCRT.@)
1207 char * CDECL
_mktemp(char *pattern
)
1210 char *retVal
= pattern
;
1215 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1219 id
= GetCurrentProcessId();
1223 int tempNum
= id
/ 10;
1224 *pattern
-- = id
- (tempNum
* 10) + '0';
1230 *pattern
= letter
++;
1231 if (GetFileAttributesA(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1232 GetLastError() == ERROR_FILE_NOT_FOUND
)
1234 } while(letter
<= 'z');
1238 /*********************************************************************
1239 * _wmktemp (MSVCRT.@)
1241 wchar_t * CDECL
_wmktemp(wchar_t *pattern
)
1244 wchar_t *retVal
= pattern
;
1246 wchar_t letter
= 'a';
1249 numX
= (*pattern
++ == 'X')? numX
+ 1 : 0;
1253 id
= GetCurrentProcessId();
1257 int tempNum
= id
/ 10;
1258 *pattern
-- = id
- (tempNum
* 10) + '0';
1264 if (GetFileAttributesW(retVal
) == INVALID_FILE_ATTRIBUTES
&&
1265 GetLastError() == ERROR_FILE_NOT_FOUND
)
1267 *pattern
= letter
++;
1268 } while(letter
!= '|');
1272 /*static */unsigned split_oflags(unsigned oflags
)
1275 unsigned unsupp
; /* until we support everything */
1277 if (oflags
& _O_APPEND
) wxflags
|= WX_APPEND
;
1278 if (oflags
& _O_BINARY
) {/* Nothing to do */}
1279 else if (oflags
& _O_TEXT
) wxflags
|= WX_TEXT
;
1280 else if (*__p__fmode() & _O_BINARY
) {/* Nothing to do */}
1281 else wxflags
|= WX_TEXT
; /* default to TEXT*/
1282 if (oflags
& _O_NOINHERIT
) wxflags
|= WX_DONTINHERIT
;
1284 if ((unsupp
= oflags
& ~(
1285 _O_BINARY
|_O_TEXT
|_O_APPEND
|
1286 _O_TRUNC
|_O_EXCL
|_O_CREAT
|
1287 _O_RDWR
|_O_WRONLY
|_O_TEMPORARY
|
1289 _O_SEQUENTIAL
|_O_RANDOM
|_O_SHORT_LIVED
1291 ERR(":unsupported oflags 0x%04x\n",unsupp
);
1296 /*********************************************************************
1299 int CDECL
_pipe(int *pfds
, unsigned int psize
, int textmode
)
1302 SECURITY_ATTRIBUTES sa
;
1303 HANDLE readHandle
, writeHandle
;
1311 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
1312 sa
.bInheritHandle
= !(textmode
& _O_NOINHERIT
);
1313 sa
.lpSecurityDescriptor
= NULL
;
1314 if (CreatePipe(&readHandle
, &writeHandle
, &sa
, psize
))
1316 unsigned int wxflags
= split_oflags(textmode
);
1320 fd
= alloc_fd(readHandle
, wxflags
);
1324 fd
= alloc_fd(writeHandle
, wxflags
);
1333 CloseHandle(writeHandle
);
1339 CloseHandle(readHandle
);
1340 CloseHandle(writeHandle
);
1346 _dosmaperr(GetLastError());
1351 /*********************************************************************
1354 int CDECL
_sopen( const char *path
, int oflags
, int shflags
, ... )
1358 DWORD access
= 0, creation
= 0, attrib
;
1362 SECURITY_ATTRIBUTES sa
;
1365 TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n",
1366 path
, oflags
, shflags
);
1368 wxflag
= split_oflags(oflags
);
1369 switch (oflags
& (_O_RDONLY
| _O_WRONLY
| _O_RDWR
))
1371 case _O_RDONLY
: access
|= GENERIC_READ
; break;
1372 case _O_WRONLY
: access
|= GENERIC_WRITE
; break;
1373 case _O_RDWR
: access
|= GENERIC_WRITE
| GENERIC_READ
; break;
1376 if (oflags
& _O_CREAT
)
1378 va_start(ap
, shflags
);
1379 pmode
= va_arg(ap
, int);
1382 if(pmode
& ~(_S_IREAD
| _S_IWRITE
))
1383 FIXME(": pmode 0x%04x ignored\n", pmode
);
1385 WARN(": pmode 0x%04x ignored\n", pmode
);
1387 if (oflags
& _O_EXCL
)
1388 creation
= CREATE_NEW
;
1389 else if (oflags
& _O_TRUNC
)
1390 creation
= CREATE_ALWAYS
;
1392 creation
= OPEN_ALWAYS
;
1394 else /* no _O_CREAT */
1396 if (oflags
& _O_TRUNC
)
1397 creation
= TRUNCATE_EXISTING
;
1399 creation
= OPEN_EXISTING
;
1408 sharing
= FILE_SHARE_READ
;
1411 sharing
= FILE_SHARE_WRITE
;
1414 sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1417 ERR( "Unhandled shflags 0x%x\n", shflags
);
1420 attrib
= FILE_ATTRIBUTE_NORMAL
;
1422 if (oflags
& _O_TEMPORARY
)
1424 attrib
|= FILE_FLAG_DELETE_ON_CLOSE
;
1426 sharing
|= FILE_SHARE_DELETE
;
1429 sa
.nLength
= sizeof( SECURITY_ATTRIBUTES
);
1430 sa
.lpSecurityDescriptor
= NULL
;
1431 sa
.bInheritHandle
= (oflags
& _O_NOINHERIT
) ? FALSE
: TRUE
;
1433 hand
= CreateFileA(path
, access
, sharing
, &sa
, creation
, attrib
, 0);
1435 if (hand
== INVALID_HANDLE_VALUE
) {
1436 WARN(":failed-last error (%d)\n",GetLastError());
1437 _dosmaperr(GetLastError());
1441 fd
= alloc_fd(hand
, wxflag
);
1443 TRACE(":fd (%d) handle (%p)\n",fd
, hand
);
1447 /*********************************************************************
1448 * _wsopen (MSVCRT.@)
1450 int CDECL
_wsopen( const wchar_t* path
, int oflags
, int shflags
, ... )
1452 const unsigned int len
= strlenW(path
);
1453 char *patha
= calloc(len
+ 1,1);
1457 va_start(ap
, shflags
);
1458 pmode
= va_arg(ap
, int);
1461 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1463 int retval
= _sopen(patha
,oflags
,shflags
,pmode
);
1467 _dosmaperr(GetLastError());
1472 /*********************************************************************
1475 int CDECL
_open( const char *path
, int flags
, ... )
1479 if (flags
& _O_CREAT
)
1482 va_start(ap
, flags
);
1483 pmode
= va_arg(ap
, int);
1485 return _sopen( path
, flags
, _SH_DENYNO
, pmode
);
1488 return _sopen( path
, flags
, _SH_DENYNO
);
1491 /*********************************************************************
1494 int CDECL
_wopen(const wchar_t *path
,int flags
,...)
1496 const unsigned int len
= strlenW(path
);
1497 char *patha
= calloc(len
+ 1,1);
1501 va_start(ap
, flags
);
1502 pmode
= va_arg(ap
, int);
1505 if (patha
&& WideCharToMultiByte(CP_ACP
,0,path
,len
,patha
,len
,NULL
,NULL
))
1507 int retval
= _open(patha
,flags
,pmode
);
1512 _dosmaperr(GetLastError());
1516 /*********************************************************************
1519 int CDECL
_creat(const char *path
, int flags
)
1521 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1522 return _open(path
, usedFlags
);
1525 /*********************************************************************
1526 * _wcreat (MSVCRT.@)
1528 int CDECL
_wcreat(const wchar_t *path
, int flags
)
1530 int usedFlags
= (flags
& _O_TEXT
)| _O_CREAT
| _O_WRONLY
| _O_TRUNC
;
1531 return _wopen(path
, usedFlags
);
1534 /*********************************************************************
1535 * _open_osfhandle (MSVCRT.@)
1537 int CDECL
_open_osfhandle(intptr_t handle
, int oflags
)
1541 /* _O_RDONLY (0) always matches, so set the read flag
1542 * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
1543 * file, so set the write flag. It also only sets _O_TEXT if it wants
1544 * text - it never sets _O_BINARY.
1546 /* don't let split_oflags() decide the mode if no mode is passed */
1547 if (!(oflags
& (_O_BINARY
| _O_TEXT
)))
1548 oflags
|= _O_BINARY
;
1550 fd
= alloc_fd((HANDLE
)(LONG_PTR
)handle
, split_oflags(oflags
));
1551 TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle
, fd
, oflags
);
1555 /*********************************************************************
1558 int CDECL
_rmtmp(void)
1560 int num_removed
= 0, i
;
1563 for (i
= 3; i
< stream_idx
; i
++)
1564 if (fstreams
[i
] && fstreams
[i
]->_tmpfname
)
1566 fclose(fstreams
[i
]);
1572 TRACE(":removed (%d) temp files\n",num_removed
);
1576 /*********************************************************************
1579 static int read_i(int fd
, void *buf
, unsigned int count
)
1582 char *bufstart
= buf
;
1583 HANDLE hand
= fdtoh(fd
);
1588 if (fdesc
[fd
].wxflag
& WX_READEOF
) {
1589 fdesc
[fd
].wxflag
|= WX_ATEOF
;
1590 TRACE("already at EOF, returning 0\n");
1593 /* Don't trace small reads, it gets *very* annoying */
1595 TRACE(":fd (%d) handle (%p) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1596 if (hand
== INVALID_HANDLE_VALUE
)
1599 /* Reading single bytes in O_TEXT mode makes things slow
1600 * So read big chunks
1602 if (ReadFile(hand
, bufstart
, count
, &num_read
, NULL
))
1604 if (count
!= 0 && num_read
== 0)
1606 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1607 TRACE(":EOF %s\n",debugstr_an(buf
,num_read
));
1609 else if (fdesc
[fd
].wxflag
& WX_TEXT
)
1612 if (bufstart
[num_read
-1] == '\r')
1616 fdesc
[fd
].wxflag
&= ~WX_READCR
;
1617 ReadFile(hand
, bufstart
, 1, &num_read
, NULL
);
1621 fdesc
[fd
].wxflag
|= WX_READCR
;
1626 fdesc
[fd
].wxflag
&= ~WX_READCR
;
1627 for (i
=0, j
=0; i
<num_read
; i
++)
1629 /* in text mode, a ctrl-z signals EOF */
1630 if (bufstart
[i
] == 0x1a)
1632 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1633 TRACE(":^Z EOF %s\n",debugstr_an(buf
,num_read
));
1636 /* in text mode, strip \r if followed by \n.
1637 * BUG: should save state across calls somehow, so CR LF that
1638 * straddles buffer boundary gets recognized properly?
1640 if ((bufstart
[i
] != '\r')
1641 || ((i
+1) < num_read
&& bufstart
[i
+1] != '\n'))
1642 bufstart
[j
++] = bufstart
[i
];
1649 if (GetLastError() == ERROR_BROKEN_PIPE
)
1651 TRACE(":end-of-pipe\n");
1652 fdesc
[fd
].wxflag
|= (WX_ATEOF
|WX_READEOF
);
1657 TRACE(":failed-last error (%d)\n",GetLastError());
1663 TRACE("(%u), %s\n",num_read
,debugstr_an(buf
, num_read
));
1667 /*********************************************************************
1670 int CDECL
_read(int fd
, void *buf
, unsigned int count
)
1673 num_read
= read_i(fd
, buf
, count
);
1677 /*********************************************************************
1678 * _setmode (MSVCRT.@)
1680 int CDECL
_setmode(int fd
,int mode
)
1682 int ret
= fdesc
[fd
].wxflag
& WX_TEXT
? _O_TEXT
: _O_BINARY
;
1683 if (mode
& (~(_O_TEXT
|_O_BINARY
)))
1684 FIXME("fd (%d) mode (0x%08x) unknown\n",fd
,mode
);
1685 if ((mode
& _O_TEXT
) == _O_TEXT
)
1686 fdesc
[fd
].wxflag
|= WX_TEXT
;
1688 fdesc
[fd
].wxflag
&= ~WX_TEXT
;
1692 /*********************************************************************
1695 long CDECL
_tell(int fd
)
1697 return _lseek(fd
, 0, SEEK_CUR
);
1700 /*********************************************************************
1701 * _telli64 (MSVCRT.@)
1703 __int64 CDECL
_telli64(int fd
)
1705 return _lseeki64(fd
, 0, SEEK_CUR
);
1708 /*********************************************************************
1709 * _tempnam (MSVCRT.@)
1711 char * CDECL
_tempnam(const char *dir
, const char *prefix
)
1713 char tmpbuf
[MAX_PATH
];
1714 const char *tmp_dir
= getenv("TMP");
1716 if (tmp_dir
) dir
= tmp_dir
;
1718 TRACE("dir (%s) prefix (%s)\n",dir
,prefix
);
1719 if (GetTempFileNameA(dir
,prefix
,0,tmpbuf
))
1721 TRACE("got name (%s)\n",tmpbuf
);
1722 DeleteFileA(tmpbuf
);
1723 return _strdup(tmpbuf
);
1725 TRACE("failed (%d)\n",GetLastError());
1729 /*********************************************************************
1730 * _wtempnam (MSVCRT.@)
1732 wchar_t * CDECL
_wtempnam(const wchar_t *dir
, const wchar_t *prefix
)
1734 wchar_t tmpbuf
[MAX_PATH
];
1736 TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir
),debugstr_w(prefix
));
1737 if (GetTempFileNameW(dir
,prefix
,0,tmpbuf
))
1739 TRACE("got name (%s)\n",debugstr_w(tmpbuf
));
1740 DeleteFileW(tmpbuf
);
1741 return _wcsdup(tmpbuf
);
1743 TRACE("failed (%d)\n",GetLastError());
1747 /*********************************************************************
1750 int CDECL
_umask(int umask
)
1752 int old_umask
= umask
;
1753 TRACE("(%d)\n",umask
);
1754 MSVCRT_umask
= umask
;
1758 /*********************************************************************
1761 int CDECL
_utime(const char* path
, struct _utimbuf
*t
)
1763 int fd
= _open(path
, _O_WRONLY
| _O_BINARY
);
1767 int retVal
= _futime(fd
, t
);
1774 /*********************************************************************
1775 * _wutime (MSVCRT.@)
1777 int CDECL
_wutime(const wchar_t* path
, struct _utimbuf
*t
)
1779 int fd
= _wopen(path
, _O_WRONLY
| _O_BINARY
);
1783 int retVal
= _futime(fd
, t
);
1790 /*********************************************************************
1793 int CDECL
_write(int fd
, const void* buf
, unsigned int count
)
1796 HANDLE hand
= fdtoh(fd
);
1798 /* Don't trace small writes, it gets *very* annoying */
1801 TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd
,hand
,buf
,count
);
1803 if (hand
== INVALID_HANDLE_VALUE
)
1809 /* If appending, go to EOF */
1810 if (fdesc
[fd
].wxflag
& WX_APPEND
)
1811 _lseek(fd
, 0, FILE_END
);
1813 if (!(fdesc
[fd
].wxflag
& WX_TEXT
))
1815 if (WriteFile(hand
, buf
, count
, &num_written
, NULL
)
1816 && (num_written
== count
))
1818 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd
,
1819 hand
, GetLastError());
1824 unsigned int i
, j
, nr_lf
;
1827 const char *s
= (const char *)buf
, *buf_start
= (const char *)buf
;
1828 /* find number of \n ( without preceding \r ) */
1829 for ( nr_lf
=0,i
= 0; i
<count
; i
++)
1834 /*if ((i >1) && (s[i-1] == '\r')) nr_lf--; */
1839 if ((q
= p
= malloc(count
+ nr_lf
)))
1841 for (s
= (const char *)buf
, i
= 0, j
= 0; i
< count
; i
++)
1846 /*if ((i >1) && (s[i-1] == '\r'))j--;*/
1853 FIXME("Malloc failed\n");
1861 if ((WriteFile(hand
, q
, count
+nr_lf
, &num_written
, NULL
) == 0 ) || (num_written
!= count
+nr_lf
))
1863 TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
1864 fd
, hand
, GetLastError(), num_written
);
1868 return s
- buf_start
;
1880 /*********************************************************************
1883 int CDECL
_putw(int val
, FILE* file
)
1886 len
= _write(file
->_file
, &val
, sizeof(val
));
1887 if (len
== sizeof(val
)) return val
;
1888 file
->_flag
|= _IOERR
;
1892 /*********************************************************************
1895 int CDECL
fclose(FILE* file
)
1900 free(file
->_tmpfname
);
1901 file
->_tmpfname
= NULL
;
1902 /* flush stdio buffers */
1903 if(file
->_flag
& _IOWRT
)
1905 if(file
->_flag
& _IOMYBUF
)
1908 r
=_close(file
->_file
);
1912 return ((r
== -1) || (flag
& _IOERR
) ? EOF
: 0);
1915 /*********************************************************************
1918 int CDECL
feof(FILE* file
)
1920 return file
->_flag
& _IOEOF
;
1923 /*********************************************************************
1926 int CDECL
ferror(FILE* file
)
1928 return file
->_flag
& _IOERR
;
1931 /*********************************************************************
1932 * _filbuf (MSVCRT.@)
1934 int CDECL
_filbuf(FILE* file
)
1936 /* Allocate buffer if needed */
1937 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
) ) {
1940 if(!(file
->_flag
& _IOREAD
)) {
1941 if(file
->_flag
& _IORW
) {
1942 file
->_flag
|= _IOREAD
;
1947 if(file
->_flag
& _IONBF
) {
1950 if ((r
= read_i(file
->_file
,&c
,1)) != 1) {
1951 file
->_flag
|= (r
== 0) ? _IOEOF
: _IOERR
;
1956 file
->_cnt
= read_i(file
->_file
, file
->_base
, file
->_bufsiz
);
1958 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
1963 file
->_ptr
= file
->_base
+1;
1964 return *(unsigned char *)file
->_base
;
1968 /*********************************************************************
1971 int CDECL
fgetc(FILE* file
)
1977 i
= (unsigned char *)file
->_ptr
++;
1984 /*********************************************************************
1985 * _fgetchar (MSVCRT.@)
1987 int CDECL
_fgetchar(void)
1989 return fgetc(stdin
);
1992 /*********************************************************************
1995 char * CDECL
fgets(char *s
, int size
, FILE* file
)
1998 char * buf_start
= s
;
2000 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
2001 file
,file
->_file
,s
,size
);
2003 while ((size
>1) && (cc
= fgetc(file
)) != EOF
&& cc
!= '\n')
2008 if ((cc
== EOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
2010 TRACE(":nothing read\n");
2013 if ((cc
!= EOF
) && (size
> 1))
2016 TRACE(":got %s\n", debugstr_a(buf_start
));
2020 /*********************************************************************
2023 * In _O_TEXT mode, multibyte characters are read from the file, dropping
2024 * the CR from CR/LF combinations
2026 wint_t CDECL
fgetwc(FILE* file
)
2030 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2036 for(i
=0; i
<sizeof(wc
); i
++)
2049 file
->_flag
|= (file
->_cnt
== 0) ? _IOEOF
: _IOERR
;
2060 if ((*__p___mb_cur_max() > 1) && isleadbyte(c
))
2062 FIXME("Treat Multibyte characters\n");
2070 /*********************************************************************
2073 int CDECL
_getw(FILE* file
)
2078 for (j
=0; j
<sizeof(int); j
++) {
2081 file
->_flag
|= _IOEOF
;
2089 /*********************************************************************
2092 wint_t CDECL
getwc(FILE* file
)
2094 return fgetwc(file
);
2097 /*********************************************************************
2098 * _fgetwchar (MSVCRT.@)
2100 wint_t CDECL
_fgetwchar(void)
2102 return fgetwc(stdin
);
2105 /*********************************************************************
2106 * getwchar (MSVCRT.@)
2108 wint_t CDECL
getwchar(void)
2110 return _fgetwchar();
2113 /*********************************************************************
2116 wchar_t * CDECL
fgetws(wchar_t *s
, int size
, FILE* file
)
2119 wchar_t * buf_start
= s
;
2121 TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
2122 file
,file
->_file
,s
,size
);
2124 while ((size
>1) && (cc
= fgetwc(file
)) != WEOF
&& cc
!= '\n')
2129 if ((cc
== WEOF
) && (s
== buf_start
)) /* If nothing read, return 0*/
2131 TRACE(":nothing read\n");
2134 if ((cc
!= WEOF
) && (size
> 1))
2137 TRACE(":got %s\n", debugstr_w(buf_start
));
2141 /*********************************************************************
2144 size_t CDECL
fwrite(const void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2146 size_t wrcnt
=size
* nmemb
;
2151 int pcnt
=(file
->_cnt
>wrcnt
)? wrcnt
: file
->_cnt
;
2152 memcpy(file
->_ptr
, ptr
, pcnt
);
2157 ptr
= (const char*)ptr
+ pcnt
;
2158 } else if(!(file
->_flag
& _IOWRT
)) {
2159 if(file
->_flag
& _IORW
) {
2160 file
->_flag
|= _IOWRT
;
2166 int res
=flush_buffer(file
);
2168 int pwritten
= _write(file
->_file
, ptr
, wrcnt
);
2171 file
->_flag
|= _IOERR
;
2174 written
+= pwritten
;
2177 return written
/ size
;
2180 /*********************************************************************
2183 wint_t CDECL
fputwc(wint_t wc
, FILE* file
)
2186 if (fwrite( &mwc
, sizeof(mwc
), 1, file
) != 1)
2191 /*********************************************************************
2192 * _fputwchar (MSVCRT.@)
2194 wint_t CDECL
_fputwchar(wint_t wc
)
2196 return fputwc(wc
, stdout
);
2199 /*********************************************************************
2200 * _fsopen (MSVCRT.@)
2202 FILE * CDECL
_fsopen(const char *path
, const char *mode
, int share
)
2205 int open_flags
, stream_flags
, fd
;
2207 TRACE("(%s,%s)\n",path
,mode
);
2209 /* map mode string to open() flags. "man fopen" for possibilities. */
2210 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2214 fd
= _sopen(path
, open_flags
, share
, _S_IREAD
| _S_IWRITE
);
2217 else if ((file
= alloc_fp()) && init_fp(file
, fd
, stream_flags
)
2219 TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd
,mode
,file
);
2226 TRACE(":got (%p)\n",file
);
2227 if (fd
>= 0 && !file
)
2233 /*********************************************************************
2234 * _wfsopen (MSVCRT.@)
2236 FILE * CDECL
_wfsopen(const wchar_t *path
, const wchar_t *mode
, int share
)
2238 const unsigned int plen
= strlenW(path
), mlen
= strlenW(mode
);
2239 char *patha
= calloc(plen
+ 1, 1);
2240 char *modea
= calloc(mlen
+ 1, 1);
2242 TRACE("(%s,%s)\n",debugstr_w(path
),debugstr_w(mode
));
2244 if (patha
&& modea
&&
2245 WideCharToMultiByte(CP_ACP
,0,path
,plen
,patha
,plen
,NULL
,NULL
) &&
2246 WideCharToMultiByte(CP_ACP
,0,mode
,mlen
,modea
,mlen
,NULL
,NULL
))
2248 FILE *retval
= _fsopen(patha
,modea
,share
);
2255 _dosmaperr(GetLastError());
2259 /*********************************************************************
2262 FILE * CDECL
fopen(const char *path
, const char *mode
)
2264 return _fsopen( path
, mode
, _SH_DENYNO
);
2267 /*********************************************************************
2268 * _wfopen (MSVCRT.@)
2270 FILE * CDECL
_wfopen(const wchar_t *path
, const wchar_t *mode
)
2272 return _wfsopen( path
, mode
, _SH_DENYNO
);
2275 /* fputc calls _flsbuf which calls fputc */
2276 int CDECL
_flsbuf(int c
, FILE* file
);
2278 /*********************************************************************
2281 int CDECL
fputc(int c
, FILE* file
)
2288 int res
= flush_buffer(file
);
2289 return res
? res
: c
;
2294 return _flsbuf(c
, file
);
2298 /*********************************************************************
2299 * _flsbuf (MSVCRT.@)
2301 int CDECL
_flsbuf(int c
, FILE* file
)
2303 /* Flush output buffer */
2304 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2307 if(!(file
->_flag
& _IOWRT
)) {
2308 if(file
->_flag
& _IORW
) {
2309 file
->_flag
|= _IOWRT
;
2315 int res
=flush_buffer(file
);
2316 return res
?res
: fputc(c
, file
);
2320 /* set _cnt to 0 for unbuffered FILEs */
2322 len
= _write(file
->_file
, &cc
, 1);
2323 if (len
== 1) return c
& 0xff;
2324 file
->_flag
|= _IOERR
;
2329 /*********************************************************************
2330 * _fputchar (MSVCRT.@)
2332 int CDECL
_fputchar(int c
)
2334 return fputc(c
, stdout
);
2337 /*********************************************************************
2340 size_t CDECL
fread(void *ptr
, size_t size
, size_t nmemb
, FILE* file
)
2341 { size_t rcnt
=size
* nmemb
;
2348 /* first buffered data */
2350 int pcnt
= (rcnt
>file
->_cnt
)? file
->_cnt
:rcnt
;
2351 memcpy(ptr
, file
->_ptr
, pcnt
);
2356 ptr
= (char*)ptr
+ pcnt
;
2357 } else if(!(file
->_flag
& _IOREAD
)) {
2358 if(file
->_flag
& _IORW
) {
2359 file
->_flag
|= _IOREAD
;
2366 /* Fill the buffer on small reads.
2367 * TODO: Use a better buffering strategy.
2369 if (!file
->_cnt
&& size
*nmemb
<= BUFSIZ
/2 && !(file
->_flag
& _IONBF
)) {
2370 if (file
->_bufsiz
== 0) {
2373 file
->_cnt
= _read(file
->_file
, file
->_base
, file
->_bufsiz
);
2374 file
->_ptr
= file
->_base
;
2375 i
= (file
->_cnt
<rcnt
) ? file
->_cnt
: rcnt
;
2376 /* If the buffer fill reaches eof but fread wouldn't, clear eof. */
2377 if (i
> 0 && i
< file
->_cnt
) {
2378 fdesc
[file
->_file
].wxflag
&= ~WX_ATEOF
;
2379 file
->_flag
&= ~_IOEOF
;
2382 memcpy(ptr
, file
->_ptr
, i
);
2387 i
= _read(file
->_file
,ptr
, rcnt
);
2391 ptr
= (char *)ptr
+i
;
2392 /* expose feof condition in the flags
2393 * MFC tests file->_flag for feof, and doesn't call feof())
2395 if ( fdesc
[file
->_file
].wxflag
& WX_ATEOF
)
2396 file
->_flag
|= _IOEOF
;
2399 file
->_flag
|= _IOERR
;
2409 /*********************************************************************
2410 * freopen (MSVCRT.@)
2413 FILE* CDECL
freopen(const char *path
, const char *mode
,FILE* file
)
2415 int open_flags
, stream_flags
, fd
;
2417 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n",path
,mode
,file
,file
->_file
);
2420 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2425 /* map mode string to open() flags. "man fopen" for possibilities. */
2426 if (get_flags(mode
, &open_flags
, &stream_flags
) == -1)
2430 fd
= _open(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2433 else if (init_fp(file
, fd
, stream_flags
) == -1)
2436 WARN(":failed-last error (%d)\n",GetLastError());
2437 _dosmaperr(GetLastError());
2446 /*********************************************************************
2447 * wfreopen (MSVCRT.@)
2450 FILE* CDECL
_wfreopen(const wchar_t *path
, const wchar_t *mode
,FILE* file
)
2452 int open_flags
, stream_flags
, fd
;
2454 TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n", debugstr_w(path
), debugstr_w(mode
), file
, file
->_file
);
2457 if (!file
|| ((fd
= file
->_file
) < 0) || fd
> fdend
)
2462 /* map mode string to open() flags. "man fopen" for possibilities. */
2463 if (get_flags((char*)mode
, &open_flags
, &stream_flags
) == -1)
2467 fd
= _wopen(path
, open_flags
, _S_IREAD
| _S_IWRITE
);
2470 else if (init_fp(file
, fd
, stream_flags
) == -1)
2473 WARN(":failed-last error (%d)\n",GetLastError());
2474 _dosmaperr(GetLastError());
2483 /*********************************************************************
2484 * fsetpos (MSVCRT.@)
2486 int CDECL
fsetpos(FILE* file
, const fpos_t *pos
)
2488 /* Note that all this has been lifted 'as is' from fseek */
2489 if(file
->_flag
& _IOWRT
)
2492 /* Discard buffered input */
2494 file
->_ptr
= file
->_base
;
2496 /* Reset direction of i/o */
2497 if(file
->_flag
& _IORW
) {
2498 file
->_flag
&= ~(_IOREAD
|_IOWRT
);
2501 return (_lseeki64(file
->_file
,*pos
,SEEK_SET
) == -1) ? -1 : 0;
2504 /*********************************************************************
2507 LONG CDECL
ftell(FILE* file
)
2509 /* TODO: just call fgetpos and return lower half of result */
2512 pos
= _tell(file
->_file
);
2513 if(pos
== -1) return -1;
2515 if( file
->_flag
& _IOWRT
) {
2516 off
= file
->_ptr
- file
->_base
;
2519 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
) {
2520 /* Black magic correction for CR removal */
2522 for (i
=0; i
<file
->_cnt
; i
++) {
2523 if (file
->_ptr
[i
] == '\n')
2532 /*********************************************************************
2533 * fgetpos (MSVCRT.@)
2535 int CDECL
fgetpos(FILE* file
, fpos_t *pos
)
2538 *pos
= _lseeki64(file
->_file
,0,SEEK_CUR
);
2539 if(*pos
== -1) return -1;
2541 if( file
->_flag
& _IOWRT
) {
2542 off
= file
->_ptr
- file
->_base
;
2545 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
) {
2546 /* Black magic correction for CR removal */
2548 for (i
=0; i
<file
->_cnt
; i
++) {
2549 if (file
->_ptr
[i
] == '\n')
2559 /*********************************************************************
2562 int CDECL
fputs(const char *s
, FILE* file
)
2564 size_t i
, len
= strlen(s
);
2565 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2566 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2567 for (i
=0; i
<len
; i
++)
2568 if (fputc(s
[i
], file
) == EOF
)
2573 /*********************************************************************
2576 int CDECL
fputws(const wchar_t *s
, FILE* file
)
2578 size_t i
, len
= strlenW(s
);
2579 if (!(fdesc
[file
->_file
].wxflag
& WX_TEXT
))
2580 return fwrite(s
,sizeof(*s
),len
,file
) == len
? 0 : EOF
;
2581 for (i
=0; i
<len
; i
++)
2583 if ((s
[i
] == '\n') && (fputc('\r', file
) == EOF
))
2585 if (fputwc(s
[i
], file
) == WEOF
)
2591 /*********************************************************************
2592 * getchar (MSVCRT.@)
2594 int CDECL
getchar(void)
2596 return fgetc(stdin
);
2599 /*********************************************************************
2602 int CDECL
getc(FILE* file
)
2607 /*********************************************************************
2610 char * CDECL
gets(char *buf
)
2613 char * buf_start
= buf
;
2615 for(cc
= fgetc(stdin
); cc
!= EOF
&& cc
!= '\n';
2617 if(cc
!= '\r') *buf
++ = (char)cc
;
2621 TRACE("got '%s'\n", buf_start
);
2625 /*********************************************************************
2628 wchar_t* CDECL
_getws(wchar_t* buf
)
2633 for (cc
= fgetwc(stdin
); cc
!= WEOF
&& cc
!= '\n';
2637 *buf
++ = (wchar_t)cc
;
2641 TRACE("got %s\n", debugstr_w(ws
));
2645 /*********************************************************************
2648 int CDECL
putc(int c
, FILE* file
)
2650 return fputc(c
, file
);
2653 /*********************************************************************
2654 * putchar (MSVCRT.@)
2656 int CDECL
putchar(int c
)
2658 return fputc(c
, stdout
);
2661 /*********************************************************************
2664 int CDECL
puts(const char *s
)
2666 size_t len
= strlen(s
);
2667 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2668 return fwrite("\n",1,1,stdout
) == 1 ? 0 : EOF
;
2671 /*********************************************************************
2674 int CDECL
_putws(const wchar_t *s
)
2676 static const wchar_t nl
= '\n';
2677 size_t len
= strlenW(s
);
2678 if (fwrite(s
,sizeof(*s
),len
,stdout
) != len
) return EOF
;
2679 return fwrite(&nl
,sizeof(nl
),1,stdout
) == 1 ? 0 : EOF
;
2682 /*********************************************************************
2685 int CDECL
remove(const char *path
)
2687 TRACE("(%s)\n",path
);
2688 if (DeleteFileA(path
))
2690 TRACE(":failed (%d)\n",GetLastError());
2691 _dosmaperr(GetLastError());
2695 /*********************************************************************
2696 * _wremove (MSVCRT.@)
2698 int CDECL
_wremove(const wchar_t *path
)
2700 TRACE("(%s)\n",debugstr_w(path
));
2701 if (DeleteFileW(path
))
2703 TRACE(":failed (%d)\n",GetLastError());
2704 _dosmaperr(GetLastError());
2708 /*********************************************************************
2711 int CDECL
rename(const char *oldpath
,const char *newpath
)
2713 TRACE(":from %s to %s\n",oldpath
,newpath
);
2714 if (MoveFileExA(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2716 TRACE(":failed (%d)\n",GetLastError());
2717 _dosmaperr(GetLastError());
2721 /*********************************************************************
2722 * _wrename (MSVCRT.@)
2724 int CDECL
_wrename(const wchar_t *oldpath
,const wchar_t *newpath
)
2726 TRACE(":from %s to %s\n",debugstr_w(oldpath
),debugstr_w(newpath
));
2727 if (MoveFileExW(oldpath
, newpath
, MOVEFILE_COPY_ALLOWED
))
2729 TRACE(":failed (%d)\n",GetLastError());
2730 _dosmaperr(GetLastError());
2734 /*********************************************************************
2735 * setvbuf (MSVCRT.@)
2737 int CDECL
setvbuf(FILE* file
, char *buf
, int mode
, size_t size
)
2739 /* TODO: Check if file busy */
2745 if(mode
== _IOFBF
) {
2746 file
->_flag
&= ~_IONBF
;
2747 file
->_base
= file
->_ptr
= buf
;
2749 file
->_bufsiz
= size
;
2752 file
->_flag
|= _IONBF
;
2757 /*********************************************************************
2760 void CDECL
setbuf(FILE* file
, char *buf
)
2762 setvbuf(file
, buf
, buf
? _IOFBF
: _IONBF
, BUFSIZ
);
2765 /*********************************************************************
2768 char * CDECL
tmpnam(char *s
)
2776 int_to_base32(GetCurrentProcessId(), tmpstr
);
2777 p
= s
+ sprintf(s
, "\\s%s.", tmpstr
);
2778 for (count
= 0; count
< TMP_MAX
; count
++)
2780 int_to_base32(unique
++, tmpstr
);
2782 if (GetFileAttributesA(s
) == INVALID_FILE_ATTRIBUTES
&&
2783 GetLastError() == ERROR_FILE_NOT_FOUND
)
2789 /*********************************************************************
2790 * wtmpnam (MSVCRT.@)
2792 wchar_t * CDECL
_wtmpnam(wchar_t *s
)
2794 ERR("UNIMPLEMENTED!\n");
2798 /*********************************************************************
2799 * tmpfile (MSVCRT.@)
2801 FILE* CDECL
tmpfile(void)
2803 char *filename
= tmpnam(NULL
);
2808 fd
= _open(filename
, _O_CREAT
| _O_BINARY
| _O_RDWR
| _O_TEMPORARY
);
2809 if (fd
!= -1 && (file
= alloc_fp()))
2811 if (init_fp(file
, fd
, _O_RDWR
) == -1)
2816 else file
->_tmpfname
= _strdup(filename
);
2822 /*********************************************************************
2823 * vfprintf (MSVCRT.@)
2825 int CDECL
vfprintf(FILE* file
, const char *format
, va_list valist
)
2827 char buf
[2048], *mem
= buf
;
2828 int written
, resize
= sizeof(buf
), retval
;
2829 /* There are two conventions for vsnprintf failing:
2830 * Return -1 if we truncated, or
2831 * Return the number of bytes that would have been written
2832 * The code below handles both cases
2834 while ((written
= _vsnprintf(mem
, resize
, format
, valist
)) == -1 ||
2837 resize
= (written
== -1 ? resize
* 2 : written
+ 1);
2840 if (!(mem
= malloc(resize
)))
2843 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2849 /*********************************************************************
2850 * vfwprintf (MSVCRT.@)
2852 * Is final char included in written (then resize is too big) or not
2853 * (then we must test for equality too)?
2855 int CDECL
vfwprintf(FILE* file
, const wchar_t *format
, va_list valist
)
2857 wchar_t buf
[2048], *mem
= buf
;
2858 int written
, resize
= sizeof(buf
) / sizeof(wchar_t), retval
;
2859 /* See vfprintf comments */
2860 while ((written
= _vsnwprintf(mem
, resize
, format
, valist
)) == -1 ||
2863 resize
= (written
== -1 ? resize
* 2 : written
+ sizeof(wchar_t));
2866 if (!(mem
= malloc(resize
*sizeof(*mem
))))
2870 /* Check if outputting to a text-file */
2871 if (fdesc
[file
->_file
].wxflag
& WX_TEXT
)
2873 /* Convert each character and stop at the first invalid character. Behavior verified by tests under WinXP SP2 */
2874 char chMultiByte
[MB_LEN_MAX
];
2880 for (p
= mem
; *p
; p
++)
2882 nReturn
= wctomb(chMultiByte
, *p
);
2887 retval
+= fwrite(chMultiByte
, 1, nReturn
, file
);
2892 retval
= fwrite(mem
, sizeof(*mem
), written
, file
);
2901 /*********************************************************************
2902 * vprintf (MSVCRT.@)
2904 int CDECL
vprintf(const char *format
, va_list valist
)
2906 return vfprintf(stdout
,format
,valist
);
2909 /*********************************************************************
2910 * vwprintf (MSVCRT.@)
2912 int CDECL
vwprintf(const wchar_t *format
, va_list valist
)
2914 return vfwprintf(stdout
,format
,valist
);
2917 /*********************************************************************
2918 * fprintf (MSVCRT.@)
2920 int CDECL
fprintf(FILE* file
, const char *format
, ...)
2924 va_start(valist
, format
);
2925 res
= vfprintf(file
, format
, valist
);
2930 /*********************************************************************
2931 * fwprintf (MSVCRT.@)
2933 int CDECL
fwprintf(FILE* file
, const wchar_t *format
, ...)
2937 va_start(valist
, format
);
2938 res
= vfwprintf(file
, format
, valist
);
2943 /*********************************************************************
2946 int CDECL
printf(const char *format
, ...)
2950 va_start(valist
, format
);
2951 res
= vfprintf(stdout
, format
, valist
);
2956 /*********************************************************************
2959 int CDECL
ungetc(int c
, FILE * file
)
2963 if(file
->_bufsiz
== 0 && !(file
->_flag
& _IONBF
)) {
2967 if(file
->_ptr
>file
->_base
) {
2977 /*********************************************************************
2978 * ungetwc (MSVCRT.@)
2980 wint_t CDECL
ungetwc(wint_t wc
, FILE * file
)
2983 char * pp
= (char *)&mwc
;
2985 for(i
=sizeof(wchar_t)-1;i
>=0;i
--) {
2986 if(pp
[i
] != ungetc(pp
[i
],file
))
2992 /*********************************************************************
2993 * wprintf (MSVCRT.@)
2995 int CDECL
wprintf(const wchar_t *format
, ...)
2999 va_start(valist
, format
);
3000 res
= vwprintf(format
, valist
);
3005 /*********************************************************************
3006 * _getmaxstdio (MSVCRT.@)
3008 int CDECL
_getmaxstdio(void)
3010 FIXME("stub, always returns 512\n");
3014 /*********************************************************************
3015 * _setmaxstdio_ (MSVCRT.@)
3017 int CDECL
_setmaxstdio(int newmax
)
3024 FIXME("stub: setting new maximum for number of simultaneously open files not implemented,returning %d\n",res
);
3028 /*********************************************************************
3029 * __pioinfo (MSVCRT.@)
3030 * FIXME: see MAX_FILES define.
3032 ioinfo
* __pioinfo
[] = { /* array of pointers to ioinfo arrays [64] */
3033 &fdesc
[0 * 64], &fdesc
[1 * 64], &fdesc
[2 * 64],
3034 &fdesc
[3 * 64], &fdesc
[4 * 64], &fdesc
[5 * 64],
3035 &fdesc
[6 * 64], &fdesc
[7 * 64], &fdesc
[8 * 64],
3036 &fdesc
[9 * 64], &fdesc
[10 * 64], &fdesc
[11 * 64],
3037 &fdesc
[12 * 64], &fdesc
[13 * 64], &fdesc
[14 * 64],
3038 &fdesc
[15 * 64], &fdesc
[16 * 64], &fdesc
[17 * 64],
3039 &fdesc
[18 * 64], &fdesc
[19 * 64], &fdesc
[20 * 64],
3040 &fdesc
[21 * 64], &fdesc
[22 * 64], &fdesc
[23 * 64],
3041 &fdesc
[24 * 64], &fdesc
[25 * 64], &fdesc
[26 * 64],
3042 &fdesc
[27 * 64], &fdesc
[28 * 64], &fdesc
[29 * 64],
3043 &fdesc
[30 * 64], &fdesc
[31 * 64]
3046 /*********************************************************************
3047 * __badioinfo (MSVCRT.@)
3049 ioinfo __badioinfo
= { INVALID_HANDLE_VALUE
, WX_TEXT
, { 0, } };