fd check blob stone

This commit is contained in:
2026-01-09 08:23:40 -06:00
parent e04b15973a
commit 86a70bce3a
3 changed files with 13 additions and 6 deletions

9
fd.c
View File

@@ -559,19 +559,22 @@ JSC_CCALL(fd_slurpwrite,
size_t len;
const char *data = js_get_blob_data(js, &len, argv[1]);
if (data == (const char *)-1)
if (!data)
return JS_EXCEPTION;
const char *str = JS_ToCString(js, argv[0]);
if (!str) return JS_EXCEPTION;
int fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
JS_FreeCString(js, str);
if (fd < 0)
if (fd < 0) {
JS_FreeCString(js, str);
return JS_ThrowInternalError(js, "open failed for %s: %s", str, strerror(errno));
}
ssize_t written = write(fd, data, len);
close(fd);
JS_FreeCString(js, str);
if (written != (ssize_t)len)
return JS_ThrowInternalError(js, "write failed for %s: %s", str, strerror(errno));