aboutsummaryrefslogtreecommitdiffstats
path: root/libskrift_open_font.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2020-04-26 11:02:57 +0200
committerMattias Andrée <maandree@kth.se>2020-04-26 11:08:13 +0200
commit933799d9f0aaf811b37aebf71db2634c4f80e23b (patch)
tree856a96f1d7f91ebb9a690078d13c6e3201753dc7 /libskrift_open_font.c
downloadlibskrift-933799d9f0aaf811b37aebf71db2634c4f80e23b.tar.gz
libskrift-933799d9f0aaf811b37aebf71db2634c4f80e23b.tar.bz2
libskrift-933799d9f0aaf811b37aebf71db2634c4f80e23b.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libskrift_open_font.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/libskrift_open_font.c b/libskrift_open_font.c
new file mode 100644
index 0000000..1eb8ff9
--- /dev/null
+++ b/libskrift_open_font.c
@@ -0,0 +1,50 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+int
+libskrift_open_font(LIBSKRIFT_FONT **fontp, FILE *fp)
+{
+ int saved_errno;
+ char *mem = NULL, *new;
+ size_t size = 0, off = 0, r;
+
+ *fontp = calloc(1, sizeof(**fontp));
+
+ saved_errno = errno;
+ errno = 0;
+ for (;;) {
+ if (off + 2048 > size) {
+ size += 8192;
+ new = realloc(mem, size);
+ if (!new) {
+ free(mem);
+ return -1;
+ }
+ mem = new;
+ }
+ r = fread(&mem[off], 1, size - off, fp);
+ if (!r)
+ break;
+ off += r;
+ }
+ if (errno) {
+ free(mem);
+ return -1;
+ }
+
+ size = off;
+ new = realloc(mem, size);
+ if (new)
+ mem = new;
+ errno = saved_errno;
+
+ if (libskrift_open_font_mem(fontp, mem, size)) {
+ free(mem);
+ return -1;
+ }
+
+ (*fontp)->memory_free = mem;
+ (*fontp)->memory_size = size;
+
+ return 0;
+}