diff options
Diffstat (limited to 'liblog_use_file.c')
| -rw-r--r-- | liblog_use_file.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/liblog_use_file.c b/liblog_use_file.c new file mode 100644 index 0000000..3083f1a --- /dev/null +++ b/liblog_use_file.c @@ -0,0 +1,32 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +struct liblog_output * +liblog_use_file(struct liblog_context *ctx, int dirfd, const char *path, const char *prefixfmt, int use_backtrace) +{ + struct liblog_output *ret; + int fd; + if (!path || !*path) + return liblog_use_fd(ctx, dirfd, prefixfmt, use_backtrace); + if (dirfd == -1 && *path != '/') { + errno = EINVAL; + return NULL; + } + fd = openat(dirfd, path, O_WRONLY | O_CREAT | O_APPEND, 0644); + if (fd < 0) + return NULL; + ret = liblog_use_fd(ctx, fd, prefixfmt, use_backtrace); + if (!ret) { + close(fd); + return NULL; + } + ret->sink.file.owns_fd = 1; + return ret; +} + +#else + +int main(void) {return 0;} /* TODO test */ + +#endif |
