grpmodule.c.h 4.1 KB

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