Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 7acadb70 authored by rswindell's avatar rswindell

The "stdio" File objects (stdin, stdout, stderr) did not work on Windows,

because the stdout FILE* is a different address in jsexec than it is in sbbs.dll
(where the actual File I/O operations occurred). Refactored by passing the
stdio file descriptor (and open mode) to js_CreateFileObject rather than the
FILE* and using fdopen() to get a FILE* associated with the descriptor.
stdout.write() now works, for example.
parent e611b31b
......@@ -3015,10 +3015,14 @@ JSObject* DLLCALL js_CreateFileClass(JSContext* cx, JSObject* parent)
return(obj);
}
JSObject* DLLCALL js_CreateFileObject(JSContext* cx, JSObject* parent, char *name, FILE* fp)
JSObject* DLLCALL js_CreateFileObject(JSContext* cx, JSObject* parent, char *name, int fd, const char* mode)
{
JSObject* obj;
private_t* p;
FILE* fp = fdopen(fd, mode);
if(fp == NULL)
return NULL;
obj = JS_DefineObject(cx, parent, name, &js_file_class, NULL
,JSPROP_ENUMERATE|JSPROP_READONLY);
......@@ -3037,7 +3041,6 @@ JSObject* DLLCALL js_CreateFileObject(JSContext* cx, JSObject* parent, char *nam
dbprintf(TRUE, p, "JS_SetPrivate failed");
return(NULL);
}
dbprintf(FALSE, p, "object created");
return(obj);
......
......@@ -398,11 +398,11 @@ js_load(JSContext *cx, uintN argc, jsval *arglist)
if (JS_HasProperty(cx, obj, "console", &success) && success)
js_CreateConsoleObject(bg->cx, bg->obj);
if (JS_HasProperty(cx, obj, "stdin", &success) && success)
js_CreateFileObject(bg->cx, bg->obj, "stdin", stdin);
js_CreateFileObject(bg->cx, bg->obj, "stdin", STDIN_FILENO, "r");
if (JS_HasProperty(cx, obj, "stdout", &success) && success)
js_CreateFileObject(bg->cx, bg->obj, "stdout", stdout);
js_CreateFileObject(bg->cx, bg->obj, "stdout", STDOUT_FILENO, "w");
if (JS_HasProperty(cx, obj, "stderr", &success) && success)
js_CreateFileObject(bg->cx, bg->obj, "stderr", stderr);
js_CreateFileObject(bg->cx, bg->obj, "stderr", STDERR_FILENO, "w");
JS_SetContextPrivate(bg->cx, bg);
exec_cx = bg->cx;
......
......@@ -856,17 +856,17 @@ static BOOL js_init(char** env)
}
/* STDIO objects */
if(!js_CreateFileObject(js_cx, js_glob, "stdout", stdout)) {
if(!js_CreateFileObject(js_cx, js_glob, "stdout", STDOUT_FILENO, "w")) {
JS_ENDREQUEST(js_cx);
return(FALSE);
}
if(!js_CreateFileObject(js_cx, js_glob, "stdin", stdin)) {
if(!js_CreateFileObject(js_cx, js_glob, "stdin", STDIN_FILENO, "r")) {
JS_ENDREQUEST(js_cx);
return(FALSE);
}
if(!js_CreateFileObject(js_cx, js_glob, "stderr", stderr)) {
if(!js_CreateFileObject(js_cx, js_glob, "stderr", STDERR_FILENO, "w")) {
JS_ENDREQUEST(js_cx);
return(FALSE);
}
......
......@@ -1336,7 +1336,7 @@ extern "C" {
/* js_file.c */
DLLEXPORT JSObject* DLLCALL js_CreateFileClass(JSContext* cx, JSObject* parent);
DLLEXPORT JSObject* DLLCALL js_CreateFileObject(JSContext* cx, JSObject* parent, char *name, FILE* fp);
DLLEXPORT JSObject* DLLCALL js_CreateFileObject(JSContext* cx, JSObject* parent, char *name, int fd, const char* mode);
/* js_sprintf.c */
DLLEXPORT char* DLLCALL js_sprintf(JSContext* cx, uint argn, unsigned argc, jsval *argv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment