diff options
author | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-02-14 10:17:09 +0000 |
---|---|---|
committer | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-02-14 10:17:09 +0000 |
commit | 465300ced9320a4e8bdf9db00fd4f8e0a35e4a4c (patch) | |
tree | 530eec7f4f2a875fa7912f6eb6eee4a7c588ce7e | |
parent | 63ca3bfe9d3c9fe062aa1826416831aee6b54f65 (diff) | |
download | busybox-w32-465300ced9320a4e8bdf9db00fd4f8e0a35e4a4c.tar.gz busybox-w32-465300ced9320a4e8bdf9db00fd4f8e0a35e4a4c.tar.bz2 busybox-w32-465300ced9320a4e8bdf9db00fd4f8e0a35e4a4c.zip |
cleanups after changes by Denis Vlasenko. Size optimization
-rw-r--r-- | libbb/procps.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 09561b533..2ebe66e9d 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -18,16 +18,19 @@ | |||
18 | #include "libbb.h" | 18 | #include "libbb.h" |
19 | 19 | ||
20 | 20 | ||
21 | static int read_to_buf(char *filename, void *buf, int bufsize) | 21 | #define PROCPS_BUFSIZE 1024 |
22 | |||
23 | static int read_to_buf(const char *filename, void *buf) | ||
22 | { | 24 | { |
23 | int fd; | 25 | int fd; |
26 | ssize_t ret; | ||
24 | 27 | ||
25 | fd = open(filename, O_RDONLY); | 28 | fd = open(filename, O_RDONLY); |
26 | if(fd < 0) | 29 | if(fd < 0) |
27 | return -1; | 30 | return -1; |
28 | bufsize = read(fd, buf, bufsize); | 31 | ret = read(fd, buf, PROCPS_BUFSIZE); |
29 | close(fd); | 32 | close(fd); |
30 | return bufsize; | 33 | return ret; |
31 | } | 34 | } |
32 | 35 | ||
33 | 36 | ||
@@ -40,7 +43,7 @@ extern procps_status_t * procps_scan(int save_user_arg0) | |||
40 | int n; | 43 | int n; |
41 | char status[32]; | 44 | char status[32]; |
42 | char *status_tail; | 45 | char *status_tail; |
43 | char buf[1024]; | 46 | char buf[PROCPS_BUFSIZE]; |
44 | procps_status_t curstatus; | 47 | procps_status_t curstatus; |
45 | int pid; | 48 | int pid; |
46 | long tasknice; | 49 | long tasknice; |
@@ -71,7 +74,7 @@ extern procps_status_t * procps_scan(int save_user_arg0) | |||
71 | bb_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user)); | 74 | bb_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user)); |
72 | 75 | ||
73 | strcpy(status_tail, "/stat"); | 76 | strcpy(status_tail, "/stat"); |
74 | n = read_to_buf(status, buf, sizeof(buf)); | 77 | n = read_to_buf(status, buf); |
75 | if(n < 0) | 78 | if(n < 0) |
76 | continue; | 79 | continue; |
77 | name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */ | 80 | name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */ |
@@ -125,7 +128,7 @@ extern procps_status_t * procps_scan(int save_user_arg0) | |||
125 | 128 | ||
126 | if(save_user_arg0) { | 129 | if(save_user_arg0) { |
127 | strcpy(status_tail, "/cmdline"); | 130 | strcpy(status_tail, "/cmdline"); |
128 | n = read_to_buf(status, buf, sizeof(buf)); | 131 | n = read_to_buf(status, buf); |
129 | if(n > 0) { | 132 | if(n > 0) { |
130 | if(buf[n-1]=='\n') | 133 | if(buf[n-1]=='\n') |
131 | buf[--n] = 0; | 134 | buf[--n] = 0; |