diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-08-21 12:48:32 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-08-29 13:34:41 +0200 |
| commit | 57a13bcea2b70c09aff2953bd0a2d451659e9bdd (patch) | |
| tree | e89623e4812e4069033b9dc7da3d2060e0bb351f /text.c | |
| parent | 6aaab772e878eb7605f2fa5d1b07b1ada1af1f30 (diff) | |
| download | vis-57a13bcea2b70c09aff2953bd0a2d451659e9bdd.tar.gz vis-57a13bcea2b70c09aff2953bd0a2d451659e9bdd.tar.xz | |
text: provide load function taking a directory descriptor
Diffstat (limited to 'text.c')
| -rw-r--r-- | text.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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; |
