• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
10 
11 PyDoc_STRVAR(grp_getgrnam__doc__,
12 "getgrnam($module, /, name)\n"
13 "--\n"
14 "\n"
15 "Return the group database entry for the given group name.\n"
16 "\n"
17 "If name is not valid, raise KeyError.");
18 
19 #define GRP_GETGRNAM_METHODDEF    \
20     {"getgrnam", _PyCFunction_CAST(grp_getgrnam), METH_FASTCALL|METH_KEYWORDS, grp_getgrnam__doc__},
21 
22 static PyObject *
23 grp_getgrnam_impl(PyObject *module, PyObject *name);
24 
25 static PyObject *
grp_getgrnam(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)26 grp_getgrnam(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
27 {
28     PyObject *return_value = NULL;
29     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
30 
31     #define NUM_KEYWORDS 1
32     static struct {
33         PyGC_Head _this_is_not_used;
34         PyObject_VAR_HEAD
35         PyObject *ob_item[NUM_KEYWORDS];
36     } _kwtuple = {
37         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
38         .ob_item = { &_Py_ID(name), },
39     };
40     #undef NUM_KEYWORDS
41     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
42 
43     #else  // !Py_BUILD_CORE
44     #  define KWTUPLE NULL
45     #endif  // !Py_BUILD_CORE
46 
47     static const char * const _keywords[] = {"name", NULL};
48     static _PyArg_Parser _parser = {
49         .keywords = _keywords,
50         .fname = "getgrnam",
51         .kwtuple = KWTUPLE,
52     };
53     #undef KWTUPLE
54     PyObject *argsbuf[1];
55     PyObject *name;
56 
57     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
58     if (!args) {
59         goto exit;
60     }
61     if (!PyUnicode_Check(args[0])) {
62         _PyArg_BadArgument("getgrnam", "argument 'name'", "str", args[0]);
63         goto exit;
64     }
65     name = args[0];
66     return_value = grp_getgrnam_impl(module, name);
67 
68 exit:
69     return return_value;
70 }
71 
72 PyDoc_STRVAR(grp_getgrall__doc__,
73 "getgrall($module, /)\n"
74 "--\n"
75 "\n"
76 "Return a list of all available group entries, in arbitrary order.\n"
77 "\n"
78 "An entry whose name starts with \'+\' or \'-\' represents an instruction\n"
79 "to use YP/NIS and may not be accessible via getgrnam or getgrgid.");
80 
81 #define GRP_GETGRALL_METHODDEF    \
82     {"getgrall", (PyCFunction)grp_getgrall, METH_NOARGS, grp_getgrall__doc__},
83 
84 static PyObject *
85 grp_getgrall_impl(PyObject *module);
86 
87 static PyObject *
grp_getgrall(PyObject * module,PyObject * Py_UNUSED (ignored))88 grp_getgrall(PyObject *module, PyObject *Py_UNUSED(ignored))
89 {
90     return grp_getgrall_impl(module);
91 }
92 /*[clinic end generated code: output=1168333f1b15de11 input=a9049054013a1b77]*/
93