
/* pymacro.h */
#define PyDoc_XSTRVAR(name,header,str) PyDoc_VAR(name) = PyDoc_XSTR(header, str)
#define PyDoc_XSTR(header, str) header str

/* could go into a separate header file */
#define OS_STAT_DOC "\n\
Perform a stat system call on the given path.\n\
\n\
  path\n\
        Path to be examined; can be string, bytes, or open-file-descriptor int.\n\
\n\
  dir_fd\n\
        If not None, it should be a file descriptor open to a directory,\n\
        and path should be a relative string; path will then be relative to\n\
        that directory.\n\
\n\
  follow_symlinks\n\
        If False, and the last element of the path is a symbolic link,\n\
        stat will examine the symbolic link itself instead of the file\n\
        the link points to.\n\
\n\
dir_fd and follow_symlinks may not be implemented\n\
  on your platform.  If they are unavailable, using them will raise a\n\
  NotImplementedError.\n\
\n\
It's an error to use dir_fd or follow_symlinks when specifying path as\n\
  an open file descriptor.\n\
\n"

/*[preprocessor]
os.stat -> stat result

ARGUMENTS
  { REQUIRED { path_t path = PATH_T_INITIALIZE("stat", 0, 1);
               converter = path_converter },

    KEYWORD  { int dir_fd = DEFAULT_DIR_FD;
               converter = OS_STAT_DIR_FD_CONVERTER;
               default = None },

    KEYWORD  { int follow_symlinks = 1;
               types = bool | int;
               default = True } }
 
[preprocessor]*/

#define OS_STAT_HEADER "os.stat(path, *[, dir_fd=None[, follow_symlinks=True]]) -> stat result\n"

static PyObject *
os_stat_impl(PyObject *self, path_t path, int dir_fd, int follow_symlinks);

static PyObject *
os_stat(PyObject *self, PyObject *args, PyObject *kwargs)
{
    path_t path = PATH_T_INITIALIZE("stat", 0, 1);
    int dir_fd = DEFAULT_DIR_FD;
    int follow_symlinks = 1;
    static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
        "O&|$O&p:stat", _keywords,
        path_converter, &path, OS_STAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
        return NULL;

    return os_stat_impl(self, path, dir_fd, follow_symlinks);
}

PyDoc_XSTRVAR(os_stat__doc__, OS_STAT_HEADER, OS_STAT_DOC);

#define OS_STAT_METHODDEF    \
    {"stat", (PyCFunction)os_stat, METH_VARARGS | METH_KEYWORDS, os_stat__doc__}

static PyObject *
os_stat_impl(PyObject *self, path_t path, int dir_fd, int follow_symlinks)
/*[preprocessor end:f3e6b328245207c240825782d908d3ff3a9c11c0]*/
{
    PyObject *return_value = posix_do_stat("stat", &path, dir_fd, follow_symlinks);
    path_cleanup(&path);
    return return_value;
}

