minix/lib/nbsd_libcompat_minix/passwd.c
Thomas Veerman a209c3ae12 Fix a ton of compiler warnings
This patch fixes most of current reasons to generate compiler warnings.
The changes consist of:
 - adding missing casts
 - hiding or unhiding function declarations
 - including headers where missing
 - add __UNCONST when assigning a const char * to a char *
 - adding missing return statements
 - changing some types from unsigned to signed, as the code seems to want
   signed ints
 - converting old-style function definitions to current style (i.e.,
   void func(param1, param2) short param1, param2; {...} to
   void func (short param1, short param2) {...})
 - making the compiler silent about signed vs unsigned comparisons. We
   have too many of those in the new libc to fix.

A number of bugs in the test set were fixed. These bugs were never
triggered with our old libc. Consequently, these tests are now forced to
link with the new libc or they will generate errors (in particular tests 43
and 55).

Most changes in NetBSD libc are limited to moving aroudn "#ifndef __minix"
or stuff related to Minix-specific things (code in sys-minix or gen/minix).
2011-11-14 10:07:49 +00:00

96 lines
1.9 KiB
C

/*
* grotesque hack to get these functions working.
*/
#include <sys/types.h>
#include <compat/pwd.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <stdio.h>
/*
* group_from_gid()
* caches the name (if any) for the gid. If noname clear, we always
* return the stored name (if valid or invalid match).
* We use a simple hash table.
* Return
* Pointer to stored name (or a empty string)
*/
const char *
group_from_gid(gid_t gid, int noname)
{
static char buf[16];
struct group *g = getgrgid(gid);
if (g == NULL) {
if (noname) {
return NULL;
} else {
sprintf(buf, "%d", gid);
return buf;
}
}
return g->gr_name;
}
/*
* user_from_uid()
* caches the name (if any) for the uid. If noname clear, we always
* return the stored name (if valid or invalid match).
* We use a simple hash table.
* Return
* Pointer to stored name (or a empty string)
*/
const char *
user_from_uid(uid_t uid, int noname)
{
static char buf[16];
struct passwd *p = getpwuid(uid);
if (p == NULL) {
if (noname) {
return NULL;
} else {
sprintf(buf, "%d", uid);
return buf;
}
}
return p->pw_name;
}
/*
* uid_from_user()
* caches the uid for a given user name. We use a simple hash table.
* Return
* the uid (if any) for a user name, or a -1 if no match can be found
*/
int
uid_from_user(const char *name, uid_t *uid)
{
struct passwd *p = getpwnam(name);
if (p == NULL) {
return -1;
}
*uid = p->pw_uid;
return *uid;
}
/*
* gid_from_group()
* caches the gid for a given group name. We use a simple hash table.
* Return
* the gid (if any) for a group name, or a -1 if no match can be found
*/
int
gid_from_group(const char *name, gid_t *gid)
{
struct group *g = getgrnam(name);
if (g == NULL) {
return -1;
}
*gid = g->gr_gid;
return *gid;
}