Chris@87: Chris@87: /* File object interface */ Chris@87: Chris@87: #ifndef Py_FILEOBJECT_H Chris@87: #define Py_FILEOBJECT_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: Chris@87: typedef struct { Chris@87: PyObject_HEAD Chris@87: FILE *f_fp; Chris@87: PyObject *f_name; Chris@87: PyObject *f_mode; Chris@87: int (*f_close)(FILE *); Chris@87: int f_softspace; /* Flag used by 'print' command */ Chris@87: int f_binary; /* Flag which indicates whether the file is Chris@87: open in binary (1) or text (0) mode */ Chris@87: char* f_buf; /* Allocated readahead buffer */ Chris@87: char* f_bufend; /* Points after last occupied position */ Chris@87: char* f_bufptr; /* Current buffer position */ Chris@87: char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */ Chris@87: int f_univ_newline; /* Handle any newline convention */ Chris@87: int f_newlinetypes; /* Types of newlines seen */ Chris@87: int f_skipnextlf; /* Skip next \n */ Chris@87: PyObject *f_encoding; Chris@87: PyObject *f_errors; Chris@87: PyObject *weakreflist; /* List of weak references */ Chris@87: int unlocked_count; /* Num. currently running sections of code Chris@87: using f_fp with the GIL released. */ Chris@87: int readable; Chris@87: int writable; Chris@87: } PyFileObject; Chris@87: Chris@87: PyAPI_DATA(PyTypeObject) PyFile_Type; Chris@87: Chris@87: #define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type) Chris@87: #define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type) Chris@87: Chris@87: PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *); Chris@87: PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int); Chris@87: PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *); Chris@87: PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors); Chris@87: PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *, Chris@87: int (*)(FILE *)); Chris@87: PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *); Chris@87: PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *); Chris@87: PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *); Chris@87: PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *); Chris@87: PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int); Chris@87: PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int); Chris@87: PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int); Chris@87: PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *); Chris@87: PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *); Chris@87: Chris@87: /* The default encoding used by the platform file system APIs Chris@87: If non-NULL, this is different than the default encoding for strings Chris@87: */ Chris@87: PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding; Chris@87: Chris@87: /* Routines to replace fread() and fgets() which accept any of \r, \n Chris@87: or \r\n as line terminators. Chris@87: */ Chris@87: #define PY_STDIOTEXTMODE "b" Chris@87: char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *); Chris@87: size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *); Chris@87: Chris@87: /* A routine to do sanity checking on the file mode string. returns Chris@87: non-zero on if an exception occurred Chris@87: */ Chris@87: int _PyFile_SanitizeMode(char *mode); Chris@87: Chris@87: #if defined _MSC_VER && _MSC_VER >= 1400 Chris@87: /* A routine to check if a file descriptor is valid on Windows. Returns 0 Chris@87: * and sets errno to EBADF if it isn't. This is to avoid Assertions Chris@87: * from various functions in the Windows CRT beginning with Chris@87: * Visual Studio 2005 Chris@87: */ Chris@87: int _PyVerify_fd(int fd); Chris@87: #elif defined _MSC_VER && _MSC_VER >= 1200 Chris@87: /* fdopen doesn't set errno EBADF and crashes for large fd on debug build */ Chris@87: #define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0) Chris@87: #else Chris@87: #define _PyVerify_fd(A) (1) /* dummy */ Chris@87: #endif Chris@87: Chris@87: /* A routine to check if a file descriptor can be select()-ed. */ Chris@87: #ifdef HAVE_SELECT Chris@87: #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE)) Chris@87: #else Chris@87: #define _PyIsSelectable_fd(FD) (1) Chris@87: #endif /* HAVE_SELECT */ Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_FILEOBJECT_H */