aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2016-06-09 16:20:17 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2016-06-09 16:20:17 +0200
commitf74d57fee040218af039f8157cf645d0902ad300 (patch)
treec723b6e5aaccec735ecb617bb9eca011269e36ca
parent16265ec44520c3926c11127d0a6a6bac82a53275 (diff)
downloadzero-of-one-f74d57fee040218af039f8157cf645d0902ad300.zip
zero-of-one-f74d57fee040218af039f8157cf645d0902ad300.tar.bz2
Adds missing file from previous commit.
-rw-r--r--src/io/data_output.c65
-rw-r--r--src/io/data_output.h11
2 files changed, 76 insertions, 0 deletions
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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h> /* defines SIZE_MAX */
+#include <stdio.h>
+
+#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;
+}
diff --git a/src/io/data_output.h b/src/io/data_output.h
new file mode 100644
index 0000000..ef963a0
--- /dev/null
+++ b/src/io/data_output.h
@@ -0,0 +1,11 @@
+#ifndef _ZoO_IO_DATA_OUTPUT_H_
+#define _ZoO_IO_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
+);
+
+#endif