From c81e80bf35874696d9735f70e5c8327f92b5aca4 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 16 Jun 2023 01:41:06 +0200 Subject: 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 --- include/compat.h | 2 ++ include/sqfs/io.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) (limited to 'include') 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 @@ -100,6 +100,21 @@ typedef enum { SQFS_FILE_OPEN_ALL_FLAGS = 0x0F, } 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 * @@ -305,6 +320,36 @@ extern "C" { 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 * -- cgit v1.2.3