diff options
author | Denys Vlasenko | 2020-11-28 13:26:44 +0100 |
---|---|---|
committer | Denys Vlasenko | 2020-11-28 13:27:36 +0100 |
commit | 885121e25db2ec9a8191a406085d91790a133d20 (patch) | |
tree | aa5c89af1b273c618bef11b836de38788007b4c9 /libbb | |
parent | fc6faac84e978c9482106f53e711ab971a0ce188 (diff) | |
download | busybox-885121e25db2ec9a8191a406085d91790a133d20.zip busybox-885121e25db2ec9a8191a406085d91790a133d20.tar.gz |
libbb: change decode_base32/64 API to return the end of _dst_, not _src_.
function old new delta
decode_base64 173 178 +5
read_base64 222 220 -2
decode_base32 186 182 -4
handle_incoming_and_exit 2263 2239 -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-30) Total: -25 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/uuencode.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/libbb/uuencode.c b/libbb/uuencode.c index 139c60b..6e63bfc 100644 --- a/libbb/uuencode.c +++ b/libbb/uuencode.c @@ -86,9 +86,9 @@ void FAST_FUNC bb_uuencode(char *p, const void *src, int length, const char *tbl * If points to '\0', then the source was fully decoded. * (*pp_dst): advanced past the last written byte. */ -const char* FAST_FUNC decode_base64(char **pp_dst, const char *src) +char* FAST_FUNC decode_base64(char *dst, const char **pp_src) { - char *dst = *pp_dst; + const char *src = pp_src ? *pp_src : dst; /* for httpd.c, support NULL 2nd param */ unsigned ch = 0; unsigned t; int i = 0; @@ -129,16 +129,17 @@ const char* FAST_FUNC decode_base64(char **pp_dst, const char *src) ch = 0; } } - *pp_dst = dst; /* i is zero here if full 4-char block was decoded */ - return src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */ + if (pp_src) + *pp_src = src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */ + return dst; } #if ENABLE_BASE32 -const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) +char* FAST_FUNC decode_base32(char *dst, const char **pp_src) { - char *dst = *pp_dst; - int64_t ch = 0; + const char *src = *pp_src; + uint64_t ch = 0; unsigned t; int i = 0; @@ -169,9 +170,9 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) *dst++ = (char) ch; } } - *pp_dst = dst; /* i is zero here if full 8-char block was decoded */ - return src - i; + *pp_src = src - i; + return dst; tail: { const char *s = src; @@ -192,8 +193,8 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) *dst++ = (char) ch; dst -= (i+1) * 2 / 3; /* discard last 1, 2, 3 or 4 bytes */ } - *pp_dst = dst; - return src; + *pp_src = src; + return dst; } #endif @@ -249,13 +250,13 @@ void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags) if (uu_style_end && strcmp(buf, "====") == 0) return; - out_tail = buf; + in_tail = buf; #if ENABLE_BASE32 if (base32) - in_tail = decode_base32(&out_tail, buf); + out_tail = decode_base32(buf, &in_tail); else #endif - in_tail = decode_base64(&out_tail, buf); + out_tail = decode_base64(buf, &in_tail); fwrite(buf, (out_tail - buf), 1, dst_stream); |