1 /**
2   Mirror _fileobject.h
3   */
4 module deimos.python.fileobject;
5 
6 import core.stdc.stdio;
7 import deimos.python.pyport;
8 import deimos.python.object;
9 
10 extern(C):
11 // Python-header-file: Include/fileobject.h:
12 
13 version(Python_3_0_Or_Later) {
14 }else{
15     /// subclass of PyObject
16     /// Availability: 2.*
17     struct PyFileObject {
18         mixin PyObject_HEAD;
19 
20         /// _
21         FILE* f_fp;
22         /// _
23         PyObject* f_name;
24         /// _
25         PyObject* f_mode;
26         /// _
27         int function(FILE*) f_close;
28         /** Flag used by 'print' command */
29         int f_softspace;
30         /** Flag which indicates whether the file is
31            open in binary (1) or text (0) mode */
32         int f_binary;
33         /** Allocated readahead buffer */
34         char* f_buf;
35         /** Points after last occupied position */
36         char* f_bufend;
37         /** Current buffer position */
38         char* f_bufptr;
39         /** Buffer for setbuf(3) and setvbuf(3) */
40         char* f_setbuf;
41         /** Handle any newline convention */
42         int f_univ_newline;
43         /** Types of newlines seen */
44         int f_newlinetypes;
45         /** Skip next \n */
46         int f_skipnextlf;
47         /// _
48         PyObject* f_encoding;
49         version(Python_2_6_Or_Later){
50             /// Availability: >= 2.6
51             PyObject* f_errors;
52         }
53         /** List of weak references */
54         PyObject* weakreflist;
55         version(Python_2_6_Or_Later){
56             /** Num. currently running sections of code
57                using f_fp with the GIL released. */
58             /// Availability: >= 2.6
59             int unlocked_count;         
60             /// Availability: >= 2.6
61             int readable;
62             /// Availability: >= 2.6
63             int writable;
64         }
65     }
66 
67     /// Availability: 2.*
68     mixin(PyAPI_DATA!"PyTypeObject PyFile_Type");
69 
70     // D translation of C macro:
71     /// Availability: 2.*
72     int PyFile_Check()(PyObject* op) {
73         return PyObject_TypeCheck(op, &PyFile_Type);
74     }
75     // D translation of C macro:
76     /// Availability: 2.*
77     int PyFile_CheckExact()(PyObject* op) {
78         return Py_TYPE(op) == &PyFile_Type;
79     }
80 
81     /// Availability: 2.*
82     PyObject* PyFile_FromString(char*, char*);
83     /// Availability: 2.*
84     void PyFile_SetBufSize(PyObject*, int);
85     /// Availability: 2.*
86     int PyFile_SetEncoding(PyObject*, const(char)*);
87     version(Python_2_6_Or_Later){
88         /// Availability: >= 2.6
89         int PyFile_SetEncodingAndErrors(PyObject* , const(char)*, const(char)* errors);
90     }
91     /// Availability: 2.*
92     PyObject* PyFile_FromFile(FILE*, char*, char*, int function(FILE*));
93     /// Availability: 2.*
94     FILE* PyFile_AsFile(PyObject*);
95     version(Python_2_6_Or_Later){
96         /// Availability: >= 2.6
97         void PyFile_IncUseCount(PyFileObject*);
98         /// Availability: >= 2.6
99         void PyFile_DecUseCount(PyFileObject*);
100     }
101     /// Availability: 2.*
102     PyObject_BorrowedRef* PyFile_Name(PyObject*);
103 }
104 version(Python_3_0_Or_Later) {
105     /// Availability: 3.*
106     PyObject* PyFile_FromFd(int, char *, char *, int, char *, char *,
107             char *, int);
108 }
109 /// _
110 PyObject* PyFile_GetLine(PyObject* , int);
111 /// _
112 int PyFile_WriteObject(PyObject*, PyObject*, int);
113 version(Python_3_0_Or_Later) {
114 }else {
115     /// Availability: 2.*
116     int PyFile_SoftSpace(PyObject*, int);
117 }
118 /// _
119 int PyFile_WriteString(const(char)*, PyObject*);
120 /// _
121 int PyObject_AsFileDescriptor(PyObject*);
122 
123 /** The default encoding used by the platform file system APIs
124    If non-NULL, this is different than the default encoding for strings
125 */
126 mixin(PyAPI_DATA!"const(char)* Py_FileSystemDefaultEncoding");
127 
128 /// _
129 enum PY_STDIOTEXTMODE = "b";
130 
131 /// _
132 /* Routine to replace fgets() which accept any of \r, \n
133    or \r\n as line terminators.
134 */
135 char* Py_UniversalNewlineFgets(char*, int, FILE*, PyObject*);
136 version(Python_3_0_Or_Later) {
137     /// Availability: 3.*
138     mixin(PyAPI_DATA!"int Py_HasFileSystemDefaultEncoding");
139     /// Availability: 3.*
140     PyObject* PyFile_NewStdPrinter(int);
141     /// Availability: 3.*
142     mixin(PyAPI_DATA!"PyTypeObject PyStdPrinter_Type");
143 }else{
144     /** Routines to replace fread() and fgets() which accept any of \r, \n
145       or \r\n as line terminators.
146      */
147     /// Availability: 2.*
148     size_t Py_UniversalNewlineFread(char*, size_t, FILE*, PyObject*);
149 }
150 
151 version(Python_3_0_Or_Later) {
152 }else version(Python_2_5_Or_Later) {
153     /** A routine to do sanity checking on the file mode string.  returns
154       non-zero on if an exception occurred
155      */
156     /// Availability: 2.*
157     int _PyFile_SanitizeMode(char *mode);
158 }
159 
160 version(Python_2_7_Or_Later) {
161     //#if defined _MSC_VER && _MSC_VER >= 1400
162     //int _PyVerify_fd(int fd);
163 }