vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 4e262d7edb7547d4620c6fd77c55890168acd5ab
parent 321129188c0f25c07f6a218d9af81d85ab3ef38d
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 21 Aug 2020 12:48:32 +0200

text: provide load function taking a directory descriptor

Diffstat:
Mtext.c | 10+++++++++-
Mtext.h | 2++
2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/text.c b/text.c @@ -1116,7 +1116,15 @@ Text *text_load(const char *filename) { return text_load_method(filename, TEXT_LOAD_AUTO); } +Text *text_loadat(int dirfd, const char *filename) { + return text_loadat_method(dirfd, filename, TEXT_LOAD_AUTO); +} + Text *text_load_method(const char *filename, enum TextLoadMethod method) { + return text_loadat_method(AT_FDCWD, filename, method); +} + +Text *text_loadat_method(int dirfd, const char *filename, enum TextLoadMethod method) { int fd = -1; size_t size = 0; Text *txt = calloc(1, sizeof *txt); @@ -1127,7 +1135,7 @@ Text *text_load_method(const char *filename, enum TextLoadMethod method) { goto out; lineno_cache_invalidate(&txt->lines); if (filename) { - if ((fd = open(filename, O_RDONLY)) == -1) + if ((fd = openat(dirfd, filename, O_RDONLY)) == -1) goto out; if (fstat(fd, &txt->info) == -1) goto out; diff --git a/text.h b/text.h @@ -95,6 +95,7 @@ enum TextLoadMethod { * @endrst */ Text *text_load(const char *filename); +Text *text_loadat(int dirfd, const char *filename); /** * Create a text instance populated with the given file content. * @@ -109,6 +110,7 @@ Text *text_load(const char *filename); * @endrst */ Text *text_load_method(const char *filename, enum TextLoadMethod); +Text *text_loadat_method(int dirfd, const char *filename, enum TextLoadMethod); /** Release all ressources associated with this text instance. */ void text_free(Text*); /**