Home | History | Annotate | Download | only in Include
      1 /** @file
      2   File object interface
      3 
      4   Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR>
      5   Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
      6   This program and the accompanying materials are licensed and made available under
      7   the terms and conditions of the BSD License that accompanies this distribution.
      8   The full text of the license may be found at
      9   http://opensource.org/licenses/bsd-license.
     10 
     11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 **/
     14 
     15 #ifndef Py_FILEOBJECT_H
     16 #define Py_FILEOBJECT_H
     17 #ifdef __cplusplus
     18 extern "C" {
     19 #endif
     20 
     21 typedef struct {
     22     PyObject_HEAD
     23     FILE *f_fp;
     24     PyObject *f_name;
     25     PyObject *f_mode;
     26     int (*f_close)(FILE *);
     27     int f_softspace;            /* Flag used by 'print' command */
     28     int f_binary;               /* Flag which indicates whether the file is
     29                                open in binary (1) or text (0) mode */
     30     char* f_buf;                /* Allocated readahead buffer */
     31     char* f_bufend;             /* Points after last occupied position */
     32     char* f_bufptr;             /* Current buffer position */
     33     char *f_setbuf;             /* Buffer for setbuf(3) and setvbuf(3) */
     34     int f_univ_newline;         /* Handle any newline convention */
     35     int f_newlinetypes;         /* Types of newlines seen */
     36     int f_skipnextlf;           /* Skip next \n */
     37     PyObject *f_encoding;
     38     PyObject *f_errors;
     39     PyObject *weakreflist; /* List of weak references */
     40     int unlocked_count;         /* Num. currently running sections of code
     41                                using f_fp with the GIL released. */
     42     int readable;
     43     int writable;
     44 } PyFileObject;
     45 
     46 PyAPI_DATA(PyTypeObject) PyFile_Type;
     47 
     48 #define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
     49 #define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)
     50 
     51 PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
     52 PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
     53 PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
     54 PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);
     55 PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
     56                                              int (*)(FILE *));
     57 PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
     58 PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);
     59 PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);
     60 PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
     61 PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
     62 PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
     63 PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
     64 PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
     65 PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
     66 
     67 /* The default encoding used by the platform file system APIs
     68    If non-NULL, this is different than the default encoding for strings
     69 */
     70 PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
     71 
     72 /* Routines to replace fread() and fgets() which accept any of \r, \n
     73    or \r\n as line terminators.
     74 */
     75 #define PY_STDIOTEXTMODE "b"
     76 char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
     77 size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
     78 
     79 /* A routine to do sanity checking on the file mode string.  returns
     80    non-zero on if an exception occurred
     81 */
     82 int _PyFile_SanitizeMode(char *mode);
     83 
     84 //#if defined _MSC_VER && _MSC_VER >= 1400
     85 /* A routine to check if a file descriptor is valid on Windows.  Returns 0
     86  * and sets errno to EBADF if it isn't.  This is to avoid Assertions
     87  * from various functions in the Windows CRT beginning with
     88  * Visual Studio 2005
     89  */
     90 //int _PyVerify_fd(int fd);
     91 //#elif defined _MSC_VER && _MSC_VER >= 1200
     92 /* fdopen doesn't set errno EBADF and crashes for large fd on debug build */
     93 //#define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0)
     94 //#else
     95 #define _PyVerify_fd(A) (1) /* dummy */
     96 //#endif
     97 
     98 /* A routine to check if a file descriptor can be select()-ed. */
     99 #ifdef HAVE_SELECT
    100  #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE))
    101 #else
    102  #define _PyIsSelectable_fd(FD) (1)
    103 #endif /* HAVE_SELECT */
    104 
    105 #ifdef __cplusplus
    106 }
    107 #endif
    108 #endif /* !Py_FILEOBJECT_H */
    109