1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-22 13:12:48 +02:00

tools/libtxt/font.c: split load_image_file (load from open file) off load_image

This commit is contained in:
Werner Almesberger 2012-07-01 20:51:47 -03:00
parent 21e4fb267e
commit 236ef1dad0
2 changed files with 22 additions and 9 deletions

View File

@ -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) {

View File

@ -13,6 +13,9 @@
#ifndef LIBTXT_H
#define LIBTXT_H
#include <stdio.h>
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);