]> granicus.if.org Git - procps-ng/commitdiff
c99
authoralbert <>
Mon, 25 Nov 2002 10:16:33 +0000 (10:16 +0000)
committeralbert <>
Mon, 25 Nov 2002 10:16:33 +0000 (10:16 +0000)
proc/compare.c
proc/devname.c
proc/devname.h
proc/ksym.c
proc/output.c
proc/procps.h
proc/readproc.c
proc/sysinfo.c
proc/sysinfo.h
top.c

index d6e780e17d65e498c08fff7efb628406a558e745..b3fb3182b8d9474c2c1d63fce3b7f067caa4ccce 100644 (file)
@@ -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) */
index 10c297c6791f67591c7f197145eb1f0a69fd06d5..541d78b5d42b3a5d3b873f332b76329ab911ac29 100644 (file)
@@ -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;
index 93f872ab457de607e98a1c45dcf75eb115004f03..60b8e75aab7d7ec0acd86c073c2cc55b03be85bb 100644 (file)
@@ -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);
index 4951b71cf96ec9ff0765bdb5c8d371119fc50b20..f572becc25d52e5651d57ad77fc904c59b5ef840 100644 (file)
@@ -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);
 }
 
index 56243e1fb0aae405ca6720f0397254d80ab2e6a4..4ea73cf614bba90ca1f4e30e1e13de76d52edc31 100644 (file)
@@ -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
index aaa68d97da44b0ef0e60314af331c95296065a76..79d144c9971fb5f31f1624334b851438fd0a3412 100644 (file)
@@ -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>
 #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 *restrict file, const char *restrict s, unsigned max);
+extern unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max);
 
-extern unsigned print_str    (FILE* file, char *s, unsigned max);
-extern unsigned print_strlist(FILE* file, char **strs, unsigned max);
+#endif
index ca4576b94a42d81190743bbf2d258dd500f1d0c4..ad08ed8d222643f1a3301089144eb3a8aaf5e623 100644 (file)
@@ -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,
index 8b8b466593e6e11b2fc31d58629f6306a9051e4b..09d620aeca5b56893eff76db5309dfa0abe1a5dd 100644 (file)
@@ -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);
index aea4e6e19487a821700fb9f333efb00c30a24853..57d12409dbba788b84df8d348ad1f036d0cafc49 100644 (file)
@@ -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 */
 
diff --git a/top.c b/top.c
index 67167c82053144dcba4364db36adae4df4ac6cf4..87d35a7bc6f95ef395a232caa6acc07a58f73718 100644 (file)
--- a/top.c
+++ b/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