Introduction
Introduction Statistics Contact Development Disclaimer Help
Fixed #63 - fiche - A pastebin adjusted for gopher use
git clone git://vernunftzentrum.de/fiche.git
Log
Files
Refs
LICENSE
---
commit 6d292a30019703f6ef27bec73e98b3263e3a89a0
parent 680bb77f2c2cd4e39344502268f4552932052881
Author: solusipse <[email protected]>
Date: Thu, 12 Oct 2017 01:28:35 +0200
Fixed #63
Diffstat:
fiche.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/fiche.c b/fiche.c
@@ -141,7 +141,7 @@ static int create_directory(char *output_dir, char *slug);
* @arg data Buffer with data received from the user
* @arg path Path at which file containing data from the buffer will be created
*/
-static int save_to_file(uint8_t *data, char *output_dir, char *slug);
+static int save_to_file(const Fiche_Settings *s, uint8_t *data, char *slug);
// Logging-related
@@ -637,7 +637,7 @@ static void *handle_connection(void *args) {
// Save to file failed, we have to finish here
- if ( save_to_file(buffer, c->settings->output_dir_path, slug) != 0 ) {
+ if ( save_to_file(c->settings, buffer, slug) != 0 ) {
print_error("Couldn't save a file!");
print_separator();
@@ -739,11 +739,11 @@ static int create_directory(char *output_dir, char *slug)…
}
-static int save_to_file(uint8_t *data, char *output_dir, char *slug) {
+static int save_to_file(const Fiche_Settings *s, uint8_t *data, char *slug) {
char *file_name = "index.txt";
// Additional 2 bytes are for 2 slashes
- size_t len = strlen(output_dir) + strlen(slug) + strlen(file_name) + 3;
+ size_t len = strlen(s->output_dir_path) + strlen(slug) + strlen(file_name)…
// Generate a path
char *path = malloc(len);
@@ -751,7 +751,7 @@ static int save_to_file(uint8_t *data, char *output_dir, ch…
return -1;
}
- snprintf(path, len, "%s%s%s%s%s", output_dir, "/", slug, "/", file_name);
+ snprintf(path, len, "%s%s%s%s%s", s->output_dir_path, "/", slug, "/", file…
// Attempt file saving
FILE *f = fopen(path, "w");
@@ -760,6 +760,14 @@ static int save_to_file(uint8_t *data, char *output_dir, c…
return -1;
}
+ // Null-terminate buffer if not null terminated already
+ for (int i = 0; i < s->buffer_len; i++) {
+ if (data[i] == 0) {
+ break;
+ }
+ data[s->buffer_len - 1] = 0;
+ }
+
if ( fprintf(f, "%s", data) < 0 ) {
fclose(f);
free(path);
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.