aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-11 23:03:21 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-12 13:34:55 +0200
commit2b10bb09beb03380c8b815a6f6be268f188ac78d (patch)
tree0d21f998d90aaa709e7ebb23c413a58232154439 /include
parente57196f2f80432900523258af1038fb95a100b6b (diff)
libio: add open handle functions to istream/ostream
For the backends, this simplifies the code as both paths (open file and open stdio) use the same basic code. Even when merging them only in the backend, it would be done in a similar way. Making the functions public allows other uses as well. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include')
-rw-r--r--include/io/file.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/include/io/file.h b/include/io/file.h
index 8c6e851..f3723b2 100644
--- a/include/io/file.h
+++ b/include/io/file.h
@@ -10,11 +10,53 @@
#include "io/istream.h"
#include "io/ostream.h"
+#if defined(_WIN32) || defined(__WINDOWS__)
+#include <handleapi.h>
+
+typedef HANDLE os_file_t;
+#else
+typedef int os_file_t;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
/**
+ * @brief Create an input stream for an OS native file handle.
+ *
+ * @memberof istream_t
+ *
+ * The functions takes up ownership of the file handle and takes care
+ * of cleaning it up. On failure, the handle remains usable, and ownership
+ * remains with the caller.
+ *
+ * @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.
+ */
+SQFS_INTERNAL istream_t *istream_open_handle(const char *path, os_file_t fd);
+
+/**
+ * @brief Create an output stream that writes to an OS native file handle.
+ *
+ * @memberof ostream_t
+ *
+ * If the flag OSTREAM_OPEN_SPARSE is set, the underlying implementation tries
+ * to use seek/truncate style API to create sparse output files. If the flag
+ * is not set, holes will always be filled with zero bytes.
+ *
+ * @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.
+ */
+SQFS_INTERNAL ostream_t *ostream_open_handle(const char *path, os_file_t hnd,
+ int flags);
+
+/**
* @brief Create an input stream that reads from a file.
*
* @memberof istream_t