Mirror of git://git.busybox.net/busybox with our patches on top
Source
"%*s %*s %*s %*s %*s %*s " /*rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright 1998 by Albert Cahalan; all rights reserved.
* Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru>
* SELinux support: (c) 2007 by Yuichi Nakamura <ynakam@hitachisoft.jp>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
typedef struct id_to_name_map_t {
uid_t id;
char name[USERNAME_MAX_SIZE];
} id_to_name_map_t;
typedef struct cache_t {
id_to_name_map_t *cache;
int size;
} cache_t;
static cache_t username, groupname;
static void clear_cache(cache_t *cp)
{
free(cp->cache);
cp->cache = NULL;
cp->size = 0;
}
void FAST_FUNC clear_username_cache(void)
{
clear_cache(&username);
clear_cache(&groupname);
}
/* more generic, but we don't need that yet */
/* Returns -N-1 if not found. */
/* cp->cache[N] is allocated and must be filled in this case */
static int get_cached(cache_t *cp, uid_t id)
{
int i;
for (i = 0; i < cp->size; i++)
if (cp->cache[i].id == id)
return i;
i = cp->size++;
cp->cache = xrealloc_vector(cp->cache, 2, i);
cp->cache[i++].id = id;
return -i;
}
static char* get_cached(cache_t *cp, uid_t id,
char* FAST_FUNC x2x_utoa(uid_t id))
{
int i;
for (i = 0; i < cp->size; i++)
if (cp->cache[i].id == id)
return cp->cache[i].name;
i = cp->size++;
cp->cache = xrealloc_vector(cp->cache, 2, i);