/Include/fileobject.h

http://unladen-swallow.googlecode.com/ · C Header · 74 lines · 52 code · 10 blank · 12 comment · 1 complexity · 9a066915d4ec0e1515747874af948153 MD5 · raw file

  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. } PyFileObject;
  29. PyAPI_DATA(PyTypeObject) PyFile_Type;
  30. #define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
  31. #define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)
  32. PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
  33. PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
  34. PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
  35. PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);
  36. PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
  37. int (*)(FILE *));
  38. PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
  39. PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);
  40. PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);
  41. PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
  42. PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
  43. PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
  44. PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
  45. PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
  46. PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
  47. /* The default encoding used by the platform file system APIs
  48. If non-NULL, this is different than the default encoding for strings
  49. */
  50. PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
  51. /* Routines to replace fread() and fgets() which accept any of \r, \n
  52. or \r\n as line terminators.
  53. */
  54. #define PY_STDIOTEXTMODE "b"
  55. char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
  56. size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
  57. /* A routine to do sanity checking on the file mode string. returns
  58. non-zero on if an exception occurred
  59. */
  60. int _PyFile_SanitizeMode(char *mode);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* !Py_FILEOBJECT_H */