aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--common.h1
-rw-r--r--libskrift.h3
-rw-r--r--libskrift_open_font_at.c18
4 files changed, 23 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 85769d0..1481734 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,7 @@ OBJ =\
libskrift_merge_glyphs.o\
libskrift_millimeters_to_pixels.o\
libskrift_open_font.o\
+ libskrift_open_font_at.o\
libskrift_open_font_fd.o\
libskrift_open_font_file.o\
libskrift_open_font_mem.o\
diff --git a/common.h b/common.h
index 79f5507..dc9bcbd 100644
--- a/common.h
+++ b/common.h
@@ -5,6 +5,7 @@
#include <alloca.h>
#include <endian.h>
#include <errno.h>
+#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
diff --git a/libskrift.h b/libskrift.h
index 57eb4d1..cbfe9df 100644
--- a/libskrift.h
+++ b/libskrift.h
@@ -233,6 +233,9 @@ _LIBSKRIFT_GCC_ONLY(__attribute__((__nonnull__)))
int libskrift_open_font_fd(LIBSKRIFT_FONT **, int);
_LIBSKRIFT_GCC_ONLY(__attribute__((__nonnull__)))
+int libskrift_open_font_at(LIBSKRIFT_FONT **, int, const char *);
+
+_LIBSKRIFT_GCC_ONLY(__attribute__((__nonnull__)))
int libskrift_open_font(LIBSKRIFT_FONT **, FILE *);
void libskrift_close_font(LIBSKRIFT_FONT *);
diff --git a/libskrift_open_font_at.c b/libskrift_open_font_at.c
new file mode 100644
index 0000000..2927dea
--- /dev/null
+++ b/libskrift_open_font_at.c
@@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+int
+libskrift_open_font_at(LIBSKRIFT_FONT **fontp, int dirfd, const char *path)
+{
+ int fd, ret;
+ if (!*path) {
+ return libskrift_open_font_fd(fontp, dirfd);
+ } else {
+ fd = openat(dirfd, path, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ ret = libskrift_open_font_fd(fontp, fd);
+ close(fd);
+ return ret;
+ }
+}