about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFulton Browne <git@fulton.software>2021-05-15 00:33:11 +0000
committerFulton Browne <git@fulton.software>2021-05-15 00:33:11 +0000
commit2e82773e3f043ce07469425225185fb17def312c (patch)
tree1366cdafd76047e0d2527c858589651587342e2d
parent88450878b4671c72726819ec30e627154bc8099f (diff)
downloadbase64-2e82773e3f043ce07469425225185fb17def312c.tar.gz
plan9
-rw-r--r--b64f.c18
-rw-r--r--base64.c4
-rw-r--r--base64.h9
3 files changed, 15 insertions, 16 deletions
diff --git a/b64f.c b/b64f.c
index 95acb6f..aa17963 100644
--- a/b64f.c
+++ b/b64f.c
@@ -1,12 +1,12 @@
+#include <u.h>
+#include <libc.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 
 #include "base64.h"
 
 int lower(int a);
 
-int main(int argc,char** argv) {
+void main(int argc,char** argv) {
 	
 	char opt = ' ';
 	if (argc > 1)
@@ -23,14 +23,14 @@ int main(int argc,char** argv) {
 		printf("\tUse the following to decode:\n\t%s b(ase64) IN_Base64\n",argv[0]);
 		
 		puts("\nERROR: insufficient or incorrect parameters...");
-		return 1;
+		exits("1");
 	}
 	
 	int bcoded = 0;
 	switch(opt) {
 		case 'd':
 			puts("\nDECODING");
-			bcoded = b64_decodef(argv[2],argv[3]);
+			bcoded = b64_decode(argv[2],argv[3]);
 			break;
 		case 'e':
 			puts("\nENCODING");
@@ -43,7 +43,7 @@ int main(int argc,char** argv) {
 				char *b64 = (char *)malloc(1 + (sizeof(char) * b64e_size(tlen)));
 				if (b64 == NULL) {
 					printf("Error: cannot allocate memory for output\n");
-					exit(1);  /* End program with error status. */
+					exits("1");  /* End program with error status. */
 				}
 			
 			bcoded = b64_encode(argv[2],tlen,b64);
@@ -57,10 +57,10 @@ int main(int argc,char** argv) {
 				char *txt = malloc(1 + (sizeof(char) * b64d_size(blen)));
 				if (txt == NULL) {
 					printf("Error: cannot allocate memory for output\n");
-					exit(1);  /* End program with error status. */
+					exits("1");  /* End program with error status. */
 				}
 			
-			bcoded = b64_decode(argv[2],blen,txt);
+			//bcoded = b64_decode(argv[2],blen,txt);
 			txt[bcoded] = '\0';
 			printf("Decoded text from base64: %s", txt);
 			free(txt);
@@ -71,8 +71,6 @@ int main(int argc,char** argv) {
 	}
 	
 	printf("\nBytes encoded/decoded: %i\n",bcoded);
-	
-	return 0;
 }
 
 int lower(int a) { //https://stackoverflow.com/a/15709023/883015
diff --git a/base64.c b/base64.c
index 06929db..8a57246 100644
--- a/base64.c
+++ b/base64.c
@@ -7,7 +7,9 @@
 	Thank you for inspiration:
 	http://www.codeproject.com/Tips/813146/Fast-base-functions-for-encode-decode
 */
-
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
 #include "base64.h"
 
 //Base64 char table - used internally for encoding
diff --git a/base64.h b/base64.h
index c700c7f..eb0dfbb 100644
--- a/base64.h
+++ b/base64.h
@@ -1,4 +1,4 @@
-/*
+/*
 	base64.c - by Joe DF (joedf@ahkscript.org)
 	Released under the MIT License
 	
@@ -8,7 +8,6 @@
 	http://www.codeproject.com/Tips/813146/Fast-base-functions-for-encode-decode
 */
 
-#include <stdio.h>
 
 //Base64 char table function - used internally for decoding
 unsigned int b64_int(unsigned int ch);
@@ -25,13 +24,13 @@ unsigned int b64d_size(unsigned int in_size);
 // in_len : number of bytes to be encoded.
 // out : pointer to buffer with enough memory, user is responsible for memory allocation, receives null-terminated string
 // returns size of output including null byte
-unsigned int b64_encode(const unsigned char* in, unsigned int in_len, unsigned char* out);
+unsigned int b64_encode(unsigned char* in, unsigned int in_len, unsigned char* out);
 
 // in : buffer of base64 string to be decoded.
 // 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(const unsigned char* in, unsigned int in_len, unsigned char* out);
+unsigned int b64_decode(unsigned char* in, unsigned int in_len, unsigned char* out);
 
 // file-version b64_encode
 // Input : filenames
@@ -41,4 +40,4 @@ unsigned int b64_encodef(char *InFile, char *OutFile);
 // file-version b64_decode
 // Input : filenames
 // returns size of output
-unsigned int b64_decodef(char *InFile, char *OutFile);
\ No newline at end of file
+unsigned int b64_decodef(char *InFile, char *OutFile);