| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-01-20 22:19:09 +0100 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-01-20 22:19:09 +0100 |
| commit | df3657b2a99ef20da99ac3c6c02f43cc23e70fca (patch) | |
| tree | 86a9e72bbbbaf7296b2d7cd2725a8bc42611a1f3 /src/storage | |
| parent | 0d49fb74eadcf933f696420cd182077927680d26 (diff) | |
Moving towards a server/clients structure.
Diffstat (limited to 'src/storage')
| -rw-r--r-- | src/storage/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/storage/storage.c | 69 | ||||
| -rw-r--r-- | src/storage/storage.h | 14 |
3 files changed, 90 insertions, 0 deletions
diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt new file mode 100644 index 0000000..782a234 --- /dev/null +++ b/src/storage/CMakeLists.txt @@ -0,0 +1,7 @@ +set( + SRC_FILES ${SRC_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/storage.c +) + +set(SRC_FILES ${SRC_FILES} PARENT_SCOPE) + diff --git a/src/storage/storage.c b/src/storage/storage.c new file mode 100644 index 0000000..22c5c49 --- /dev/null +++ b/src/storage/storage.c @@ -0,0 +1,69 @@ +#define _POSIX_C_SOURCE 200809L + +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <stdint.h> /* defines SIZE_MAX */ +#include <stdio.h> + +#include "../pipe/pipe.h" + +#include "storage.h" + +int ZoO_storage_write_line +( + const char filename [const restrict static 1], + char line [const restrict static 1], + size_t const line_size, + const struct ZoO_pipe io [const restrict static 1] +) +{ + const int old_errno = errno; + FILE * file; + + file = fopen(filename, "a"); + + if (file == (FILE *) NULL) + { + ZoO_ERROR + ( + io, + "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 + ( + io, + "Could not store line '%s' in %s.", + line, + filename + ); + + fclose(file); + + return -1; + } + + fclose(file); + + return 0; +} diff --git a/src/storage/storage.h b/src/storage/storage.h new file mode 100644 index 0000000..c287b23 --- /dev/null +++ b/src/storage/storage.h @@ -0,0 +1,14 @@ +#ifndef _ZoO_STORAGE_STORAGE_H_ +#define _ZoO_STORAGE_STORAGE_H_ + +#include "../pipe/pipe_types.h" + +int ZoO_storage_write_line +( + const char filename [const restrict static 1], + char line [const restrict static 1], + size_t const line_size, + const struct ZoO_pipe io [const restrict static 1] +); + +#endif |


