2001-07-29 02:36:13 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2000 by Glenn McGrath
|
2000-06-13 12:24:53 +05:30
|
|
|
*
|
2001-07-29 02:36:13 +05:30
|
|
|
* based on the function base64_encode from http.c in wget v1.6
|
|
|
|
* Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
|
2000-06-13 12:24:53 +05:30
|
|
|
*
|
2006-07-12 13:26:04 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2000-06-13 12:24:53 +05:30
|
|
|
*/
|
2006-08-03 21:11:12 +05:30
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2000-06-13 12:24:53 +05:30
|
|
|
|
2007-06-26 21:29:37 +05:30
|
|
|
enum {
|
|
|
|
SRC_BUF_SIZE = 45, /* This *MUST* be a multiple of 3 */
|
|
|
|
DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
|
|
|
|
};
|
2000-06-13 12:24:53 +05:30
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int uuencode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2010-01-04 18:45:38 +05:30
|
|
|
int uuencode_main(int argc UNUSED_PARAM, char **argv)
|
2000-06-13 12:24:53 +05:30
|
|
|
{
|
2001-07-29 02:36:13 +05:30
|
|
|
struct stat stat_buf;
|
2007-06-26 21:29:37 +05:30
|
|
|
int src_fd = STDIN_FILENO;
|
2003-03-19 14:43:01 +05:30
|
|
|
const char *tbl;
|
2001-07-29 02:36:13 +05:30
|
|
|
mode_t mode;
|
2007-06-26 21:29:37 +05:30
|
|
|
char src_buf[SRC_BUF_SIZE];
|
|
|
|
char dst_buf[DST_BUF_SIZE + 1];
|
2001-07-29 02:36:13 +05:30
|
|
|
|
2006-09-03 21:19:40 +05:30
|
|
|
tbl = bb_uuenc_tbl_std;
|
2007-06-26 21:29:37 +05:30
|
|
|
mode = 0666 & ~umask(0666);
|
|
|
|
opt_complementary = "-1:?2"; /* must have 1 or 2 args */
|
2007-08-18 21:02:12 +05:30
|
|
|
if (getopt32(argv, "m")) {
|
2006-09-03 21:19:40 +05:30
|
|
|
tbl = bb_uuenc_tbl_base64;
|
2001-07-29 02:36:13 +05:30
|
|
|
}
|
2007-06-26 21:29:37 +05:30
|
|
|
argv += optind;
|
2010-01-04 18:45:38 +05:30
|
|
|
if (argv[1]) {
|
2007-06-26 21:29:37 +05:30
|
|
|
src_fd = xopen(*argv, O_RDONLY);
|
|
|
|
fstat(src_fd, &stat_buf);
|
|
|
|
mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
|
|
|
argv++;
|
2001-07-29 02:36:13 +05:30
|
|
|
}
|
|
|
|
|
2007-06-26 21:29:37 +05:30
|
|
|
printf("begin%s %o %s", tbl == bb_uuenc_tbl_std ? "" : "-base64", mode, *argv);
|
|
|
|
while (1) {
|
|
|
|
size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE);
|
|
|
|
if (!size)
|
|
|
|
break;
|
|
|
|
if ((ssize_t)size < 0)
|
|
|
|
bb_perror_msg_and_die(bb_msg_read_error);
|
2001-07-29 02:36:13 +05:30
|
|
|
/* Encode the buffer we just read in */
|
2007-06-26 21:29:37 +05:30
|
|
|
bb_uuencode(dst_buf, src_buf, size, tbl);
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2006-09-03 21:19:40 +05:30
|
|
|
if (tbl == bb_uuenc_tbl_std) {
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar(tbl[size]);
|
2002-05-01 11:27:16 +05:30
|
|
|
}
|
2007-06-26 21:29:37 +05:30
|
|
|
fflush(stdout);
|
|
|
|
xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3));
|
2001-07-29 02:36:13 +05:30
|
|
|
}
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(tbl == bb_uuenc_tbl_std ? "\n`\nend\n" : "\n====\n");
|
2003-03-19 14:43:01 +05:30
|
|
|
|
2006-10-27 04:51:47 +05:30
|
|
|
fflush_stdout_and_exit(EXIT_SUCCESS);
|
2000-06-13 12:24:53 +05:30
|
|
|
}
|