Roll back ill-considered attempts to fix printf specifier mismatch for off_t.
[python.git] / Modules / _io / _iomodule.h
blobe220ec1fc3c17566a3acd2acd124031f761fc079
1 /*
2 * Declarations shared between the different parts of the io module
3 */
5 /* ABCs */
6 extern PyTypeObject PyIOBase_Type;
7 extern PyTypeObject PyRawIOBase_Type;
8 extern PyTypeObject PyBufferedIOBase_Type;
9 extern PyTypeObject PyTextIOBase_Type;
11 /* Concrete classes */
12 extern PyTypeObject PyFileIO_Type;
13 extern PyTypeObject PyBytesIO_Type;
14 extern PyTypeObject PyStringIO_Type;
15 extern PyTypeObject PyBufferedReader_Type;
16 extern PyTypeObject PyBufferedWriter_Type;
17 extern PyTypeObject PyBufferedRWPair_Type;
18 extern PyTypeObject PyBufferedRandom_Type;
19 extern PyTypeObject PyTextIOWrapper_Type;
20 extern PyTypeObject PyIncrementalNewlineDecoder_Type;
22 /* These functions are used as METH_NOARGS methods, are normally called
23 * with args=NULL, and return a new reference.
24 * BUT when args=Py_True is passed, they return a borrowed reference.
26 extern PyObject* _PyIOBase_check_readable(PyObject *self, PyObject *args);
27 extern PyObject* _PyIOBase_check_writable(PyObject *self, PyObject *args);
28 extern PyObject* _PyIOBase_check_seekable(PyObject *self, PyObject *args);
29 extern PyObject* _PyIOBase_check_closed(PyObject *self, PyObject *args);
31 /* Helper for finalization.
32 This function will revive an object ready to be deallocated and try to
33 close() it. It returns 0 if the object can be destroyed, or -1 if it
34 is alive again. */
35 extern int _PyIOBase_finalize(PyObject *self);
37 /* Returns true if the given FileIO object is closed.
38 Doesn't check the argument type, so be careful! */
39 extern int _PyFileIO_closed(PyObject *self);
41 /* Shortcut to the core of the IncrementalNewlineDecoder.decode method */
42 extern PyObject *_PyIncrementalNewlineDecoder_decode(
43 PyObject *self, PyObject *input, int final);
45 /* Finds the first line ending between `start` and `end`.
46 If found, returns the index after the line ending and doesn't touch
47 `*consumed`.
48 If not found, returns -1 and sets `*consumed` to the number of characters
49 which can be safely put aside until another search.
51 NOTE: for performance reasons, `end` must point to a NUL character ('\0').
52 Otherwise, the function will scan further and return garbage. */
53 extern Py_ssize_t _PyIO_find_line_ending(
54 int translated, int universal, PyObject *readnl,
55 Py_UNICODE *start, Py_UNICODE *end, Py_ssize_t *consumed);
58 #define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
60 typedef struct {
61 /* This is the equivalent of PyException_HEAD in 3.x */
62 PyObject_HEAD
63 PyObject *dict;
64 PyObject *args;
65 PyObject *message;
67 PyObject *myerrno;
68 PyObject *strerror;
69 PyObject *filename; /* Not used, but part of the IOError object */
70 Py_ssize_t written;
71 } PyBlockingIOErrorObject;
72 PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
75 * Offset type for positioning.
78 #if defined(MS_WIN64) || defined(MS_WINDOWS)
80 /* Windows uses long long for offsets */
81 typedef PY_LONG_LONG Py_off_t;
82 # define PyLong_AsOff_t PyLong_AsLongLong
83 # define PyLong_FromOff_t PyLong_FromLongLong
84 # define PY_OFF_T_MAX PY_LLONG_MAX
85 # define PY_OFF_T_MIN PY_LLONG_MIN
87 #else
89 /* Other platforms use off_t */
90 typedef off_t Py_off_t;
91 #if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
92 # define PyLong_AsOff_t PyLong_AsSsize_t
93 # define PyLong_FromOff_t PyLong_FromSsize_t
94 # define PY_OFF_T_MAX PY_SSIZE_T_MAX
95 # define PY_OFF_T_MIN PY_SSIZE_T_MIN
96 #elif (SIZEOF_OFF_T == SIZEOF_LONG_LONG)
97 # define PyLong_AsOff_t PyLong_AsLongLong
98 # define PyLong_FromOff_t PyLong_FromLongLong
99 # define PY_OFF_T_MAX PY_LLONG_MAX
100 # define PY_OFF_T_MIN PY_LLONG_MIN
101 #elif (SIZEOF_OFF_T == SIZEOF_LONG)
102 # define PyLong_AsOff_t PyLong_AsLong
103 # define PyLong_FromOff_t PyLong_FromLong
104 # define PY_OFF_T_MAX LONG_MAX
105 # define PY_OFF_T_MIN LONG_MIN
106 #else
107 # error off_t does not match either size_t, long, or long long!
108 #endif
110 #endif
112 extern Py_off_t PyNumber_AsOff_t(PyObject *item, PyObject *err);
114 /* Implementation details */
116 extern PyObject *_PyIO_os_module;
117 extern PyObject *_PyIO_locale_module;
118 extern PyObject *_PyIO_unsupported_operation;
120 extern PyObject *_PyIO_str_close;
121 extern PyObject *_PyIO_str_closed;
122 extern PyObject *_PyIO_str_decode;
123 extern PyObject *_PyIO_str_encode;
124 extern PyObject *_PyIO_str_fileno;
125 extern PyObject *_PyIO_str_flush;
126 extern PyObject *_PyIO_str_getstate;
127 extern PyObject *_PyIO_str_isatty;
128 extern PyObject *_PyIO_str_newlines;
129 extern PyObject *_PyIO_str_nl;
130 extern PyObject *_PyIO_str_read;
131 extern PyObject *_PyIO_str_read1;
132 extern PyObject *_PyIO_str_readable;
133 extern PyObject *_PyIO_str_readinto;
134 extern PyObject *_PyIO_str_readline;
135 extern PyObject *_PyIO_str_reset;
136 extern PyObject *_PyIO_str_seek;
137 extern PyObject *_PyIO_str_seekable;
138 extern PyObject *_PyIO_str_setstate;
139 extern PyObject *_PyIO_str_tell;
140 extern PyObject *_PyIO_str_truncate;
141 extern PyObject *_PyIO_str_writable;
142 extern PyObject *_PyIO_str_write;
144 extern PyObject *_PyIO_empty_str;
145 extern PyObject *_PyIO_empty_bytes;
146 extern PyObject *_PyIO_zero;