disruption
This commit is contained in:
@@ -17,13 +17,13 @@ static SDFile* js2sdfile(JSContext *js, JSValueConst val) {
|
||||
// --- File Functions ---
|
||||
|
||||
JSC_CCALL(file_geterr,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
const char *err = pd_file->geterr();
|
||||
return err ? JS_NewString(js, err) : JS_NULL;
|
||||
)
|
||||
|
||||
JSC_SCALL(file_stat,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
FileStat st;
|
||||
if (pd_file->stat(str, &st) != 0) {
|
||||
ret = JS_NULL;
|
||||
@@ -42,18 +42,18 @@ JSC_SCALL(file_stat,
|
||||
)
|
||||
|
||||
JSC_SCALL(file_mkdir,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
ret = JS_NewBool(js, pd_file->mkdir(str) == 0);
|
||||
)
|
||||
|
||||
JSC_SCALL(file_unlink,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
int recursive = argc > 1 ? JS_ToBool(js, argv[1]) : 0;
|
||||
ret = JS_NewBool(js, pd_file->unlink(str, recursive) == 0);
|
||||
)
|
||||
|
||||
JSC_SCALL(file_rename,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
const char *to = JS_ToCString(js, argv[1]);
|
||||
int result = pd_file->rename(str, to);
|
||||
JS_FreeCString(js, to);
|
||||
@@ -61,7 +61,7 @@ JSC_SCALL(file_rename,
|
||||
)
|
||||
|
||||
JSC_SCALL(file_open,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
FileOptions mode = kFileRead;
|
||||
if (argc > 1) mode = (FileOptions)(int)js2number(js, argv[1]);
|
||||
SDFile *f = pd_file->open(str, mode);
|
||||
@@ -69,17 +69,17 @@ JSC_SCALL(file_open,
|
||||
)
|
||||
|
||||
JSC_CCALL(file_close,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
return JS_NewBool(js, pd_file->close(f) == 0);
|
||||
)
|
||||
|
||||
JSC_CCALL(file_read,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
unsigned int len = (unsigned int)js2number(js, argv[1]);
|
||||
void *buf = malloc(len);
|
||||
if (!buf) return JS_ThrowInternalError(js, "malloc failed");
|
||||
if (!buf) return JS_RaiseDisrupt(js, "malloc failed");
|
||||
int read = pd_file->read(f, buf, len);
|
||||
if (read < 0) {
|
||||
free(buf);
|
||||
@@ -91,7 +91,7 @@ JSC_CCALL(file_read,
|
||||
)
|
||||
|
||||
JSC_CCALL(file_write,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
size_t len;
|
||||
const void *data = js_get_blob_data(js, &len, argv[1]);
|
||||
@@ -101,19 +101,19 @@ JSC_CCALL(file_write,
|
||||
)
|
||||
|
||||
JSC_CCALL(file_flush,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
return JS_NewBool(js, pd_file->flush(f) == 0);
|
||||
)
|
||||
|
||||
JSC_CCALL(file_tell,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
return JS_NewInt32(js, pd_file->tell(f));
|
||||
)
|
||||
|
||||
JSC_CCALL(file_seek,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
SDFile *f = js2sdfile(js, argv[0]);
|
||||
int pos = (int)js2number(js, argv[1]);
|
||||
int whence = argc > 2 ? (int)js2number(js, argv[2]) : SEEK_SET;
|
||||
@@ -132,7 +132,7 @@ static void listfiles_cb(const char *path, void *userdata) {
|
||||
}
|
||||
|
||||
JSC_SCALL(file_listfiles,
|
||||
if (!pd_file) return JS_ThrowInternalError(js, "file not initialized");
|
||||
if (!pd_file) return JS_RaiseDisrupt(js, "file not initialized");
|
||||
int showhidden = argc > 1 ? JS_ToBool(js, argv[1]) : 0;
|
||||
JSValue arr = JS_NewArray(js);
|
||||
struct listfiles_ctx ctx = { js, arr, 0 };
|
||||
|
||||
Reference in New Issue
Block a user