fix fd.c bugs

This commit is contained in:
2026-02-10 14:21:49 -06:00
parent 54673e4a04
commit fe5dc6ecc9
10 changed files with 815 additions and 794 deletions

18
fd.c
View File

@@ -504,7 +504,7 @@ JSC_SCALL(fd_readdir,
ret = JS_NewArray(js);
do {
if (strcmp(ffd.cFileName, ".") == 0 || strcmp(ffd.cFileName, "..") == 0) continue;
JS_ArrayPush(js, ret,JS_NewString(js, ffd.cFileName));
JS_ArrayPush(js, &ret, JS_NewString(js, ffd.cFileName));
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
@@ -516,7 +516,7 @@ JSC_SCALL(fd_readdir,
ret = JS_NewArray(js);
while ((dir = readdir(d)) != NULL) {
if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) continue;
JS_ArrayPush(js, ret, JS_NewString(js, dir->d_name));
JS_ArrayPush(js, &ret, JS_NewString(js, dir->d_name));
}
closedir(d);
} else {
@@ -565,18 +565,22 @@ JSC_CCALL(fd_slurpwrite,
if (!str) return JS_EXCEPTION;
int fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
ret = JS_ThrowInternalError(js, "open failed for %s: %s", str, strerror(errno));
JS_FreeCString(js, str);
return JS_ThrowInternalError(js, "open failed for %s: %s", str, strerror(errno));
return ret;
}
ssize_t written = write(fd, data, len);
close(fd);
if (written != (ssize_t)len) {
ret = JS_ThrowInternalError(js, "write failed for %s: %s", str, strerror(errno));
JS_FreeCString(js, str);
return ret;
}
JS_FreeCString(js, str);
if (written != (ssize_t)len)
return JS_ThrowInternalError(js, "write failed for %s: %s", str, strerror(errno));
return JS_NULL;
)