From f74d57fee040218af039f8157cf645d0902ad300 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Thu, 9 Jun 2016 16:20:17 +0200 Subject: Adds missing file from previous commit. --- src/io/data_output.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/io/data_output.c (limited to 'src/io/data_output.c') diff --git a/src/io/data_output.c b/src/io/data_output.c new file mode 100644 index 0000000..796d3d0 --- /dev/null +++ b/src/io/data_output.c @@ -0,0 +1,65 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include /* defines SIZE_MAX */ +#include + +#include "error.h" + +#include "data_output.h" + +int ZoO_data_output_write_line +( + const char filename [const restrict static 1], + char line [const restrict static 1], + size_t const line_size +) +{ + const int old_errno = errno; + FILE * file; + + file = fopen(filename, "a"); + + if (file == (FILE *) NULL) + { + ZoO_ERROR + ( + "Could not open file '%s' in appending mode.", + filename + ); + + return -1; + } + + line[line_size - 1] = '\n'; + + if + ( + fwrite + ( + (const void *) line, + sizeof(char), + line_size, + file + ) < line_size + ) + { + line[line_size - 1] = '\0'; + + ZoO_ERROR + ( + "Could not store line '%s' in %s.", + line, + filename + ); + + fclose(file); + + return -1; + } + + fclose(file); + + return 0; +} -- cgit v1.2.3-70-g09d2