aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cat.c8
-rw-r--r--coreutils/chroot.c9
-rw-r--r--coreutils/df.c8
-rw-r--r--coreutils/du.c71
-rw-r--r--coreutils/ln.c8
-rw-r--r--coreutils/sort.c28
6 files changed, 63 insertions, 69 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 86f85fe8e..58a1b0f54 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -59,3 +59,11 @@ extern int cat_main(int argc, char **argv)
59 } 59 }
60 exit(TRUE); 60 exit(TRUE);
61} 61}
62
63/*
64Local Variables:
65c-file-style: "linux"
66c-basic-offset: 4
67tab-width: 4
68End:
69*/
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index 6a01be603..3622c26dc 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -65,3 +65,12 @@ int chroot_main(int argc, char **argv)
65 *argv, strerror(errno)); 65 *argv, strerror(errno));
66 exit(FALSE); 66 exit(FALSE);
67} 67}
68
69
70/*
71Local Variables:
72c-file-style: "linux"
73c-basic-offset: 4
74tab-width: 4
75End:
76*/
diff --git a/coreutils/df.c b/coreutils/df.c
index 43d5d26e7..bc843f7a2 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -108,3 +108,11 @@ extern int df_main(int argc, char **argv)
108 108
109 exit(TRUE); 109 exit(TRUE);
110} 110}
111
112/*
113Local Variables:
114c-file-style: "linux"
115c-basic-offset: 4
116tab-width: 4
117End:
118*/
diff --git a/coreutils/du.c b/coreutils/du.c
index 4dc7ea13a..b6ebaca7a 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -36,16 +36,6 @@
36 36
37typedef void (Display) (long, char *); 37typedef void (Display) (long, char *);
38 38
39typedef struct inode_type {
40 struct inode_type *next;
41 ino_t ino;
42} INODETYPE;
43
44#define HASH_SIZE 311 /* Should be prime */
45#define hash_inode(i) ((i) % HASH_SIZE)
46
47static INODETYPE *inode_hash_list[HASH_SIZE];
48
49static const char du_usage[] = 39static const char du_usage[] =
50 "du [OPTION]... [FILE]...\n\n" 40 "du [OPTION]... [FILE]...\n\n"
51 "Summarize disk space used for each FILE and/or directory.\n" 41 "Summarize disk space used for each FILE and/or directory.\n"
@@ -71,52 +61,6 @@ static void print_summary(long size, char *filename)
71 } 61 }
72} 62}
73 63
74/* Return 1 if inode is in inode hash list, else return 0 */
75static int is_in_list(const ino_t ino)
76{
77 INODETYPE *inode;
78
79 inode = inode_hash_list[hash_inode(ino)];
80 while (inode != NULL) {
81 if (inode->ino == ino)
82 return 1;
83 inode = inode->next;
84 }
85
86 return 0;
87}
88
89/* Add inode to inode hash list */
90static void add_inode(const ino_t ino)
91{
92 int i;
93 INODETYPE *inode;
94
95 i = hash_inode(ino);
96 inode = malloc(sizeof(INODETYPE));
97 if (inode == NULL)
98 fatalError("du: Not enough memory.");
99
100 inode->ino = ino;
101 inode->next = inode_hash_list[i];
102 inode_hash_list[i] = inode;
103}
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
120/* tiny recursive du */ 64/* tiny recursive du */
121static long du(char *filename) 65static long du(char *filename)
122{ 66{
@@ -175,13 +119,13 @@ static long du(char *filename)
175 } 119 }
176 else if (statbuf.st_nlink > 1 && !count_hardlinks) { 120 else if (statbuf.st_nlink > 1 && !count_hardlinks) {
177 /* Add files with hard links only once */ 121 /* Add files with hard links only once */
178 if (is_in_list(statbuf.st_ino)) { 122 if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
179 sum = 0L; 123 sum = 0L;
180 if (du_depth == 1) 124 if (du_depth == 1)
181 print(sum, filename); 125 print(sum, filename);
182 } 126 }
183 else { 127 else {
184 add_inode(statbuf.st_ino); 128 add_to_ino_dev_hashtable(&statbuf, NULL);
185 } 129 }
186 } 130 }
187 du_depth--; 131 du_depth--;
@@ -231,11 +175,18 @@ int du_main(int argc, char **argv)
231 if (sum && isDirectory(argv[i], FALSE, NULL)) { 175 if (sum && isDirectory(argv[i], FALSE, NULL)) {
232 print_normal(sum, argv[i]); 176 print_normal(sum, argv[i]);
233 } 177 }
234 reset_inode_list(); 178 reset_ino_dev_hashtable();
235 } 179 }
236 } 180 }
237 181
238 exit(0); 182 exit(0);
239} 183}
240 184
241/* $Id: du.c,v 1.15 2000/02/21 17:27:17 erik Exp $ */ 185/* $Id: du.c,v 1.16 2000/03/04 21:19:32 erik Exp $ */
186/*
187Local Variables:
188c-file-style: "linux"
189c-basic-offset: 4
190tab-width: 4
191End:
192*/
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 0715bfaed..c54026c62 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -128,3 +128,11 @@ extern int ln_main(int argc, char **argv)
128 } 128 }
129 exit TRUE; 129 exit TRUE;
130} 130}
131
132/*
133Local Variables:
134c-file-style: "linux"
135c-basic-offset: 4
136tab-width: 4
137End:
138*/
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 609c5e08c..e6894f6c3 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -29,7 +29,18 @@
29#include <stdio.h> 29#include <stdio.h>
30#include <errno.h> 30#include <errno.h>
31 31
32static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n"; 32static const char sort_usage[] = "sort [-n]"
33#ifdef BB_FEATURE_SORT_REVERSE
34" [-r]"
35#endif
36" [FILE]...\n\n";
37
38#ifdef BB_FEATURE_SORT_REVERSE
39#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
40static int reverse = 0;
41#else
42#define APPLY_REVERSE(x) (x)
43#endif
33 44
34/* typedefs _______________________________________________________________ */ 45/* typedefs _______________________________________________________________ */
35 46
@@ -120,7 +131,7 @@ static int compare_ascii(const void *a, const void *b)
120 y = *doh; 131 y = *doh;
121 132
122 // fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data); 133 // fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
123 return strcmp(x->data, y->data); 134 return APPLY_REVERSE(strcmp(x->data, y->data));
124} 135}
125 136
126/* numeric order */ 137/* numeric order */
@@ -138,7 +149,7 @@ static int compare_numeric(const void *a, const void *b)
138 xint = strtoul(x->data, NULL, 10); 149 xint = strtoul(x->data, NULL, 10);
139 yint = strtoul(y->data, NULL, 10); 150 yint = strtoul(y->data, NULL, 10);
140 151
141 return (xint - yint); 152 return APPLY_REVERSE(xint - yint);
142} 153}
143 154
144 155
@@ -254,20 +265,19 @@ int sort_main(int argc, char **argv)
254 if (argv[i][0] == '-') { 265 if (argv[i][0] == '-') {
255 opt = argv[i][1]; 266 opt = argv[i][1];
256 switch (opt) { 267 switch (opt) {
257 case 'g':
258 /* what's the diff between -g && -n? */
259 compare = compare_numeric;
260 break;
261 case 'h': 268 case 'h':
262 usage(sort_usage); 269 usage(sort_usage);
263 break; 270 break;
264 case 'n': 271 case 'n':
265 /* what's the diff between -g && -n? */ 272 /* numeric comparison */
266 compare = compare_numeric; 273 compare = compare_numeric;
267 break; 274 break;
275#ifdef BB_FEATURE_SORT_REVERSE
268 case 'r': 276 case 'r':
269 /* reverse */ 277 /* reverse */
278 reverse = 1;
270 break; 279 break;
280#endif
271 default: 281 default:
272 fprintf(stderr, "sort: invalid option -- %c\n", opt); 282 fprintf(stderr, "sort: invalid option -- %c\n", opt);
273 usage(sort_usage); 283 usage(sort_usage);
@@ -310,4 +320,4 @@ int sort_main(int argc, char **argv)
310 exit(0); 320 exit(0);
311} 321}
312 322
313/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */ 323/* $Id: sort.c,v 1.12 2000/03/04 21:19:32 erik Exp $ */