aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cat.c8
-rw-r--r--coreutils/chown.c12
-rw-r--r--coreutils/chroot.c20
-rw-r--r--coreutils/cp.c10
-rw-r--r--coreutils/date.c172
-rw-r--r--coreutils/pwd.c8
6 files changed, 106 insertions, 124 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 0f2460eb7..8718c4d02 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -29,9 +29,9 @@ extern int cat_more_main(int argc, char **argv)
29 int c; 29 int c;
30 FILE *file = stdin; 30 FILE *file = stdin;
31 31
32 if (argc < 2) { 32 if ( (argc < 2) || (**(argv+1) == '-') ) {
33 fprintf(stderr, "Usage: %s %s", *argv, cat_usage); 33 fprintf(stderr, "Usage: %s %s", *argv, cat_usage);
34 return(FALSE); 34 exit(FALSE);
35 } 35 }
36 argc--; 36 argc--;
37 argv++; 37 argv++;
@@ -40,7 +40,7 @@ extern int cat_more_main(int argc, char **argv)
40 file = fopen(*argv, "r"); 40 file = fopen(*argv, "r");
41 if (file == NULL) { 41 if (file == NULL) {
42 perror(*argv); 42 perror(*argv);
43 return(FALSE); 43 exit(FALSE);
44 } 44 }
45 while ((c = getc(file)) != EOF) 45 while ((c = getc(file)) != EOF)
46 putc(c, stdout); 46 putc(c, stdout);
@@ -50,5 +50,5 @@ extern int cat_more_main(int argc, char **argv)
50 argc--; 50 argc--;
51 argv++; 51 argv++;
52 } 52 }
53 return(TRUE); 53 exit(TRUE);
54} 54}
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 5ac48f772..bcaeea38e 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -66,7 +66,7 @@ int chown_main(int argc, char **argv)
66 if (argc < 2) { 66 if (argc < 2) {
67 fprintf(stderr, "Usage: %s %s", *argv, 67 fprintf(stderr, "Usage: %s %s", *argv,
68 (chownApp==TRUE)? chown_usage : chgrp_usage); 68 (chownApp==TRUE)? chown_usage : chgrp_usage);
69 return( FALSE); 69 exit( FALSE);
70 } 70 }
71 invocationName=*argv; 71 invocationName=*argv;
72 argc--; 72 argc--;
@@ -80,7 +80,7 @@ int chown_main(int argc, char **argv)
80 break; 80 break;
81 default: 81 default:
82 fprintf(stderr, "Unknown option: %c\n", **argv); 82 fprintf(stderr, "Unknown option: %c\n", **argv);
83 return( FALSE); 83 exit( FALSE);
84 } 84 }
85 argc--; 85 argc--;
86 argv++; 86 argv++;
@@ -95,7 +95,7 @@ int chown_main(int argc, char **argv)
95 grp = getgrnam(groupName); 95 grp = getgrnam(groupName);
96 if (grp == NULL) { 96 if (grp == NULL) {
97 fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName); 97 fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName);
98 return( FALSE); 98 exit( FALSE);
99 } 99 }
100 gid = grp->gr_gid; 100 gid = grp->gr_gid;
101 101
@@ -104,7 +104,7 @@ int chown_main(int argc, char **argv)
104 pwd = getpwnam(*argv); 104 pwd = getpwnam(*argv);
105 if (pwd == NULL) { 105 if (pwd == NULL) {
106 fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv); 106 fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv);
107 return( FALSE); 107 exit( FALSE);
108 } 108 }
109 uid = pwd->pw_uid; 109 uid = pwd->pw_uid;
110 } 110 }
@@ -112,11 +112,11 @@ int chown_main(int argc, char **argv)
112 /* Ok, ready to do the deed now */ 112 /* Ok, ready to do the deed now */
113 if (argc <= 1) { 113 if (argc <= 1) {
114 fprintf(stderr, "%s: too few arguments", invocationName); 114 fprintf(stderr, "%s: too few arguments", invocationName);
115 return( FALSE); 115 exit( FALSE);
116 } 116 }
117 while (argc-- > 1) { 117 while (argc-- > 1) {
118 argv++; 118 argv++;
119 recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction); 119 recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction);
120 } 120 }
121 return(TRUE); 121 exit(TRUE);
122} 122}
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index d39549496..3b6fdae3b 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -20,8 +20,9 @@
20 */ 20 */
21 21
22#include "internal.h" 22#include "internal.h"
23#include <stdlib.h>
23#include <stdio.h> 24#include <stdio.h>
24#include <unistd.h> 25#include <errno.h>
25 26
26 27
27static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" 28static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
@@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
31 32
32int chroot_main(int argc, char **argv) 33int chroot_main(int argc, char **argv)
33{ 34{
34 if (argc < 2) { 35 if ( (argc < 2) || (**(argv+1) == '-') ) {
35 fprintf(stderr, "Usage: %s %s", *argv, chroot_usage); 36 fprintf(stderr, "Usage: %s %s", *argv, chroot_usage);
36 return( FALSE); 37 exit( FALSE);
37 } 38 }
38 argc--; 39 argc--;
39 argv++; 40 argv++;
40 41
41 fprintf(stderr, "new root: %s\n", *argv);
42
43 if (chroot (*argv) || (chdir ("/"))) { 42 if (chroot (*argv) || (chdir ("/"))) {
44 perror("cannot chroot"); 43 fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
45 return( FALSE); 44 *argv, strerror(errno));
45 exit( FALSE);
46 } 46 }
47 47
48 argc--; 48 argc--;
@@ -56,10 +56,10 @@ int chroot_main(int argc, char **argv)
56 prog = getenv ("SHELL"); 56 prog = getenv ("SHELL");
57 if (!prog) 57 if (!prog)
58 prog = "/bin/sh"; 58 prog = "/bin/sh";
59 fprintf(stderr, "no command. running: %s\n", prog);
60 execlp (prog, prog, NULL); 59 execlp (prog, prog, NULL);
61 } 60 }
62 perror("cannot exec"); 61 fprintf(stderr, "chroot: cannot execute %s: %s\n",
63 return(FALSE); 62 *argv, strerror(errno));
63 exit( FALSE);
64} 64}
65 65
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 797663d2b..4cdfc843b 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -91,7 +91,7 @@ extern int cp_main(int argc, char **argv)
91 91
92 if (argc < 3) { 92 if (argc < 3) {
93 fprintf(stderr, "Usage: %s", cp_usage); 93 fprintf(stderr, "Usage: %s", cp_usage);
94 return (FALSE); 94 exit (FALSE);
95 } 95 }
96 argc--; 96 argc--;
97 argv++; 97 argv++;
@@ -129,13 +129,13 @@ extern int cp_main(int argc, char **argv)
129 129
130 if ((argc > 3) && !dirFlag) { 130 if ((argc > 3) && !dirFlag) {
131 fprintf(stderr, "%s: not a directory\n", destName); 131 fprintf(stderr, "%s: not a directory\n", destName);
132 return (FALSE); 132 exit (FALSE);
133 } 133 }
134 134
135 while (argc-- >= 2) { 135 while (argc-- >= 2) {
136 srcName = *(argv++); 136 srcName = *(argv++);
137 return recursiveAction(srcName, recursiveFlag, followLinks, 137 exit( recursiveAction(srcName, recursiveFlag, followLinks,
138 fileAction, fileAction); 138 fileAction, fileAction));
139 } 139 }
140 return( TRUE); 140 exit( TRUE);
141} 141}
diff --git a/coreutils/date.c b/coreutils/date.c
index 558517086..2df9e0cc7 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -1,3 +1,24 @@
1/*
2 * Mini date implementation for busybox
3 *
4 * Copyright (C) 1999 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20*/
21
1#include "internal.h" 22#include "internal.h"
2#include <stdlib.h> 23#include <stdlib.h>
3#include <errno.h> 24#include <errno.h>
@@ -5,7 +26,6 @@
5#include <unistd.h> 26#include <unistd.h>
6#include <time.h> 27#include <time.h>
7#include <stdio.h> 28#include <stdio.h>
8#include <getopt.h>
9 29
10 30
11/* This 'date' command supports only 2 time setting formats, 31/* This 'date' command supports only 2 time setting formats,
@@ -14,25 +34,12 @@
14 an RFC 822 complient date output for shell scripting 34 an RFC 822 complient date output for shell scripting
15 mail commands */ 35 mail commands */
16 36
17const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n" 37const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n"
18"| [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]"; 38" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
19 39"Display the current time in the given FORMAT, or set the system date.\n"
20//static const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n" 40"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
21//"or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n" 41"\t-s\t\tset time described by STRING\n"
22//"Display the current time in the given FORMAT, or set the system date.\n"; 42"\t-u\t\tprint or set Coordinated Universal Time\n";
23
24
25static struct option const long_options[] =
26{
27 {"date", required_argument, NULL, 'd'},
28 /* {"rfc-822", no_argument, NULL, 'R'},
29 {"set", required_argument, NULL, 's'},
30 {"uct", no_argument, NULL, 'u'},
31 {"utc", no_argument, NULL, 'u'},
32 {"universal", no_argument, NULL, 'u'}, */
33 {NULL, 0, NULL, 0}
34};
35
36 43
37 44
38/* Input parsing code is always bulky - used heavy duty libc stuff as 45/* Input parsing code is always bulky - used heavy duty libc stuff as
@@ -53,7 +60,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) {
53 60
54 if(nr < 4 || nr > 5) { 61 if(nr < 4 || nr > 5) {
55 fprintf(stderr, "date: invalid date `%s'\n", t_string); 62 fprintf(stderr, "date: invalid date `%s'\n", t_string);
56 exit(1); 63 exit( FALSE);
57 } 64 }
58 65
59 /* correct for century - minor Y2K problem here? */ 66 /* correct for century - minor Y2K problem here? */
@@ -147,15 +154,15 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) {
147 154
148 fprintf(stderr, "date: invalid date `%s'\n", t_string); 155 fprintf(stderr, "date: invalid date `%s'\n", t_string);
149 156
150 exit(1); 157 exit( FALSE);
151 158
152} 159}
153 160
154 161
155void 162void
156date_err(void) { 163date_err(void) {
157 fprintf(stderr, "date: only one date argument can be given at a time.\n"); 164 fprintf (stderr, "%s\n", date_usage);
158 exit(1); 165 exit( FALSE);
159} 166}
160 167
161int 168int
@@ -164,82 +171,56 @@ date_main(int argc, char * * argv)
164 char *date_str = NULL; 171 char *date_str = NULL;
165 char *date_fmt = NULL; 172 char *date_fmt = NULL;
166 char *t_buff; 173 char *t_buff;
174 int i;
167 int set_time = 0; 175 int set_time = 0;
168 int rfc822 = 0; 176 int rfc822 = 0;
169 int utc = 0; 177 int utc = 0;
170 int use_arg = 0; 178 int use_arg = 0;
171 int n_args;
172 time_t tm; 179 time_t tm;
173 struct tm tm_time; 180 struct tm tm_time;
174 char optc;
175 181
176 /* Interpret command line args */ 182 /* Interpret command line args */
177 183 i = --argc;
178 184 argv++;
179 while ((optc = getopt_long (argc, argv, "d:Rs:u", long_options, NULL)) 185 while (i > 0 && **argv) {
180 != EOF) { 186 if (**argv == '-') {
181 switch (optc) { 187 while (i>0 && *++(*argv)) switch (**argv) {
182 case 0: 188 case 'R':
183 break; 189 rfc822 = 1;
184 190 break;
185 case 'R': 191 case 's':
186 rfc822 = 1; 192 set_time = 1;
187 break; 193 if(date_str != NULL) date_err();
188 194 date_str = optarg;
189 case 's': 195 break;
190 set_time = 1; 196 case 'u':
191 if(date_str != NULL) date_err(); 197 utc = 1;
192 date_str = optarg; 198 if (putenv ("TZ=UTC0") != 0) {
193 break; 199 fprintf(stderr,"date: memory exhausted\n");
194 200 exit( FALSE);
195 case 'u': 201 }
196 utc = 1; 202 /* Look ma, no break. Don't fix it either. */
197 if (putenv ("TZ=UTC0") != 0) { 203 case 'd':
198 fprintf(stderr,"date: memory exhausted\n"); 204 use_arg = 1;
199 return(1); 205 if(date_str != NULL) date_err();
200 } 206 date_str = optarg;
201#if LOCALTIME_CACHE 207 break;
202 tzset (); 208 case '-':
203#endif break; 209 date_err();
204 210 }
205 case 'd': 211 } else {
206 use_arg = 1; 212 if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
207 if(date_str != NULL) date_err(); 213 date_fmt=*argv;
208 date_str = optarg; 214 else if (date_str == NULL) {
209 break; 215 set_time = 1;
210 216 date_str=*argv;
211 default: 217 } else {
212 fprintf(stderr, "Usage: %s", date_usage); 218 date_err();
213 break; 219 }
220 }
221 i--;
222 argv++;
214 } 223 }
215 }
216
217
218 n_args = argc - optind;
219
220 while (n_args--){
221 switch(argv[optind][0]) {
222 case '+':
223 /* Date format strings */
224 if(date_fmt != NULL) {
225 fprintf(stderr, "date: only one date format can be given.\n");
226 return(1);
227 }
228 date_fmt = &argv[optind][1];
229 break;
230
231 case '\0':
232 break;
233
234 default:
235 /* Anything left over must be a date string to set the time */
236 set_time = 1;
237 if(date_str != NULL) date_err();
238 date_str = argv[optind];
239 break;
240 }
241 optind++;
242 }
243 224
244 225
245 /* Now we have parsed all the information except the date format 226 /* Now we have parsed all the information except the date format
@@ -267,14 +248,14 @@ date_main(int argc, char * * argv)
267 tm = mktime(&tm_time); 248 tm = mktime(&tm_time);
268 if (tm < 0 ) { 249 if (tm < 0 ) {
269 fprintf(stderr, "date: invalid date `%s'\n", date_str); 250 fprintf(stderr, "date: invalid date `%s'\n", date_str);
270 exit(1); 251 exit( FALSE);
271 } 252 }
272 253
273 /* if setting time, set it */ 254 /* if setting time, set it */
274 if(set_time) { 255 if(set_time) {
275 if( stime(&tm) < 0) { 256 if( stime(&tm) < 0) {
276 fprintf(stderr, "date: can't set date.\n"); 257 fprintf(stderr, "date: can't set date.\n");
277 exit(1); 258 exit( FALSE);
278 } 259 }
279 } 260 }
280 } 261 }
@@ -292,7 +273,7 @@ date_main(int argc, char * * argv)
292 } else if ( *date_fmt == '\0' ) { 273 } else if ( *date_fmt == '\0' ) {
293 /* Imitate what GNU 'date' does with NO format string! */ 274 /* Imitate what GNU 'date' does with NO format string! */
294 printf ("\n"); 275 printf ("\n");
295 return(0); 276 exit( TRUE);
296 } 277 }
297 278
298 /* Handle special conversions */ 279 /* Handle special conversions */
@@ -306,6 +287,7 @@ date_main(int argc, char * * argv)
306 strftime(t_buff, 200, date_fmt, &tm_time); 287 strftime(t_buff, 200, date_fmt, &tm_time);
307 printf("%s\n", t_buff); 288 printf("%s\n", t_buff);
308 289
309 return(0); 290 exit( TRUE);
310 291
311} 292}
293
diff --git a/coreutils/pwd.c b/coreutils/pwd.c
index d9ab54e48..893ed1e15 100644
--- a/coreutils/pwd.c
+++ b/coreutils/pwd.c
@@ -4,15 +4,15 @@
4const char pwd_usage[] = "Print the current directory.\n"; 4const char pwd_usage[] = "Print the current directory.\n";
5 5
6extern int 6extern int
7pwd_main(struct FileInfo * i, int argc, char * * argv) 7pwd_main(int argc, char * * argv)
8{ 8{
9 char buf[1024]; 9 char buf[1024];
10 10
11 if ( getcwd(buf, sizeof(buf)) == NULL ) { 11 if ( getcwd(buf, sizeof(buf)) == NULL ) {
12 name_and_error("get working directory"); 12 perror("get working directory");
13 return 1; 13 exit( FALSE);
14 } 14 }
15 15
16 printf("%s\n", buf); 16 printf("%s\n", buf);
17 return 0; 17 exit( TRUE);
18} 18}