blob: ebbb521d17be986a7e049c5195f2e26270209f82 [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;
Raymond Hettingercb87bc82004-05-31 00:35:52 +000027 PyObject *weakreflist; /* List of weak references */
Martin v. Löwisf6eebbb2002-03-15 17:42:16 +000028} PyFileObject;
29
Mark Hammond91a681d2002-08-12 07:21:58 +000030PyAPI_DATA(PyTypeObject) PyFile_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000031
Tim Peters59c9a642001-09-13 05:38:56 +000032#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
33#define PyFile_CheckExact(op) ((op)->ob_type == &PyFile_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000034
Mark Hammond91a681d2002-08-12 07:21:58 +000035PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
36PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000037PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
Mark Hammond91a681d2002-08-12 07:21:58 +000038PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000039 int (*)(FILE *));
Mark Hammond91a681d2002-08-12 07:21:58 +000040PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
41PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
42PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
43PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
44PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
45PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
46PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000047
Mark Hammond26cffde42001-05-14 12:17:34 +000048/* The default encoding used by the platform file system APIs
Tim Peters058b1412002-04-21 07:29:14 +000049 If non-NULL, this is different than the default encoding for strings
Mark Hammond26cffde42001-05-14 12:17:34 +000050*/
Mark Hammond91a681d2002-08-12 07:21:58 +000051PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
Mark Hammond26cffde42001-05-14 12:17:34 +000052
Jack Jansen7b8c7542002-04-14 20:12:41 +000053/* Routines to replace fread() and fgets() which accept any of \r, \n
54 or \r\n as line terminators.
55*/
56#define PY_STDIOTEXTMODE "b"
57char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
Tim Peters058b1412002-04-21 07:29:14 +000058size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
Skip Montanarodb608052004-02-07 13:53:46 +000059
Guido van Rossuma3309961993-07-28 09:05:47 +000060#ifdef __cplusplus
61}
62#endif
63#endif /* !Py_FILEOBJECT_H */