blob: 2ec4b24a2b819381b1cecadeefbc284317d2ee68 [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#ifdef WITH_UNIVERSAL_NEWLINES
24 int f_univ_newline; /* Handle any newline convention */
25 int f_newlinetypes; /* Types of newlines seen */
26 int f_skipnextlf; /* Skip next \n */
27#endif
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000028 PyObject *f_encoding;
Martin v. Löwisf6eebbb2002-03-15 17:42:16 +000029} PyFileObject;
30
Mark Hammond91a681d2002-08-12 07:21:58 +000031PyAPI_DATA(PyTypeObject) PyFile_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000032
Tim Peters59c9a642001-09-13 05:38:56 +000033#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
34#define PyFile_CheckExact(op) ((op)->ob_type == &PyFile_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000035
Mark Hammond91a681d2002-08-12 07:21:58 +000036PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
37PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
Martin v. Löwis5467d4c2003-05-10 07:10:12 +000038PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
Mark Hammond91a681d2002-08-12 07:21:58 +000039PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000040 int (*)(FILE *));
Mark Hammond91a681d2002-08-12 07:21:58 +000041PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
42PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
43PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
44PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
45PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
46PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
47PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000048
Mark Hammond26cffde42001-05-14 12:17:34 +000049/* The default encoding used by the platform file system APIs
Tim Peters058b1412002-04-21 07:29:14 +000050 If non-NULL, this is different than the default encoding for strings
Mark Hammond26cffde42001-05-14 12:17:34 +000051*/
Mark Hammond91a681d2002-08-12 07:21:58 +000052PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
Mark Hammond26cffde42001-05-14 12:17:34 +000053
Jack Jansen7b8c7542002-04-14 20:12:41 +000054#ifdef WITH_UNIVERSAL_NEWLINES
55/* Routines to replace fread() and fgets() which accept any of \r, \n
56 or \r\n as line terminators.
57*/
58#define PY_STDIOTEXTMODE "b"
59char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
Tim Peters058b1412002-04-21 07:29:14 +000060size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
Jack Jansen7b8c7542002-04-14 20:12:41 +000061#else
62#define PY_STDIOTEXTMODE ""
Tim Peters058b1412002-04-21 07:29:14 +000063#define Py_UniversalNewlineFgets(buf, len, fp, obj) fgets((buf), (len), (fp))
Guido van Rossuma0a6c5a2002-05-24 15:24:38 +000064#define Py_UniversalNewlineFread(buf, len, fp, obj) \
Tim Peters058b1412002-04-21 07:29:14 +000065 fread((buf), 1, (len), (fp))
Jack Jansen7b8c7542002-04-14 20:12:41 +000066#endif /* WITH_UNIVERSAL_NEWLINES */
Guido van Rossuma3309961993-07-28 09:05:47 +000067#ifdef __cplusplus
68}
69#endif
70#endif /* !Py_FILEOBJECT_H */