1a9fe09a4d827fef85d42e7f59b2dfa93ccaf114
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
25 #define _IORMONCL 004000 /* remove on close, for temp files */
27 /* if _flag & _IORMONCL, ._name_to_remove needs freeing */
30 #define _IOUNGETC 010000 /* there is an ungetc'ed character in the buffer */
33 /* might need check for IO_APPEND aswell */
34 #define OPEN4WRITING(f) ((((f)->_flag & _IOWRT) == _IOWRT))
35 #define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD))
37 /* might need check for IO_APPEND aswell */
38 #define WRITE_STREAM(f) ((((f)->_flag & _IOWRT) == _IOWRT))
39 #define READ_STREAM(f) ((((f)->_flag & _IOREAD) == _IOREAD))
41 char __validfp(FILE*);
42 int __set_errno(int err
);
43 int __set_doserrno(int error
);
44 void* filehnd(int fn
);
45 char __is_text_file(FILE*);
46 int alloc_fd(void* hFile
, char mode
);
47 int _doprnt(const char* fmt
, va_list args
, FILE *);
48 int _doscan(FILE* iop
, const char* fmt
, va_list argp
);
49 int __fileno_dup2(int handle1
, int handle2
);
50 char __fileno_getmode(int _fd
);
51 int __fileno_setmode(int _fd
, int _newmode
);
52 void free_fd(int _fd
);
53 void sigabort_handler(int sig
);
54 char split_oflags(int oflags
);
56 unsigned create_io_inherit_block(STARTUPINFOA
* si
);
57 void UnixTimeToFileTime(time_t unix_time
, FILETIME
* filetime
, DWORD remainder
);
58 time_t FileTimeToUnixTime(const FILETIME
* filetime
, DWORD
*remainder
);
61 #define __FILE_REC_MAX 20
62 typedef struct __file_rec
64 struct __file_rec
* next
;
66 FILE* files
[__FILE_REC_MAX
];
69 extern __file_rec
* __file_rec_list
;
72 typedef struct _FDINFO
76 char pipechar
; /* one char buffer for handles opened on pipes */
78 CRITICAL_SECTION lock
;
81 #define FDINFO_ENTRIES_PER_BUCKET_SHIFT 5 /* log2(32) = 5 */
82 #define FDINFO_BUCKETS 64
83 #define FDINFO_ENTRIES_PER_BUCKET 32
84 #define FDINFO_ENTRIES (FDINFO_BUCKETS * FDINFO_ENTRIES_PER_BUCKET)
87 #define LF 10 /* line feed */
88 #define CR 13 /* carriage return */
89 #define CTRLZ 26 /* ctrl-z means eof for text */
92 #define FOPEN 0x01 /* file handle open */
93 #define FEOFLAG 0x02 /* end of file has been encountered */
94 #define FCRLF 0x04 /* CR-LF across read buffer (in text mode) */
95 #define FPIPE 0x08 /* file refers to a pipe */
96 #define FNOINHERIT 0x10 /* file handle opened _O_NOINHERIT */
97 #define FAPPEND 0x20 /* file opened O_APPEND */
98 #define FDEV 0x40 /* file refers to device */
99 #define FTEXT 0x80 /* file is in text mode (absence = binary) */
101 /* get bucket index (0-63) from an fd */
102 #define fdinfo_bucket_idx(i) ((i) >> FDINFO_ENTRIES_PER_BUCKET_SHIFT)
103 /* get position inside a bucket (0-31) from an fd */
104 #define fdinfo_bucket_entry_idx(i) ((i) & (FDINFO_ENTRIES_PER_BUCKET - 1))
105 /* get bucket ptr. (ptr. to fist fdinfo inside a bucket) from an fd */
106 #define fdinfo_bucket(i) ( __pioinfo[fdinfo_bucket_idx(i)])
107 /* get fdinfo ptr. from an fd */
108 #define fdinfo(i) (fdinfo_bucket(i) + fdinfo_bucket_entry_idx(i))
110 extern FDINFO
* __pioinfo
[];
113 void _dosmaperr(unsigned long oserrcode
);
117 FILE* __alloc_file(void);
121 int access_dirA(const char *_path
);
122 int access_dirW(const wchar_t *_path
);
125 #define access_dirT access_dirW
127 #define access_dirT access_dirA
132 void _fwalk(void (*func
)(FILE*)); // not exported
137 #define MB_CUR_MAX __mb_cur_max
140 int _isnanl(double x
);
141 int _isinfl(double x
);
142 int _isnan(double x
);
143 int _isinf(double x
);
147 /* Flags for the iobuf structure (for reference) */
149 #define _IOREAD 1 /* currently reading */
150 #define _IOWRT 2 /* currently writing */
151 #define _IORW 0x0080 /* opened as "r+w" */
154 /* internal FILE->_flag flags */
156 #define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
157 #define _IOEOF 0x0010 /* EOF reached on read */
158 #define _IOERR 0x0020 /* I/O error from system */
159 #define _IOSTRG 0x0040 /* Strange or no file descriptor */
161 #define _IOBINARY 0x040000
162 #define _IOTEXT 0x000000
164 #define _IOCOMMIT 0x100000
166 #define _IODIRTY 0x010000
167 #define _IOAHEAD 0x020000
173 * The three possible buffering mode (nMode) values for setvbuf.
174 * NOTE: _IOFBF works, but _IOLBF seems to work like unbuffered...
175 * maybe I'm testing it wrong?
177 #define _IOFBF 0x0000 /* full buffered */
178 #define _IOLBF 0x0040 /* line buffered */
179 #define _IONBF 0x0004 /* not buffered */
181 #define _IO_LBF 0x80000 /* this value is used insteat of _IOLBF within the
182 structure FILE as value for _flags,
183 because _IOLBF has the same value as _IOSTRG */
186 wint_t _filwbuf(FILE *f
);
188 #if __MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 2
189 int __cdecl
_filbuf (FILE*);
190 int __cdecl
_flsbuf (int, FILE*);
194 #endif /* __dj_include_libc_file_h__ */