Commit fcea4a6e authored by deuce's avatar deuce
Browse files

Start converting from *_TO_STRING() macros and only strip the 'e' chars when

cleaning up the open mode rather than truncating at the first 'e' char.  Also,
allow passing more than three flags through to fdopen().
parent 2952b4eb
......@@ -130,7 +130,6 @@ js_open(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* mode="w+"; /* default mode */
BOOL shareable=FALSE;
int file;
uintN i;
......@@ -149,32 +148,38 @@ js_open(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp!=NULL)
return(JS_TRUE);
SAFECOPY(p->mode,"w+"); /* default mode */
for(i=0;i<argc;i++) {
if(JSVAL_IS_STRING(argv[i])) { /* mode */
if((str = JS_ValueToString(cx, argv[i]))==NULL) {
JS_ReportError(cx,"Invalid mode specified: %s",str);
return(JS_TRUE);
}
JSSTRING_TO_STRING(cx, str, mode, NULL);
} else if(JSVAL_IS_BOOLEAN(argv[i])) /* shareable */
JSSTRING_TO_STRBUF(cx, str, p->mode, sizeof(p->mode), NULL);
}
else if(JSVAL_IS_BOOLEAN(argv[i])) /* shareable */
shareable=JSVAL_TO_BOOLEAN(argv[i]);
else if(JSVAL_IS_NUMBER(argv[i])) { /* bufsize */
if(!JS_ValueToInt32(cx,argv[i],&bufsize))
return(JS_FALSE);
}
}
SAFECOPY(p->mode,mode);
rc=JS_SUSPENDREQUEST(cx);
if(shareable)
p->fp=fopen(p->name,p->mode);
else {
if((file=nopen(p->name,fopenflags(p->mode)))!=-1) {
char fdomode[4];
SAFECOPY(fdomode,p->mode);
fdomode[strspn(fdomode,"abrwt+")]=0; /* MSVC10 fdopen() asserts when passed a mode with an unsupported char (e.g. 'e') */
if((p->fp=fdopen(file,fdomode))==NULL)
close(file);
char *fdomode=strdup(p->mode);
char *e=fdomode;
if(fdomode && e) {
for(e=strchr(fdomode, 'e'); e ; e=strchr(e, 'e'))
memmove(e, e+1, strlen(e));
if((p->fp=fdopen(file,fdomode))==NULL)
close(file);
}
free(fdomode);
}
}
if(p->fp!=NULL) {
......@@ -195,7 +200,6 @@ js_popen(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* mode="r+"; /* default mode */
uintN i;
jsint bufsize=2*1024;
JSString* str;
......@@ -212,20 +216,20 @@ js_popen(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp!=NULL)
return(JS_TRUE);
SAFECOPY(p->mode,"r+"); /* default mode */
for(i=0;i<argc;i++) {
if(JSVAL_IS_STRING(argv[i])) { /* mode */
if((str = JS_ValueToString(cx, argv[i]))==NULL) {
JS_ReportError(cx,"Invalid mode specified: %s",str);
return(JS_TRUE);
}
JSSTRING_TO_STRING(cx, str, mode, NULL);
JSSTRING_TO_STRBUF(cx, str, p->mode, sizeof(p->mode), NULL);
}
else if(JSVAL_IS_NUMBER(argv[i])) { /* bufsize */
if(!JS_ValueToInt32(cx,argv[i],&bufsize))
return(JS_FALSE);
}
}
SAFECOPY(p->mode,mode);
rc=JS_SUSPENDREQUEST(cx);
p->fp=popen(p->name,p->mode);
......@@ -666,9 +670,12 @@ js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
}
else {
array = JS_NewArrayObject(cx, 0, NULL);
JSVALUE_TO_STRING(cx, dflt, cstr, NULL);
JSVALUE_TO_MSTRING(cx, dflt, cstr, NULL);
HANDLE_PENDING(cx);
rc=JS_SUSPENDREQUEST(cx);
list=iniReadStringList(p->fp,section,key,",",cstr);
if(cstr)
free(cstr);
JS_RESUMEREQUEST(cx, rc);
for(i=0;list && list[i];i++) {
val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx,list[i]));
......@@ -695,9 +702,12 @@ js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,INT_TO_JSVAL(i));
} else {
JSVALUE_TO_STRING(cx, dflt, cstr, NULL);
JSVALUE_TO_MSTRING(cx, dflt, cstr, NULL);
HANDLE_PENDING(cx);
rc=JS_SUSPENDREQUEST(cx);
cstr2=iniReadString(p->fp,section,key,cstr,buf);
if(cstr)
free(cstr);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cstr2)));
}
......@@ -766,9 +776,12 @@ js_iniSetValue_internal(JSContext *cx, JSObject *obj, uintN argc, jsval* argv, j
result = iniSetDateTime(&list,section,key,/* include_time */TRUE, tt,NULL);
JS_RESUMEREQUEST(cx, rc);
} else {
JSVALUE_TO_STRING(cx, value, cstr, NULL);
JSVALUE_TO_MSTRING(cx, value, cstr, NULL);
HANDLE_PENDING(cx);
rc=JS_SUSPENDREQUEST(cx);
result = iniSetString(&list,section,key, cstr,NULL);
if(cstr)
free(cstr);
JS_RESUMEREQUEST(cx, rc);
}
......
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