blob: 56cf40a364725107f80f5745e9f128bba6db73c9 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* File object interface */
3
Fred Drakeea9cb5a2000-07-09 00:20:36 +00004#ifndef Py_FILEOBJECT_H
5#define Py_FILEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
Martin v. Löwisf6eebbb2002-03-15 17:42:16 +000010typedef struct {
11 PyObject_HEAD
12 FILE *f_fp;
13 PyObject *f_name;
14 PyObject *f_mode;
15 int (*f_close)(FILE *);
Guido van Rossum7a6e9592002-08-06 15:55:28 +000016 int f_softspace; /* Flag used by 'print' command */
17 int f_binary; /* Flag which indicates whether the file is
18 open in binary (1) or text (0) mode */
19 char* f_buf; /* Allocated readahead buffer */
20 char* f_bufend; /* Points after last occupied position */
21 char* f_bufptr; /* Current buffer position */
Martin v. Löwis1e3bdf62003-09-04 19:01:46 +000022 char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */
Jack Jansen7b8c7542002-04-14 20:12:41 +000023 int f_univ_newline; /* Handle any newline convention */
24 int f_newlinetypes; /* Types of newlines seen */
25 int f_skipnextlf; /* Skip next \n */
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000026 PyObject *f_encoding;
Martin v. Löwis99815892008-06-01 07:20:46 +000027 PyObject *f_errors;
Raymond Hettingercb87bc82004-05-31 00:35:52 +000028 PyObject *weakreflist; /* List of weak references */
Gregory P. Smithaa63d0d2008-04-06 23:11:17 +000029 int unlocked_count; /* Num. currently running sections of code
30 using f_fp with the GIL released. */
Martin v. Löwisf6eebbb2002-03-15 17:42:16 +000031} PyFileObject;
32
Mark Hammond91a681d2002-08-12 07:21:58 +000033PyAPI_DATA(PyTypeObject) PyFile_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000034
Tim Peters59c9a642001-09-13 05:38:56 +000035#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
Christian Heimese93237d2007-12-19 02:37:44 +000036#define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000037
Mark Hammond91a681d2002-08-12 07:21:58 +000038PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
39PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000040PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
Martin v. Löwis99815892008-06-01 07:20:46 +000041PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);
Mark Hammond91a681d2002-08-12 07:21:58 +000042PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000043 int (*)(FILE *));
Mark Hammond91a681d2002-08-12 07:21:58 +000044PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
Gregory P. Smithaa63d0d2008-04-06 23:11:17 +000045PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);
46PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);
Mark Hammond91a681d2002-08-12 07:21:58 +000047PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
48PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
49PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
50PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
51PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
52PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000053
Mark Hammond26cffde2001-05-14 12:17:34 +000054/* The default encoding used by the platform file system APIs
Tim Peters058b1412002-04-21 07:29:14 +000055 If non-NULL, this is different than the default encoding for strings
Mark Hammond26cffde2001-05-14 12:17:34 +000056*/
Mark Hammond91a681d2002-08-12 07:21:58 +000057PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
Mark Hammond26cffde2001-05-14 12:17:34 +000058
Jack Jansen7b8c7542002-04-14 20:12:41 +000059/* Routines to replace fread() and fgets() which accept any of \r, \n
60 or \r\n as line terminators.
61*/
62#define PY_STDIOTEXTMODE "b"
63char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
Tim Peters058b1412002-04-21 07:29:14 +000064size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
Skip Montanarodb608052004-02-07 13:53:46 +000065
Kristján Valur Jónsson0a440d42007-04-26 09:15:08 +000066/* A routine to do sanity checking on the file mode string. returns
67 non-zero on if an exception occurred
68*/
69int _PyFile_SanitizeMode(char *mode);
70
Guido van Rossuma3309961993-07-28 09:05:47 +000071#ifdef __cplusplus
72}
73#endif
74#endif /* !Py_FILEOBJECT_H */