c99
This commit is contained in:
parent
fe1be01b3a
commit
bd1a19b577
@ -91,7 +91,7 @@ static int cmp_ ## NAME (proc_t** P, proc_t** Q) { \
|
||||
*/
|
||||
|
||||
/* CMP_STR(cmdline) */
|
||||
CMP_STR(ruser)
|
||||
/* CMP_STR(ruser) */
|
||||
CMP_STR(euser)
|
||||
CMP_STR(cmd)
|
||||
/* CMP_INT(state) */
|
||||
|
@ -95,7 +95,7 @@ fail:
|
||||
}
|
||||
|
||||
/* Try to guess the device name from /proc/tty/drivers info. */
|
||||
static int driver_name(char * const buf, int maj, int min){
|
||||
static int driver_name(char *restrict const buf, int maj, int min){
|
||||
struct stat sbuf;
|
||||
tty_map_node *tmn;
|
||||
if(!tty_map) load_drivers();
|
||||
@ -118,7 +118,7 @@ static int driver_name(char * const buf, int maj, int min){
|
||||
}
|
||||
|
||||
/* Try to guess the device name (useful until /proc/PID/tty is added) */
|
||||
static int guess_name(char * const buf, int maj, int min){
|
||||
static int guess_name(char *restrict const buf, int maj, int min){
|
||||
struct stat sbuf;
|
||||
int t0, t1;
|
||||
int tmpmin = min;
|
||||
@ -175,7 +175,7 @@ static int guess_name(char * const buf, int maj, int min){
|
||||
* Useful names could be in /proc/PID/fd/2 (stderr, seldom redirected)
|
||||
* and in /proc/PID/fd/255 (used by bash to remember the tty).
|
||||
*/
|
||||
static int link_name(char * const buf, int maj, int min, int pid, const char *name){
|
||||
static int link_name(char *restrict const buf, int maj, int min, int pid, const char *restrict name){
|
||||
struct stat sbuf;
|
||||
char path[32];
|
||||
int count;
|
||||
@ -190,10 +190,10 @@ static int link_name(char * const buf, int maj, int min, int pid, const char *na
|
||||
}
|
||||
|
||||
/* number --> name */
|
||||
int dev_to_tty(char *ret, int chop, int dev, int pid, unsigned int flags) {
|
||||
unsigned dev_to_tty(char *restrict ret, unsigned chop, int dev, int pid, unsigned int flags) {
|
||||
static char buf[PAGE_SIZE];
|
||||
char *tmp = buf;
|
||||
int i = 0;
|
||||
char *restrict tmp = buf;
|
||||
unsigned i = 0;
|
||||
int c;
|
||||
if((short)dev == (short)-1) goto fail;
|
||||
if(linux_version_code > LINUX_VERSION(2, 5, 0)){ /* didn't get done yet */
|
||||
@ -211,7 +211,7 @@ abbrev:
|
||||
if((flags&ABBREV_TTY) && !strncmp(tmp,"tty", 3) && tmp[3]) tmp += 3;
|
||||
if((flags&ABBREV_PTS) && !strncmp(tmp,"pts/", 4) && tmp[4]) tmp += 4;
|
||||
/* gotta check before we chop or we may chop someone else's memory */
|
||||
if(tmp + chop - buf <= PAGE_SIZE)
|
||||
if(chop + (unsigned long)(tmp-buf) <= sizeof buf)
|
||||
tmp[chop] = '\0';
|
||||
/* replace non-ASCII characters with '?' and return the number of chars */
|
||||
for(;;){
|
||||
@ -229,7 +229,7 @@ abbrev:
|
||||
}
|
||||
|
||||
/* name --> number */
|
||||
int tty_to_dev(char *name) {
|
||||
int tty_to_dev(const char *restrict const name) {
|
||||
struct stat sbuf;
|
||||
static char buf[32];
|
||||
if(stat(name, &sbuf) >= 0) return sbuf.st_rdev;
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include "procps.h"
|
||||
|
||||
#define ABBREV_DEV 1 /* remove /dev/ */
|
||||
#define ABBREV_TTY 2 /* remove tty */
|
||||
#define ABBREV_PTS 4 /* remove pts/ */
|
||||
|
||||
extern int dev_to_tty(char *ret, int chop, int dev, int pid, unsigned int flags);
|
||||
extern unsigned dev_to_tty(char *restrict ret, unsigned chop, int dev, int pid, unsigned int flags);
|
||||
|
||||
extern int tty_to_dev(char *name);
|
||||
extern int tty_to_dev(const char *restrict const name);
|
||||
|
14
proc/ksym.c
14
proc/ksym.c
@ -206,13 +206,13 @@ static const symb *search(unsigned long address, symb *idx, unsigned count){
|
||||
/*********************************/
|
||||
|
||||
/* allocate if needed, read, and return buffer size */
|
||||
static void read_file(const char *filename, char **bufp, unsigned *roomp) {
|
||||
static void read_file(const char *restrict filename, char **bufp, unsigned *restrict roomp) {
|
||||
int fd = 0;
|
||||
ssize_t done;
|
||||
char *buf;
|
||||
char *buf = *bufp;
|
||||
ssize_t total = 0;
|
||||
unsigned room = *roomp;
|
||||
buf = *bufp;
|
||||
|
||||
if(!room) goto hell; /* failed before */
|
||||
if(!buf) buf = malloc(room);
|
||||
if(!buf) goto hell;
|
||||
@ -322,7 +322,7 @@ quiet_goodbye:
|
||||
|
||||
#define VCNT 16
|
||||
|
||||
static int sysmap_mmap(const char *filename, void (*message)(const char *, ...)) {
|
||||
static int sysmap_mmap(const char *restrict const filename, void (*message)(const char *restrict, ...)) {
|
||||
struct stat sbuf;
|
||||
char *endp;
|
||||
int fd;
|
||||
@ -454,7 +454,7 @@ static void read_and_parse(void){
|
||||
|
||||
/*********************************/
|
||||
|
||||
static void default_message(const char *format, ...) {
|
||||
static void default_message(const char *restrict format, ...) {
|
||||
va_list arg;
|
||||
|
||||
va_start (arg, format);
|
||||
@ -464,7 +464,7 @@ static void default_message(const char *format, ...) {
|
||||
|
||||
/*********************************/
|
||||
|
||||
int open_psdb_message(const char *override, void (*message)(const char *, ...)) {
|
||||
int open_psdb_message(const char *restrict override, void (*message)(const char *, ...)) {
|
||||
static const char *sysmap_paths[] = {
|
||||
"/boot/System.map-%s",
|
||||
"/boot/System.map",
|
||||
@ -500,7 +500,7 @@ int open_psdb_message(const char *override, void (*message)(const char *, ...))
|
||||
|
||||
/***************************************/
|
||||
|
||||
int open_psdb(const char *override) {
|
||||
int open_psdb(const char *restrict override) {
|
||||
return open_psdb_message(override, default_message);
|
||||
}
|
||||
|
||||
|
@ -7,16 +7,17 @@
|
||||
#include <string.h>
|
||||
#include "procps.h"
|
||||
|
||||
#if 0
|
||||
/* output a string, converting unprintables to octal as we go, and stopping after
|
||||
processing max chars of output (accounting for expansion due to octal rep).
|
||||
*/
|
||||
unsigned print_str(FILE* file, char *s, unsigned max) {
|
||||
int i;
|
||||
unsigned print_str(FILE *restrict file, const char *restrict const s, unsigned max) {
|
||||
unsigned i;
|
||||
for (i=0; s[i] && i < max; i++)
|
||||
if (isprint(s[i]) || s[i] == ' ')
|
||||
fputc(s[i], file);
|
||||
else {
|
||||
if (max - i > 3) {
|
||||
if (max > i+3) {
|
||||
fprintf(file, "\\%03o", (unsigned char)s[i]);
|
||||
i += 3; /* 4 printed, but i counts one */
|
||||
} else
|
||||
@ -24,19 +25,20 @@ unsigned print_str(FILE* file, char *s, unsigned max) {
|
||||
}
|
||||
return max - i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* output an argv style NULL-terminated string list, converting unprintables
|
||||
to octal as we go, separating items of the list by 'sep' and stopping after
|
||||
processing max chars of output (accounting for expansion due to octal rep).
|
||||
*/
|
||||
unsigned print_strlist(FILE* file, char **strs, unsigned max) {
|
||||
int i, n;
|
||||
unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max) {
|
||||
unsigned i, n;
|
||||
for (n=0; *strs && n < max; strs++) {
|
||||
for (i=0; strs[0][i] && n+i < max; i++)
|
||||
if (isprint(strs[0][i]) || strs[0][i] == ' ')
|
||||
fputc(strs[0][i], file);
|
||||
else {
|
||||
if (max-(n+i) > 3) {
|
||||
if (max > n+i+3) {
|
||||
fprintf(file, "\\%03o", (unsigned char)strs[0][i]);
|
||||
n += 3; /* 4 printed, but i counts one */
|
||||
} else
|
||||
|
@ -1,3 +1,6 @@
|
||||
#ifndef PROCPS_PROC_PROCPS_H
|
||||
#define PROCPS_PROC_PROCPS_H
|
||||
|
||||
/* The shadow of the original with only common prototypes now. */
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
@ -18,10 +21,17 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// won't alias anything, and aligned enough for anything
|
||||
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
|
||||
#define MALLOC __attribute__ ((__malloc__))
|
||||
#else
|
||||
#define MALLOC
|
||||
#endif
|
||||
|
||||
extern void *xrealloc(void *oldp, unsigned int size);
|
||||
extern void *xmalloc(unsigned int size);
|
||||
extern void *xcalloc(void *pointer, int size);
|
||||
|
||||
extern void *xrealloc(void *oldp, unsigned int size) MALLOC;
|
||||
extern void *xmalloc(unsigned int size) MALLOC;
|
||||
extern void *xcalloc(void *pointer, int size) MALLOC;
|
||||
|
||||
extern int mult_lvl_cmp(void* a, void* b);
|
||||
|
||||
@ -29,8 +39,10 @@ extern char *user_from_uid(uid_t uid);
|
||||
extern char *group_from_gid(gid_t gid);
|
||||
|
||||
extern const char * wchan(unsigned long address);
|
||||
extern int open_psdb(const char *override);
|
||||
extern int open_psdb_message(const char *override, void (*message)(const char *, ...));
|
||||
extern int open_psdb(const char *restrict override);
|
||||
extern int open_psdb_message(const char *restrict override, void (*message)(const char *, ...));
|
||||
|
||||
extern unsigned print_str (FILE* file, char *s, unsigned max);
|
||||
extern unsigned print_strlist(FILE* file, char **strs, unsigned max);
|
||||
extern unsigned print_str (FILE *restrict file, const char *restrict s, unsigned max);
|
||||
extern unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max);
|
||||
|
||||
#endif
|
||||
|
@ -74,7 +74,7 @@ void freeproc(proc_t* p) {
|
||||
|
||||
|
||||
|
||||
static void status2proc (char* S, proc_t* P, int fill) {
|
||||
static void status2proc(const char *S, proc_t *restrict P, int fill){
|
||||
char* tmp;
|
||||
if (fill == 1) {
|
||||
memset(P->cmd, 0, sizeof P->cmd);
|
||||
@ -151,7 +151,7 @@ static void status2proc (char* S, proc_t* P, int fill) {
|
||||
* Such names confuse %s (see scanf(3)), so the string is split and %39c
|
||||
* is used instead. (except for embedded ')' "(%[^)]c)" would work.
|
||||
*/
|
||||
static void stat2proc(char* S, proc_t* P) {
|
||||
static void stat2proc(const char* S, proc_t *restrict P) {
|
||||
int num;
|
||||
char* tmp = strrchr(S, ')'); /* split into "PID (cmd" and "<rest>" */
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
@ -199,7 +199,7 @@ static void stat2proc(char* S, proc_t* P) {
|
||||
P->tty = -1; /* the old notty val, update elsewhere bef. moving to 0 */
|
||||
}
|
||||
|
||||
static void statm2proc(char* s, proc_t* P) {
|
||||
static void statm2proc(const char* s, proc_t *restrict P) {
|
||||
int num;
|
||||
num = sscanf(s, "%ld %ld %ld %ld %ld %ld %ld",
|
||||
&P->size, &P->resident, &P->share,
|
||||
|
@ -69,9 +69,9 @@ static char buf[1024];
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
int uptime(double *uptime_secs, double *idle_secs) {
|
||||
int uptime(double *restrict uptime_secs, double *restrict idle_secs) {
|
||||
double up=0, idle=0;
|
||||
char *savelocale;
|
||||
char *restrict savelocale;
|
||||
|
||||
FILE_TO_BUF(UPTIME_FILE,uptime_fd);
|
||||
savelocale = setlocale(LC_NUMERIC, NULL);
|
||||
@ -125,7 +125,7 @@ static void old_Hertz_hack(void){
|
||||
double up_1, up_2, seconds;
|
||||
unsigned long long jiffies;
|
||||
unsigned h;
|
||||
char *savelocale;
|
||||
char *restrict savelocale;
|
||||
|
||||
savelocale = setlocale(LC_NUMERIC, NULL);
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
@ -212,7 +212,7 @@ static void init_libproc(void){
|
||||
#define NAN (-0.0)
|
||||
#endif
|
||||
#define JT unsigned long long
|
||||
void five_cpu_numbers(double *uret, double *nret, double *sret, double *iret, double *wret){
|
||||
void five_cpu_numbers(double *restrict uret, double *restrict nret, double *restrict sret, double *restrict iret, double *restrict wret){
|
||||
double tmp_u, tmp_n, tmp_s, tmp_i, tmp_w;
|
||||
double scale; /* scale values to % */
|
||||
static JT old_u, old_n, old_s, old_i, old_w;
|
||||
@ -253,9 +253,9 @@ void five_cpu_numbers(double *uret, double *nret, double *sret, double *iret, do
|
||||
#undef JT
|
||||
|
||||
/***********************************************************************/
|
||||
void loadavg(double *av1, double *av5, double *av15) {
|
||||
void loadavg(double *restrict av1, double *restrict av5, double *restrict av15) {
|
||||
double avg_1=0, avg_5=0, avg_15=0;
|
||||
char *savelocale;
|
||||
char *restrict savelocale;
|
||||
|
||||
FILE_TO_BUF(LOADAVG_FILE,loadavg_fd);
|
||||
savelocale = setlocale(LC_NUMERIC, NULL);
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef SYSINFO_H
|
||||
#define SYSINFO_H
|
||||
|
||||
#include "procps.h"
|
||||
|
||||
extern unsigned long long Hertz; /* clock tick frequency */
|
||||
extern long smp_num_cpus; /* number of CPUs */
|
||||
|
||||
|
18
top.c
18
top.c
@ -266,7 +266,7 @@ static const char *fmtmk (const char *fmts, ...)
|
||||
/*
|
||||
* This guy is just our way of avoiding the overhead of the standard
|
||||
* strcat function (should the caller choose to participate) */
|
||||
static inline char *scat (register char *dst, register const char *src)
|
||||
static inline char *scat (char *restrict dst, const char *restrict src)
|
||||
{
|
||||
while (*dst) dst++;
|
||||
while ((*(dst++) = *(src++)));
|
||||
@ -857,7 +857,7 @@ static CPUS_t *cpus_refresh (CPUS_t *cpus)
|
||||
* 2) counting the number of tasks in each state (run, sleep, etc)
|
||||
* 3) maintaining the HIST_t's and priming the proc_t pcpu field
|
||||
* 4) establishing the total number tasks for this frame */
|
||||
static void prochlp (register proc_t *this)
|
||||
static void prochlp (proc_t *this)
|
||||
{
|
||||
static HIST_t *hist_sav = NULL;
|
||||
static HIST_t *hist_new = NULL;
|
||||
@ -919,9 +919,9 @@ static void prochlp (register proc_t *this)
|
||||
hist_new[Frame_maxtask].pid = this->pid;
|
||||
hist_new[Frame_maxtask].tics = tics = (this->utime + this->stime);
|
||||
|
||||
{ register int i;
|
||||
register int lo = 0;
|
||||
register int hi = maxt_sav - 1;
|
||||
{ int i;
|
||||
int lo = 0;
|
||||
int hi = maxt_sav - 1;
|
||||
|
||||
// find matching entry from previous frame and make ticks elapsed
|
||||
while (lo <= hi) {
|
||||
@ -955,7 +955,7 @@ static proc_t **procs_refresh (proc_t **table, int flags)
|
||||
#define ENTsz sizeof(proc_t)
|
||||
static unsigned savmax = 0; // first time, Bypass: (i)
|
||||
proc_t *ptsk = (proc_t *)-1; // first time, Force: (ii)
|
||||
register unsigned curmax = 0; // every time (jeeze)
|
||||
unsigned curmax = 0; // every time (jeeze)
|
||||
PROCTAB* PT;
|
||||
|
||||
prochlp(NULL); // prep for a new frame
|
||||
@ -2163,7 +2163,7 @@ static void do_key (unsigned c)
|
||||
* 2) modest smp boxes with room for each cpu's percentages
|
||||
* 3) massive smp guys leaving little or no room for process
|
||||
* display and thus requiring the cpu summary toggle */
|
||||
static void summaryhlp (CPUS_t *cpu, const char *pfx)
|
||||
static void summaryhlp (CPUS_t *restrict cpu, const char *restrict pfx)
|
||||
{
|
||||
/* we'll trim to zero if we get negative time ticks,
|
||||
which has happened with some SMP kernels (pre-2.4?) */
|
||||
@ -2303,7 +2303,7 @@ static void task_show (WIN_t *q, proc_t *p)
|
||||
|
||||
for (x = 0; x < q->maxpflgs; x++) {
|
||||
char cbuf[ROWBUFSIZ], _z[ROWBUFSIZ];
|
||||
register PFLG_t i = q->procflags[x]; // support for our field/column
|
||||
PFLG_t i = q->procflags[x]; // support for our field/column
|
||||
const char *f = Fieldstab[i].fmts; // macro AND sometimes the fmt
|
||||
unsigned s = Fieldstab[i].scale; // string must be altered !
|
||||
unsigned w = Fieldstab[i].width;
|
||||
@ -2519,7 +2519,7 @@ static void window_show (proc_t **ppt, WIN_t *q, int *lscr)
|
||||
* remaining amount of screen real estate under multiple windows */
|
||||
static void framehlp (int wix, int max)
|
||||
{
|
||||
register int i;
|
||||
int i;
|
||||
int rsvd, size, wins;
|
||||
|
||||
// calc remaining number of visible windows + total 'user' lines
|
||||
|
Loading…
Reference in New Issue
Block a user