mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Update fs.
This commit is contained in:
Vendored
+25
-2
@@ -2105,8 +2105,15 @@ FS_API fs_result fs_mkdir(fs* pFS, const char* pPath)
|
||||
char* pRunningPath = pRunningPathStack;
|
||||
size_t runningPathLen = 0;
|
||||
fs_path_iterator iSegment;
|
||||
const fs_backend* pBackend;
|
||||
|
||||
if (pFS == NULL || pPath == NULL) {
|
||||
pBackend = fs_get_backend_or_default(pFS);
|
||||
|
||||
if (pBackend == NULL) {
|
||||
return FS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (pPath == NULL) {
|
||||
return FS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
@@ -2144,7 +2151,7 @@ FS_API fs_result fs_mkdir(fs* pFS, const char* pPath)
|
||||
runningPathLen += iSegment.segmentLength;
|
||||
pRunningPath[runningPathLen] = '\0';
|
||||
|
||||
result = fs_backend_mkdir(pFS->pBackend, pFS, pRunningPath);
|
||||
result = fs_backend_mkdir(pBackend, pFS, pRunningPath);
|
||||
|
||||
/* We just pretend to be successful if the directory already exists. */
|
||||
if (result == FS_ALREADY_EXISTS) {
|
||||
@@ -3040,6 +3047,7 @@ FS_API fs_result fs_file_open_or_info(fs* pFS, const char* pFilePath, int openMo
|
||||
We'll need to iterate over every mount point and keep track of the mount point with the longest
|
||||
prefix that matches the start of the file path.
|
||||
*/
|
||||
if (pFS != NULL) {
|
||||
fs_mount_list_iterator iMountPoint;
|
||||
fs_mount_point* pBestMountPoint = NULL;
|
||||
const char* pBestMountPointPath = NULL;
|
||||
@@ -3129,6 +3137,21 @@ FS_API fs_result fs_file_open_or_info(fs* pFS, const char* pFilePath, int openMo
|
||||
} else {
|
||||
return FS_DOES_NOT_EXIST; /* Couldn't find an appropriate mount point. */
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
No "fs" object was supplied. Open using the default backend without using mount points. This is as if you were
|
||||
opening a file using `fopen()`.
|
||||
*/
|
||||
if ((openMode & FS_ONLY_MOUNTS) == 0) {
|
||||
return fs_file_alloc_if_necessary_and_open_or_info(pFS, pFilePath, openMode, ppFile, pInfo);
|
||||
} else {
|
||||
/*
|
||||
Getting here means only the mount points can be used to open the file (cannot open straight from
|
||||
the file system natively).
|
||||
*/
|
||||
return FS_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Opening in read mode. */
|
||||
fs_mount_list_iterator iMountPoint;
|
||||
|
||||
Vendored
+6
-1
@@ -267,9 +267,14 @@ be saved:
|
||||
|
||||
```c
|
||||
fs_file_open(pFS, "config/game.cfg", FS_WRITE, &pFile); // Prefixed with "config", so will use the "config" mount point.
|
||||
fs_file_open(pFs, "saves/save0.sav", FS_WRITE, &pFile); // Prefixed with "saves", so will use the "saves" mount point.
|
||||
fs_file_open(pFS, "saves/save0.sav", FS_WRITE, &pFile); // Prefixed with "saves", so will use the "saves" mount point.
|
||||
```
|
||||
|
||||
When opening a file for writing, if you pass in NULL for the `pFS` parameter it will open the file
|
||||
like normal using the standard file system. That is it'll work exactly as if you were using stdio
|
||||
`fopen()` and you will not be able use mount points. Keep in mind that there is no notion of a
|
||||
"current directory" in this library so you'll be stuck with the initial working directory.
|
||||
|
||||
By default, you can move outside the mount point with ".." segments. If you want to disable this
|
||||
functionality, you can use the `FS_NO_ABOVE_ROOT_NAVIGATION` flag:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user