blob: 8fed9a3f40f1d97d3e498120865a715ea77e3bb8 [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_binary; /* Flag which indicates whether the file is
17 open in binary (1) or text (0) mode */
18 char* f_buf; /* Allocated readahead buffer */
19 char* f_bufend; /* Points after last occupied position */
20 char* f_bufptr; /* Current buffer position */
Martin v. Löwis1e3bdf62003-09-04 19:01:46 +000021 char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */
Jack Jansen7b8c7542002-04-14 20:12:41 +000022 int f_univ_newline; /* Handle any newline convention */
23 int f_newlinetypes; /* Types of newlines seen */
24 int f_skipnextlf; /* Skip next \n */
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000025 PyObject *f_encoding;
Raymond Hettingercb87bc82004-05-31 00:35:52 +000026 PyObject *weakreflist; /* List of weak references */
Martin v. Löwisf6eebbb2002-03-15 17:42:16 +000027} PyFileObject;
28
Mark Hammond91a681d2002-08-12 07:21:58 +000029PyAPI_DATA(PyTypeObject) PyFile_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000030
Tim Peters59c9a642001-09-13 05:38:56 +000031#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
32#define PyFile_CheckExact(op) ((op)->ob_type == &PyFile_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000033
Mark Hammond91a681d2002-08-12 07:21:58 +000034PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
35PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000036PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
Mark Hammond91a681d2002-08-12 07:21:58 +000037PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000038 int (*)(FILE *));
Mark Hammond91a681d2002-08-12 07:21:58 +000039PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
40PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
41PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
42PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
Mark Hammond91a681d2002-08-12 07:21:58 +000043PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
44PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000045
Mark Hammond26cffde2001-05-14 12:17:34 +000046/* The default encoding used by the platform file system APIs
Tim Peters058b1412002-04-21 07:29:14 +000047 If non-NULL, this is different than the default encoding for strings
Mark Hammond26cffde2001-05-14 12:17:34 +000048*/
Mark Hammond91a681d2002-08-12 07:21:58 +000049PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
Mark Hammond26cffde2001-05-14 12:17:34 +000050
Jack Jansen7b8c7542002-04-14 20:12:41 +000051/* Routines to replace fread() and fgets() which accept any of \r, \n
52 or \r\n as line terminators.
53*/
54#define PY_STDIOTEXTMODE "b"
55char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
Tim Peters058b1412002-04-21 07:29:14 +000056size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
Skip Montanarodb608052004-02-07 13:53:46 +000057
Guido van Rossumd8faa362007-04-27 19:54:29 +000058/* A routine to do sanity checking on the file mode string. returns
59 non-zero on if an exception occurred
60*/
61int _PyFile_SanitizeMode(char *mode);
62
Guido van Rossuma3309961993-07-28 09:05:47 +000063#ifdef __cplusplus
64}
65#endif
66#endif /* !Py_FILEOBJECT_H */