2001-07-29 02:36:13 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2017-10-05 18:10:24 +05:30
|
|
|
* Copyright (C) 2000 by Glenn McGrath
|
2000-06-13 12:24:53 +05:30
|
|
|
*
|
2017-10-05 18:10:24 +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
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2000-06-13 12:24:53 +05:30
|
|
|
*/
|
2016-11-23 19:16:56 +05:30
|
|
|
//config:config UUENCODE
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "uuencode (4.4 kb)"
|
2016-11-23 19:16:56 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: uuencode is used to uuencode a file.
|
2016-11-23 19:16:56 +05:30
|
|
|
|
|
|
|
//applet:IF_UUENCODE(APPLET(uuencode, BB_DIR_USR_BIN, BB_SUID_DROP))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_UUENCODE) += uuencode.o
|
2006-08-03 21:11:12 +05:30
|
|
|
|
2011-03-31 18:13:25 +05:30
|
|
|
//usage:#define uuencode_trivial_usage
|
2012-03-05 18:52:33 +05:30
|
|
|
//usage: "[-m] [FILE] STORED_FILENAME"
|
2011-03-31 18:13:25 +05:30
|
|
|
//usage:#define uuencode_full_usage "\n\n"
|
2012-03-05 18:52:33 +05:30
|
|
|
//usage: "Uuencode FILE (or stdin) to stdout\n"
|
2011-03-31 18:13:25 +05:30
|
|
|
//usage: "\n -m Use base64 encoding per RFC1521"
|
|
|
|
//usage:
|
|
|
|
//usage:#define uuencode_example_usage
|
|
|
|
//usage: "$ uuencode busybox busybox\n"
|
|
|
|
//usage: "begin 755 busybox\n"
|
|
|
|
//usage: "<encoded file snipped>\n"
|
|
|
|
//usage: "$ uudecode busybox busybox > busybox.uu\n"
|
|
|
|
//usage: "$\n"
|
|
|
|
|
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 {
|
2010-08-31 17:39:22 +05:30
|
|
|
SRC_BUF_SIZE = 15*3, /* This *MUST* be a multiple of 3 */
|
2007-06-26 21:29:37 +05:30
|
|
|
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);
|
2017-08-09 01:25:02 +05:30
|
|
|
if (getopt32(argv, "^" "m" "\0" "-1:?2"/*must have 1 or 2 args*/)) {
|
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]) {
|
2010-08-31 17:39:22 +05:30
|
|
|
src_fd = xopen(argv[0], O_RDONLY);
|
2007-06-26 21:29:37 +05:30
|
|
|
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)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_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
|
|
|
|
2022-01-05 04:01:58 +05:30
|
|
|
fflush_stdout_and_exit_SUCCESS();
|
2000-06-13 12:24:53 +05:30
|
|
|
}
|