fileobject.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* File object interface */
  2. #ifndef Py_FILEOBJECT_H
  3. #define Py_FILEOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct {
  8. PyObject_HEAD
  9. FILE *f_fp;
  10. PyObject *f_name;
  11. PyObject *f_mode;
  12. int (*f_close)(FILE *);
  13. int f_softspace; /* Flag used by 'print' command */
  14. int f_binary; /* Flag which indicates whether the file is
  15. open in binary (1) or text (0) mode */
  16. char* f_buf; /* Allocated readahead buffer */
  17. char* f_bufend; /* Points after last occupied position */
  18. char* f_bufptr; /* Current buffer position */
  19. char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */
  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. PyObject *f_encoding;
  24. PyObject *f_errors;
  25. PyObject *weakreflist; /* List of weak references */
  26. int unlocked_count; /* Num. currently running sections of code
  27. using f_fp with the GIL released. */
  28. int readable;
  29. int writable;
  30. } PyFileObject;
  31. PyAPI_DATA(PyTypeObject) PyFile_Type;
  32. #define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
  33. #define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)
  34. PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
  35. PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
  36. PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
  37. PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);
  38. PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
  39. int (*)(FILE *));
  40. PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
  41. PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);
  42. PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);
  43. PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
  44. PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
  45. PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
  46. PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
  47. PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
  48. PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
  49. /* The default encoding used by the platform file system APIs
  50. If non-NULL, this is different than the default encoding for strings
  51. */
  52. PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
  53. /* Routines to replace fread() and fgets() which accept any of \r, \n
  54. or \r\n as line terminators.
  55. */
  56. #define PY_STDIOTEXTMODE "b"
  57. char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
  58. size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
  59. /* A routine to do sanity checking on the file mode string. returns
  60. non-zero on if an exception occurred
  61. */
  62. int _PyFile_SanitizeMode(char *mode);
  63. #if defined _MSC_VER && _MSC_VER >= 1400
  64. /* A routine to check if a file descriptor is valid on Windows. Returns 0
  65. * and sets errno to EBADF if it isn't. This is to avoid Assertions
  66. * from various functions in the Windows CRT beginning with
  67. * Visual Studio 2005
  68. */
  69. int _PyVerify_fd(int fd);
  70. #elif defined _MSC_VER && _MSC_VER >= 1200
  71. /* fdopen doesn't set errno EBADF and crashes for large fd on debug build */
  72. #define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0)
  73. #else
  74. #define _PyVerify_fd(A) (1) /* dummy */
  75. #endif
  76. /* A routine to check if a file descriptor can be select()-ed. */
  77. #ifdef HAVE_SELECT
  78. #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE))
  79. #else
  80. #define _PyIsSelectable_fd(FD) (1)
  81. #endif /* HAVE_SELECT */
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif /* !Py_FILEOBJECT_H */