Chris@87
|
1
|
Chris@87
|
2 /* File object interface */
|
Chris@87
|
3
|
Chris@87
|
4 #ifndef Py_FILEOBJECT_H
|
Chris@87
|
5 #define Py_FILEOBJECT_H
|
Chris@87
|
6 #ifdef __cplusplus
|
Chris@87
|
7 extern "C" {
|
Chris@87
|
8 #endif
|
Chris@87
|
9
|
Chris@87
|
10 typedef struct {
|
Chris@87
|
11 PyObject_HEAD
|
Chris@87
|
12 FILE *f_fp;
|
Chris@87
|
13 PyObject *f_name;
|
Chris@87
|
14 PyObject *f_mode;
|
Chris@87
|
15 int (*f_close)(FILE *);
|
Chris@87
|
16 int f_softspace; /* Flag used by 'print' command */
|
Chris@87
|
17 int f_binary; /* Flag which indicates whether the file is
|
Chris@87
|
18 open in binary (1) or text (0) mode */
|
Chris@87
|
19 char* f_buf; /* Allocated readahead buffer */
|
Chris@87
|
20 char* f_bufend; /* Points after last occupied position */
|
Chris@87
|
21 char* f_bufptr; /* Current buffer position */
|
Chris@87
|
22 char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */
|
Chris@87
|
23 int f_univ_newline; /* Handle any newline convention */
|
Chris@87
|
24 int f_newlinetypes; /* Types of newlines seen */
|
Chris@87
|
25 int f_skipnextlf; /* Skip next \n */
|
Chris@87
|
26 PyObject *f_encoding;
|
Chris@87
|
27 PyObject *f_errors;
|
Chris@87
|
28 PyObject *weakreflist; /* List of weak references */
|
Chris@87
|
29 int unlocked_count; /* Num. currently running sections of code
|
Chris@87
|
30 using f_fp with the GIL released. */
|
Chris@87
|
31 int readable;
|
Chris@87
|
32 int writable;
|
Chris@87
|
33 } PyFileObject;
|
Chris@87
|
34
|
Chris@87
|
35 PyAPI_DATA(PyTypeObject) PyFile_Type;
|
Chris@87
|
36
|
Chris@87
|
37 #define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
|
Chris@87
|
38 #define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)
|
Chris@87
|
39
|
Chris@87
|
40 PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
|
Chris@87
|
41 PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
|
Chris@87
|
42 PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
|
Chris@87
|
43 PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);
|
Chris@87
|
44 PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
|
Chris@87
|
45 int (*)(FILE *));
|
Chris@87
|
46 PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
|
Chris@87
|
47 PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);
|
Chris@87
|
48 PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);
|
Chris@87
|
49 PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
|
Chris@87
|
50 PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
|
Chris@87
|
51 PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
|
Chris@87
|
52 PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
|
Chris@87
|
53 PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
|
Chris@87
|
54 PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
|
Chris@87
|
55
|
Chris@87
|
56 /* The default encoding used by the platform file system APIs
|
Chris@87
|
57 If non-NULL, this is different than the default encoding for strings
|
Chris@87
|
58 */
|
Chris@87
|
59 PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
|
Chris@87
|
60
|
Chris@87
|
61 /* Routines to replace fread() and fgets() which accept any of \r, \n
|
Chris@87
|
62 or \r\n as line terminators.
|
Chris@87
|
63 */
|
Chris@87
|
64 #define PY_STDIOTEXTMODE "b"
|
Chris@87
|
65 char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
|
Chris@87
|
66 size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
|
Chris@87
|
67
|
Chris@87
|
68 /* A routine to do sanity checking on the file mode string. returns
|
Chris@87
|
69 non-zero on if an exception occurred
|
Chris@87
|
70 */
|
Chris@87
|
71 int _PyFile_SanitizeMode(char *mode);
|
Chris@87
|
72
|
Chris@87
|
73 #if defined _MSC_VER && _MSC_VER >= 1400
|
Chris@87
|
74 /* A routine to check if a file descriptor is valid on Windows. Returns 0
|
Chris@87
|
75 * and sets errno to EBADF if it isn't. This is to avoid Assertions
|
Chris@87
|
76 * from various functions in the Windows CRT beginning with
|
Chris@87
|
77 * Visual Studio 2005
|
Chris@87
|
78 */
|
Chris@87
|
79 int _PyVerify_fd(int fd);
|
Chris@87
|
80 #elif defined _MSC_VER && _MSC_VER >= 1200
|
Chris@87
|
81 /* fdopen doesn't set errno EBADF and crashes for large fd on debug build */
|
Chris@87
|
82 #define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0)
|
Chris@87
|
83 #else
|
Chris@87
|
84 #define _PyVerify_fd(A) (1) /* dummy */
|
Chris@87
|
85 #endif
|
Chris@87
|
86
|
Chris@87
|
87 /* A routine to check if a file descriptor can be select()-ed. */
|
Chris@87
|
88 #ifdef HAVE_SELECT
|
Chris@87
|
89 #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE))
|
Chris@87
|
90 #else
|
Chris@87
|
91 #define _PyIsSelectable_fd(FD) (1)
|
Chris@87
|
92 #endif /* HAVE_SELECT */
|
Chris@87
|
93
|
Chris@87
|
94 #ifdef __cplusplus
|
Chris@87
|
95 }
|
Chris@87
|
96 #endif
|
Chris@87
|
97 #endif /* !Py_FILEOBJECT_H */
|