From 236ef1dad0de8b848e6104743aae51f014df1e1a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 1 Jul 2012 20:51:47 -0300 Subject: [PATCH] tools/libtxt/font.c: split load_image_file (load from open file) off load_image --- tools/libtxt/font.c | 27 ++++++++++++++++++--------- tools/libtxt/libtxt.h | 4 ++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/libtxt/font.c b/tools/libtxt/font.c index 69c8fe8..e321e0c 100644 --- a/tools/libtxt/font.c +++ b/tools/libtxt/font.c @@ -99,19 +99,11 @@ static const char *read_xbm_file(FILE *file, struct image *img) } -struct image *load_image(const char *name, const char **error) +struct image *load_image_file(FILE *file, const char **error) { - FILE *file; struct image *img; const char *err; - file = fopen(name, "r"); - if (!file) { - if (error) - *error = alloc_sprintf("%s: %s", name, strerror(errno)); - return NULL; - } - img = alloc_type(struct image); err = read_xbm_file(file, img); if (err) { @@ -124,6 +116,23 @@ struct image *load_image(const char *name, const char **error) } +struct image *load_image(const char *name, const char **error) +{ + FILE *file; + struct image *img; + + file = fopen(name, "r"); + if (!file) { + if (error) + *error = alloc_sprintf("%s: %s", name, strerror(errno)); + return NULL; + } + img = load_image_file(file, error); + fclose(file); + return img; +} + + void free_image(struct image *img) { if (img) { diff --git a/tools/libtxt/libtxt.h b/tools/libtxt/libtxt.h index 7aea2bf..49973df 100644 --- a/tools/libtxt/libtxt.h +++ b/tools/libtxt/libtxt.h @@ -13,6 +13,9 @@ #ifndef LIBTXT_H #define LIBTXT_H +#include + + struct image; struct font; @@ -51,6 +54,7 @@ struct edit { * Newline leaves one blank row between text lines. */ +struct image *load_image_file(FILE *file, const char **error); struct image *load_image(const char *name, const char **error); void free_image(struct image *img);