Skip to content
Snippets Groups Projects
Commit fbc225e9 authored by rswindell's avatar rswindell
Browse files

Created global file_utime() method to set a file's last-accessed and

modification times to the specified times or the current time (if unspecified)
parent 593de1df
No related branches found
No related tags found
No related merge requests found
......@@ -1210,6 +1210,32 @@ js_fdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return(JS_TRUE);
}
static JSBool
js_utime(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* fname;
struct utimbuf tbuf;
struct utimbuf* t=NULL;
*rval = JSVAL_FALSE;
if((fname=JS_GetStringBytes(JS_ValueToString(cx, argv[0])))==NULL)
return(JS_TRUE);
if(argc>1) {
memset(&tbuf,0,sizeof(tbuf));
tbuf.actime=tbuf.modtime=time(NULL);
JS_ValueToInt32(cx,argv[1],&tbuf.actime);
JS_ValueToInt32(cx,argv[2],&tbuf.modtime);
t=&tbuf;
}
*rval = BOOLEAN_TO_JSVAL(utime(fname,t)==0);
return(JS_TRUE);
}
static JSBool
js_flength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
......@@ -1463,7 +1489,11 @@ static jsMethodSpec js_global_functions[] = {
},
{"file_date", js_fdate, 1, JSTYPE_NUMBER, JSDOCSTR("string filename")
,JSDOCSTR("get a file's last modified date/time (in time_t format)")
},
},
{"file_utime", js_utime, 3, JSTYPE_BOOLEAN, JSDOCSTR("string filename [,access_time] [,mod_time]")
,JSDOCSTR("change a file's last accessed and modification date/time (in time_t format), "
"or change to current time")
},
{"file_size", js_flength, 1, JSTYPE_NUMBER, JSDOCSTR("string filename")
,JSDOCSTR("get a file's length (in bytes)")
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment