about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFulton Browne <git@fulton.software>2021-05-16 19:21:23 +0000
committerFulton Browne <git@fulton.software>2021-05-16 19:21:23 +0000
commita97878bf4502f48a80f5b48ee32752bff7696f71 (patch)
treefad44e544a4f1a0c4728bc8416393c82b3d29b7f
parent712a87ab8526492284f6dcfe0249d24ea3ffc66f (diff)
downloadbase64-a97878bf4502f48a80f5b48ee32752bff7696f71.tar.gz
almost... HEAD master
-rw-r--r--base64.c2
-rw-r--r--base64.h2
-rw-r--r--base64decode.c6
3 files changed, 5 insertions, 5 deletions
diff --git a/base64.c b/base64.c
index 253bf4e..efcf3d4 100644
--- a/base64.c
+++ b/base64.c
@@ -86,7 +86,7 @@ b64_encode(char* in, unsigned int in_len, char* out){
 	return k;
 }
 
-unsigned int
+int
 b64_decode(char* in, unsigned int in_len, char* out){
 
 	unsigned int i=0, j=0, k=0, s[4];
diff --git a/base64.h b/base64.h
index 7f7e319..d5d05be 100644
--- a/base64.h
+++ b/base64.h
@@ -30,4 +30,4 @@ unsigned int b64_encode(char* in, unsigned int in_len, char* out);
 // in_len : number of bytes to be decoded.
 // out : pointer to buffer with enough memory, user is responsible for memory allocation, receives "raw" binary
 // returns size of output excluding null byte
-unsigned int b64_decode(char* in, unsigned int in_len, char* out);
+int b64_decode(char* in, unsigned int in_len, char* out);
diff --git a/base64decode.c b/base64decode.c
index 625f08f..3e30fb8 100644
--- a/base64decode.c
+++ b/base64decode.c
@@ -12,7 +12,7 @@ usage(void)
 static void 
 decode(int fd, char *name)
 {
-	int n;
+	int n, nb;
 	long tot;
 	char *buf, *outbuf;
 	outbuf = nil;
@@ -29,9 +29,9 @@ decode(int fd, char *name)
 		tot += n;
 	}
 	buf[tot] = 0;
-	print("DEBUG: %d \n", strlen(outbuf));
 	outbuf =  malloc(b64d_size(strlen(buf)));
-	b64_decode(buf, strlen(buf), outbuf);
+	nb = b64_decode(buf, strlen(buf), outbuf);
+	outbuf[nb] = 0;
 	if((n=write(1,  outbuf, strlen(outbuf))) != strlen(outbuf))
 		sysfatal("writing bytes failed");
 }