2006-03-04 18:16:49 +00:00
|
|
|
/*
|
|
|
|
htop - UsersTable.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2006-03-04 18:16:49 +00:00
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UsersTable.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2011-12-25 20:23:53 +00:00
|
|
|
#include <string.h>
|
2006-03-04 18:16:49 +00:00
|
|
|
#include <strings.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <sys/types.h>
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <stdlib.h>
|
2006-03-04 18:16:49 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*{
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "Hashtable.h"
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
typedef struct UsersTable_ {
|
|
|
|
Hashtable* users;
|
|
|
|
} UsersTable;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
UsersTable* UsersTable_new() {
|
|
|
|
UsersTable* this;
|
|
|
|
this = malloc(sizeof(UsersTable));
|
|
|
|
this->users = Hashtable_new(20, true);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UsersTable_delete(UsersTable* this) {
|
|
|
|
Hashtable_delete(this->users);
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2007-04-05 19:53:23 +00:00
|
|
|
char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
2006-03-04 18:16:49 +00:00
|
|
|
char* name = (char*) (Hashtable_get(this->users, uid));
|
|
|
|
if (name == NULL) {
|
|
|
|
struct passwd* userData = getpwuid(uid);
|
|
|
|
if (userData != NULL) {
|
2011-12-25 20:23:53 +00:00
|
|
|
name = strdup(userData->pw_name);
|
2006-03-04 18:16:49 +00:00
|
|
|
Hashtable_put(this->users, uid, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData) {
|
|
|
|
Hashtable_foreach(this->users, f, userData);
|
|
|
|
}
|