mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-06 05:48:04 +03:00
system.ExistFile() should return false if path ends with a backslash
The system.ExistsFile() system call returns 1 if a file or directory exists, but returns 0 when the provided path ends with a directory separator, regardless of whether a directory exists at that location. This subtle difference in behavior caused problems in Pastel Chime 3.
This commit is contained in:
@@ -559,7 +559,13 @@ static void system_call(enum syscall_code code)
|
||||
case SYS_EXISTS_FILE: { // system.ExistsFile(string szFileName)
|
||||
int str = stack_pop().i;
|
||||
char *path = gamedir_path(heap_get_string(str)->text);
|
||||
stack_push(file_exists(path));
|
||||
int len = strlen(path);
|
||||
// Return true for directories, but false if the path ends with a directory separator.
|
||||
if (len > 0 && (path[len-1] == '/' || path[len-1] == '\\')) {
|
||||
stack_push(0);
|
||||
} else {
|
||||
stack_push(file_exists(path));
|
||||
}
|
||||
heap_unref(str);
|
||||
free(path);
|
||||
break;
|
||||
|
||||
Binary file not shown.
@@ -84,6 +84,10 @@ int main(void)
|
||||
test_arrays();
|
||||
test_end("arrays");
|
||||
|
||||
test_start("system");
|
||||
test_system();
|
||||
test_end("system");
|
||||
|
||||
test_start("Math.dll");
|
||||
test_math();
|
||||
test_end("Math.dll");
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// -*-mode: C; coding: sjis; -*-
|
||||
|
||||
void test_system(void)
|
||||
{
|
||||
string savedir = system.GetSaveFolderName();
|
||||
test_equal("system.ExistFile(savedir) == 1", system.ExistFile(savedir), 1);
|
||||
test_equal("system.ExistFile(savedir + \"\\\\\") == 1", system.ExistFile(savedir + "\\"), 0);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ Source = {
|
||||
"arithmetic.jaf",
|
||||
"strings.jaf",
|
||||
"structs.jaf",
|
||||
"system.jaf",
|
||||
"arrays.jaf",
|
||||
"math.jaf"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user