VFS: Move VDirOptionalOpenFile to vfs-dirent.c
This commit is contained in:
parent
c0fcec22b7
commit
a992fcd3d1
@ -17,34 +17,6 @@ ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) {
|
|||||||
return buffer[bytesRead] = '\0';
|
return buffer[bytesRead] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode) {
|
|
||||||
char path[PATH_MAX];
|
|
||||||
path[PATH_MAX - 1] = '\0';
|
|
||||||
struct VFile* vf;
|
|
||||||
if (!dir) {
|
|
||||||
if (!realPath) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
char* dotPoint = strrchr(realPath, '.');
|
|
||||||
if (dotPoint - realPath + 1 >= PATH_MAX - 1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (dotPoint > strrchr(realPath, '/')) {
|
|
||||||
int len = dotPoint - realPath;
|
|
||||||
strncpy(path, realPath, len);
|
|
||||||
path[len] = 0;
|
|
||||||
strncat(path + len, suffix, PATH_MAX - len - 1);
|
|
||||||
} else {
|
|
||||||
snprintf(path, PATH_MAX - 1, "%s%s", realPath, suffix);
|
|
||||||
}
|
|
||||||
vf = VFileOpen(path, mode);
|
|
||||||
} else {
|
|
||||||
snprintf(path, PATH_MAX - 1, "%s%s", prefix, suffix);
|
|
||||||
vf = dir->openFile(dir, path, mode);
|
|
||||||
}
|
|
||||||
return vf;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t VFileWrite32LE(struct VFile* vf, int32_t word) {
|
ssize_t VFileWrite32LE(struct VFile* vf, int32_t word) {
|
||||||
uint32_t leword;
|
uint32_t leword;
|
||||||
STORE_32LE(word, 0, &leword);
|
STORE_32LE(word, 0, &leword);
|
||||||
|
@ -190,3 +190,31 @@ const char* _vdeName(struct VDirEntry* vde) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode) {
|
||||||
|
char path[PATH_MAX];
|
||||||
|
path[PATH_MAX - 1] = '\0';
|
||||||
|
struct VFile* vf;
|
||||||
|
if (!dir) {
|
||||||
|
if (!realPath) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
char* dotPoint = strrchr(realPath, '.');
|
||||||
|
if (dotPoint - realPath + 1 >= PATH_MAX - 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (dotPoint > strrchr(realPath, '/')) {
|
||||||
|
int len = dotPoint - realPath;
|
||||||
|
strncpy(path, realPath, len);
|
||||||
|
path[len] = 0;
|
||||||
|
strncat(path + len, suffix, PATH_MAX - len - 1);
|
||||||
|
} else {
|
||||||
|
snprintf(path, PATH_MAX - 1, "%s%s", realPath, suffix);
|
||||||
|
}
|
||||||
|
vf = VFileOpen(path, mode);
|
||||||
|
} else {
|
||||||
|
snprintf(path, PATH_MAX - 1, "%s%s", prefix, suffix);
|
||||||
|
vf = dir->openFile(dir, path, mode);
|
||||||
|
}
|
||||||
|
return vf;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user