I've been working a bit with apr, and noticed that the implementation of
apr_get_groupname is missing from the unix code.
This patch has only been tested on Linux, so commit at your own risk.
Index: userinfo.c
===================================================================
RCS file: /home/cvspublic/apr/user/unix/userinfo.c,v
retrieving revision 1.6
diff -u -r1.6 userinfo.c
--- userinfo.c 2001/01/28 23:45:57 1.6
+++ userinfo.c 2001/02/02 08:40:02
@@ -59,6 +59,9 @@
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
#if APR_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -100,5 +103,21 @@
}
*username = apr_pstrdup(p, pw->pw_name);
return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, apr_gid_t
groupid, apr_pool_t *p)
+{
+ struct group *gp;
+#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) &&
defined(HAVE_GETGRGID_R)
+ struct group grp;
+ char grpbuf[512];
+
+ if(getgrgid_r(groupid, &grp, grpbuf, sizeof(grpbuf), &gp)) {
+#else
+ if((gp = getgrgid(groupid)) == NULL) {
+#endif
+ return errno;
+ }
+ *groupname = apr_pstrdup(p, gp->gr_name);
+ return APR_SUCCESS;
}
-