diff options
author | mjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | mjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-19 09:13:01 +0000 |
commit | e901c15d890dbbdce4c086963cb1513653fc46b5 (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/uuencode.c | |
parent | 40758c00616c3b2c85d83eb4afdeb04b1f65c9f1 (diff) | |
download | busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.gz busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.bz2 busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.zip |
Major coreutils update.
git-svn-id: svn://busybox.net/trunk/busybox@6751 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils/uuencode.c')
-rw-r--r-- | coreutils/uuencode.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c index 49b2d9189..fd3326d80 100644 --- a/coreutils/uuencode.c +++ b/coreutils/uuencode.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #include "busybox.h" | 29 | #include "busybox.h" |
30 | 30 | ||
31 | /* Conversion table. for base 64 */ | 31 | /* Conversion table. for base 64 */ |
32 | static char tbl_base64[65] = { | 32 | static const char tbl_base64[65] = { |
33 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', | 33 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', |
34 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', | 34 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
35 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', | 35 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', |
@@ -41,7 +41,7 @@ static char tbl_base64[65] = { | |||
41 | '=' /* termination character */ | 41 | '=' /* termination character */ |
42 | }; | 42 | }; |
43 | 43 | ||
44 | static char tbl_std[65] = { | 44 | static const char tbl_std[65] = { |
45 | '`', '!', '"', '#', '$', '%', '&', '\'', | 45 | '`', '!', '"', '#', '$', '%', '&', '\'', |
46 | '(', ')', '*', '+', ',', '-', '.', '/', | 46 | '(', ')', '*', '+', ',', '-', '.', '/', |
47 | '0', '1', '2', '3', '4', '5', '6', '7', | 47 | '0', '1', '2', '3', '4', '5', '6', '7', |
@@ -92,40 +92,36 @@ int uuencode_main(int argc, char **argv) | |||
92 | int write_size = dst_buf_size; | 92 | int write_size = dst_buf_size; |
93 | struct stat stat_buf; | 93 | struct stat stat_buf; |
94 | FILE *src_stream = stdin; | 94 | FILE *src_stream = stdin; |
95 | char *tbl = tbl_std; | 95 | const char *tbl; |
96 | size_t size; | 96 | size_t size; |
97 | mode_t mode; | 97 | mode_t mode; |
98 | int opt; | ||
99 | RESERVE_CONFIG_BUFFER(src_buf, SRC_BUF_SIZE + 1); | 98 | RESERVE_CONFIG_BUFFER(src_buf, SRC_BUF_SIZE + 1); |
100 | RESERVE_CONFIG_BUFFER(dst_buf, DST_BUF_SIZE + 1); | 99 | RESERVE_CONFIG_BUFFER(dst_buf, DST_BUF_SIZE + 1); |
101 | 100 | ||
102 | while ((opt = getopt(argc, argv, "m")) != -1) { | 101 | tbl = tbl_std; |
103 | switch (opt) { | 102 | if (bb_getopt_ulflags(argc, argv, "m") & 1) { |
104 | case 'm': | 103 | tbl = tbl_base64; |
105 | tbl = tbl_base64; | ||
106 | break; | ||
107 | default: | ||
108 | show_usage(); | ||
109 | } | ||
110 | } | 104 | } |
111 | 105 | ||
112 | switch (argc - optind) { | 106 | switch (argc - optind) { |
113 | case 2: | 107 | case 2: |
114 | src_stream = xfopen(argv[optind], "r"); | 108 | src_stream = bb_xfopen(argv[optind], "r"); |
115 | stat(argv[optind], &stat_buf); | 109 | if (stat(argv[optind], &stat_buf) < 0) { |
110 | bb_perror_msg_and_die("stat"); | ||
111 | } | ||
116 | mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); | 112 | mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); |
117 | if (src_stream == stdout) { | 113 | if (src_stream == stdout) { |
118 | printf("NULL\n"); | 114 | puts("NULL"); |
119 | } | 115 | } |
120 | break; | 116 | break; |
121 | case 1: | 117 | case 1: |
122 | mode = 0666 & ~umask(0666); | 118 | mode = 0666 & ~umask(0666); |
123 | break; | 119 | break; |
124 | default: | 120 | default: |
125 | show_usage(); | 121 | bb_show_usage(); |
126 | } | 122 | } |
127 | 123 | ||
128 | printf("begin%s %o %s", tbl == tbl_std ? "" : "-base64", mode, argv[argc - 1]); | 124 | bb_printf("begin%s %o %s", tbl == tbl_std ? "" : "-base64", mode, argv[argc - 1]); |
129 | 125 | ||
130 | while ((size = fread(src_buf, 1, src_buf_size, src_stream)) > 0) { | 126 | while ((size = fread(src_buf, 1, src_buf_size, src_stream)) > 0) { |
131 | if (size != src_buf_size) { | 127 | if (size != src_buf_size) { |
@@ -142,10 +138,12 @@ int uuencode_main(int argc, char **argv) | |||
142 | putchar(tbl[size]); | 138 | putchar(tbl[size]); |
143 | } | 139 | } |
144 | if (fwrite(dst_buf, 1, write_size, stdout) != write_size) { | 140 | if (fwrite(dst_buf, 1, write_size, stdout) != write_size) { |
145 | perror("Couldnt finish writing"); | 141 | bb_perror_msg_and_die(bb_msg_write_error); |
146 | } | 142 | } |
147 | } | 143 | } |
148 | printf(tbl == tbl_std ? "\n`\nend\n" : "\n====\n"); | 144 | bb_printf(tbl == tbl_std ? "\n`\nend\n" : "\n====\n"); |
145 | |||
146 | bb_xferror(src_stream, "source"); /* TODO - Fix this! */ | ||
149 | 147 | ||
150 | return(EXIT_SUCCESS); | 148 | bb_fflush_stdout_and_exit(EXIT_SUCCESS); |
151 | } | 149 | } |