blob: e2053df2e4f7c1427c0fd78ae98f49a6ad3d84b7 [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 */
Jack Jansen7b8c7542002-04-14 20:12:41 +000022#ifdef WITH_UNIVERSAL_NEWLINES
23 int f_univ_newline; /* Handle any newline convention */
24 int f_newlinetypes; /* Types of newlines seen */
25 int f_skipnextlf; /* Skip next \n */
26#endif
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000027 PyObject *f_encoding;
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#ifdef WITH_UNIVERSAL_NEWLINES
54/* Routines to replace fread() and fgets() which accept any of \r, \n
55 or \r\n as line terminators.
56*/
57#define PY_STDIOTEXTMODE "b"
58char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
Tim Peters058b1412002-04-21 07:29:14 +000059size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
Jack Jansen7b8c7542002-04-14 20:12:41 +000060#else
61#define PY_STDIOTEXTMODE ""
Tim Peters058b1412002-04-21 07:29:14 +000062#define Py_UniversalNewlineFgets(buf, len, fp, obj) fgets((buf), (len), (fp))
Guido van Rossuma0a6c5a2002-05-24 15:24:38 +000063#define Py_UniversalNewlineFread(buf, len, fp, obj) \
Tim Peters058b1412002-04-21 07:29:14 +000064 fread((buf), 1, (len), (fp))
Jack Jansen7b8c7542002-04-14 20:12:41 +000065#endif /* WITH_UNIVERSAL_NEWLINES */
Guido van Rossuma3309961993-07-28 09:05:47 +000066#ifdef __cplusplus
67}
68#endif
69#endif /* !Py_FILEOBJECT_H */