Commit fb99b55a authored by deuce's avatar deuce
Browse files

Revert last two commits. You can't use setvbuf() for this type of thing

portably.

Also, we're really interested in termios stuff, so we don't actually want
to call setvbuf anyway.
parent d2ac211a
......@@ -52,8 +52,6 @@ typedef struct
char name[MAX_PATH+1];
char mode[4];
uchar etx;
size_t bufsize;
int bufmode;
BOOL external; /* externally created, don't close */
BOOL debug;
BOOL rot13;
......@@ -166,7 +164,6 @@ js_open(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
}
}
p->bufsize = bufsize;
rc=JS_SUSPENDREQUEST(cx);
if(shareable)
......@@ -188,17 +185,15 @@ js_open(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp!=NULL) {
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
dbprintf(FALSE, p, "opened: %s",p->name);
if(!bufsize) {
p->bufmode = _IONBF;
}
if(!bufsize)
setvbuf(p->fp,NULL,_IONBF,0); /* no buffering */
else {
#ifdef _WIN32
if(bufsize < 2)
bufsize = 2;
#endif
p->bufmode = _IOFBF;
setvbuf(p->fp,NULL,_IOFBF,bufsize);
}
setvbuf(p->fp,NULL,p->bufmode,p->bufsize);
}
JS_RESUMEREQUEST(cx, rc);
......@@ -1452,7 +1447,6 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
char* cp;
char* uubuf=NULL;
size_t len; /* string length */
int decoded_len;
size_t tlen; /* total length to write (may be greater than len) */
int32 i;
JSString* str;
......@@ -1481,12 +1475,12 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
if((p->uuencoded || p->b64encoded || p->yencoded)
&& len && (uubuf=malloc(len))!=NULL) {
if(p->uuencoded)
decoded_len=uudecode(uubuf,len,cp,len);
len=uudecode(uubuf,len,cp,len);
else if(p->yencoded)
decoded_len=ydecode(uubuf,len,cp,len);
len=ydecode(uubuf,len,cp,len);
else
decoded_len=b64_decode(uubuf,len,cp,len);
if(decoded_len<0) {
len=b64_decode(uubuf,len,cp,len);
if(len<0) {
free(uubuf);
free(cp);
JS_RESUMEREQUEST(cx, rc);
......@@ -1494,7 +1488,6 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
}
free(cp);
cp=uubuf;
len = decoded_len;
}
if(p->rot13)
......@@ -2035,8 +2028,6 @@ enum {
,FILE_PROP_B64ENCODED
,FILE_PROP_ROT13
,FILE_PROP_NETWORK_ORDER
,FILE_PROP_BUFSIZE
,FILE_PROP_BUFMODE
/* dynamically calculated */
,FILE_PROP_CHKSUM
,FILE_PROP_CRC16
......@@ -2050,7 +2041,6 @@ static JSBool js_file_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict,
{
jsval idval;
int32 i=0;
uint32_t u=0;
jsint tiny;
private_t* p;
jsrefcount rc;
......@@ -2123,36 +2113,6 @@ static JSBool js_file_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict,
return(JS_FALSE);
p->etx = (uchar)i;
break;
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;
break;
case FILE_PROP_BUFMODE:
if(!JS_ValueToInt32(cx,*vp,&i))
return(JS_FALSE);
switch(i) {
case 0:
i = _IONBF;
break;
case 1:
i = _IOLBF;
break;
case 2:
i = _IOFBF;
break;
default:
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;
}
return(JS_TRUE);
......@@ -2360,25 +2320,6 @@ static JSBool js_file_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
if(js_str!=NULL)
*vp = STRING_TO_JSVAL(js_str);
break;
case FILE_PROP_BUFSIZE:
*vp = UINT_TO_JSVAL(p->bufsize);
break;
case FILE_PROP_BUFMODE:
switch(p->bufmode) {
case _IONBF:
*vp = INT_TO_JSVAL(0);
break;
case _IOLBF:
*vp = INT_TO_JSVAL(1);
break;
case _IOFBF:
*vp = INT_TO_JSVAL(2);
break;
default:
JS_ReportError(cx,"Invalid buffer mode");
return JS_FALSE;
}
break;
}
return(JS_TRUE);
......@@ -2407,8 +2348,6 @@ static jsSyncPropertySpec js_file_properties[] = {
{ "uue" ,FILE_PROP_UUENCODED ,JSPROP_ENUMERATE, 311},
{ "yenc" ,FILE_PROP_YENCODED ,JSPROP_ENUMERATE, 311},
{ "base64" ,FILE_PROP_B64ENCODED ,JSPROP_ENUMERATE, 311},
{ "bufsize" ,FILE_PROP_BUFSIZE ,JSPROP_ENUMERATE, 317},
{ "bufmode" ,FILE_PROP_BUFMODE ,JSPROP_ENUMERATE, 317},
/* dynamically calculated */
{ "crc16" ,FILE_PROP_CRC16 ,FILE_PROP_FLAGS, 311},
{ "crc32" ,FILE_PROP_CRC32 ,FILE_PROP_FLAGS, 311},
......@@ -2438,8 +2377,6 @@ static char* file_prop_desc[] = {
,"set to <i>true</i> to enable automatic Unix-to-Unix encode and decode on <tt>read</tt> and <tt>write</tt> calls"
,"set to <i>true</i> to enable automatic yEnc encode and decode on <tt>read</tt> and <tt>write</tt> calls"
,"set to <i>true</i> to enable automatic Base64 encode and decode on <tt>read</tt> and <tt>write</tt> calls"
,"size of file buffer"
,"file buffer mode. 0 means unbuffered, 1 means line buffered, and 2 means fully buffered"
,"calculated 16-bit CRC of file contents - <small>READ ONLY</small>"
,"calculated 32-bit CRC of file contents - <small>READ ONLY</small>"
,"calculated 32-bit checksum of file contents - <small>READ ONLY</small>"
......
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