static FT_Stream FT_New_Xfs_Stream(const char * pathname) { FT_Stream stream = NULL; struct xfs_file_t * file; stream = malloc(sizeof(*stream)); if(!stream) return NULL; file = xfs_open_read(pathname); if(!file) { free(stream); return NULL; } stream->size = xfs_filelength(file); if(!stream->size) { xfs_close(file); free(stream); return NULL; } xfs_seek(file, 0); stream->descriptor.pointer = file; stream->pathname.pointer = (char *)pathname; stream->read = ft_xfs_stream_io; stream->close = ft_xfs_stream_close; return stream; }
static cairo_surface_t * cairo_image_surface_create_from_png_xfs(const char * filename) { struct xfs_file_t * file; cairo_surface_t * surface; file = xfs_open_read(filename); if(!file) return _cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_FILE_NOT_FOUND)); surface = cairo_image_surface_create_from_png_stream(xfs_read_func, file); xfs_close(file); return surface; }