diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cp.c | 127 | ||||
-rw-r--r-- | coreutils/date.c | 17 | ||||
-rw-r--r-- | coreutils/dd.c | 37 | ||||
-rw-r--r-- | coreutils/du.c | 34 | ||||
-rw-r--r-- | coreutils/head.c | 2 | ||||
-rw-r--r-- | coreutils/length.c | 2 | ||||
-rw-r--r-- | coreutils/ln.c | 79 | ||||
-rw-r--r-- | coreutils/ls.c | 2 | ||||
-rw-r--r-- | coreutils/mkdir.c | 34 | ||||
-rw-r--r-- | coreutils/mv.c | 112 | ||||
-rw-r--r-- | coreutils/printf.c | 2 | ||||
-rw-r--r-- | coreutils/pwd.c | 3 | ||||
-rw-r--r-- | coreutils/sort.c | 2 | ||||
-rw-r--r-- | coreutils/tail.c | 2 | ||||
-rw-r--r-- | coreutils/tee.c | 2 | ||||
-rw-r--r-- | coreutils/uniq.c | 2 |
16 files changed, 139 insertions, 320 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c deleted file mode 100644 index e96012d50..000000000 --- a/coreutils/cp.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* | ||
2 | * Mini cp implementation for busybox | ||
3 | * | ||
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 | #include <time.h> | ||
27 | #include <utime.h> | ||
28 | #include <dirent.h> | ||
29 | |||
30 | static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n" | ||
31 | " or: cp [OPTION]... SOURCE... DIRECTORY\n\n" | ||
32 | "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n" | ||
33 | "\n" | ||
34 | "\t-a\tsame as -dpR\n" | ||
35 | "\t-d\tpreserve links\n" | ||
36 | "\t-p\tpreserve file attributes if possible\n" | ||
37 | "\t-R\tcopy directories recursively\n"; | ||
38 | |||
39 | |||
40 | static int recursiveFlag = FALSE; | ||
41 | static int followLinks = FALSE; | ||
42 | static int preserveFlag = FALSE; | ||
43 | static const char *srcName; | ||
44 | static const char *destName; | ||
45 | static int destDirFlag = FALSE; | ||
46 | static int srcDirFlag = FALSE; | ||
47 | |||
48 | static int fileAction(const char *fileName, struct stat* statbuf) | ||
49 | { | ||
50 | char newdestName[NAME_MAX]; | ||
51 | char* newsrcName = NULL; | ||
52 | |||
53 | strcpy(newdestName, destName); | ||
54 | if ( srcDirFlag == TRUE ) { | ||
55 | if (recursiveFlag!=TRUE ) { | ||
56 | fprintf(stderr, "cp: %s: omitting directory\n", srcName); | ||
57 | return( TRUE); | ||
58 | } | ||
59 | strcat(newdestName, strstr(fileName, srcName) + strlen(srcName)); | ||
60 | } | ||
61 | |||
62 | if (destDirFlag==TRUE && srcDirFlag == FALSE) { | ||
63 | if (newdestName[strlen(newdestName)-1] != '/' ) { | ||
64 | strcat(newdestName, "/"); | ||
65 | } | ||
66 | newsrcName = strrchr(srcName, '/'); | ||
67 | if (newsrcName && *newsrcName != '\0') | ||
68 | strcat(newdestName, newsrcName); | ||
69 | else | ||
70 | strcat(newdestName, srcName); | ||
71 | } | ||
72 | |||
73 | return (copyFile(fileName, newdestName, preserveFlag, followLinks)); | ||
74 | } | ||
75 | |||
76 | extern int cp_main(int argc, char **argv) | ||
77 | { | ||
78 | if (argc < 3) { | ||
79 | usage (cp_usage); | ||
80 | } | ||
81 | argc--; | ||
82 | argv++; | ||
83 | |||
84 | /* Parse any options */ | ||
85 | while (**argv == '-') { | ||
86 | while (*++(*argv)) | ||
87 | switch (**argv) { | ||
88 | case 'a': | ||
89 | followLinks = TRUE; | ||
90 | preserveFlag = TRUE; | ||
91 | recursiveFlag = TRUE; | ||
92 | break; | ||
93 | case 'd': | ||
94 | followLinks = TRUE; | ||
95 | break; | ||
96 | case 'p': | ||
97 | preserveFlag = TRUE; | ||
98 | break; | ||
99 | case 'R': | ||
100 | recursiveFlag = TRUE; | ||
101 | break; | ||
102 | default: | ||
103 | usage (cp_usage); | ||
104 | } | ||
105 | argc--; | ||
106 | argv++; | ||
107 | } | ||
108 | |||
109 | |||
110 | destName = argv[argc - 1]; | ||
111 | destDirFlag = isDirectory(destName); | ||
112 | |||
113 | if ((argc > 3) && destDirFlag==FALSE) { | ||
114 | fprintf(stderr, "%s: not a directory\n", destName); | ||
115 | exit (FALSE); | ||
116 | } | ||
117 | |||
118 | while (argc-- > 1) { | ||
119 | srcName = *(argv++); | ||
120 | srcDirFlag = isDirectory(srcName); | ||
121 | if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE, | ||
122 | fileAction, fileAction) == FALSE) { | ||
123 | exit( FALSE); | ||
124 | } | ||
125 | } | ||
126 | exit( TRUE); | ||
127 | } | ||
diff --git a/coreutils/date.c b/coreutils/date.c index 77e7c39db..a3528921d 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -20,6 +20,10 @@ | |||
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include "internal.h" | 22 | #include "internal.h" |
23 | #define BB_DECLARE_EXTERN | ||
24 | #define bb_need_invalid_date | ||
25 | #define bb_need_memory_exhausted | ||
26 | #include "messages.c" | ||
23 | #include <stdlib.h> | 27 | #include <stdlib.h> |
24 | #include <errno.h> | 28 | #include <errno.h> |
25 | #include <sys/time.h> | 29 | #include <sys/time.h> |
@@ -59,7 +63,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) { | |||
59 | &(tm_time->tm_year)); | 63 | &(tm_time->tm_year)); |
60 | 64 | ||
61 | if(nr < 4 || nr > 5) { | 65 | if(nr < 4 || nr > 5) { |
62 | fprintf(stderr, "date: invalid date `%s'\n", t_string); | 66 | fprintf(stderr, invalid_date, "date", t_string); |
63 | exit( FALSE); | 67 | exit( FALSE); |
64 | } | 68 | } |
65 | 69 | ||
@@ -152,7 +156,7 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) { | |||
152 | 156 | ||
153 | } | 157 | } |
154 | 158 | ||
155 | fprintf(stderr, "date: invalid date `%s'\n", t_string); | 159 | fprintf(stderr, invalid_date, "date", t_string); |
156 | 160 | ||
157 | exit( FALSE); | 161 | exit( FALSE); |
158 | 162 | ||
@@ -190,7 +194,7 @@ date_main(int argc, char * * argv) | |||
190 | case 'u': | 194 | case 'u': |
191 | utc = 1; | 195 | utc = 1; |
192 | if (putenv ("TZ=UTC0") != 0) { | 196 | if (putenv ("TZ=UTC0") != 0) { |
193 | fprintf(stderr,"date: memory exhausted\n"); | 197 | fprintf(stderr, memory_exhausted, "date"); |
194 | exit( FALSE); | 198 | exit( FALSE); |
195 | } | 199 | } |
196 | /* Look ma, no break. Don't fix it either. */ | 200 | /* Look ma, no break. Don't fix it either. */ |
@@ -204,10 +208,10 @@ date_main(int argc, char * * argv) | |||
204 | } | 208 | } |
205 | } else { | 209 | } else { |
206 | if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) ) | 210 | if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) ) |
207 | date_fmt = *argv; | 211 | date_fmt=*argv; |
208 | else if (date_str == NULL) { | 212 | else if (date_str == NULL) { |
209 | set_time = 1; | 213 | set_time = 1; |
210 | date_str = *argv; | 214 | date_str=*argv; |
211 | } else { | 215 | } else { |
212 | usage ( date_usage); | 216 | usage ( date_usage); |
213 | } | 217 | } |
@@ -241,7 +245,7 @@ date_main(int argc, char * * argv) | |||
241 | /* Correct any day of week and day of year etc fields */ | 245 | /* Correct any day of week and day of year etc fields */ |
242 | tm = mktime(&tm_time); | 246 | tm = mktime(&tm_time); |
243 | if (tm < 0 ) { | 247 | if (tm < 0 ) { |
244 | fprintf(stderr, "date: invalid date `%s'\n", date_str); | 248 | fprintf(stderr, invalid_date, "date", date_str); |
245 | exit( FALSE); | 249 | exit( FALSE); |
246 | } | 250 | } |
247 | 251 | ||
@@ -284,4 +288,3 @@ date_main(int argc, char * * argv) | |||
284 | exit( TRUE); | 288 | exit( TRUE); |
285 | 289 | ||
286 | } | 290 | } |
287 | |||
diff --git a/coreutils/dd.c b/coreutils/dd.c index bc01eedbf..3e1024a60 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -40,15 +40,16 @@ typedef unsigned long long int uintmax_t; | |||
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | static const char dd_usage[] = | 42 | static const char dd_usage[] = |
43 | "dd [if=name] [of=name] [bs=n] [count=n]\n\n" | 43 | "dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n" |
44 | "Copy a file, converting and formatting according to options\n\n" | 44 | "Copy a file, converting and formatting according to options\n\n" |
45 | "\tif=FILE\tread from FILE instead of stdin\n" | 45 | "\tif=FILE\tread from FILE instead of stdin\n" |
46 | "\tof=FILE\twrite to FILE instead of stout\n" | 46 | "\tof=FILE\twrite to FILE instead of stdout\n" |
47 | "\tbs=n\tread and write N BYTES at a time\n" | 47 | "\tbs=n\tread and write n bytes at a time\n" |
48 | "\tcount=n\tcopy only n input blocks\n" | 48 | "\tcount=n\tcopy only n input blocks\n" |
49 | //"\tskip=n\tskip n input blocks\n" | 49 | "\tskip=n\tskip n input blocks\n" |
50 | "\tseek=n\tskip n output blocks\n" | ||
50 | "\n" | 51 | "\n" |
51 | "BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n"; | 52 | "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"; |
52 | 53 | ||
53 | 54 | ||
54 | 55 | ||
@@ -61,8 +62,9 @@ extern int dd_main (int argc, char **argv) | |||
61 | int outFd; | 62 | int outFd; |
62 | int inCc = 0; | 63 | int inCc = 0; |
63 | int outCc; | 64 | int outCc; |
64 | size_t blockSize = 512; | 65 | long blockSize = 512; |
65 | //uintmax_t skipBlocks = 0; | 66 | uintmax_t skipBlocks = 0; |
67 | uintmax_t seekBlocks = 0; | ||
66 | uintmax_t count = (uintmax_t)-1; | 68 | uintmax_t count = (uintmax_t)-1; |
67 | uintmax_t intotal; | 69 | uintmax_t intotal; |
68 | uintmax_t outTotal; | 70 | uintmax_t outTotal; |
@@ -91,16 +93,22 @@ extern int dd_main (int argc, char **argv) | |||
91 | goto usage; | 93 | goto usage; |
92 | } | 94 | } |
93 | } | 95 | } |
94 | #if 0 | ||
95 | else if (strncmp(*argv, "skip", 4) == 0) { | 96 | else if (strncmp(*argv, "skip", 4) == 0) { |
96 | skipBlocks = atoi( *argv); | 97 | skipBlocks = getNum ((strchr(*argv, '='))+1); |
97 | if (skipBlocks <= 0) { | 98 | if (skipBlocks <= 0) { |
98 | fprintf (stderr, "Bad skip value %d\n", skipBlocks); | 99 | fprintf (stderr, "Bad skip value %s\n", *argv); |
100 | goto usage; | ||
101 | } | ||
102 | |||
103 | } | ||
104 | else if (strncmp(*argv, "seek", 4) == 0) { | ||
105 | seekBlocks = getNum ((strchr(*argv, '='))+1); | ||
106 | if (seekBlocks <= 0) { | ||
107 | fprintf (stderr, "Bad seek value %s\n", *argv); | ||
99 | goto usage; | 108 | goto usage; |
100 | } | 109 | } |
101 | 110 | ||
102 | } | 111 | } |
103 | #endif | ||
104 | else { | 112 | else { |
105 | goto usage; | 113 | goto usage; |
106 | } | 114 | } |
@@ -131,7 +139,7 @@ extern int dd_main (int argc, char **argv) | |||
131 | if (outFile == NULL) | 139 | if (outFile == NULL) |
132 | outFd = fileno(stdout); | 140 | outFd = fileno(stdout); |
133 | else | 141 | else |
134 | outFd = creat (outFile, 0666); | 142 | outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
135 | 143 | ||
136 | if (outFd < 0) { | 144 | if (outFd < 0) { |
137 | perror (outFile); | 145 | perror (outFile); |
@@ -140,10 +148,11 @@ extern int dd_main (int argc, char **argv) | |||
140 | exit( FALSE); | 148 | exit( FALSE); |
141 | } | 149 | } |
142 | 150 | ||
143 | //lseek(inFd, skipBlocks*blockSize, SEEK_SET); | 151 | lseek(inFd, skipBlocks*blockSize, SEEK_SET); |
152 | lseek(outFd, seekBlocks*blockSize, SEEK_SET); | ||
144 | // | 153 | // |
145 | //TODO: Convert to using fullRead & fullWrite | 154 | //TODO: Convert to using fullRead & fullWrite |
146 | // from utilitity.c | 155 | // from utility.c |
147 | // -Erik | 156 | // -Erik |
148 | while (outTotal < count * blockSize) { | 157 | while (outTotal < count * blockSize) { |
149 | inCc = read (inFd, buf, blockSize); | 158 | inCc = read (inFd, buf, blockSize); |
diff --git a/coreutils/du.c b/coreutils/du.c index 79b553643..e2cf3f7c0 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -22,17 +22,18 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #define BB_DECLARE_EXTERN | ||
26 | #define bb_need_name_too_long | ||
27 | #include "messages.c" | ||
28 | |||
25 | #include <sys/types.h> | 29 | #include <sys/types.h> |
26 | #include <fcntl.h> | 30 | #include <fcntl.h> |
27 | #include <dirent.h> | 31 | #include <dirent.h> |
28 | #include <stdio.h> | 32 | #include <stdio.h> |
29 | #include <errno.h> | 33 | #include <errno.h> |
30 | #if 0 | 34 | #include <sys/param.h> /* for PATH_MAX */ |
31 | #include <unistd.h> | ||
32 | #include <sys/stat.h> | ||
33 | #endif | ||
34 | 35 | ||
35 | typedef void (Display)(size_t, char *); | 36 | typedef void (Display)(long, char *); |
36 | 37 | ||
37 | static const char du_usage[] = | 38 | static const char du_usage[] = |
38 | "du [OPTION]... [FILE]...\n\n" | 39 | "du [OPTION]... [FILE]...\n\n" |
@@ -44,13 +45,13 @@ static int du_depth = 0; | |||
44 | static Display *print; | 45 | static Display *print; |
45 | 46 | ||
46 | static void | 47 | static void |
47 | print_normal(size_t size, char *filename) | 48 | print_normal(long size, char *filename) |
48 | { | 49 | { |
49 | fprintf(stdout, "%-7d %s\n", (size >> 1), filename); | 50 | fprintf(stdout, "%-7ld %s\n", size, filename); |
50 | } | 51 | } |
51 | 52 | ||
52 | static void | 53 | static void |
53 | print_summary(size_t size, char *filename) | 54 | print_summary(long size, char *filename) |
54 | { | 55 | { |
55 | if (du_depth == 1) { | 56 | if (du_depth == 1) { |
56 | print_normal(size, filename); | 57 | print_normal(size, filename); |
@@ -59,11 +60,11 @@ print_summary(size_t size, char *filename) | |||
59 | 60 | ||
60 | 61 | ||
61 | /* tiny recursive du */ | 62 | /* tiny recursive du */ |
62 | static size_t | 63 | static long |
63 | du(char *filename) | 64 | du(char *filename) |
64 | { | 65 | { |
65 | struct stat statbuf; | 66 | struct stat statbuf; |
66 | size_t sum; | 67 | long sum; |
67 | 68 | ||
68 | if ((lstat(filename, &statbuf)) != 0) { | 69 | if ((lstat(filename, &statbuf)) != 0) { |
69 | fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); | 70 | fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); |
@@ -80,14 +81,19 @@ du(char *filename) | |||
80 | dir = opendir(filename); | 81 | dir = opendir(filename); |
81 | if (!dir) { return 0; } | 82 | if (!dir) { return 0; } |
82 | while ((entry = readdir(dir))) { | 83 | while ((entry = readdir(dir))) { |
83 | char newfile[512]; | 84 | char newfile[PATH_MAX + 1]; |
84 | char *name = entry->d_name; | 85 | char *name = entry->d_name; |
85 | 86 | ||
86 | if ( (strcmp(name, "..") == 0) | 87 | if ( (strcmp(name, "..") == 0) |
87 | || (strcmp(name, ".") == 0)) | 88 | || (strcmp(name, ".") == 0)) |
88 | { continue; } | 89 | { continue; } |
89 | 90 | ||
91 | if (strlen(filename) + strlen(name) + 1 > PATH_MAX) { | ||
92 | fprintf(stderr, name_too_long, "du"); | ||
93 | return 0; | ||
94 | } | ||
90 | sprintf(newfile, "%s/%s", filename, name); | 95 | sprintf(newfile, "%s/%s", filename, name); |
96 | |||
91 | sum += du(newfile); | 97 | sum += du(newfile); |
92 | } | 98 | } |
93 | closedir(dir); | 99 | closedir(dir); |
@@ -130,14 +136,14 @@ du_main(int argc, char **argv) | |||
130 | if (i >= argc) { | 136 | if (i >= argc) { |
131 | du("."); | 137 | du("."); |
132 | } else { | 138 | } else { |
133 | int sum; | 139 | long sum; |
134 | for ( ; i < argc; i++) { | 140 | for ( ; i < argc; i++) { |
135 | sum = du(argv[i]); | 141 | sum = du(argv[i]); |
136 | if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); } | 142 | if ((sum) && (isDirectory(argv[i], FALSE))) { print_normal(sum, argv[i]); } |
137 | } | 143 | } |
138 | } | 144 | } |
139 | 145 | ||
140 | exit(0); | 146 | exit(0); |
141 | } | 147 | } |
142 | 148 | ||
143 | /* $Id: du.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */ | 149 | /* $Id: du.c,v 1.10 2000/02/07 05:29:42 erik Exp $ */ |
diff --git a/coreutils/head.c b/coreutils/head.c index bc7f35429..b80d06580 100644 --- a/coreutils/head.c +++ b/coreutils/head.c | |||
@@ -105,4 +105,4 @@ head_main(int argc, char **argv) | |||
105 | exit(0); | 105 | exit(0); |
106 | } | 106 | } |
107 | 107 | ||
108 | /* $Id: head.c,v 1.6 2000/01/25 18:13:53 erik Exp $ */ | 108 | /* $Id: head.c,v 1.7 2000/02/07 05:29:42 erik Exp $ */ |
diff --git a/coreutils/length.c b/coreutils/length.c index 46242b529..2c83cdfd2 100644 --- a/coreutils/length.c +++ b/coreutils/length.c | |||
@@ -6,7 +6,7 @@ | |||
6 | extern int | 6 | extern int |
7 | length_main(int argc, char * * argv) | 7 | length_main(int argc, char * * argv) |
8 | { | 8 | { |
9 | if ( **(argv+1) == '-' ) { | 9 | if ( argc != 2 || **(argv+1) == '-' ) { |
10 | usage("length string\n"); | 10 | usage("length string\n"); |
11 | } | 11 | } |
12 | printf("%d\n", strlen(argv[1])); | 12 | printf("%d\n", strlen(argv[1])); |
diff --git a/coreutils/ln.c b/coreutils/ln.c index 60fe39438..f20b340ea 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c | |||
@@ -22,26 +22,32 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #define BB_DECLARE_EXTERN | ||
26 | #define bb_need_name_too_long | ||
27 | #define bb_need_not_a_directory | ||
28 | #include "messages.c" | ||
29 | |||
25 | #include <stdio.h> | 30 | #include <stdio.h> |
26 | #include <dirent.h> | 31 | #include <dirent.h> |
27 | #include <errno.h> | 32 | #include <errno.h> |
33 | #include <sys/param.h> /* for PATH_MAX */ | ||
28 | 34 | ||
29 | 35 | static const char ln_usage[] = | |
30 | static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n" | 36 | "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n" |
31 | "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n" | 37 | "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n" |
32 | "Options:\n" | 38 | "Options:\n" |
33 | "\t-s\tmake symbolic links instead of hard links\n" | 39 | "\t-s\tmake symbolic links instead of hard links\n" |
34 | "\t-f\tremove existing destination files\n"; | 40 | "\t-f\tremove existing destination files\n" |
35 | 41 | "\t-n\tno dereference symlinks - treat like normal file\n"; | |
36 | 42 | ||
37 | static int symlinkFlag = FALSE; | 43 | static int symlinkFlag = FALSE; |
38 | static int removeoldFlag = FALSE; | 44 | static int removeoldFlag = FALSE; |
39 | 45 | static int followLinks = TRUE; | |
40 | 46 | ||
41 | extern int ln_main(int argc, char **argv) | 47 | extern int ln_main(int argc, char **argv) |
42 | { | 48 | { |
43 | int status; | 49 | char *linkName; |
44 | static char* linkName; | 50 | int linkIntoDirFlag; |
45 | 51 | ||
46 | if (argc < 3) { | 52 | if (argc < 3) { |
47 | usage (ln_usage); | 53 | usage (ln_usage); |
@@ -59,6 +65,9 @@ extern int ln_main(int argc, char **argv) | |||
59 | case 'f': | 65 | case 'f': |
60 | removeoldFlag = TRUE; | 66 | removeoldFlag = TRUE; |
61 | break; | 67 | break; |
68 | case 'n': | ||
69 | followLinks = FALSE; | ||
70 | break; | ||
62 | default: | 71 | default: |
63 | usage (ln_usage); | 72 | usage (ln_usage); |
64 | } | 73 | } |
@@ -66,30 +75,54 @@ extern int ln_main(int argc, char **argv) | |||
66 | argv++; | 75 | argv++; |
67 | } | 76 | } |
68 | 77 | ||
69 | |||
70 | linkName = argv[argc - 1]; | 78 | linkName = argv[argc - 1]; |
71 | 79 | ||
72 | if ((argc > 3) && !(isDirectory(linkName))) { | 80 | if (strlen(linkName) > PATH_MAX) { |
73 | fprintf(stderr, "%s: not a directory\n", linkName); | 81 | fprintf(stderr, name_too_long, "ln"); |
74 | exit (FALSE); | 82 | exit FALSE; |
83 | } | ||
84 | |||
85 | linkIntoDirFlag = isDirectory(linkName, TRUE); | ||
86 | |||
87 | if ((argc > 3) && !linkIntoDirFlag) { | ||
88 | fprintf(stderr, not_a_directory, "ln", linkName); | ||
89 | exit FALSE; | ||
75 | } | 90 | } |
76 | 91 | ||
77 | while (argc-- >= 2) { | 92 | while (argc-- >= 2) { |
78 | if (removeoldFlag==TRUE ) { | 93 | char srcName[PATH_MAX + 1]; |
94 | int nChars, status; | ||
95 | |||
96 | if (strlen(*argv) > PATH_MAX) { | ||
97 | fprintf(stderr, name_too_long, "ln"); | ||
98 | exit FALSE; | ||
99 | } | ||
100 | |||
101 | if (followLinks == FALSE) { | ||
102 | strcpy(srcName, *argv); | ||
103 | } else { | ||
104 | /* Warning! This can silently truncate if > PATH_MAX, but | ||
105 | I don't think that there can be one > PATH_MAX anyway. */ | ||
106 | nChars = readlink(*argv, srcName, PATH_MAX); | ||
107 | srcName[nChars] = '\0'; | ||
108 | } | ||
109 | |||
110 | if (removeoldFlag == TRUE) { | ||
79 | status = ( unlink(linkName) && errno != ENOENT ); | 111 | status = ( unlink(linkName) && errno != ENOENT ); |
80 | if ( status != 0 ) { | 112 | if (status != 0) { |
81 | perror(linkName); | 113 | perror(linkName); |
82 | exit( FALSE); | 114 | exit FALSE; |
83 | } | 115 | } |
84 | } | 116 | } |
85 | if ( symlinkFlag==TRUE) | 117 | |
86 | status = symlink(*argv, linkName); | 118 | if (symlinkFlag == TRUE) |
119 | status = symlink(*argv, linkName); | ||
87 | else | 120 | else |
88 | status = link(*argv, linkName); | 121 | status = link(*argv, linkName); |
89 | if ( status != 0 ) { | 122 | if (status != 0) { |
90 | perror(linkName); | 123 | perror(linkName); |
91 | exit( FALSE); | 124 | exit FALSE; |
92 | } | 125 | } |
93 | } | 126 | } |
94 | exit( TRUE); | 127 | exit TRUE; |
95 | } | 128 | } |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 78193e7c1..450ea1814 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -178,7 +178,7 @@ static char append_char(mode_t mode) | |||
178 | 178 | ||
179 | static void list_single(const char *name, struct stat *info, const char *fullname) | 179 | static void list_single(const char *name, struct stat *info, const char *fullname) |
180 | { | 180 | { |
181 | char scratch[PATH_MAX]; | 181 | char scratch[PATH_MAX + 1]; |
182 | short len = strlen(name); | 182 | short len = strlen(name); |
183 | #ifdef BB_FEATURE_LS_FILETYPES | 183 | #ifdef BB_FEATURE_LS_FILETYPES |
184 | char append = append_char(info->st_mode); | 184 | char append = append_char(info->st_mode); |
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index 017ef9b08..8e3f51bfb 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c | |||
@@ -22,9 +22,13 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #define bb_need_name_too_long | ||
26 | #define BB_DECLARE_EXTERN | ||
27 | #include "messages.c" | ||
28 | |||
25 | #include <stdio.h> | 29 | #include <stdio.h> |
26 | #include <errno.h> | 30 | #include <errno.h> |
27 | #include <sys/param.h> | 31 | #include <sys/param.h> /* for PATH_MAX */ |
28 | 32 | ||
29 | static const char mkdir_usage[] = | 33 | static const char mkdir_usage[] = |
30 | "mkdir [OPTION] DIRECTORY...\n\n" | 34 | "mkdir [OPTION] DIRECTORY...\n\n" |
@@ -40,27 +44,27 @@ static mode_t mode = 0777; | |||
40 | 44 | ||
41 | extern int mkdir_main(int argc, char **argv) | 45 | extern int mkdir_main(int argc, char **argv) |
42 | { | 46 | { |
43 | int i=FALSE; | 47 | int i = FALSE; |
44 | argc--; | 48 | argc--; |
45 | argv++; | 49 | argv++; |
46 | 50 | ||
47 | /* Parse any options */ | 51 | /* Parse any options */ |
48 | while (argc > 0 && **argv == '-') { | 52 | while (argc > 0 && **argv == '-') { |
49 | while (i==FALSE && *++(*argv)) { | 53 | while (i == FALSE && *++(*argv)) { |
50 | switch (**argv) { | 54 | switch (**argv) { |
51 | case 'm': | 55 | case 'm': |
52 | if (--argc == 0) | 56 | if (--argc == 0) |
53 | usage( mkdir_usage); | 57 | usage( mkdir_usage); |
54 | /* Find the specified modes */ | 58 | /* Find the specified modes */ |
55 | mode = 0; | 59 | mode = 0; |
56 | if ( parse_mode(*(++argv), &mode) == FALSE ) { | 60 | if (parse_mode(*(++argv), &mode) == FALSE ) { |
57 | fprintf(stderr, "Unknown mode: %s\n", *argv); | 61 | fprintf(stderr, "Unknown mode: %s\n", *argv); |
58 | exit( FALSE); | 62 | exit FALSE; |
59 | } | 63 | } |
60 | /* Set the umask for this process so it doesn't | 64 | /* Set the umask for this process so it doesn't |
61 | * screw up whatever the user just entered. */ | 65 | * screw up whatever the user just entered. */ |
62 | umask(0); | 66 | umask(0); |
63 | i=TRUE; | 67 | i = TRUE; |
64 | break; | 68 | break; |
65 | case 'p': | 69 | case 'p': |
66 | parentFlag = TRUE; | 70 | parentFlag = TRUE; |
@@ -73,7 +77,6 @@ extern int mkdir_main(int argc, char **argv) | |||
73 | argv++; | 77 | argv++; |
74 | } | 78 | } |
75 | 79 | ||
76 | |||
77 | if (argc < 1) { | 80 | if (argc < 1) { |
78 | usage( mkdir_usage); | 81 | usage( mkdir_usage); |
79 | } | 82 | } |
@@ -81,13 +84,16 @@ extern int mkdir_main(int argc, char **argv) | |||
81 | while (argc > 0) { | 84 | while (argc > 0) { |
82 | int status; | 85 | int status; |
83 | struct stat statBuf; | 86 | struct stat statBuf; |
84 | char buf[NAME_MAX]; | 87 | char buf[PATH_MAX + 1]; |
85 | 88 | if (strlen(*argv) > PATH_MAX - 1) { | |
89 | fprintf(stderr, name_too_long, "mkdir"); | ||
90 | exit FALSE; | ||
91 | } | ||
86 | strcpy (buf, *argv); | 92 | strcpy (buf, *argv); |
87 | status=stat(buf, &statBuf); | 93 | status = stat(buf, &statBuf); |
88 | if (parentFlag == FALSE && status != -1 && status != ENOENT ) { | 94 | if (parentFlag == FALSE && status != -1 && errno != ENOENT) { |
89 | fprintf(stderr, "%s: File exists\n", buf); | 95 | fprintf(stderr, "%s: File exists\n", buf); |
90 | exit( FALSE); | 96 | exit FALSE; |
91 | } | 97 | } |
92 | if (parentFlag == TRUE) { | 98 | if (parentFlag == TRUE) { |
93 | strcat( buf, "/"); | 99 | strcat( buf, "/"); |
@@ -96,13 +102,13 @@ extern int mkdir_main(int argc, char **argv) | |||
96 | else { | 102 | else { |
97 | if (mkdir (buf, mode) != 0 && parentFlag == FALSE) { | 103 | if (mkdir (buf, mode) != 0 && parentFlag == FALSE) { |
98 | perror(buf); | 104 | perror(buf); |
99 | exit( FALSE); | 105 | exit FALSE; |
100 | } | 106 | } |
101 | } | 107 | } |
102 | argc--; | 108 | argc--; |
103 | argv++; | 109 | argv++; |
104 | } | 110 | } |
105 | exit( TRUE); | 111 | exit TRUE; |
106 | } | 112 | } |
107 | 113 | ||
108 | 114 | ||
diff --git a/coreutils/mv.c b/coreutils/mv.c deleted file mode 100644 index 467a360de..000000000 --- a/coreutils/mv.c +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /* | ||
2 | * Mini mv implementation for busybox | ||
3 | * | ||
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 | #include <time.h> | ||
27 | #include <utime.h> | ||
28 | #include <dirent.h> | ||
29 | |||
30 | static const char mv_usage[] = "mv SOURCE DEST\n" | ||
31 | " or: mv SOURCE... DIRECTORY\n\n" | ||
32 | "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"; | ||
33 | |||
34 | |||
35 | static const char *srcName; | ||
36 | static const char *destName; | ||
37 | static int destDirFlag = FALSE; | ||
38 | static int srcDirFlag = FALSE; | ||
39 | |||
40 | static int fileAction(const char *fileName, struct stat* statbuf) | ||
41 | { | ||
42 | char newdestName[NAME_MAX]; | ||
43 | char* newsrcName = NULL; | ||
44 | |||
45 | strcpy(newdestName, destName); | ||
46 | if ( srcDirFlag == TRUE ) { | ||
47 | strcat(newdestName, strstr(fileName, srcName) + strlen(srcName)); | ||
48 | } | ||
49 | |||
50 | if (destDirFlag==TRUE && srcDirFlag == FALSE) { | ||
51 | if (newdestName[strlen(newdestName)-1] != '/' ) { | ||
52 | strcat(newdestName, "/"); | ||
53 | } | ||
54 | newsrcName = strrchr(srcName, '/'); | ||
55 | if (newsrcName && *newsrcName != '\0') | ||
56 | strcat(newdestName, newsrcName); | ||
57 | else | ||
58 | strcat(newdestName, srcName); | ||
59 | } | ||
60 | |||
61 | return (copyFile(fileName, newdestName, TRUE, TRUE)); | ||
62 | } | ||
63 | |||
64 | static int rmfileAction(const char *fileName, struct stat* statbuf) | ||
65 | { | ||
66 | if (unlink( fileName) < 0 ) { | ||
67 | perror( fileName); | ||
68 | return ( FALSE); | ||
69 | } | ||
70 | return ( TRUE); | ||
71 | } | ||
72 | |||
73 | static int rmdirAction(const char *fileName, struct stat* statbuf) | ||
74 | { | ||
75 | if (rmdir( fileName) < 0 ) { | ||
76 | perror( fileName); | ||
77 | return ( FALSE); | ||
78 | } | ||
79 | return ( TRUE); | ||
80 | } | ||
81 | |||
82 | |||
83 | extern int mv_main(int argc, char **argv) | ||
84 | { | ||
85 | if (argc < 3) { | ||
86 | usage (mv_usage); | ||
87 | } | ||
88 | argc--; | ||
89 | argv++; | ||
90 | |||
91 | destName = argv[argc - 1]; | ||
92 | destDirFlag = isDirectory(destName); | ||
93 | |||
94 | if ((argc > 3) && destDirFlag==FALSE) { | ||
95 | fprintf(stderr, "%s: not a directory\n", destName); | ||
96 | exit (FALSE); | ||
97 | } | ||
98 | |||
99 | while (argc-- > 1) { | ||
100 | srcName = *(argv++); | ||
101 | srcDirFlag = isDirectory(srcName); | ||
102 | if (recursiveAction(srcName, TRUE, TRUE, FALSE, | ||
103 | fileAction, fileAction) == FALSE) { | ||
104 | exit( FALSE); | ||
105 | } | ||
106 | if (recursiveAction(srcName, TRUE, TRUE, TRUE, | ||
107 | rmfileAction, rmdirAction) == FALSE) { | ||
108 | exit( FALSE); | ||
109 | } | ||
110 | } | ||
111 | exit( TRUE); | ||
112 | } | ||
diff --git a/coreutils/printf.c b/coreutils/printf.c index 5be3a67cb..5fd5ea303 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -143,7 +143,7 @@ printf_main(int argc, char** argv) | |||
143 | int args_used; | 143 | int args_used; |
144 | 144 | ||
145 | exit_status = 0; | 145 | exit_status = 0; |
146 | if ( **(argv+1) == '-' ) { | 146 | if ( argc <= 1 || **(argv+1) == '-' ) { |
147 | usage (printf_usage); | 147 | usage (printf_usage); |
148 | } | 148 | } |
149 | 149 | ||
diff --git a/coreutils/pwd.c b/coreutils/pwd.c index c5ce6ff89..bacabd77a 100644 --- a/coreutils/pwd.c +++ b/coreutils/pwd.c | |||
@@ -23,11 +23,12 @@ | |||
23 | #include "internal.h" | 23 | #include "internal.h" |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <dirent.h> | 25 | #include <dirent.h> |
26 | #include <sys/param.h> | ||
26 | 27 | ||
27 | extern int | 28 | extern int |
28 | pwd_main(int argc, char * * argv) | 29 | pwd_main(int argc, char * * argv) |
29 | { | 30 | { |
30 | char buf[NAME_MAX]; | 31 | char buf[PATH_MAX + 1]; |
31 | 32 | ||
32 | if ( getcwd(buf, sizeof(buf)) == NULL ) { | 33 | if ( getcwd(buf, sizeof(buf)) == NULL ) { |
33 | perror("get working directory"); | 34 | perror("get working directory"); |
diff --git a/coreutils/sort.c b/coreutils/sort.c index 4df5627ac..d529ce722 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -309,4 +309,4 @@ sort_main(int argc, char **argv) | |||
309 | exit(0); | 309 | exit(0); |
310 | } | 310 | } |
311 | 311 | ||
312 | /* $Id: sort.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */ | 312 | /* $Id: sort.c,v 1.10 2000/02/07 05:29:42 erik Exp $ */ |
diff --git a/coreutils/tail.c b/coreutils/tail.c index 5198892b6..0ab8f11b0 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -33,7 +33,7 @@ | |||
33 | and generally busyboxed, Erik Andersen <andersen@lineo.com> | 33 | and generally busyboxed, Erik Andersen <andersen@lineo.com> |
34 | 34 | ||
35 | Removed superfluous options and associated code ("-c", "-n", "-q"). | 35 | Removed superfluous options and associated code ("-c", "-n", "-q"). |
36 | Removed "tail -f" suport for multiple files. | 36 | Removed "tail -f" support for multiple files. |
37 | Both changes by Friedrich Vedder <fwv@myrtle.lahn.de>. | 37 | Both changes by Friedrich Vedder <fwv@myrtle.lahn.de>. |
38 | 38 | ||
39 | */ | 39 | */ |
diff --git a/coreutils/tee.c b/coreutils/tee.c index 8d1ca6efd..4c5c691c6 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c | |||
@@ -123,4 +123,4 @@ tee_main(int argc, char **argv) | |||
123 | exit(0); | 123 | exit(0); |
124 | } | 124 | } |
125 | 125 | ||
126 | /* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */ | 126 | /* $Id: tee.c,v 1.5 2000/02/07 05:29:42 erik Exp $ */ |
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index a7bff54ec..965d290c2 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c | |||
@@ -193,4 +193,4 @@ uniq_main(int argc, char **argv) | |||
193 | exit(0); | 193 | exit(0); |
194 | } | 194 | } |
195 | 195 | ||
196 | /* $Id: uniq.c,v 1.5 2000/01/23 18:19:02 erik Exp $ */ | 196 | /* $Id: uniq.c,v 1.6 2000/02/07 05:29:42 erik Exp $ */ |