diff options
| author | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2025-12-19 14:15:54 +1100 |
|---|---|---|
| committer | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2025-12-19 14:15:54 +1100 |
| commit | 1ff725b6211940b6ba78ba16c8740a2a18659de2 (patch) | |
| tree | 2908bf3aaa1eb32dfe837ef110458b60e6a95b44 | |
| parent | 3c6ae042158df0236a8f9ccdaddb69a89ba66d57 (diff) | |
refactor(png): ff_open_png returns ff_result
| -rw-r--r-- | include/tinyff/image/png.h | 2 | ||||
| -rw-r--r-- | include/tinyff/result.h | 3 | ||||
| -rw-r--r-- | src/format/image/png.c | 6 |
3 files changed, 7 insertions, 4 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h index caed675..de21b07 100644 --- a/include/tinyff/image/png.h +++ b/include/tinyff/image/png.h @@ -24,6 +24,6 @@ typedef struct { } ff_png_ctx; ff_result ff_png_isvalid(FILE *file); -ff_png_ctx *ff_open_png(const char *filepath); +ff_result ff_open_png(const char *filepath, ff_png_ctx **out_ctx); #endif diff --git a/include/tinyff/result.h b/include/tinyff/result.h index a837c66..27b1ce4 100644 --- a/include/tinyff/result.h +++ b/include/tinyff/result.h @@ -3,8 +3,11 @@ typedef enum { FF_RESULT_OK = 0, + + // File FF_RESULT_ERROR_INVALID_FILE_SIGNITURE, FF_RESULT_ERROR_INVALID_FILE, + FF_RESULT_ERROR_READ_FILE_FAILURE, // More will be created when more errors occur } ff_result; diff --git a/src/format/image/png.c b/src/format/image/png.c index b29e271..6adfe86 100644 --- a/src/format/image/png.c +++ b/src/format/image/png.c @@ -19,18 +19,18 @@ ff_result ff_png_isvalid(FILE *file) return FF_RESULT_OK; } -ff_png_ctx *ff_open_png(const char *filepath) { +ff_result ff_open_png(const char *filepath, ff_png_ctx **out_ctx) { // Validate ff_png_ctx ctx; ctx.raw = fopen(filepath, "rb"); if (!ctx.raw) { - return NULL; + return FF_RESULT_ERROR_READ_FILE_FAILURE; } if (ff_png_isvalid(ctx.raw) != FF_RESULT_OK) { - return NULL; + return ff_png_isvalid(ctx.raw); } // TODO: Parse |
