From 84194373370b46a346231c1762c038cc683abc45 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Jan 2009 12:48:30 +0000 Subject: added #define PROC_STAT "/proc/stat" --- common.h | 2 ++ cpu.c | 16 ++++++++-------- forks.c | 10 +++++----- interrupts.c | 8 ++++---- swap.c | 13 +++++++------ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/common.h b/common.h index 67a5beb..8db440a 100644 --- a/common.h +++ b/common.h @@ -1,6 +1,8 @@ #ifndef COMMON_H #define COMMON_H +#define PROC_STAT "/proc/stat" + int writeyes(void); int writeno(const char *); diff --git a/cpu.c b/cpu.c index 120293d..627eb7c 100644 --- a/cpu.c +++ b/cpu.c @@ -19,8 +19,8 @@ int cpu(int argc, char **argv) { if(s && !strcmp(s, "yes")) scaleto100=1; - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { @@ -37,7 +37,7 @@ int cpu(int argc, char **argv) { fclose(f); if(ncpu < 1 || extinfo < 4) { - fputs("cannot parse /proc/stat\n", stderr); + fputs("cannot parse " PROC_STAT "\n", stderr); return 1; } @@ -114,14 +114,14 @@ int cpu(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { @@ -152,6 +152,6 @@ int cpu(int argc, char **argv) { } } fclose(f); - fputs("no cpu line found in /proc/stat\n", stderr); + fputs("no cpu line found in " PROC_STAT "\n", stderr); return 1; } diff --git a/forks.c b/forks.c index fa4dadb..3d4a198 100644 --- a/forks.c +++ b/forks.c @@ -21,14 +21,14 @@ int forks(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { @@ -39,6 +39,6 @@ int forks(int argc, char **argv) { } } fclose(f); - fputs("no processes line found in /proc/stat\n", stderr); + fputs("no processes line found in " PROC_STAT "\n", stderr); return 1; } diff --git a/interrupts.c b/interrupts.c index 2755ccf..8c800c6 100644 --- a/interrupts.c +++ b/interrupts.c @@ -26,14 +26,14 @@ int interrupts(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { diff --git a/swap.c b/swap.c index 1a270fe..3decfbb 100644 --- a/swap.c +++ b/swap.c @@ -27,10 +27,10 @@ int swap(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } if(!access("/proc/vmstat", F_OK)) { @@ -56,15 +56,16 @@ int swap(int argc, char **argv) { } return 0; } else { - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { if(!strncmp(buff, "swap ", 5)) { fclose(f); if(2 != sscanf(buff+5, "%d %d", &in, &out)) { - fputs("bad data on /proc/stat\n", stderr); + fputs("bad data on " PROC_STAT "\n", + stderr); return 1; } printf("swap_in.value %d\nswap_out.value %d\n", in, out); @@ -72,7 +73,7 @@ int swap(int argc, char **argv) { } } fclose(f); - fputs("no swap line found in /proc/stat\n", stderr); + fputs("no swap line found in " PROC_STAT "\n", stderr); return 1; } } -- cgit v1.2.3