cpython/Objects/fileobject.c

/* File object implementation (what's left of it -- see io.py) */

#include "Python.h"
#include "pycore_call.h"          // _PyObject_CallNoArgs()
#include "pycore_runtime.h"       // _PyRuntime

#ifdef HAVE_UNISTD_H
#  include <unistd.h>             // isatty()
#endif

#if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER)
   /* clang MemorySanitizer doesn't yet understand getc_unlocked. */
#define GETC(f)
#define FLOCKFILE(f)
#define FUNLOCKFILE(f)
#else
#define GETC
#define FLOCKFILE
#define FUNLOCKFILE
#endif

/* Newline flags */
#define NEWLINE_UNKNOWN
#define NEWLINE_CR
#define NEWLINE_LF
#define NEWLINE_CRLF

/* External C interface */

PyObject *
PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const char *encoding,
              const char *errors, const char *newline, int closefd)
{}

PyObject *
PyFile_GetLine(PyObject *f, int n)
{}

/* Interfaces to write objects/strings to file-like objects */

int
PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
{}

int
PyFile_WriteString(const char *s, PyObject *f)
{}

/* Try to get a file-descriptor from a Python object.  If the object
   is an integer, its value is returned.  If not, the
   object's fileno() method is called if it exists; the method must return
   an integer, which is returned as the file descriptor value.
   -1 is returned on failure.
*/

int
PyObject_AsFileDescriptor(PyObject *o)
{}

int
_PyLong_FileDescriptor_Converter(PyObject *o, void *ptr)
{}

char *
_Py_UniversalNewlineFgetsWithSize(char *buf, int n, FILE *stream, PyObject *fobj, size_t* size)
{}

/*
** Py_UniversalNewlineFgets is an fgets variation that understands
** all of \r, \n and \r\n conventions.
** The stream should be opened in binary mode.
** The fobj parameter exists solely for legacy reasons and must be NULL.
** Note that we need no error handling: fgets() treats error and eof
** identically.
*/

char *
Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) {}

/* **************************** std printer ****************************
 * The stdprinter is used during the boot strapping phase as a preliminary
 * file like object for sys.stderr.
 */

PyStdPrinter_Object;

PyObject *
PyFile_NewStdPrinter(int fd)
{}

static PyObject *
stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
{}

static PyObject *
stdprinter_fileno(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject *
stdprinter_repr(PyStdPrinter_Object *self)
{}

static PyObject *
stdprinter_noop(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject *
stdprinter_isatty(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored))
{}

static PyMethodDef stdprinter_methods[] =;

static PyObject *
get_closed(PyStdPrinter_Object *self, void *closure)
{}

static PyObject *
get_mode(PyStdPrinter_Object *self, void *closure)
{}

static PyObject *
get_encoding(PyStdPrinter_Object *self, void *closure)
{}

static PyGetSetDef stdprinter_getsetlist[] =;

PyTypeObject PyStdPrinter_Type =;


/* ************************** open_code hook ***************************
 * The open_code hook allows embedders to override the method used to
 * open files that are going to be used by the runtime to execute code
 */

int
PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData) {}

PyObject *
PyFile_OpenCodeObject(PyObject *path)
{}

PyObject *
PyFile_OpenCode(const char *utf8path)
{}


int
_PyFile_Flush(PyObject *file)
{}