Renamed.
This commit is contained in:
parent
96bd636ad1
commit
b2b44e5b8a
|
@ -31,29 +31,28 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* UNIX group file access module */
|
/* UNIX group file access module */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "Python.h"
|
||||||
#include "modsupport.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
|
||||||
static object *mkgrent(p)
|
static PyObject *mkgrent(p)
|
||||||
struct group *p;
|
struct group *p;
|
||||||
{
|
{
|
||||||
object *v, *w;
|
PyObject *v, *w;
|
||||||
char **member;
|
char **member;
|
||||||
if ((w = newlistobject(0)) == NULL) {
|
if ((w = PyList_New(0)) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (member = p->gr_mem; *member != NULL; member++) {
|
for (member = p->gr_mem; *member != NULL; member++) {
|
||||||
object *x = newstringobject(*member);
|
PyObject *x = PyString_FromString(*member);
|
||||||
if (x == NULL || addlistitem(w, x) != 0) {
|
if (x == NULL || PyList_Append(w, x) != 0) {
|
||||||
XDECREF(x);
|
Py_XDECREF(x);
|
||||||
DECREF(w);
|
Py_DECREF(w);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v = mkvalue("(sslO)",
|
v = Py_BuildValue("(sslO)",
|
||||||
p->gr_name,
|
p->gr_name,
|
||||||
p->gr_passwd,
|
p->gr_passwd,
|
||||||
#if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__)
|
#if defined(NeXT) && defined(_POSIX_SOURCE) && defined(__LITTLE_ENDIAN__)
|
||||||
|
@ -64,60 +63,60 @@ static object *mkgrent(p)
|
||||||
(long)p->gr_gid,
|
(long)p->gr_gid,
|
||||||
#endif
|
#endif
|
||||||
w);
|
w);
|
||||||
DECREF(w);
|
Py_DECREF(w);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *grp_getgrgid(self, args)
|
static PyObject *grp_getgrgid(self, args)
|
||||||
object *self, *args;
|
PyObject *self, *args;
|
||||||
{
|
{
|
||||||
int gid;
|
int gid;
|
||||||
struct group *p;
|
struct group *p;
|
||||||
if (!getintarg(args, &gid))
|
if (!getintarg(args, &gid))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((p = getgrgid(gid)) == NULL) {
|
if ((p = getgrgid(gid)) == NULL) {
|
||||||
err_setstr(KeyError, "getgrgid(): gid not found");
|
PyErr_SetString(PyExc_KeyError, "getgrgid(): gid not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkgrent(p);
|
return mkgrent(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *grp_getgrnam(self, args)
|
static PyObject *grp_getgrnam(self, args)
|
||||||
object *self, *args;
|
PyObject *self, *args;
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
struct group *p;
|
struct group *p;
|
||||||
if (!getstrarg(args, &name))
|
if (!getstrarg(args, &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((p = getgrnam(name)) == NULL) {
|
if ((p = getgrnam(name)) == NULL) {
|
||||||
err_setstr(KeyError, "getgrnam(): name not found");
|
PyErr_SetString(PyExc_KeyError, "getgrnam(): name not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkgrent(p);
|
return mkgrent(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *grp_getgrall(self, args)
|
static PyObject *grp_getgrall(self, args)
|
||||||
object *self, *args;
|
PyObject *self, *args;
|
||||||
{
|
{
|
||||||
object *d;
|
PyObject *d;
|
||||||
struct group *p;
|
struct group *p;
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((d = newlistobject(0)) == NULL)
|
if ((d = PyList_New(0)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
setgrent();
|
setgrent();
|
||||||
while ((p = getgrent()) != NULL) {
|
while ((p = getgrent()) != NULL) {
|
||||||
object *v = mkgrent(p);
|
PyObject *v = mkgrent(p);
|
||||||
if (v == NULL || addlistitem(d, v) != 0) {
|
if (v == NULL || PyList_Append(d, v) != 0) {
|
||||||
XDECREF(v);
|
Py_XDECREF(v);
|
||||||
DECREF(d);
|
Py_DECREF(d);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist grp_methods[] = {
|
static PyMethodDef grp_methods[] = {
|
||||||
{"getgrgid", grp_getgrgid},
|
{"getgrgid", grp_getgrgid},
|
||||||
{"getgrnam", grp_getgrnam},
|
{"getgrnam", grp_getgrnam},
|
||||||
{"getgrall", grp_getgrall},
|
{"getgrall", grp_getgrall},
|
||||||
|
@ -127,5 +126,5 @@ static struct methodlist grp_methods[] = {
|
||||||
void
|
void
|
||||||
initgrp()
|
initgrp()
|
||||||
{
|
{
|
||||||
initmodule("grp", grp_methods);
|
Py_InitModule("grp", grp_methods);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue