free(output);
}
-int read_base64_file(char* path, char** ciphertext, int *ciphertext_length) {
- char* ciphertext_base64=NULL;
- int ciphertext_base64_length=0;
+void gulp_file_strip_newlines(char* path, char** result_text, int *result_length) {
+ *result_length=0;
FILE *f = fopen(path, "r");
int line_length=0;
int line_buf_length;
while ((line_length = getline(&line, &line_buf_length, f))>0) {
if (line[line_length-1] == '\000') line_length--;
if (line[line_length-1] == '\n') line_length--;
- ciphertext_base64 = realloc(ciphertext_base64, ciphertext_base64_length+line_length+1);
- memcpy(ciphertext_base64+ciphertext_base64_length, line, line_length);
- ciphertext_base64_length += line_length;
+ *result_text = realloc(*result_text, (*result_length)+line_length+1);
+ memcpy((*result_text)+(*result_length), line, line_length);
+ (result_length) += line_length;
}
free(line);
fclose(f);
- ciphertext_base64[ciphertext_base64_length]=0;
+ (*result_text)[*result_length]=0;
+ (*result_length)++;
+}
+
+int read_base64_file(char* path, char** ciphertext, int *ciphertext_length) {
+ char* ciphertext_base64=NULL;
+ int ciphertext_base64_length=0;
+ gulp_file_strip_newlines(path, &ciphertext_base64, &ciphertext_base64_length);
int succ = decode_base64(ciphertext_base64, *ciphertext, ciphertext_length);
free(ciphertext_base64);
return succ;