aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-24 14:59:45 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-24 14:59:45 +0000
commitb8a8e601df9e912faa20857b4b5c07024618f7b3 (patch)
tree2dde275d11a03e45f7fe4aca444d0195c415a59c /libbb
parentc50f370f98e5f5d24d18ca3df444770dacce1824 (diff)
downloadbusybox-w32-b8a8e601df9e912faa20857b4b5c07024618f7b3.tar.gz
busybox-w32-b8a8e601df9e912faa20857b4b5c07024618f7b3.tar.bz2
busybox-w32-b8a8e601df9e912faa20857b4b5c07024618f7b3.zip
tar: small fixes:
* size-optimize mapping code * kill double close
Diffstat (limited to 'libbb')
-rw-r--r--libbb/procps.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/libbb/procps.c b/libbb/procps.c
index 52203ee9a..2581d03b2 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -35,6 +35,7 @@ void clear_username_cache(void)
35 clear_cache(&groupname); 35 clear_cache(&groupname);
36} 36}
37 37
38#if 0 /* more generic, but we don't need that yet */
38/* Returns -N-1 if not found. */ 39/* Returns -N-1 if not found. */
39/* cp->cache[N] is allocated and must be filled in this case */ 40/* cp->cache[N] is allocated and must be filled in this case */
40static int get_cached(cache_t *cp, unsigned id) 41static int get_cached(cache_t *cp, unsigned id)
@@ -48,25 +49,28 @@ static int get_cached(cache_t *cp, unsigned id)
48 cp->cache[i++].id = id; 49 cp->cache[i++].id = id;
49 return -i; 50 return -i;
50} 51}
52#endif
53
54typedef char* ug_func(char *name, long uid, int bufsize);
55static char* get_cached(cache_t *cp, unsigned id, ug_func* fp)
56{
57 int i;
58 for (i = 0; i < cp->size; i++)
59 if (cp->cache[i].id == id)
60 return cp->cache[i].name;
61 i = cp->size++;
62 cp->cache = xrealloc(cp->cache, cp->size * sizeof(*cp->cache));
63 cp->cache[i].id = id;
64 fp(cp->cache[i].name, id, sizeof(cp->cache[i].name));
65 return cp->cache[i].name;
66}
51const char* get_cached_username(uid_t uid) 67const char* get_cached_username(uid_t uid)
52{ 68{
53 int i = get_cached(&username, uid); 69 return get_cached(&username, uid, bb_getpwuid);
54 if (i < 0) {
55 i = -i - 1;
56 bb_getpwuid(username.cache[i].name, uid,
57 sizeof(username.cache[i].name));
58 }
59 return username.cache[i].name;
60} 70}
61const char* get_cached_groupname(uid_t uid) 71const char* get_cached_groupname(gid_t gid)
62{ 72{
63 int i = get_cached(&groupname, uid); 73 return get_cached(&groupname, gid, bb_getgrgid);
64 if (i < 0) {
65 i = -i - 1;
66 bb_getgrgid(groupname.cache[i].name, uid,
67 sizeof(groupname.cache[i].name));
68 }
69 return username.cache[i].name;
70} 74}
71 75
72 76