comparison lib/idcache.c @ 4544:9a6a29a7ae3c

Include "xalloc.h" (xmalloc, xrealloc): Remove decls. (getuser): Remove casts no longer required in C89.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 14 Aug 2003 23:03:13 +0000
parents dfd7c775c5d0
children fa597018cd8b
comparison
equal deleted inserted replaced
4543:a6b4c227ffae 4544:9a6a29a7ae3c
1 /* idcache.c -- map user and group IDs, cached for speed 1 /* idcache.c -- map user and group IDs, cached for speed
2 Copyright (C) 1985, 1988, 1989, 1990, 1997, 1998 Free Software 2 Copyright (C) 1985, 1988, 1989, 1990, 1997, 1998, 2003 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 2, or (at your option)
32 #endif 32 #endif
33 33
34 #if HAVE_UNISTD_H 34 #if HAVE_UNISTD_H
35 # include <unistd.h> 35 # include <unistd.h>
36 #endif 36 #endif
37
38 #include "xalloc.h"
37 39
38 #ifndef _POSIX_VERSION 40 #ifndef _POSIX_VERSION
39 struct passwd *getpwuid (); 41 struct passwd *getpwuid ();
40 struct passwd *getpwnam (); 42 struct passwd *getpwnam ();
41 struct group *getgrgid (); 43 struct group *getgrgid ();
42 struct group *getgrnam (); 44 struct group *getgrnam ();
43 #endif 45 #endif
44
45 char *xmalloc ();
46 char *xstrdup ();
47 46
48 #ifdef __DJGPP__ 47 #ifdef __DJGPP__
49 static char digits[] = "0123456789"; 48 static char digits[] = "0123456789";
50 #endif 49 #endif
51 50
76 for (tail = user_alist; tail; tail = tail->next) 75 for (tail = user_alist; tail; tail = tail->next)
77 if (tail->id.u == uid) 76 if (tail->id.u == uid)
78 return tail->name; 77 return tail->name;
79 78
80 pwent = getpwuid (uid); 79 pwent = getpwuid (uid);
81 tail = (struct userid *) xmalloc (sizeof (struct userid)); 80 tail = xmalloc (sizeof (struct userid));
82 tail->id.u = uid; 81 tail->id.u = uid;
83 tail->name = pwent ? xstrdup (pwent->pw_name) : NULL; 82 tail->name = pwent ? xstrdup (pwent->pw_name) : NULL;
84 83
85 /* Add to the head of the list, so most recently used is first. */ 84 /* Add to the head of the list, so most recently used is first. */
86 tail->next = user_alist; 85 tail->next = user_alist;
118 setenv ("USER", user, 1); 117 setenv ("USER", user, 1);
119 pwent = getpwnam (user); /* now it will succeed */ 118 pwent = getpwnam (user); /* now it will succeed */
120 } 119 }
121 #endif 120 #endif
122 121
123 tail = (struct userid *) xmalloc (sizeof (struct userid)); 122 tail = xmalloc (sizeof (struct userid));
124 tail->name = xstrdup (user); 123 tail->name = xstrdup (user);
125 124
126 /* Add to the head of the list, so most recently used is first. */ 125 /* Add to the head of the list, so most recently used is first. */
127 if (pwent) 126 if (pwent)
128 { 127 {
152 for (tail = group_alist; tail; tail = tail->next) 151 for (tail = group_alist; tail; tail = tail->next)
153 if (tail->id.g == gid) 152 if (tail->id.g == gid)
154 return tail->name; 153 return tail->name;
155 154
156 grent = getgrgid (gid); 155 grent = getgrgid (gid);
157 tail = (struct userid *) xmalloc (sizeof (struct userid)); 156 tail = xmalloc (sizeof (struct userid));
158 tail->id.g = gid; 157 tail->id.g = gid;
159 tail->name = grent ? xstrdup (grent->gr_name) : NULL; 158 tail->name = grent ? xstrdup (grent->gr_name) : NULL;
160 159
161 /* Add to the head of the list, so most recently used is first. */ 160 /* Add to the head of the list, so most recently used is first. */
162 tail->next = group_alist; 161 tail->next = group_alist;
194 setenv ("GROUP", group, 1); 193 setenv ("GROUP", group, 1);
195 grent = getgrnam (group); /* now it will succeed */ 194 grent = getgrnam (group); /* now it will succeed */
196 } 195 }
197 #endif 196 #endif
198 197
199 tail = (struct userid *) xmalloc (sizeof (struct userid)); 198 tail = xmalloc (sizeof (struct userid));
200 tail->name = xstrdup (group); 199 tail->name = xstrdup (group);
201 200
202 /* Add to the head of the list, so most recently used is first. */ 201 /* Add to the head of the list, so most recently used is first. */
203 if (grent) 202 if (grent)
204 { 203 {