more msvc compile fixes by Brezenbak and I
[reactos.git] / reactos / lib / crt / include / internal / file.h
1 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
2 /*
3 * Some stuff taken from active perl: perl\win32.c (ioinfo stuff)
4 *
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.
8 *
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.
11 */
12
13 #ifndef __CRT_INTERNAL_FILE_H
14 #define __CRT_INTERNAL_FILE_H
15
16 #include <stdio.h>
17 #include <fcntl.h>
18 #include <stdarg.h>
19 #include <time.h>
20
21
22 #include <windef.h>
23 #include <winbase.h>
24 #include <winnt.h>
25
26 #ifndef _IORMONCL
27 #define _IORMONCL 004000 /* remove on close, for temp files */
28 #endif
29 /* if _flag & _IORMONCL, ._name_to_remove needs freeing */
30
31 #ifndef _IOUNGETC
32 #define _IOUNGETC 010000 /* there is an ungetc'ed character in the buffer */
33 #endif
34
35 /* might need check for IO_APPEND aswell */
36 #define OPEN4WRITING(f) ((((f)->_flag & _IOWRT) == _IOWRT))
37 #define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD))
38
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))
42
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);
57
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);
61
62
63 #define __FILE_REC_MAX 20
64 typedef struct __file_rec
65 {
66 struct __file_rec* next;
67 int count;
68 FILE* files[__FILE_REC_MAX];
69 } __file_rec;
70
71 extern __file_rec* __file_rec_list;
72
73
74 typedef struct _FDINFO
75 {
76 HANDLE hFile;
77 char fdflags;
78 char pipechar; /* one char buffer for handles opened on pipes */
79 int lockinitflag;
80 CRITICAL_SECTION lock;
81 } FDINFO;
82
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)
87
88 /* pipech */
89 #define LF 10 /* line feed */
90 #define CR 13 /* carriage return */
91 #define CTRLZ 26 /* ctrl-z means eof for text */
92
93 /* mode */
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) */
102
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))
111
112 extern FDINFO* __pioinfo[];
113
114
115 void _dosmaperr(unsigned long oserrcode);
116
117
118
119 FILE* __alloc_file(void);
120
121
122
123 int access_dirA(const char *_path);
124 int access_dirW(const wchar_t *_path);
125
126 #ifdef _UNICODE
127 #define access_dirT access_dirW
128 #else
129 #define access_dirT access_dirA
130 #endif
131
132
133
134 void _fwalk(void (*func)(FILE*)); // not exported
135
136
137
138 #undef MB_CUR_MAX
139 #define MB_CUR_MAX __mb_cur_max
140
141
142 int _isnanl(double x);
143 int _isinfl(double x);
144 int _isnan(double x);
145 int _isinf(double x);
146
147
148
149 /* Flags for the iobuf structure (for reference) */
150 #if 0
151 #define _IOREAD 1 /* currently reading */
152 #define _IOWRT 2 /* currently writing */
153 #define _IORW 0x0080 /* opened as "r+w" */
154 #endif
155
156 /* internal FILE->_flag flags */
157
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 */
162
163 #define _IOBINARY 0x040000
164 #define _IOTEXT 0x000000
165
166 #define _IOCOMMIT 0x100000
167
168 #define _IODIRTY 0x010000
169 #define _IOAHEAD 0x020000
170
171
172
173
174 /*
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?
178 */
179 #define _IOFBF 0x0000 /* full buffered */
180 #define _IOLBF 0x0040 /* line buffered */
181 #define _IONBF 0x0004 /* not buffered */
182
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 */
186
187
188 wint_t _filwbuf(FILE *f);
189
190 #if __MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 2
191 int __cdecl _filbuf (FILE*);
192 int __cdecl _flsbuf (int, FILE*);
193 #endif
194
195
196 #endif /* __dj_include_libc_file_h__ */