fileobject.h revision 058b141ef77edcd8000bc169f3b9b7cc9d362ffa
1 2/* File object interface */ 3 4#ifndef Py_FILEOBJECT_H 5#define Py_FILEOBJECT_H 6#ifdef __cplusplus 7extern "C" { 8#endif 9 10typedef struct { 11 PyObject_HEAD 12 FILE *f_fp; 13 PyObject *f_name; 14 PyObject *f_mode; 15 int (*f_close)(FILE *); 16 int f_softspace; /* Flag used by 'print' command */ 17 int f_binary; /* Flag which indicates whether the file is open 18 open in binary (1) or test (0) mode */ 19#ifdef WITH_UNIVERSAL_NEWLINES 20 int f_univ_newline; /* Handle any newline convention */ 21 int f_newlinetypes; /* Types of newlines seen */ 22 int f_skipnextlf; /* Skip next \n */ 23#endif 24} PyFileObject; 25 26extern DL_IMPORT(PyTypeObject) PyFile_Type; 27 28#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type) 29#define PyFile_CheckExact(op) ((op)->ob_type == &PyFile_Type) 30 31extern DL_IMPORT(PyObject *) PyFile_FromString(char *, char *); 32extern DL_IMPORT(void) PyFile_SetBufSize(PyObject *, int); 33extern DL_IMPORT(PyObject *) PyFile_FromFile(FILE *, char *, char *, 34 int (*)(FILE *)); 35extern DL_IMPORT(FILE *) PyFile_AsFile(PyObject *); 36extern DL_IMPORT(PyObject *) PyFile_Name(PyObject *); 37extern DL_IMPORT(PyObject *) PyFile_GetLine(PyObject *, int); 38extern DL_IMPORT(int) PyFile_WriteObject(PyObject *, PyObject *, int); 39extern DL_IMPORT(int) PyFile_SoftSpace(PyObject *, int); 40extern DL_IMPORT(int) PyFile_WriteString(const char *, PyObject *); 41extern DL_IMPORT(int) PyObject_AsFileDescriptor(PyObject *); 42 43/* The default encoding used by the platform file system APIs 44 If non-NULL, this is different than the default encoding for strings 45*/ 46extern DL_IMPORT(const char *) Py_FileSystemDefaultEncoding; 47 48#ifdef WITH_UNIVERSAL_NEWLINES 49/* Routines to replace fread() and fgets() which accept any of \r, \n 50 or \r\n as line terminators. 51*/ 52#define PY_STDIOTEXTMODE "b" 53char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *); 54size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *); 55#else 56#define PY_STDIOTEXTMODE "" 57#define Py_UniversalNewlineFgets(buf, len, fp, obj) fgets((buf), (len), (fp)) 58#define Py_UniversalNewlineFread(buf, len, fp, obj) 59 fread((buf), 1, (len), (fp)) 60#endif /* WITH_UNIVERSAL_NEWLINES */ 61#ifdef __cplusplus 62} 63#endif 64#endif /* !Py_FILEOBJECT_H */ 65