top(1): Use uid_t for uid rather than 'int'

Remove unneeded define while here.
This commit is contained in:
eadler 2018-06-02 03:54:50 +00:00
parent 5af3d07de3
commit d08be95677
8 changed files with 19 additions and 21 deletions

View File

@ -914,7 +914,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
static char fmt[512]; /* static area where result is built */ static char fmt[512]; /* static area where result is built */
char * char *
format_next_process(caddr_t xhandle, char *(*get_userid)(int), int flags) format_next_process(caddr_t xhandle, char *(*get_userid)(uid_t), int flags)
{ {
struct kinfo_proc *pp; struct kinfo_proc *pp;
const struct kinfo_proc *oldp; const struct kinfo_proc *oldp;

View File

@ -75,7 +75,7 @@ struct process_select
/* routines defined by the machine dependent module */ /* routines defined by the machine dependent module */
char *format_header(char *uname_field); char *format_header(char *uname_field);
char *format_next_process(caddr_t handle, char *(*get_userid)(int), char *format_next_process(caddr_t handle, char *(*get_userid)(uid_t),
int flags); int flags);
void toggle_pcpustats(void); void toggle_pcpustats(void);
void get_system_info(struct system_info *si); void get_system_info(struct system_info *si);

View File

@ -25,7 +25,6 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define TERMIOS
#include <termios.h> #include <termios.h>
#include <curses.h> #include <curses.h>
#include <termcap.h> #include <termcap.h>

View File

@ -206,7 +206,7 @@ main(int argc, char *argv[])
int displays = 0; /* indicates unspecified */ int displays = 0; /* indicates unspecified */
int sel_ret = 0; int sel_ret = 0;
time_t curr_time; time_t curr_time;
char *(*get_userid)(int) = username; char *(*get_userid)(uid_t) = username;
char *uname_field = "USERNAME"; char *uname_field = "USERNAME";
char *header_text; char *header_text;
char *env_top; char *env_top;

View File

@ -37,29 +37,27 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "utils.h" #include "utils.h"
#include "username.h" #include "username.h"
struct hash_el { struct hash_el {
int uid; uid_t uid;
char name[MAXLOGNAME]; char name[MAXLOGNAME];
}; };
#define is_empty_hash(x) (hash_table[x].name[0] == 0) #define is_empty_hash(x) (hash_table[x].name[0] == 0)
/* simple minded hashing function */ /* simple minded hashing function */
/* Uid "nobody" is -2 results in hashit(-2) = -2 which is out of bounds for #define hashit(i) (i % Table_size)
the hash_table. Applied abs() function to fix. 2/16/96 tpugh
*/
#define hashit(i) (abs(i) % Table_size)
/* K&R requires that statically declared tables be initialized to zero. */ /* K&R requires that statically declared tables be initialized to zero. */
/* We depend on that for hash_table and YOUR compiler had BETTER do it! */ /* We depend on that for hash_table and YOUR compiler had BETTER do it! */
static struct hash_el hash_table[Table_size]; static struct hash_el hash_table[Table_size];
char *username(int uid) char *username(uid_t uid)
{ {
int hashindex; int hashindex;
@ -72,7 +70,7 @@ char *username(int uid)
return(hash_table[hashindex].name); return(hash_table[hashindex].name);
} }
int userid(char username[]) uid_t userid(char username[])
{ {
struct passwd *pwd; struct passwd *pwd;
@ -93,7 +91,7 @@ int userid(char username[])
} }
/* wecare 1 = enter it always, 0 = nice to have */ /* wecare 1 = enter it always, 0 = nice to have */
int enter_user(int uid, char name[], bool wecare) int enter_user(uid_t uid, char name[], bool wecare)
{ {
int hashindex; int hashindex;
@ -124,7 +122,7 @@ int enter_user(int uid, char name[], bool wecare)
*/ */
int int
get_user(int uid) get_user(uid_t uid)
{ {
struct passwd *pwd; struct passwd *pwd;

View File

@ -12,12 +12,13 @@
#define USERNAME_H #define USERNAME_H
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h>
int enter_user(int uid, char *name, bool wecare); int enter_user(uid_t uid, char *name, bool wecare);
int get_user(int uid); int get_user(uid_t uid);
void init_hash(void); void init_hash(void);
char *username(int uid); char *username(uid_t uid);
int userid(char *username); uid_t userid(char *username);
/* /*
* "Table_size" defines the size of the hash tables used to map uid to * "Table_size" defines the size of the hash tables used to map uid to

View File

@ -59,7 +59,7 @@ atoiwi(char *str)
*/ */
_Static_assert(sizeof(int) <= 4, "buffer too small for this sized int"); _Static_assert(sizeof(int) <= 4, "buffer too small for this sized int");
char *itoa(int val) char *itoa(unsigned int val)
{ {
char *ptr; char *ptr;
static char buffer[16]; /* result is built here */ static char buffer[16]; /* result is built here */
@ -87,7 +87,7 @@ char *itoa(int val)
* a front end to a more general routine for efficiency. * a front end to a more general routine for efficiency.
*/ */
char *itoa7(int val) char *itoa7(unsigned int val)
{ {
char *ptr; char *ptr;
static char buffer[16]; /* result is built here */ static char buffer[16]; /* result is built here */

View File

@ -11,8 +11,8 @@
*/ */
int atoiwi(char *); int atoiwi(char *);
char *itoa(int); char *itoa(unsigned int);
char *itoa7(int); char *itoa7(unsigned int);
int digits(int); int digits(int);
char *strecpy(char *, char *); char *strecpy(char *, char *);
char **argparse(char *, int *); char **argparse(char *, int *);