diff options
Diffstat (limited to 'liblog_destroy_output.c')
| -rw-r--r-- | liblog_destroy_output.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/liblog_destroy_output.c b/liblog_destroy_output.c new file mode 100644 index 0000000..98bb2dd --- /dev/null +++ b/liblog_destroy_output.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +int +liblog_destroy_output(struct liblog_output *output) +{ + int saved_errno = 0; /* initialised to silence false warning */ + int ret = 0; + + if (!output) + return 0; + + if (output->sink_type == LIBLOG_FILE && output->sink.file.owns_fd) { + saved_errno = errno; + ret = close(output->sink.file.fd); + output->sink.file.fd = -1; + } else if (output->sink_type == LIBLOG_STREAM && output->sink.stream.owns_stream) { + saved_errno = errno; + ret = fclose(output->sink.stream.stream); + output->sink.stream.stream = NULL; +#if EOF != -1 + if (ret == EOF) + ret = -1; +#endif + } + + if (ret && errno != EINTR) { + ret = 0; + errno = saved_errno; + } + + return ret; +} + +#else + +int main(void) {return 0;} /* TODO test */ + +#endif |
