1a9fe09a4d827fef85d42e7f59b2dfa93ccaf114
[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
20 #include <windef.h>
21 #include <winbase.h>
22 #include <winnt.h>
23
24 #ifndef _IORMONCL
25 #define _IORMONCL 004000 /* remove on close, for temp files */
26 #endif
27 /* if _flag & _IORMONCL, ._name_to_remove needs freeing */
28
29 #ifndef _IOUNGETC
30 #define _IOUNGETC 010000 /* there is an ungetc'ed character in the buffer */
31 #endif
32
33 /* might need check for IO_APPEND aswell */
34 #define OPEN4WRITING(f) ((((f)->_flag & _IOWRT) == _IOWRT))
35 #define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD))
36
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))
40
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);
55
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);
59
60
61 #define __FILE_REC_MAX 20
62 typedef struct __file_rec
63 {
64 struct __file_rec* next;
65 int count;
66 FILE* files[__FILE_REC_MAX];
67 } __file_rec;
68
69 extern __file_rec* __file_rec_list;
70
71
72 typedef struct _FDINFO
73 {
74 HANDLE hFile;
75 char fdflags;
76 char pipechar; /* one char buffer for handles opened on pipes */
77 int lockinitflag;
78 CRITICAL_SECTION lock;
79 } FDINFO;
80
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)
85
86 /* pipech */
87 #define LF 10 /* line feed */
88 #define CR 13 /* carriage return */
89 #define CTRLZ 26 /* ctrl-z means eof for text */
90
91 /* mode */
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) */
100
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))
109
110 extern FDINFO* __pioinfo[];
111
112
113 void _dosmaperr(unsigned long oserrcode);
114
115
116
117 FILE* __alloc_file(void);
118
119
120
121 int access_dirA(const char *_path);
122 int access_dirW(const wchar_t *_path);
123
124 #ifdef _UNICODE
125 #define access_dirT access_dirW
126 #else
127 #define access_dirT access_dirA
128 #endif
129
130
131
132 void _fwalk(void (*func)(FILE*)); // not exported
133
134
135
136 #undef MB_CUR_MAX
137 #define MB_CUR_MAX __mb_cur_max
138
139
140 int _isnanl(double x);
141 int _isinfl(double x);
142 int _isnan(double x);
143 int _isinf(double x);
144
145
146
147 /* Flags for the iobuf structure (for reference) */
148 #if 0
149 #define _IOREAD 1 /* currently reading */
150 #define _IOWRT 2 /* currently writing */
151 #define _IORW 0x0080 /* opened as "r+w" */
152 #endif
153
154 /* internal FILE->_flag flags */
155
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 */
160
161 #define _IOBINARY 0x040000
162 #define _IOTEXT 0x000000
163
164 #define _IOCOMMIT 0x100000
165
166 #define _IODIRTY 0x010000
167 #define _IOAHEAD 0x020000
168
169
170
171
172 /*
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?
176 */
177 #define _IOFBF 0x0000 /* full buffered */
178 #define _IOLBF 0x0040 /* line buffered */
179 #define _IONBF 0x0004 /* not buffered */
180
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 */
184
185
186 wint_t _filwbuf(FILE *f);
187
188 #if __MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 2
189 int __cdecl _filbuf (FILE*);
190 int __cdecl _flsbuf (int, FILE*);
191 #endif
192
193
194 #endif /* __dj_include_libc_file_h__ */