From fd5c9f1259d0191af57b20f06dda35e62acb6275 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 13 Jun 2023 23:44:19 +0200 Subject: Overhaul sqfs_istream_t/sqfs_ostream_t error handling Report an error number from the implementations, change the users to forward that error number (which also means libtar write header/link now returns an error code) and all subsequent binaries to use sqfs_perror() instead of relying on the function to print an error internally. Also, make sure to preserve errno/GetLastError() in the implementations and print out a stringified error in sqfs_perror() if the error code indicates an I/O error. Signed-off-by: David Oberhollenzer --- include/io/file.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'include/io/file.h') diff --git a/include/io/file.h b/include/io/file.h index 5065619..e7ffb0d 100644 --- a/include/io/file.h +++ b/include/io/file.h @@ -22,13 +22,15 @@ extern "C" { * of cleaning it up. On failure, the handle remains usable, and ownership * remains with the caller. * + * @param out Returns a pointer to an input stream on success. * @param path The name to associate with the handle. * @param fd A native file handle. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ SQFS_INTERNAL -sqfs_istream_t *istream_open_handle(const char *path, sqfs_file_handle_t fd); +int istream_open_handle(sqfs_istream_t **out, const char *path, + sqfs_file_handle_t fd); /** * @brief Create an output stream that writes to an OS native file handle. @@ -40,26 +42,27 @@ sqfs_istream_t *istream_open_handle(const char *path, sqfs_file_handle_t fd); * Otherwise, it tries to use seek/truncate style APIs to create sparse output * files. * + * @param out Returns a pointer to an output stream on success. * @param path The name to associate with the handle. * @param fd A native file handle. * @param flags A combination of flags. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_ostream_t *ostream_open_handle(const char *path, - sqfs_file_handle_t hnd, - int flags); +SQFS_INTERNAL int ostream_open_handle(sqfs_ostream_t **out, const char *path, + sqfs_file_handle_t hnd, int flags); /** * @brief Create an input stream that reads from a file. * * @memberof sqfs_istream_t * + * @param out Returns a pointer to an input stream on success. * @param path A path to the file to open or create. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_istream_t *istream_open_file(const char *path); +SQFS_INTERNAL int istream_open_file(sqfs_istream_t **out, const char *path); /** * @brief Create an output stream that writes to a file. @@ -75,12 +78,14 @@ SQFS_INTERNAL sqfs_istream_t *istream_open_file(const char *path); * Otherwise, it tries to use seek/truncate style APIs to create sparse output * files. * + * @param out Returns a pointer to an output stream on success. * @param path A path to the file to open or create. * @param flags A combination of flags controling how to open/create the file. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_ostream_t *ostream_open_file(const char *path, int flags); +SQFS_INTERNAL int ostream_open_file(sqfs_ostream_t **out, + const char *path, int flags); #ifdef __cplusplus } -- cgit v1.2.3