Annotation of /trunk/mkinitrd-magellan/busybox/coreutils/uuencode.c
Parent Directory | Revision Log
Revision 984 -
(hide annotations)
(download)
Sun May 30 11:32:42 2010 UTC (14 years ago) by niro
File MIME type: text/plain
File size: 1641 byte(s)
Sun May 30 11:32:42 2010 UTC (14 years ago) by niro
File MIME type: text/plain
File size: 1641 byte(s)
-updated to busybox-1.16.1 and enabled blkid/uuid support in default config
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * Copyright (C) 2000 by Glenn McGrath | ||
4 | * | ||
5 | * based on the function base64_encode from http.c in wget v1.6 | ||
6 | * Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc. | ||
7 | * | ||
8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
9 | */ | ||
10 | |||
11 | niro | 816 | #include "libbb.h" |
12 | niro | 532 | |
13 | niro | 816 | enum { |
14 | SRC_BUF_SIZE = 45, /* This *MUST* be a multiple of 3 */ | ||
15 | DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3), | ||
16 | }; | ||
17 | niro | 532 | |
18 | niro | 816 | int uuencode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
19 | niro | 984 | int uuencode_main(int argc UNUSED_PARAM, char **argv) |
20 | niro | 532 | { |
21 | struct stat stat_buf; | ||
22 | niro | 816 | int src_fd = STDIN_FILENO; |
23 | niro | 532 | const char *tbl; |
24 | mode_t mode; | ||
25 | niro | 816 | char src_buf[SRC_BUF_SIZE]; |
26 | char dst_buf[DST_BUF_SIZE + 1]; | ||
27 | niro | 532 | |
28 | tbl = bb_uuenc_tbl_std; | ||
29 | niro | 816 | mode = 0666 & ~umask(0666); |
30 | opt_complementary = "-1:?2"; /* must have 1 or 2 args */ | ||
31 | if (getopt32(argv, "m")) { | ||
32 | niro | 532 | tbl = bb_uuenc_tbl_base64; |
33 | } | ||
34 | niro | 816 | argv += optind; |
35 | niro | 984 | if (argv[1]) { |
36 | niro | 816 | src_fd = xopen(*argv, O_RDONLY); |
37 | fstat(src_fd, &stat_buf); | ||
38 | mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); | ||
39 | argv++; | ||
40 | } | ||
41 | niro | 532 | |
42 | niro | 816 | printf("begin%s %o %s", tbl == bb_uuenc_tbl_std ? "" : "-base64", mode, *argv); |
43 | while (1) { | ||
44 | size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE); | ||
45 | if (!size) | ||
46 | niro | 532 | break; |
47 | niro | 816 | if ((ssize_t)size < 0) |
48 | bb_perror_msg_and_die(bb_msg_read_error); | ||
49 | niro | 532 | /* Encode the buffer we just read in */ |
50 | niro | 816 | bb_uuencode(dst_buf, src_buf, size, tbl); |
51 | bb_putchar('\n'); | ||
52 | niro | 532 | if (tbl == bb_uuenc_tbl_std) { |
53 | niro | 816 | bb_putchar(tbl[size]); |
54 | niro | 532 | } |
55 | niro | 816 | fflush(stdout); |
56 | xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3)); | ||
57 | niro | 532 | } |
58 | printf(tbl == bb_uuenc_tbl_std ? "\n`\nend\n" : "\n====\n"); | ||
59 | |||
60 | fflush_stdout_and_exit(EXIT_SUCCESS); | ||
61 | } |