summaryrefslogtreecommitdiffstats
path: root/include/zix/filesystem.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/zix/filesystem.h')
-rw-r--r--include/zix/filesystem.h82
1 files changed, 36 insertions, 46 deletions
diff --git a/include/zix/filesystem.h b/include/zix/filesystem.h
index 9abafe1..dff4145 100644
--- a/include/zix/filesystem.h
+++ b/include/zix/filesystem.h
@@ -4,9 +4,9 @@
#ifndef ZIX_FILESYSTEM_H
#define ZIX_FILESYSTEM_H
-#include "zix/allocator.h"
-#include "zix/attributes.h"
-#include "zix/status.h"
+#include <zix/allocator.h>
+#include <zix/attributes.h>
+#include <zix/status.h>
#if !(defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
# include <stddef.h>
@@ -51,8 +51,7 @@ typedef uint32_t ZixCopyOptions;
@param options Options to control the kind of copy and error conditions.
@return #ZIX_STATUS_SUCCESS if `dst` was successfully created, or an error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_copy_file(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL src,
const char* ZIX_NONNULL dst,
@@ -64,8 +63,7 @@ zix_copy_file(ZixAllocator* ZIX_NULLABLE allocator,
@return #ZIX_STATUS_SUCCESS if `dir_path` was successfully created, or an
error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_create_directory(const char* ZIX_NONNULL dir_path);
/**
@@ -77,8 +75,7 @@ zix_create_directory(const char* ZIX_NONNULL dir_path);
@return #ZIX_STATUS_SUCCESS if `dir_path` was successfully created, or an
error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_create_directory_like(const char* ZIX_NONNULL dir_path,
const char* ZIX_NONNULL existing_path);
@@ -92,8 +89,7 @@ zix_create_directory_like(const char* ZIX_NONNULL dir_path,
@return #ZIX_STATUS_SUCCESS if all directories in `dir_path` were
successfully created (or already existed), or an error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_create_directories(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL dir_path);
@@ -102,8 +98,7 @@ zix_create_directories(ZixAllocator* ZIX_NULLABLE allocator,
@return #ZIX_STATUS_SUCCESS, or an error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_create_hard_link(const char* ZIX_NONNULL target_path,
const char* ZIX_NONNULL link_path);
@@ -116,8 +111,7 @@ zix_create_hard_link(const char* ZIX_NONNULL target_path,
@return #ZIX_STATUS_SUCCESS, or an error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_create_symlink(const char* ZIX_NONNULL target_path,
const char* ZIX_NONNULL link_path);
@@ -129,8 +123,7 @@ zix_create_symlink(const char* ZIX_NONNULL target_path,
@return #ZIX_STATUS_SUCCESS, or an error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_create_directory_symlink(const char* ZIX_NONNULL target_path,
const char* ZIX_NONNULL link_path);
@@ -146,14 +139,12 @@ zix_create_directory_symlink(const char* ZIX_NONNULL target_path,
@return The path of the created directory, or null.
*/
-ZIX_API
-char* ZIX_NULLABLE
+ZIX_MALLOC_API char* ZIX_NULLABLE
zix_create_temporary_directory(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL path_pattern);
/// Remove the file or empty directory at `path`
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_remove(const char* ZIX_NONNULL path);
/**
@@ -163,6 +154,17 @@ zix_remove(const char* ZIX_NONNULL path);
*/
/**
+ Function for reading input bytes from a stream.
+
+ @param path Path to the directory being visited.
+ @param name Name of the directory entry.
+ @param data Opaque user data.
+*/
+typedef void (*ZixDirEntryVisitFunc)(const char* ZIX_NONNULL path,
+ const char* ZIX_NONNULL name,
+ void* ZIX_NONNULL data);
+
+/**
Visit every file in the directory at `path`.
@param path A path to a directory.
@@ -173,13 +175,10 @@ zix_remove(const char* ZIX_NONNULL path);
parameter is always the directory path passed to this function, the `name`
parameter is the name of the directory entry (not its full path).
*/
-ZIX_API
-void
-zix_dir_for_each(const char* ZIX_NONNULL path,
- void* ZIX_NULLABLE data,
- void (*ZIX_NONNULL f)(const char* ZIX_NONNULL path,
- const char* ZIX_NONNULL name,
- void* ZIX_NONNULL data));
+ZIX_API void
+zix_dir_for_each(const char* ZIX_NONNULL path,
+ void* ZIX_NULLABLE data,
+ ZixDirEntryVisitFunc ZIX_NONNULL f);
/**
Return whether the given paths point to files with identical contents.
@@ -193,8 +192,7 @@ zix_dir_for_each(const char* ZIX_NONNULL path,
@return True if the two files have byte-for-byte identical contents.
*/
-ZIX_API
-bool
+ZIX_API ZIX_NODISCARD bool
zix_file_equals(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NONNULL a_path,
const char* ZIX_NONNULL b_path);
@@ -227,8 +225,7 @@ zix_file_equals(ZixAllocator* ZIX_NULLABLE allocator,
@return A new canonical version of `path`, or null if it doesn't exist.
*/
-ZIX_API
-char* ZIX_NULLABLE
+ZIX_MALLOC_API char* ZIX_NULLABLE
zix_canonical_path(ZixAllocator* ZIX_NULLABLE allocator,
const char* ZIX_NULLABLE path);
@@ -255,8 +252,7 @@ typedef enum {
@param mode Lock mode.
@return #ZIX_STATUS_SUCCESS if the file was locked, or an error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_file_lock(FILE* ZIX_NONNULL file, ZixFileLockMode mode);
/**
@@ -266,8 +262,7 @@ zix_file_lock(FILE* ZIX_NONNULL file, ZixFileLockMode mode);
@param mode Lock mode.
@return #ZIX_STATUS_SUCCESS if the file was unlocked, or an error.
*/
-ZIX_API
-ZixStatus
+ZIX_API ZixStatus
zix_file_unlock(FILE* ZIX_NONNULL file, ZixFileLockMode mode);
/**
@@ -308,8 +303,7 @@ typedef enum {
/**
Return the type of a file or directory, resolving symlinks.
*/
-ZIX_API
-ZixFileType
+ZIX_API ZixFileType
zix_file_type(const char* ZIX_NONNULL path);
/**
@@ -318,8 +312,7 @@ zix_file_type(const char* ZIX_NONNULL path);
On Windows, a directory symlink (actually a "reparse point") always appears
as a directory.
*/
-ZIX_API
-ZixFileType
+ZIX_API ZixFileType
zix_symlink_type(const char* ZIX_NONNULL path);
/**
@@ -331,8 +324,7 @@ zix_symlink_type(const char* ZIX_NONNULL path);
@return A non-negative size in bytes, or -1 on error.
*/
-ZIX_API
-ZixFileOffset
+ZIX_API ZixFileOffset
zix_file_size(const char* ZIX_NONNULL path);
/**
@@ -346,8 +338,7 @@ zix_file_size(const char* ZIX_NONNULL path);
@param allocator Allocator used for the returned path.
*/
-ZIX_API
-char* ZIX_ALLOCATED
+ZIX_MALLOC_API char* ZIX_ALLOCATED
zix_current_path(ZixAllocator* ZIX_NULLABLE allocator);
/**
@@ -357,8 +348,7 @@ zix_current_path(ZixAllocator* ZIX_NULLABLE allocator);
@return A new path to a temporary directory, or null on error.
*/
-ZIX_API
-char* ZIX_ALLOCATED
+ZIX_MALLOC_API char* ZIX_ALLOCATED
zix_temp_directory_path(ZixAllocator* ZIX_NULLABLE allocator);
/**