summaryrefslogtreecommitdiffstats
path: root/liblog_use_file_for_range.c
diff options
context:
space:
mode:
Diffstat (limited to 'liblog_use_file_for_range.c')
-rw-r--r--liblog_use_file_for_range.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/liblog_use_file_for_range.c b/liblog_use_file_for_range.c
new file mode 100644
index 0000000..e312c4b
--- /dev/null
+++ b/liblog_use_file_for_range.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+struct liblog_output *
+liblog_use_file_for_range(struct liblog_context *ctx, int dirfd, const char *path, const char *prefixfmt,
+ int use_backtrace, enum liblog_level least_verbose, enum liblog_level most_verbose)
+{
+ struct liblog_output *ret;
+ int fd;
+ if (!path || !*path)
+ return liblog_use_fd_for_range(ctx, dirfd, prefixfmt, use_backtrace, least_verbose, most_verbose);
+ 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_for_range(ctx, fd, prefixfmt, use_backtrace, least_verbose, most_verbose);
+ if (!ret) {
+ close(fd);
+ return NULL;
+ }
+ ret->sink.file.owns_fd = 1;
+ return ret;
+}
+
+#else
+
+int main(void) {return 0;} /* TODO test */
+
+#endif