feature: add platform-specific path separator functions for Unix and Windows

This commit is contained in:
MechSlayer 2025-09-09 20:02:45 +02:00
parent 05f5933111
commit c43748d1d4
3 changed files with 30 additions and 1 deletions

View file

@ -132,6 +132,25 @@ typedef struct fs_dir_entry
drang_fs_type_t type; /**< Entry type */
} drang_fs_dir_entry_t;
/**
* @brief Gets the platform-specific path separator character.
*
* Returns the character used to separate path components on the current platform.
* This is typically '/' on Unix-like systems (Linux, macOS) and '\' on Windows.
*
* @return Platform-specific path separator character.
* @retval '/' On Unix-like systems (Linux, macOS, BSD, etc.).
* @retval '\' On Windows systems.
* @remarks This function is useful for constructing portable file paths.
* The returned character should be used when manually building paths
* or when parsing path strings in a platform-aware manner.
* For portable path construction, consider using this function instead
* of hardcoding separator characters.
*/
DRANG_PLATFORM_API char drang_fs_path_separator(void);
/**
* @brief Opens a file with specified access mode.
*
@ -187,7 +206,7 @@ DRANG_PLATFORM_API int drang_fs_close(drang_fs_file_t *file);
* @retval DRANG_EIO I/O error occurred during reading.
* @retval DRANG_EPERM File not opened for reading.
* @remarks Reading beyond end of file is not an error - bytes_read will indicate
* actual bytes read. File position advances by bytes read.
* actual bytes read. File position advances to bytes read.
*/
DRANG_PLATFORM_API int drang_fs_read(drang_fs_file_t *file, void *buffer, size_t count, size_t size, size_t *bytes_read);

View file

@ -61,6 +61,11 @@ static int drang_permissions_to_linux(const drang_fs_permissions_t permissions)
return result;
}
char drang_fs_separator(void)
{
return '/';
}
int drang_fs_open(const char *path, drang_fs_mode_t mode, drang_fs_file_t **out_file)
{
struct drang_fs_file *file = NULL;

View file

@ -32,6 +32,11 @@ static void mode_to_access(drang_fs_mode_t mode, DWORD *out_access, DWORD *out_c
*out_creation = creation;
}
char drang_fs_path_separator(void)
{
return '\\';
}
int drang_fs_open(const char *path, drang_fs_mode_t mode, drang_fs_file_t **out_file)
{
struct drang_fs_file *file = NULL;