diff options
author | John Beppu <beppu@lbox.org> | 1999-12-09 18:23:54 +0000 |
---|---|---|
committer | John Beppu <beppu@lbox.org> | 1999-12-09 18:23:54 +0000 |
commit | 0f5e1ab949193ee7b6228bc66730da9d573464eb (patch) | |
tree | 10e4f7602ba51714d7a85c9afbc65075aebd1cac | |
parent | f0758dd6ba19f6039b6fed7da4ca2844b8c1032d (diff) | |
download | busybox-w32-0f5e1ab949193ee7b6228bc66730da9d573464eb.tar.gz busybox-w32-0f5e1ab949193ee7b6228bc66730da9d573464eb.tar.bz2 busybox-w32-0f5e1ab949193ee7b6228bc66730da9d573464eb.zip |
This is my preliminary
du implementation. It
was written from scratch
(doesn't use recursiveAction).
I still need to flesh out
du_main().
-rw-r--r-- | coreutils/du.c | 83 | ||||
-rw-r--r-- | du.c | 83 |
2 files changed, 166 insertions, 0 deletions
diff --git a/coreutils/du.c b/coreutils/du.c new file mode 100644 index 000000000..9e4e11473 --- /dev/null +++ b/coreutils/du.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * Mini du implementation for busybox | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 1999 by Lineo, inc. | ||
6 | * Written by John Beppu <beppu@line.com> | ||
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 <sys/types.h> | ||
26 | #include <fcntl.h> | ||
27 | #include <dirent.h> | ||
28 | #include <stdio.h> | ||
29 | /* | ||
30 | #include <unistd.h> | ||
31 | #include <sys/stat.h> | ||
32 | */ | ||
33 | |||
34 | |||
35 | typedef void (Display)(size_t, char *); | ||
36 | |||
37 | static void | ||
38 | print(size_t size, char *filename) | ||
39 | { | ||
40 | fprintf(stdout, "%-7d %s\n", (size >> 1), filename); | ||
41 | } | ||
42 | |||
43 | /* tiny recursive du */ | ||
44 | static size_t | ||
45 | size(char *filename) | ||
46 | { | ||
47 | struct stat statbuf; | ||
48 | size_t sum; | ||
49 | |||
50 | if ((lstat(filename, &statbuf)) != 0) { return 0; } | ||
51 | sum = statbuf.st_blocks; | ||
52 | |||
53 | if (S_ISDIR(statbuf.st_mode)) { | ||
54 | DIR *dir; | ||
55 | struct dirent *entry; | ||
56 | |||
57 | dir = opendir(filename); | ||
58 | if (!dir) { return 0; } | ||
59 | while ((entry = readdir(dir))) { | ||
60 | char newfile[512]; | ||
61 | char *name = entry->d_name; | ||
62 | |||
63 | if ( (strcmp(name, "..") == 0) | ||
64 | || (strcmp(name, ".") == 0)) | ||
65 | { continue; } | ||
66 | |||
67 | sprintf(newfile, "%s/%s", filename, name); | ||
68 | sum += size(newfile); | ||
69 | } | ||
70 | closedir(dir); | ||
71 | print(sum, filename); | ||
72 | } | ||
73 | return sum; | ||
74 | } | ||
75 | |||
76 | int | ||
77 | du_main(int argc, char **argv) | ||
78 | { | ||
79 | /* I'll fill main() in shortly */ | ||
80 | size("."); | ||
81 | exit(0); | ||
82 | } | ||
83 | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * Mini du implementation for busybox | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 1999 by Lineo, inc. | ||
6 | * Written by John Beppu <beppu@line.com> | ||
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 <sys/types.h> | ||
26 | #include <fcntl.h> | ||
27 | #include <dirent.h> | ||
28 | #include <stdio.h> | ||
29 | /* | ||
30 | #include <unistd.h> | ||
31 | #include <sys/stat.h> | ||
32 | */ | ||
33 | |||
34 | |||
35 | typedef void (Display)(size_t, char *); | ||
36 | |||
37 | static void | ||
38 | print(size_t size, char *filename) | ||
39 | { | ||
40 | fprintf(stdout, "%-7d %s\n", (size >> 1), filename); | ||
41 | } | ||
42 | |||
43 | /* tiny recursive du */ | ||
44 | static size_t | ||
45 | size(char *filename) | ||
46 | { | ||
47 | struct stat statbuf; | ||
48 | size_t sum; | ||
49 | |||
50 | if ((lstat(filename, &statbuf)) != 0) { return 0; } | ||
51 | sum = statbuf.st_blocks; | ||
52 | |||
53 | if (S_ISDIR(statbuf.st_mode)) { | ||
54 | DIR *dir; | ||
55 | struct dirent *entry; | ||
56 | |||
57 | dir = opendir(filename); | ||
58 | if (!dir) { return 0; } | ||
59 | while ((entry = readdir(dir))) { | ||
60 | char newfile[512]; | ||
61 | char *name = entry->d_name; | ||
62 | |||
63 | if ( (strcmp(name, "..") == 0) | ||
64 | || (strcmp(name, ".") == 0)) | ||
65 | { continue; } | ||
66 | |||
67 | sprintf(newfile, "%s/%s", filename, name); | ||
68 | sum += size(newfile); | ||
69 | } | ||
70 | closedir(dir); | ||
71 | print(sum, filename); | ||
72 | } | ||
73 | return sum; | ||
74 | } | ||
75 | |||
76 | int | ||
77 | du_main(int argc, char **argv) | ||
78 | { | ||
79 | /* I'll fill main() in shortly */ | ||
80 | size("."); | ||
81 | exit(0); | ||
82 | } | ||
83 | |||