aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-21 17:27:17 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-21 17:27:17 +0000
commit42387e496463f6dbba168b5d36807b858f94fa96 (patch)
tree9958d84e73c0f497e80a110a56d7dca1b41d0565
parent27fdd081efa060edf7467c43d76071f1c960d228 (diff)
downloadbusybox-w32-42387e496463f6dbba168b5d36807b858f94fa96.tar.gz
busybox-w32-42387e496463f6dbba168b5d36807b858f94fa96.tar.bz2
busybox-w32-42387e496463f6dbba168b5d36807b858f94fa96.zip
Forgot to add basename. More fixes to du from
Friedrich Vedder <fwv@myrtle.lahn.de>. -Erik
-rw-r--r--Changelog8
-rw-r--r--basename.c40
-rw-r--r--coreutils/basename.c40
-rw-r--r--coreutils/du.c47
-rw-r--r--du.c47
5 files changed, 162 insertions, 20 deletions
diff --git a/Changelog b/Changelog
index a0cc13aa3..ffdca37ec 100644
--- a/Changelog
+++ b/Changelog
@@ -1,15 +1,15 @@
10.43 10.43
2 * Wrote basename 2 * Wrote basename.
3 * tar wouldn't create directory entries that don't end in '/', 3 * tar wouldn't create directory entries that don't end in '/',
4 now it does (fix thanks to Avery Pennarun <apenwarr@worldvisions.ca>) 4 now it does (thanks to Avery Pennarun <apenwarr@worldvisions.ca>)
5 * Several fixes from Pavel Roskin <pavel_roskin@geocities.com>: 5 * Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
6 - When `tail' fails to open a file it now exits. 6 - When `tail' fails to open a file it now exits.
7 - When `syslogd' is given the `-n' option it should still use 7 - When `syslogd' is given the `-n' option it should still use
8 fork() for running klogd. 8 fork() for running klogd.
9 * nslookup types are now changed to u_int32_t (instead of uint32_t) 9 * nslookup types are now changed to u_int32_t (instead of uint32_t)
10 changed per a patch from Pascal Bellard <pascal.bellard@ascend.com> 10 changed per a patch from Pascal Bellard <pascal.bellard@ascend.com>
11 * Fixed "du" so it gives the same answers as GNU "du" (busybox du used to 11 * Fixed "du" so it gives the same answers as GNU "du" (busybox du used
12 count hard-linked files more then once). Many thanks to 12 to count hard-linked files more then once). Many thanks to
13 Friedrich Vedder <fwv@myrtle.lahn.de> for the fix. 13 Friedrich Vedder <fwv@myrtle.lahn.de> for the fix.
14 14
15 -Erik Andersen 15 -Erik Andersen
diff --git a/basename.c b/basename.c
new file mode 100644
index 000000000..1db885f62
--- /dev/null
+++ b/basename.c
@@ -0,0 +1,40 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini basename implementation for busybox
4 *
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include "internal.h"
25#include <stdio.h>
26
27extern int basename_main(int argc, char **argv)
28{
29 char* s;
30
31 if ((argc < 2) || (**(argv + 1) == '-')) {
32 usage("basename [file ...]\n");
33 }
34 argv++;
35
36 s = strrchr(*argv, '/');
37 printf("%s\n", (s)? s + 1 : *argv);
38 exit(TRUE);
39}
40
diff --git a/coreutils/basename.c b/coreutils/basename.c
new file mode 100644
index 000000000..1db885f62
--- /dev/null
+++ b/coreutils/basename.c
@@ -0,0 +1,40 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini basename implementation for busybox
4 *
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include "internal.h"
25#include <stdio.h>
26
27extern int basename_main(int argc, char **argv)
28{
29 char* s;
30
31 if ((argc < 2) || (**(argv + 1) == '-')) {
32 usage("basename [file ...]\n");
33 }
34 argv++;
35
36 s = strrchr(*argv, '/');
37 printf("%s\n", (s)? s + 1 : *argv);
38 exit(TRUE);
39}
40
diff --git a/coreutils/du.c b/coreutils/du.c
index 02d1d9737..4dc7ea13a 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -102,14 +102,30 @@ static void add_inode(const ino_t ino)
102 inode_hash_list[i] = inode; 102 inode_hash_list[i] = inode;
103} 103}
104 104
105/* Clear inode hash list */
106static void reset_inode_list(void)
107{
108 int i;
109 INODETYPE *inode;
110
111 for (i = 0; i < HASH_SIZE; i++) {
112 while (inode_hash_list[i] != NULL) {
113 inode = inode_hash_list[i]->next;
114 free(inode_hash_list[i]);
115 inode_hash_list[i] = inode;
116 }
117 }
118}
119
105/* tiny recursive du */ 120/* tiny recursive du */
106static long du(char *filename) 121static long du(char *filename)
107{ 122{
108 struct stat statbuf; 123 struct stat statbuf;
109 long sum; 124 long sum;
125 int len;
110 126
111 if ((lstat(filename, &statbuf)) != 0) { 127 if ((lstat(filename, &statbuf)) != 0) {
112 fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); 128 printf("du: %s: %s\n", filename, strerror(errno));
113 return 0; 129 return 0;
114 } 130 }
115 131
@@ -118,7 +134,9 @@ static long du(char *filename)
118 134
119 /* Don't add in stuff pointed to by symbolic links */ 135 /* Don't add in stuff pointed to by symbolic links */
120 if (S_ISLNK(statbuf.st_mode)) { 136 if (S_ISLNK(statbuf.st_mode)) {
121 return 0; 137 sum = 0L;
138 if (du_depth == 1)
139 print(sum, filename);
122 } 140 }
123 if (S_ISDIR(statbuf.st_mode)) { 141 if (S_ISDIR(statbuf.st_mode)) {
124 DIR *dir; 142 DIR *dir;
@@ -126,8 +144,14 @@ static long du(char *filename)
126 144
127 dir = opendir(filename); 145 dir = opendir(filename);
128 if (!dir) { 146 if (!dir) {
147 du_depth--;
129 return 0; 148 return 0;
130 } 149 }
150
151 len = strlen(filename);
152 if (filename[len - 1] == '/')
153 filename[--len] = '\0';
154
131 while ((entry = readdir(dir))) { 155 while ((entry = readdir(dir))) {
132 char newfile[PATH_MAX + 1]; 156 char newfile[PATH_MAX + 1];
133 char *name = entry->d_name; 157 char *name = entry->d_name;
@@ -137,8 +161,9 @@ static long du(char *filename)
137 continue; 161 continue;
138 } 162 }
139 163
140 if (strlen(filename) + strlen(name) + 1 > PATH_MAX) { 164 if (len + strlen(name) + 1 > PATH_MAX) {
141 fprintf(stderr, name_too_long, "du"); 165 fprintf(stderr, name_too_long, "du");
166 du_depth--;
142 return 0; 167 return 0;
143 } 168 }
144 sprintf(newfile, "%s/%s", filename, name); 169 sprintf(newfile, "%s/%s", filename, name);
@@ -150,9 +175,14 @@ static long du(char *filename)
150 } 175 }
151 else if (statbuf.st_nlink > 1 && !count_hardlinks) { 176 else if (statbuf.st_nlink > 1 && !count_hardlinks) {
152 /* Add files with hard links only once */ 177 /* Add files with hard links only once */
153 if (is_in_list(statbuf.st_ino)) 178 if (is_in_list(statbuf.st_ino)) {
154 return 0; 179 sum = 0L;
155 add_inode(statbuf.st_ino); 180 if (du_depth == 1)
181 print(sum, filename);
182 }
183 else {
184 add_inode(statbuf.st_ino);
185 }
156 } 186 }
157 du_depth--; 187 du_depth--;
158 return sum; 188 return sum;
@@ -198,13 +228,14 @@ int du_main(int argc, char **argv)
198 228
199 for (; i < argc; i++) { 229 for (; i < argc; i++) {
200 sum = du(argv[i]); 230 sum = du(argv[i]);
201 if ((sum) && (isDirectory(argv[i], FALSE, NULL))) { 231 if (sum && isDirectory(argv[i], FALSE, NULL)) {
202 print_normal(sum, argv[i]); 232 print_normal(sum, argv[i]);
203 } 233 }
234 reset_inode_list();
204 } 235 }
205 } 236 }
206 237
207 exit(0); 238 exit(0);
208} 239}
209 240
210/* $Id: du.c,v 1.14 2000/02/19 18:16:49 erik Exp $ */ 241/* $Id: du.c,v 1.15 2000/02/21 17:27:17 erik Exp $ */
diff --git a/du.c b/du.c
index 02d1d9737..4dc7ea13a 100644
--- a/du.c
+++ b/du.c
@@ -102,14 +102,30 @@ static void add_inode(const ino_t ino)
102 inode_hash_list[i] = inode; 102 inode_hash_list[i] = inode;
103} 103}
104 104
105/* Clear inode hash list */
106static void reset_inode_list(void)
107{
108 int i;
109 INODETYPE *inode;
110
111 for (i = 0; i < HASH_SIZE; i++) {
112 while (inode_hash_list[i] != NULL) {
113 inode = inode_hash_list[i]->next;
114 free(inode_hash_list[i]);
115 inode_hash_list[i] = inode;
116 }
117 }
118}
119
105/* tiny recursive du */ 120/* tiny recursive du */
106static long du(char *filename) 121static long du(char *filename)
107{ 122{
108 struct stat statbuf; 123 struct stat statbuf;
109 long sum; 124 long sum;
125 int len;
110 126
111 if ((lstat(filename, &statbuf)) != 0) { 127 if ((lstat(filename, &statbuf)) != 0) {
112 fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); 128 printf("du: %s: %s\n", filename, strerror(errno));
113 return 0; 129 return 0;
114 } 130 }
115 131
@@ -118,7 +134,9 @@ static long du(char *filename)
118 134
119 /* Don't add in stuff pointed to by symbolic links */ 135 /* Don't add in stuff pointed to by symbolic links */
120 if (S_ISLNK(statbuf.st_mode)) { 136 if (S_ISLNK(statbuf.st_mode)) {
121 return 0; 137 sum = 0L;
138 if (du_depth == 1)
139 print(sum, filename);
122 } 140 }
123 if (S_ISDIR(statbuf.st_mode)) { 141 if (S_ISDIR(statbuf.st_mode)) {
124 DIR *dir; 142 DIR *dir;
@@ -126,8 +144,14 @@ static long du(char *filename)
126 144
127 dir = opendir(filename); 145 dir = opendir(filename);
128 if (!dir) { 146 if (!dir) {
147 du_depth--;
129 return 0; 148 return 0;
130 } 149 }
150
151 len = strlen(filename);
152 if (filename[len - 1] == '/')
153 filename[--len] = '\0';
154
131 while ((entry = readdir(dir))) { 155 while ((entry = readdir(dir))) {
132 char newfile[PATH_MAX + 1]; 156 char newfile[PATH_MAX + 1];
133 char *name = entry->d_name; 157 char *name = entry->d_name;
@@ -137,8 +161,9 @@ static long du(char *filename)
137 continue; 161 continue;
138 } 162 }
139 163
140 if (strlen(filename) + strlen(name) + 1 > PATH_MAX) { 164 if (len + strlen(name) + 1 > PATH_MAX) {
141 fprintf(stderr, name_too_long, "du"); 165 fprintf(stderr, name_too_long, "du");
166 du_depth--;
142 return 0; 167 return 0;
143 } 168 }
144 sprintf(newfile, "%s/%s", filename, name); 169 sprintf(newfile, "%s/%s", filename, name);
@@ -150,9 +175,14 @@ static long du(char *filename)
150 } 175 }
151 else if (statbuf.st_nlink > 1 && !count_hardlinks) { 176 else if (statbuf.st_nlink > 1 && !count_hardlinks) {
152 /* Add files with hard links only once */ 177 /* Add files with hard links only once */
153 if (is_in_list(statbuf.st_ino)) 178 if (is_in_list(statbuf.st_ino)) {
154 return 0; 179 sum = 0L;
155 add_inode(statbuf.st_ino); 180 if (du_depth == 1)
181 print(sum, filename);
182 }
183 else {
184 add_inode(statbuf.st_ino);
185 }
156 } 186 }
157 du_depth--; 187 du_depth--;
158 return sum; 188 return sum;
@@ -198,13 +228,14 @@ int du_main(int argc, char **argv)
198 228
199 for (; i < argc; i++) { 229 for (; i < argc; i++) {
200 sum = du(argv[i]); 230 sum = du(argv[i]);
201 if ((sum) && (isDirectory(argv[i], FALSE, NULL))) { 231 if (sum && isDirectory(argv[i], FALSE, NULL)) {
202 print_normal(sum, argv[i]); 232 print_normal(sum, argv[i]);
203 } 233 }
234 reset_inode_list();
204 } 235 }
205 } 236 }
206 237
207 exit(0); 238 exit(0);
208} 239}
209 240
210/* $Id: du.c,v 1.14 2000/02/19 18:16:49 erik Exp $ */ 241/* $Id: du.c,v 1.15 2000/02/21 17:27:17 erik Exp $ */