aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-16 01:41:06 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-16 03:51:11 +0200
commitc81e80bf35874696d9735f70e5c8327f92b5aca4 (patch)
tree5ef99ab43bde73674391d02ccc65d357874a34c1 /include
parent8bff2715bfdfd2e6ce0c707f1310b169d4e454d0 (diff)
libsquashfs: merge windows & unix file I/O primitives
By adding additional close/duplicate primitives, the remaining, mostly identical istream/ostream/file code is mostly identical between Windows and Unix and be merged, mostly without stitches. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include')
-rw-r--r--include/compat.h2
-rw-r--r--include/sqfs/io.h45
2 files changed, 47 insertions, 0 deletions
diff --git a/include/compat.h b/include/compat.h
index f376665..e62df81 100644
--- a/include/compat.h
+++ b/include/compat.h
@@ -240,6 +240,8 @@ char *strchrnul(const char *s, int c);
#define AT_FDCWD ((int)0xDEADBEEF)
#define AT_SYMLINK_NOFOLLOW (0x01)
+typedef SSIZE_T ssize_t;
+
int fchownat(int dirfd, const char *path, int uid, int gid, int flags);
int fchmodat(int dirfd, const char *path, int mode, int flags);
diff --git a/include/sqfs/io.h b/include/sqfs/io.h
index a697dc3..7d76881 100644
--- a/include/sqfs/io.h
+++ b/include/sqfs/io.h
@@ -101,6 +101,21 @@ typedef enum {
} SQFS_FILE_OPEN_FLAGS;
/**
+ * @enum SQFS_FILE_SEEK_FLAGS
+ *
+ * @brief Controls the behavior of @ref sqfs_seek_native_file
+ */
+typedef enum {
+ SQFS_FILE_SEEK_CURRENT = 0x00,
+ SQFS_FILE_SEEK_START = 0x01,
+ SQFS_FILE_SEEK_END = 0x02,
+ SQFS_FILE_SEEK_TRUNCATE = 0x10,
+
+ SQFS_FILE_SEEK_TYPE_MASK = 0x03,
+ SQFS_FILE_SEEK_FLAG_MASK = 0x10,
+} SQFS_FILE_SEEK_FLAGS;
+
+/**
* @interface sqfs_file_t
*
* @extends sqfs_object_t
@@ -306,6 +321,36 @@ SQFS_API int sqfs_open_native_file(sqfs_file_handle_t *out,
const char *filename, sqfs_u32 flags);
/**
+ * @brief Despose of a file handle returned by @ref sqfs_open_native_file
+ *
+ * @param fd A native OS file handle
+ */
+SQFS_API void sqfs_close_native_file(sqfs_file_handle_t fd);
+
+/**
+ * @brief Duplicate a file handle returned by @ref sqfs_open_native_file
+ *
+ * @param in A native OS file handle
+ * @param out A new file handle pointing to the same kernel object
+ *
+ * @return Zero on success, a negative @ref SQFS_ERROR code on failure.
+ */
+SQFS_API int sqfs_duplicate_native_file(sqfs_file_handle_t in,
+ sqfs_file_handle_t *out);
+
+/**
+ * @brief Set the file read/write pointer on a native file handle
+ *
+ * @param in A native OS file handle
+ * @param offset A relative offset to seek to
+ * @param flags A combination of @ref SQFS_FILE_SEEK_FLAGS flags
+ *
+ * @return Zero on success, a negative @ref SQFS_ERROR code on failure.
+ */
+SQFS_API int sqfs_seek_native_file(sqfs_file_handle_t hnd,
+ sqfs_s64 offset, sqfs_u32 flags);
+
+/**
* @brief Open a file through the operating systems filesystem API
*
* This function internally creates an instance of a reference implementation