summaryrefslogtreecommitdiff
path: root/lib/idcache.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-03-10 22:55:20 +0000
committerJim Meyering <jim@meyering.net>1998-03-10 22:55:20 +0000
commita991132f3ecd9befe801c25901617c3cf1d7e70b (patch)
tree1ea1310faadf4db94931b8752b8d6caa784a0c2c /lib/idcache.c
parent7f0867df009907e3a0f5fdbbb634aafb50ef809b (diff)
downloadcoreutils-a991132f3ecd9befe801c25901617c3cf1d7e70b.tar.xz
(getuidbyname) [__DJGPP__]: Make function know about
any arbitrary user name. (getgidbyname) [__DJGPP__]: Make function know about any arbitrary group name. From Eli.
Diffstat (limited to 'lib/idcache.c')
-rw-r--r--lib/idcache.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/idcache.c b/lib/idcache.c
index c00ee869d..b8104f179 100644
--- a/lib/idcache.c
+++ b/lib/idcache.c
@@ -44,6 +44,10 @@ struct group *getgrnam ();
char *xmalloc ();
char *xstrdup ();
+#ifdef __DJGPP__
+static char digits[] = "0123456789";
+#endif
+
struct userid
{
union
@@ -105,6 +109,15 @@ getuidbyname (const char *user)
return 0;
pwent = getpwnam (user);
+#ifdef __DJGPP__
+ /* We need to pretend to be the user USER, to make
+ pwd functions know about an arbitrary user name. */
+ if (!pwent && strspn (user, digits) < strlen (user))
+ {
+ setenv ("USER", user, 1);
+ pwent = getpwnam (user); /* now it will succeed */
+ }
+#endif
tail = (struct userid *) xmalloc (sizeof (struct userid));
tail->name = xstrdup (user);
@@ -172,6 +185,15 @@ getgidbyname (const char *group)
return 0;
grent = getgrnam (group);
+#ifdef __DJGPP__
+ /* We need to pretend to belong to group GROUP, to make
+ grp functions know about any arbitrary group name. */
+ if (!grent && strspn (group, digits) < strlen (group))
+ {
+ setenv ("GROUP", group, 1);
+ grent = getgrnam (group); /* now it will succeed */
+ }
+#endif
tail = (struct userid *) xmalloc (sizeof (struct userid));
tail->name = xstrdup (group);