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:
kichikuou
2026-03-07 11:31:43 +09:00
parent 9474e321e1
commit d4121032db
5 changed files with 20 additions and 1 deletions
+7 -1
View File
@@ -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;
BIN
View File
Binary file not shown.
+4
View File
@@ -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");
+8
View File
@@ -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);
}
+1
View File
@@ -4,6 +4,7 @@ Source = {
"arithmetic.jaf",
"strings.jaf",
"structs.jaf",
"system.jaf",
"arrays.jaf",
"math.jaf"
}