cpython/Modules/_stat.c

/* stat.h interface
 *
 * The module defines all S_IF*, S_I*, UF_*, SF_* and ST_* constants to
 * sensible default values as well as defines S_IS*() macros in order to keep
 * backward compatibility with the old stat.py module.
 *
 * New constants and macros such as S_IFDOOR / S_ISDOOR() are always defined
 * as int 0.
 *
 * NOTE: POSIX only defines the values of the S_I* permission bits.
 *
 */

// Need limited C API version 3.13 for PyModule_Add() on Windows
#include "pyconfig.h"   // Py_GIL_DISABLED
#ifndef Py_GIL_DISABLED
#define Py_LIMITED_API
#endif

#include "Python.h"

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */

#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif /* HAVE_SYS_STAT_H */

#ifdef MS_WINDOWS
#include <windows.h>
typedef unsigned short mode_t;

/* FILE_ATTRIBUTE_INTEGRITY_STREAM and FILE_ATTRIBUTE_NO_SCRUB_DATA
   are not present in VC2010, so define them manually */
#ifndef FILE_ATTRIBUTE_INTEGRITY_STREAM
#define FILE_ATTRIBUTE_INTEGRITY_STREAM
#endif

#ifndef FILE_ATTRIBUTE_NO_SCRUB_DATA
#define FILE_ATTRIBUTE_NO_SCRUB_DATA
#endif

#ifndef IO_REPARSE_TAG_APPEXECLINK
#define IO_REPARSE_TAG_APPEXECLINK
#endif

#endif /* MS_WINDOWS */

/* From Python's stat.py */
#ifndef S_IMODE
#define S_IMODE
#endif

/* S_IFXXX constants (file types)
 *
 * Only the names are defined by POSIX but not their value. All common file
 * types seems to have the same numeric value on all platforms, though.
 *
 * pyport.h guarantees S_IFMT, S_IFDIR, S_IFCHR, S_IFREG and S_IFLNK
 */

#ifndef S_IFBLK
#define S_IFBLK
#endif

#ifndef S_IFIFO
#define S_IFIFO
#endif

#ifndef S_IFSOCK
#define S_IFSOCK
#endif

#ifndef S_IFDOOR
#define S_IFDOOR
#endif

#ifndef S_IFPORT
#define S_IFPORT
#endif

#ifndef S_IFWHT
#define S_IFWHT
#endif


/* S_ISXXX()
 * pyport.h defines S_ISDIR(), S_ISREG() and S_ISCHR()
 */

#ifndef S_ISBLK
#define S_ISBLK
#endif

#ifndef S_ISFIFO
#define S_ISFIFO
#endif

#ifndef S_ISLNK
#define S_ISLNK
#endif

#ifndef S_ISSOCK
#define S_ISSOCK
#endif

#ifndef S_ISDOOR
#define S_ISDOOR(mode)
#endif

#ifndef S_ISPORT
#define S_ISPORT(mode)
#endif

#ifndef S_ISWHT
#define S_ISWHT(mode)
#endif


/* S_I* file permission
 *
 * The permission bit value are defined by POSIX standards.
 */
#ifndef S_ISUID
#define S_ISUID
#endif

#ifndef S_ISGID
#define S_ISGID
#endif

/* what is S_ENFMT? */
#ifndef S_ENFMT
#define S_ENFMT
#endif

#ifndef S_ISVTX
#define S_ISVTX
#endif

#ifndef S_IREAD
#define S_IREAD
#endif

#ifndef S_IWRITE
#define S_IWRITE
#endif

#ifndef S_IEXEC
#define S_IEXEC
#endif

#ifndef S_IRWXU
#define S_IRWXU
#endif

#ifndef S_IRUSR
#define S_IRUSR
#endif

#ifndef S_IWUSR
#define S_IWUSR
#endif

#ifndef S_IXUSR
#define S_IXUSR
#endif

#ifndef S_IRWXG
#define S_IRWXG
#endif

#ifndef S_IRGRP
#define S_IRGRP
#endif

#ifndef S_IWGRP
#define S_IWGRP
#endif

#ifndef S_IXGRP
#define S_IXGRP
#endif

#ifndef S_IRWXO
#define S_IRWXO
#endif

#ifndef S_IROTH
#define S_IROTH
#endif

#ifndef S_IWOTH
#define S_IWOTH
#endif

#ifndef S_IXOTH
#define S_IXOTH
#endif


/* Names for file flags */
#ifndef UF_SETTABLE
#define UF_SETTABLE
#endif

#ifndef UF_NODUMP
#define UF_NODUMP
#endif

#ifndef UF_IMMUTABLE
#define UF_IMMUTABLE
#endif

#ifndef UF_APPEND
#define UF_APPEND
#endif

#ifndef UF_OPAQUE
#define UF_OPAQUE
#endif

#ifndef UF_NOUNLINK
#define UF_NOUNLINK
#endif

#ifndef UF_COMPRESSED
#define UF_COMPRESSED
#endif

#ifndef UF_TRACKED
#define UF_TRACKED
#endif

#ifndef UF_DATAVAULT
#define UF_DATAVAULT
#endif

#ifndef UF_HIDDEN
#define UF_HIDDEN
#endif

#ifndef SF_SETTABLE
#define SF_SETTABLE
#endif

#ifndef SF_ARCHIVED
#define SF_ARCHIVED
#endif

#ifndef SF_IMMUTABLE
#define SF_IMMUTABLE
#endif

#ifndef SF_APPEND
#define SF_APPEND
#endif

#ifndef SF_NOUNLINK
#define SF_NOUNLINK
#endif

#ifndef SF_SNAPSHOT
#define SF_SNAPSHOT
#endif

#ifndef SF_FIRMLINK
#define SF_FIRMLINK
#endif

#ifndef SF_DATALESS
#define SF_DATALESS
#endif

#if defined(__APPLE__) && !defined(SF_SUPPORTED)
   /* On older macOS versions the definition of SF_SUPPORTED is different
    * from that on newer versions.
    *
    * Provide a consistent experience by redefining.
    *
    * None of bit bits set in the actual SF_SUPPORTED but not in this
    * definition are defined on these versions of macOS.
    */
#  undef SF_SETTABLE
#define SF_SUPPORTED
#define SF_SETTABLE
#define SF_SYNTHETIC
#endif


static mode_t
_PyLong_AsMode_t(PyObject *op)
{}


#define stat_S_ISFUNC(isfunc, doc)

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();

stat_S_ISFUNC();


PyDoc_STRVAR(stat_S_IMODE_doc,
"Return the portion of the file's mode that can be set by os.chmod().");

static PyObject *
stat_S_IMODE(PyObject *self, PyObject *omode)
{}


PyDoc_STRVAR(stat_S_IFMT_doc,
"Return the portion of the file's mode that describes the file type.");

static PyObject *
stat_S_IFMT(PyObject *self, PyObject *omode)
{}

/* file type chars according to
   http://en.wikibooks.org/wiki/C_Programming/POSIX_Reference/sys/stat.h */

static char
filetype(mode_t mode)
{}

static void
fileperm(mode_t mode, char *buf)
{}

PyDoc_STRVAR(stat_filemode_doc,
"Convert a file's mode to a string of the form '-rwxrwxrwx'");

static PyObject *
stat_filemode(PyObject *self, PyObject *omode)
{}


static PyMethodDef stat_methods[] =;


PyDoc_STRVAR(module_doc,
"S_IFMT_: file type bits\n\
S_IFDIR: directory\n\
S_IFCHR: character device\n\
S_IFBLK: block device\n\
S_IFREG: regular file\n\
S_IFIFO: fifo (named pipe)\n\
S_IFLNK: symbolic link\n\
S_IFSOCK: socket file\n\
S_IFDOOR: door\n\
S_IFPORT: event port\n\
S_IFWHT: whiteout\n\
\n"

"S_ISUID: set UID bit\n\
S_ISGID: set GID bit\n\
S_ENFMT: file locking enforcement\n\
S_ISVTX: sticky bit\n\
S_IREAD: Unix V7 synonym for S_IRUSR\n\
S_IWRITE: Unix V7 synonym for S_IWUSR\n\
S_IEXEC: Unix V7 synonym for S_IXUSR\n\
S_IRWXU: mask for owner permissions\n\
S_IRUSR: read by owner\n\
S_IWUSR: write by owner\n\
S_IXUSR: execute by owner\n\
S_IRWXG: mask for group permissions\n\
S_IRGRP: read by group\n\
S_IWGRP: write by group\n\
S_IXGRP: execute by group\n\
S_IRWXO: mask for others (not in group) permissions\n\
S_IROTH: read by others\n\
S_IWOTH: write by others\n\
S_IXOTH: execute by others\n\
\n"

"UF_SETTABLE: mask of owner changeable flags\n\
UF_NODUMP: do not dump file\n\
UF_IMMUTABLE: file may not be changed\n\
UF_APPEND: file may only be appended to\n\
UF_OPAQUE: directory is opaque when viewed through a union stack\n\
UF_NOUNLINK: file may not be renamed or deleted\n\
UF_COMPRESSED: macOS: file is hfs-compressed\n\
UF_TRACKED: used for dealing with document IDs\n\
UF_DATAVAULT: entitlement required for reading and writing\n\
UF_HIDDEN: macOS: file should not be displayed\n\
SF_SETTABLE: mask of super user changeable flags\n\
SF_ARCHIVED: file may be archived\n\
SF_IMMUTABLE: file may not be changed\n\
SF_APPEND: file may only be appended to\n\
SF_RESTRICTED: entitlement required for writing\n\
SF_NOUNLINK: file may not be renamed or deleted\n\
SF_SNAPSHOT: file is a snapshot file\n\
SF_FIRMLINK: file is a firmlink\n\
SF_DATALESS: file is a dataless object\n\
\n\
On macOS:\n\
SF_SUPPORTED: mask of super user supported flags\n\
SF_SYNTHETIC: mask of read-only synthetic flags\n\
\n"

"ST_MODE\n\
ST_INO\n\
ST_DEV\n\
ST_NLINK\n\
ST_UID\n\
ST_GID\n\
ST_SIZE\n\
ST_ATIME\n\
ST_MTIME\n\
ST_CTIME\n\
\n"

"FILE_ATTRIBUTE_*: Windows file attribute constants\n\
                   (only present on Windows)\n\
");


static int
stat_exec(PyObject *module)
{}


static PyModuleDef_Slot stat_slots[] =;


static struct PyModuleDef statmodule =;


PyMODINIT_FUNC
PyInit__stat(void)
{}