diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-12 15:42:48 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-12 15:42:48 +0000 |
commit | 2ce1edcf544ac675e6762c9861a6b918401ea716 (patch) | |
tree | 34245558cd448f01969679fc420de4dfd246dc13 | |
parent | f811e07b072600a3784a92e5a1dc8a93dac477eb (diff) | |
download | busybox-w32-2ce1edcf544ac675e6762c9861a6b918401ea716.tar.gz busybox-w32-2ce1edcf544ac675e6762c9861a6b918401ea716.tar.bz2 busybox-w32-2ce1edcf544ac675e6762c9861a6b918401ea716.zip |
Latest and greatest.
-Erik
-rw-r--r-- | Changelog | 3 | ||||
-rw-r--r-- | applets/busybox.c | 5 | ||||
-rw-r--r-- | busybox.c | 5 | ||||
-rw-r--r-- | busybox.def.h | 4 | ||||
-rw-r--r-- | cat.c | 8 | ||||
-rw-r--r-- | chown.c | 12 | ||||
-rw-r--r-- | chroot.c | 20 | ||||
-rw-r--r-- | clear.c | 2 | ||||
-rw-r--r-- | console-tools/clear.c | 2 | ||||
-rw-r--r-- | coreutils/cat.c | 8 | ||||
-rw-r--r-- | coreutils/chown.c | 12 | ||||
-rw-r--r-- | coreutils/chroot.c | 20 | ||||
-rw-r--r-- | coreutils/cp.c | 10 | ||||
-rw-r--r-- | coreutils/date.c | 172 | ||||
-rw-r--r-- | coreutils/pwd.c | 8 | ||||
-rw-r--r-- | cp.c | 10 | ||||
-rw-r--r-- | date.c | 172 | ||||
-rw-r--r-- | mnc.c | 79 | ||||
-rw-r--r-- | pwd.c | 8 |
19 files changed, 255 insertions, 305 deletions
@@ -1,3 +1,6 @@ | |||
1 | 0.28 | ||
2 | mini-netcat (mnc) rewritten. | ||
3 | |||
1 | 0.27 | 4 | 0.27 |
2 | Mount now supports -a, and -t auto. | 5 | Mount now supports -a, and -t auto. |
3 | Mount now updates mtab correctly for 'ro'. | 6 | Mount now updates mtab correctly for 'ro'. |
diff --git a/applets/busybox.c b/applets/busybox.c index cdbefbe94..f0258c36e 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -189,7 +189,7 @@ int main(int argc, char **argv) | |||
189 | } | 189 | } |
190 | a++; | 190 | a++; |
191 | } | 191 | } |
192 | return (busybox_main(argc, argv)); | 192 | exit (busybox_main(argc, argv)); |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
@@ -216,8 +216,7 @@ int busybox_main(int argc, char **argv) | |||
216 | fprintf(stderr, "\nCurrently defined functions:\n"); | 216 | fprintf(stderr, "\nCurrently defined functions:\n"); |
217 | 217 | ||
218 | while (a->name != 0) { | 218 | while (a->name != 0) { |
219 | col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), a->name); | 219 | col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name); |
220 | a++; | ||
221 | if (col>60) { | 220 | if (col>60) { |
222 | fprintf(stderr, ",\n"); | 221 | fprintf(stderr, ",\n"); |
223 | col=0; | 222 | col=0; |
@@ -189,7 +189,7 @@ int main(int argc, char **argv) | |||
189 | } | 189 | } |
190 | a++; | 190 | a++; |
191 | } | 191 | } |
192 | return (busybox_main(argc, argv)); | 192 | exit (busybox_main(argc, argv)); |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
@@ -216,8 +216,7 @@ int busybox_main(int argc, char **argv) | |||
216 | fprintf(stderr, "\nCurrently defined functions:\n"); | 216 | fprintf(stderr, "\nCurrently defined functions:\n"); |
217 | 217 | ||
218 | while (a->name != 0) { | 218 | while (a->name != 0) { |
219 | col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), a->name); | 219 | col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name); |
220 | a++; | ||
221 | if (col>60) { | 220 | if (col>60) { |
222 | fprintf(stderr, ",\n"); | 221 | fprintf(stderr, ",\n"); |
223 | col=0; | 222 | col=0; |
diff --git a/busybox.def.h b/busybox.def.h index 3999df37e..a5c5957a1 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
@@ -35,7 +35,7 @@ | |||
35 | //#define BB_MKDIR | 35 | //#define BB_MKDIR |
36 | //#define BB_MKNOD | 36 | //#define BB_MKNOD |
37 | ////#define BB_MKSWAP | 37 | ////#define BB_MKSWAP |
38 | //#define BB_MNC | 38 | #define BB_MNC |
39 | //#define BB_MONADIC | 39 | //#define BB_MONADIC |
40 | #define BB_MORE | 40 | #define BB_MORE |
41 | #define BB_MOUNT | 41 | #define BB_MOUNT |
@@ -43,7 +43,7 @@ | |||
43 | #define BB_MV | 43 | #define BB_MV |
44 | //#define BB_POSTPROCESS | 44 | //#define BB_POSTPROCESS |
45 | //#define BB_PRINTF | 45 | //#define BB_PRINTF |
46 | //#define BB_PWD | 46 | #define BB_PWD |
47 | //#define BB_REBOOT | 47 | //#define BB_REBOOT |
48 | //#define BB_RM | 48 | //#define BB_RM |
49 | //#define BB_RMDIR | 49 | //#define BB_RMDIR |
@@ -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 | } |
@@ -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 | } |
@@ -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 | ||
27 | static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" | 28 | static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" |
@@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" | |||
31 | 32 | ||
32 | int chroot_main(int argc, char **argv) | 33 | int 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 | ||
@@ -27,5 +27,5 @@ extern int | |||
27 | clear_main(int argc, char** argv) | 27 | clear_main(int argc, char** argv) |
28 | { | 28 | { |
29 | printf("\033[H\033[J"); | 29 | printf("\033[H\033[J"); |
30 | return 0; | 30 | exit( TRUE); |
31 | } | 31 | } |
diff --git a/console-tools/clear.c b/console-tools/clear.c index c0c94d06e..bc813064e 100644 --- a/console-tools/clear.c +++ b/console-tools/clear.c | |||
@@ -27,5 +27,5 @@ extern int | |||
27 | clear_main(int argc, char** argv) | 27 | clear_main(int argc, char** argv) |
28 | { | 28 | { |
29 | printf("\033[H\033[J"); | 29 | printf("\033[H\033[J"); |
30 | return 0; | 30 | exit( TRUE); |
31 | } | 31 | } |
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 | ||
27 | static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" | 28 | static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" |
@@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" | |||
31 | 32 | ||
32 | int chroot_main(int argc, char **argv) | 33 | int 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 | ||
17 | const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n" | 37 | const 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 | |||
25 | static 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 | ||
155 | void | 162 | void |
156 | date_err(void) { | 163 | date_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 | ||
161 | int | 168 | int |
@@ -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 @@ | |||
4 | const char pwd_usage[] = "Print the current directory.\n"; | 4 | const char pwd_usage[] = "Print the current directory.\n"; |
5 | 5 | ||
6 | extern int | 6 | extern int |
7 | pwd_main(struct FileInfo * i, int argc, char * * argv) | 7 | pwd_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 | } |
@@ -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 | } |
@@ -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 | ||
17 | const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n" | 37 | const 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 | |||
25 | static 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 | ||
155 | void | 162 | void |
156 | date_err(void) { | 163 | date_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 | ||
161 | int | 168 | int |
@@ -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 | |||
@@ -3,9 +3,11 @@ | |||
3 | 3 | ||
4 | 0.0.1 6K It works. | 4 | 0.0.1 6K It works. |
5 | 0.0.2 5K Smaller and you can also check the exit condition if you wish. | 5 | 0.0.2 5K Smaller and you can also check the exit condition if you wish. |
6 | 6 | 0.0.3 Uses select() | |
7 | 7 | ||
8 | 19980918 Busy Boxed! Dave Cinege | 8 | 19980918 Busy Boxed! Dave Cinege |
9 | 19990512 Uses Select. Charles P. Wright | ||
10 | 19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright | ||
9 | 11 | ||
10 | This program is free software; you can redistribute it and/or modify | 12 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | 13 | it under the terms of the GNU General Public License as published by |
@@ -35,26 +37,24 @@ | |||
35 | #include <sys/time.h> | 37 | #include <sys/time.h> |
36 | #include <sys/ioctl.h> | 38 | #include <sys/ioctl.h> |
37 | 39 | ||
40 | #define BUFSIZE 100 | ||
41 | |||
38 | const char mnc_usage[] = | 42 | const char mnc_usage[] = |
39 | "mini-netcat 0.0.1 -- Open pipe to IP:port\n" | 43 | "mini-netcat 0.0.3 -- Open pipe to IP:port\n" |
40 | "\tmnc [IP] [port]\n"; | 44 | "\tmnc [IP] [port]\n"; |
41 | 45 | ||
42 | int | 46 | int |
43 | mnc_main(struct FileInfo * i, int argc, char **argv) | 47 | mnc_main(int argc, char **argv) |
44 | { | 48 | { |
45 | |||
46 | int sfd; | 49 | int sfd; |
47 | int result; | 50 | int result; |
48 | int len; | 51 | int len; |
49 | int pid; | 52 | char ch[BUFSIZE]; |
50 | char ch; | ||
51 | 53 | ||
52 | struct sockaddr_in address; | 54 | struct sockaddr_in address; |
53 | struct hostent *hostinfo; | 55 | struct hostent *hostinfo; |
54 | 56 | ||
55 | #ifdef SELECT | ||
56 | fd_set readfds, testfds; | 57 | fd_set readfds, testfds; |
57 | #endif | ||
58 | 58 | ||
59 | sfd = socket(AF_INET, SOCK_STREAM, 0); | 59 | sfd = socket(AF_INET, SOCK_STREAM, 0); |
60 | 60 | ||
@@ -78,7 +78,6 @@ mnc_main(struct FileInfo * i, int argc, char **argv) | |||
78 | exit(2); | 78 | exit(2); |
79 | } | 79 | } |
80 | 80 | ||
81 | #ifdef SELECT | ||
82 | FD_ZERO(&readfds); | 81 | FD_ZERO(&readfds); |
83 | FD_SET(sfd, &readfds); | 82 | FD_SET(sfd, &readfds); |
84 | FD_SET(fileno(stdin), &readfds); | 83 | FD_SET(fileno(stdin), &readfds); |
@@ -86,6 +85,7 @@ mnc_main(struct FileInfo * i, int argc, char **argv) | |||
86 | while(1) | 85 | while(1) |
87 | { | 86 | { |
88 | int fd; | 87 | int fd; |
88 | int ofd; | ||
89 | int nread; | 89 | int nread; |
90 | 90 | ||
91 | testfds = readfds; | 91 | testfds = readfds; |
@@ -101,48 +101,33 @@ mnc_main(struct FileInfo * i, int argc, char **argv) | |||
101 | { | 101 | { |
102 | if(FD_ISSET(fd,&testfds)) | 102 | if(FD_ISSET(fd,&testfds)) |
103 | { | 103 | { |
104 | ioctl(fd, FIONREAD, &nread); | 104 | int trn = 0; |
105 | int rn; | ||
105 | 106 | ||
106 | if (nread == 0) | 107 | ioctl(fd, FIONREAD, &nread); |
107 | exit(0); | ||
108 | 108 | ||
109 | if(fd == sfd) | 109 | if(fd == sfd) |
110 | { | 110 | { |
111 | read(sfd, &ch, 1); | 111 | if (nread == 0) |
112 | write(fileno(stdout), &ch, 1); | 112 | exit(0); |
113 | } | 113 | ofd = fileno(stdout); |
114 | else | 114 | } |
115 | { | 115 | else |
116 | read(fileno(stdin), &ch, 1); | 116 | { |
117 | write(sfd, &ch, 1); | 117 | ofd = sfd; |
118 | } | 118 | } |
119 | } | 119 | |
120 | |||
121 | |||
122 | do | ||
123 | { | ||
124 | rn = (BUFSIZE < nread - trn) ? BUFSIZE : nread - trn; | ||
125 | trn += rn; | ||
126 | read(fd, ch, rn); | ||
127 | write(ofd, ch, rn); | ||
128 | } | ||
129 | while (trn < nread); | ||
130 | } | ||
120 | } | 131 | } |
121 | } | 132 | } |
122 | #else | ||
123 | pid = fork(); | ||
124 | |||
125 | if (!pid) | ||
126 | { | ||
127 | int retval; | ||
128 | retval = 1; | ||
129 | while(retval == 1) | ||
130 | { | ||
131 | retval = read(fileno(stdin), &ch, 1); | ||
132 | write(sfd, &ch, 1); | ||
133 | } | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | int retval; | ||
138 | retval = 1; | ||
139 | while(retval == 1) | ||
140 | { | ||
141 | retval = read(sfd, &ch, 1); | ||
142 | write(fileno(stdout), &ch, 1); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | exit(0); | ||
147 | #endif | ||
148 | } | 133 | } |
@@ -4,15 +4,15 @@ | |||
4 | const char pwd_usage[] = "Print the current directory.\n"; | 4 | const char pwd_usage[] = "Print the current directory.\n"; |
5 | 5 | ||
6 | extern int | 6 | extern int |
7 | pwd_main(struct FileInfo * i, int argc, char * * argv) | 7 | pwd_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 | } |