aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-13 23:44:19 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-15 14:09:56 +0200
commitfd5c9f1259d0191af57b20f06dda35e62acb6275 (patch)
treee45b73872c40531c5c2fa9c3b07096e5827ac6ea /include
parent89cdef0859259fdea0165b0d3918777d1ed42955 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include')
-rw-r--r--include/io/file.h25
-rw-r--r--include/io/std.h12
2 files changed, 23 insertions, 14 deletions
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
}
diff --git a/include/io/std.h b/include/io/std.h
index f622491..c5dddfa 100644
--- a/include/io/std.h
+++ b/include/io/std.h
@@ -18,18 +18,22 @@ extern "C" {
*
* @memberof sqfs_istream_t
*
- * @return A pointer to an input stream on success, NULL on failure.
+ * @param out Returns a pointer to an input stream on success.
+ *
+ * @return Zero on success, a negative @ref SQFS_ERROR number on failure
*/
-SQFS_INTERNAL sqfs_istream_t *istream_open_stdin(void);
+SQFS_INTERNAL int istream_open_stdin(sqfs_istream_t **out);
/**
* @brief Create an output stream that writes to standard output.
*
* @memberof sqfs_ostream_t
*
- * @return A pointer to an output stream on success, NULL on failure.
+ * @param out Returns a pointer to an output stream on success.
+ *
+ * @return Zero on success, a negative @ref SQFS_ERROR number on failure
*/
-SQFS_INTERNAL sqfs_ostream_t *ostream_open_stdout(void);
+SQFS_INTERNAL int ostream_open_stdout(sqfs_ostream_t **out);
#ifdef __cplusplus
}