aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-07 22:49:43 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-07 22:49:43 +0000
commit04b0354d8e0b09ed2af80f590e2203137114819b (patch)
tree3459f582185256f84a7aa9c9e9953267f93e8684
parent8f3e51b4adac772957633eaa070bad011f4724ed (diff)
downloadbusybox-w32-04b0354d8e0b09ed2af80f590e2203137114819b.tar.gz
busybox-w32-04b0354d8e0b09ed2af80f590e2203137114819b.tar.bz2
busybox-w32-04b0354d8e0b09ed2af80f590e2203137114819b.zip
Patch from Vladimir to use last_char_is to simplify du.c
-rw-r--r--coreutils/du.c11
-rw-r--r--du.c11
2 files changed, 10 insertions, 12 deletions
diff --git a/coreutils/du.c b/coreutils/du.c
index b618e0760..3e4821a39 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -76,7 +76,6 @@ static long du(char *filename)
76{ 76{
77 struct stat statbuf; 77 struct stat statbuf;
78 long sum; 78 long sum;
79 int len;
80 79
81 if ((lstat(filename, &statbuf)) != 0) { 80 if ((lstat(filename, &statbuf)) != 0) {
82 perror_msg("%s", filename); 81 perror_msg("%s", filename);
@@ -95,6 +94,7 @@ static long du(char *filename)
95 if (S_ISDIR(statbuf.st_mode)) { 94 if (S_ISDIR(statbuf.st_mode)) {
96 DIR *dir; 95 DIR *dir;
97 struct dirent *entry; 96 struct dirent *entry;
97 char *newfile;
98 98
99 dir = opendir(filename); 99 dir = opendir(filename);
100 if (!dir) { 100 if (!dir) {
@@ -102,12 +102,11 @@ static long du(char *filename)
102 return 0; 102 return 0;
103 } 103 }
104 104
105 len = strlen(filename); 105 newfile = last_char_is(filename, '/');
106 if (filename[len - 1] == '/') 106 if (newfile)
107 filename[--len] = '\0'; 107 *newfile = '\0';
108 108
109 while ((entry = readdir(dir))) { 109 while ((entry = readdir(dir))) {
110 char *newfile;
111 char *name = entry->d_name; 110 char *name = entry->d_name;
112 111
113 if ((strcmp(name, "..") == 0) 112 if ((strcmp(name, "..") == 0)
@@ -188,7 +187,7 @@ int du_main(int argc, char **argv)
188 return status; 187 return status;
189} 188}
190 189
191/* $Id: du.c,v 1.46 2001/05/03 04:45:40 kraai Exp $ */ 190/* $Id: du.c,v 1.47 2001/05/07 22:49:43 andersen Exp $ */
192/* 191/*
193Local Variables: 192Local Variables:
194c-file-style: "linux" 193c-file-style: "linux"
diff --git a/du.c b/du.c
index b618e0760..3e4821a39 100644
--- a/du.c
+++ b/du.c
@@ -76,7 +76,6 @@ static long du(char *filename)
76{ 76{
77 struct stat statbuf; 77 struct stat statbuf;
78 long sum; 78 long sum;
79 int len;
80 79
81 if ((lstat(filename, &statbuf)) != 0) { 80 if ((lstat(filename, &statbuf)) != 0) {
82 perror_msg("%s", filename); 81 perror_msg("%s", filename);
@@ -95,6 +94,7 @@ static long du(char *filename)
95 if (S_ISDIR(statbuf.st_mode)) { 94 if (S_ISDIR(statbuf.st_mode)) {
96 DIR *dir; 95 DIR *dir;
97 struct dirent *entry; 96 struct dirent *entry;
97 char *newfile;
98 98
99 dir = opendir(filename); 99 dir = opendir(filename);
100 if (!dir) { 100 if (!dir) {
@@ -102,12 +102,11 @@ static long du(char *filename)
102 return 0; 102 return 0;
103 } 103 }
104 104
105 len = strlen(filename); 105 newfile = last_char_is(filename, '/');
106 if (filename[len - 1] == '/') 106 if (newfile)
107 filename[--len] = '\0'; 107 *newfile = '\0';
108 108
109 while ((entry = readdir(dir))) { 109 while ((entry = readdir(dir))) {
110 char *newfile;
111 char *name = entry->d_name; 110 char *name = entry->d_name;
112 111
113 if ((strcmp(name, "..") == 0) 112 if ((strcmp(name, "..") == 0)
@@ -188,7 +187,7 @@ int du_main(int argc, char **argv)
188 return status; 187 return status;
189} 188}
190 189
191/* $Id: du.c,v 1.46 2001/05/03 04:45:40 kraai Exp $ */ 190/* $Id: du.c,v 1.47 2001/05/07 22:49:43 andersen Exp $ */
192/* 191/*
193Local Variables: 192Local Variables:
194c-file-style: "linux" 193c-file-style: "linux"