diff --git a/Source/DrangPlatform/Include/drang/fs.h b/Source/DrangPlatform/Include/drang/fs.h index c4a8cbc..8d5d7a3 100644 --- a/Source/DrangPlatform/Include/drang/fs.h +++ b/Source/DrangPlatform/Include/drang/fs.h @@ -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); diff --git a/Source/DrangPlatform/Source/linux/fs/file.c b/Source/DrangPlatform/Source/linux/fs/file.c index 745bf90..17211cb 100644 --- a/Source/DrangPlatform/Source/linux/fs/file.c +++ b/Source/DrangPlatform/Source/linux/fs/file.c @@ -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; diff --git a/Source/DrangPlatform/Source/win32/fs/file.c b/Source/DrangPlatform/Source/win32/fs/file.c index 4ad5be1..7c50442 100644 --- a/Source/DrangPlatform/Source/win32/fs/file.c +++ b/Source/DrangPlatform/Source/win32/fs/file.c @@ -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;