1 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
3 * Some stuff taken from active perl: perl\win32.c (ioinfo stuff)
5 * (c) 1995 Microsoft Corporation. All rights reserved.
6 * Developed by hip communications inc., http://info.hip.com/info/
7 * Portions (c) 1993 Intergraph Corporation. All rights reserved.
9 * You may distribute under the terms of either the GNU General Public
10 * License or the Artistic License, as specified in the README file.
13 #ifndef __CRT_INTERNAL_FILE_H
14 #define __CRT_INTERNAL_FILE_H
27 #define _IORMONCL 004000 /* remove on close, for temp files */
29 /* if _flag & _IORMONCL, ._name_to_remove needs freeing */
32 #define _IOUNGETC 010000 /* there is an ungetc'ed character in the buffer */
35 /* might need check for IO_APPEND aswell */
36 #define OPEN4WRITING(f) ((((f)->_flag & _IOWRT) == _IOWRT))
37 #define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD))
39 /* might need check for IO_APPEND aswell */
40 #define WRITE_STREAM(f) ((((f)->_flag & _IOWRT) == _IOWRT))
41 #define READ_STREAM(f) ((((f)->_flag & _IOREAD) == _IOREAD))
43 char __validfp(FILE*);
44 int __set_errno(int err
);
45 int __set_doserrno(int error
);
46 void* filehnd(int fn
);
47 char __is_text_file(FILE*);
48 int alloc_fd(void* hFile
, char mode
);
49 int _doprnt(const char* fmt
, va_list args
, FILE *);
50 int _doscan(FILE* iop
, const char* fmt
, va_list argp
);
51 int __fileno_dup2(int handle1
, int handle2
);
52 char __fileno_getmode(int _fd
);
53 int __fileno_setmode(int _fd
, int _newmode
);
54 void free_fd(int _fd
);
55 void sigabort_handler(int sig
);
56 char split_oflags(int oflags
);
58 unsigned create_io_inherit_block(STARTUPINFOA
* si
);
59 void UnixTimeToFileTime(time_t unix_time
, FILETIME
* filetime
, DWORD remainder
);
60 time_t FileTimeToUnixTime(const FILETIME
* filetime
, DWORD
*remainder
);
63 #define __FILE_REC_MAX 20
64 typedef struct __file_rec
66 struct __file_rec
* next
;
68 FILE* files
[__FILE_REC_MAX
];
71 extern __file_rec
* __file_rec_list
;
74 typedef struct _FDINFO
78 char pipechar
; /* one char buffer for handles opened on pipes */
80 CRITICAL_SECTION lock
;
83 #define FDINFO_ENTRIES_PER_BUCKET_SHIFT 5 /* log2(32) = 5 */
84 #define FDINFO_BUCKETS 64
85 #define FDINFO_ENTRIES_PER_BUCKET 32
86 #define FDINFO_ENTRIES (FDINFO_BUCKETS * FDINFO_ENTRIES_PER_BUCKET)
89 #define LF 10 /* line feed */
90 #define CR 13 /* carriage return */
91 #define CTRLZ 26 /* ctrl-z means eof for text */
94 #define FOPEN 0x01 /* file handle open */
95 #define FEOFLAG 0x02 /* end of file has been encountered */
96 #define FCRLF 0x04 /* CR-LF across read buffer (in text mode) */
97 #define FPIPE 0x08 /* file refers to a pipe */
98 #define FNOINHERIT 0x10 /* file handle opened _O_NOINHERIT */
99 #define FAPPEND 0x20 /* file opened O_APPEND */
100 #define FDEV 0x40 /* file refers to device */
101 #define FTEXT 0x80 /* file is in text mode (absence = binary) */
103 /* get bucket index (0-63) from an fd */
104 #define fdinfo_bucket_idx(i) ((i) >> FDINFO_ENTRIES_PER_BUCKET_SHIFT)
105 /* get position inside a bucket (0-31) from an fd */
106 #define fdinfo_bucket_entry_idx(i) ((i) & (FDINFO_ENTRIES_PER_BUCKET - 1))
107 /* get bucket ptr. (ptr. to first fdinfo inside a bucket) from an fd */
108 #define fdinfo_bucket(i) ( __pioinfo[fdinfo_bucket_idx(i)])
109 /* get fdinfo ptr. from an fd */
110 #define fdinfo(i) (fdinfo_bucket(i) + fdinfo_bucket_entry_idx(i))
112 extern FDINFO
* __pioinfo
[];
115 void _dosmaperr(unsigned long oserrcode
);
119 FILE* __alloc_file(void);
123 int access_dirA(const char *_path
);
124 int access_dirW(const wchar_t *_path
);
127 #define access_dirT access_dirW
129 #define access_dirT access_dirA
134 void _fwalk(void (*func
)(FILE*)); // not exported
139 #define MB_CUR_MAX __mb_cur_max
142 int _isnanl(double x
);
143 int _isinfl(double x
);
144 int _isnan(double x
);
145 int _isinf(double x
);
149 /* Flags for the iobuf structure (for reference) */
151 #define _IOREAD 1 /* currently reading */
152 #define _IOWRT 2 /* currently writing */
153 #define _IORW 0x0080 /* opened as "r+w" */
156 /* internal FILE->_flag flags */
158 #define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
159 #define _IOEOF 0x0010 /* EOF reached on read */
160 #define _IOERR 0x0020 /* I/O error from system */
161 #define _IOSTRG 0x0040 /* Strange or no file descriptor */
163 #define _IOBINARY 0x040000
164 #define _IOTEXT 0x000000
166 #define _IOCOMMIT 0x100000
168 #define _IODIRTY 0x010000
169 #define _IOAHEAD 0x020000
175 * The three possible buffering mode (nMode) values for setvbuf.
176 * NOTE: _IOFBF works, but _IOLBF seems to work like unbuffered...
177 * maybe I'm testing it wrong?
179 #define _IOFBF 0x0000 /* full buffered */
180 #define _IOLBF 0x0040 /* line buffered */
181 #define _IONBF 0x0004 /* not buffered */
183 #define _IO_LBF 0x80000 /* this value is used insteat of _IOLBF within the
184 structure FILE as value for _flags,
185 because _IOLBF has the same value as _IOSTRG */
188 wint_t _filwbuf(FILE *f
);
190 #if __MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 2
191 int __cdecl
_filbuf (FILE*);
192 int __cdecl
_flsbuf (int, FILE*);
196 #endif /* __dj_include_libc_file_h__ */