]> pd.if.org Git - pdclib/blob - internals/_PDCLIB_io.h
0dfdad258fc6356a107597cfc830080cd1ccf82a
[pdclib] / internals / _PDCLIB_io.h
1 #ifndef _PDCLIB_IO_H\r
2 #define _PDCLIB_IO_H\r
3 #include "_PDCLIB_int.h"\r
4 #include "_PDCLIB_threadconfig.h"\r
5 \r
6 /* PDCLib internal I/O logic <_PDCLIB_int.h>\r
7 \r
8    This file is part of the Public Domain C Library (PDCLib).\r
9    Permission is granted to use, modify, and / or redistribute at will.\r
10 */\r
11 \r
12 /* Flags for representing mode (see fopen()). Note these must fit the same\r
13    status field as the _IO?BF flags in <stdio.h> and the internal flags below.\r
14 */\r
15 #define _PDCLIB_FREAD     8u\r
16 #define _PDCLIB_FWRITE   16u\r
17 #define _PDCLIB_FAPPEND  32u \r
18 #define _PDCLIB_FRW      64u\r
19 #define _PDCLIB_FBIN    128u\r
20 \r
21 /* Internal flags, made to fit the same status field as the flags above. */\r
22 /* -------------------------------------------------------------------------- */\r
23 /* free() the buffer memory on closing (false for user-supplied buffer) */\r
24 #define _PDCLIB_FREEBUFFER   512u\r
25 /* stream has encountered error / EOF */\r
26 #define _PDCLIB_ERRORFLAG   1024u\r
27 #define _PDCLIB_EOFFLAG     2048u\r
28 /* stream is wide-oriented */\r
29 #define _PDCLIB_WIDESTREAM  4096u\r
30 /* stream is byte-oriented */\r
31 #define _PDCLIB_BYTESTREAM  8192u\r
32 /* file associated with stream should be remove()d on closing (tmpfile()) */\r
33 #define _PDCLIB_DELONCLOSE 16384u\r
34 /* stream handle should not be free()d on close (stdin, stdout, stderr) */\r
35 #define _PDCLIB_STATIC     32768u\r
36 \r
37 /* Position / status structure for getpos() / fsetpos(). */\r
38 struct _PDCLIB_fpos_t\r
39 {\r
40     _PDCLIB_uint64_t offset; /* File position offset */\r
41     int              status; /* Multibyte parsing state (unused, reserved) */\r
42 };\r
43 \r
44 /* FILE structure */\r
45 struct _PDCLIB_file_t\r
46 {\r
47     _PDCLIB_fd_t            handle;   /* OS file handle */\r
48     _PDCLIB_MTX_T           lock;     /* file lock */\r
49     char *                  buffer;   /* Pointer to buffer memory */\r
50     _PDCLIB_size_t          bufsize;  /* Size of buffer */\r
51     _PDCLIB_size_t          bufidx;   /* Index of current position in buffer */\r
52     _PDCLIB_size_t          bufend;   /* Index of last pre-read character in buffer */\r
53     struct _PDCLIB_fpos_t   pos;      /* Offset and multibyte parsing state */\r
54     _PDCLIB_size_t          ungetidx; /* Number of ungetc()'ed characters */\r
55     unsigned char *         ungetbuf; /* ungetc() buffer */\r
56     unsigned int            status;   /* Status flags; see above */\r
57     /* multibyte parsing status to be added later */\r
58     char *                  filename; /* Name the current stream has been opened with */\r
59     struct _PDCLIB_file_t * next;     /* Pointer to next struct (internal) */\r
60 };\r
61 \r
62 \r
63 #endif\r