diff --git a/src/sbbs3/js_global.c b/src/sbbs3/js_global.c index c35cef82644d4ce4eaaa75ce61c93ffb597bd98e..5f352d359314a790159abf40e32d8a68a49c8734 100644 --- a/src/sbbs3/js_global.c +++ b/src/sbbs3/js_global.c @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -2241,16 +2241,20 @@ js_fmutex(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { char* fname; char* text=NULL; + int32 max_age=0; + uintN argn=0; if(JSVAL_IS_VOID(argv[0])) return(JS_TRUE); - if((fname=js_ValueToStringBytes(cx, argv[0], NULL))==NULL) + if((fname=js_ValueToStringBytes(cx, argv[argn++], NULL))==NULL) return(JS_FALSE); - if(argc>1) - text=js_ValueToStringBytes(cx,argv[1], NULL); + if(argc > argn && JSVAL_IS_STRING(argv[argn])) + text=js_ValueToStringBytes(cx, argv[argn++], NULL); + if(argc > argn && JSVAL_IS_NUMBER(argv[argn])) + JS_ValueToInt32(cx, argv[argn++], &max_age); - *rval = BOOLEAN_TO_JSVAL(fmutex(fname,text)); + *rval = BOOLEAN_TO_JSVAL(fmutex(fname,text,max_age)); return(JS_TRUE); } @@ -2765,9 +2769,12 @@ static jsSyncMethodSpec js_global_functions[] = { "creating an empty file if it doesn't already exist") ,311 }, - {"file_mutex", js_fmutex, 1, JSTYPE_BOOLEAN, JSDOCSTR("string filename [,text]") + {"file_mutex", js_fmutex, 1, JSTYPE_BOOLEAN, JSDOCSTR("string filename [,string text] [,number max_age]") ,JSDOCSTR("attempts to create an exclusive (e.g. lock) file, " - "optionally with the contents of <i>text</i>") + "optionally with the contents of <i>text</i>. " + "If a non-zero <i>max_age</i> (supported in v3.13b+) is specified " + "and the lock file exists, but is older than this value (in seconds), " + "it is presumed stale and removed/over-written") ,312 }, {"directory", js_directory, 1, JSTYPE_ARRAY, JSDOCSTR("string pattern [,flags]")