Skip to content
Snippets Groups Projects
Commit d2ac211a authored by deuce's avatar deuce
Browse files

Fix bugs in last commit and check the return value of setvbuf().

parent e7d0e1c3
No related branches found
No related tags found
No related merge requests found
......@@ -2126,26 +2126,32 @@ static JSBool js_file_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict,
case FILE_PROP_BUFSIZE:
if(!JS_ValueToECMAUint32(cx,*vp,&u))
return(JS_FALSE);
if (setvbuf(p->fp, NULL, p->bufmode, p->bufsize) == -1)
JS_ReportError(cx, "Unable to set buffer size to %u", u);
else
p->bufsize = u;
setvbuf(p->fp, NULL, p->bufmode, p->bufsize);
break;
case FILE_PROP_BUFMODE:
if(!JS_ValueToInt32(cx,*vp,&i))
return(JS_FALSE);
switch(i) {
case 0:
p->bufmode = _IONBF;
i = _IONBF;
break;
case 1:
p->bufmode = _IOLBF;
i = _IOLBF;
break;
case 2:
p->bufmode = _IOFBF;
i = _IOFBF;
break;
default:
JS_ReportError(cx,"Invalid buffer mode",WHERE);
JS_ReportError(cx,"Invalid buffer mode");
return JS_FALSE;
}
if (setvbuf(p->fp, NULL, i, p->bufsize) == -1)
JS_ReportError(cx, "Unable to set buffer mode to %d", p->bufmode);
else
p->bufmode = i;
break;
}
......@@ -2369,7 +2375,7 @@ static JSBool js_file_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
*vp = INT_TO_JSVAL(2);
break;
default:
JS_ReportError(cx,"Invalid buffer mode",WHERE);
JS_ReportError(cx,"Invalid buffer mode");
return JS_FALSE;
}
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment