{
#define err signo
if (SIGALRM == signo) {
- bb_error_msg_and_die("timed out");
+ bb_simple_error_msg_and_die("timed out");
}
// SIGCHLD. reap zombies
}
*/
-void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol)
+static void encode_n_base64(const char *fname, const char *text, size_t len)
{
enum {
SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */
#define src_buf text
char src[SRC_BUF_SIZE];
FILE *fp = fp;
- ssize_t len = len;
char dst_buf[DST_BUF_SIZE + 1];
if (fname) {
- fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : (FILE *)text;
+ fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : stdin;
src_buf = src;
- } else if (text) {
- // though we do not call uuencode(NULL, NULL) explicitly
- // still we do not want to break things suddenly
- len = strlen(text);
- } else
- return;
+ }
while (1) {
size_t size;
if (fname) {
size = fread((char *)src_buf, 1, SRC_BUF_SIZE, fp);
if ((ssize_t)size < 0)
- bb_perror_msg_and_die(bb_msg_read_error);
+ bb_simple_perror_msg_and_die(bb_msg_read_error);
} else {
size = len;
if (len > SRC_BUF_SIZE)
// encode the buffer we just read in
bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
if (fname) {
- puts(eol);
+ puts("");
} else {
src_buf += size;
len -= size;
#undef src_buf
}
+void FAST_FUNC printstr_base64(const char *text)
+{
+ encode_n_base64(NULL, text, strlen(text));
+}
+
+void FAST_FUNC printbuf_base64(const char *text, unsigned len)
+{
+ encode_n_base64(NULL, text, len);
+}
+
+void FAST_FUNC printfile_base64(const char *fname)
+{
+ encode_n_base64(fname, NULL, 0);
+}
+
/*
* get username and password from a file descriptor
*/
G.pass = xmalloc_reads(fd, /* maxsize: */ NULL);
}
if (!G.user || !*G.user || !G.pass)
- bb_error_msg_and_die("no username or password");
+ bb_simple_error_msg_and_die("no username or password");
}