diff options
author | damkerngt <damkerngt@gmail.com> | 2013-10-17 18:04:17 (GMT) |
---|---|---|
committer | damkerngt <damkerngt@gmail.com> | 2013-10-17 18:04:17 (GMT) |
commit | 4f9396f701084d05bb20d74112b22e651484349e (patch) | |
tree | 61f2546e2b191115a2e548d99f3f1eab85a37b78 | |
parent | 4c804f7a60e7c598c395b6942d5313298b2cb535 (diff) | |
download | tcl-damkerngt_file_utime.zip tcl-damkerngt_file_utime.tar.gz tcl-damkerngt_file_utime.tar.bz2 |
Add new sub-command: file utime ?ATIME? MTIMEdamkerngt_file_utime
(re-checkin a mistaken checkin: [fa2e445528])
-rw-r--r-- | generic/tclCmdAH.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index f90819a..79250ac 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -77,6 +77,7 @@ static Tcl_ObjCmdProc FileAttrIsReadableCmd; static Tcl_ObjCmdProc FileAttrIsWritableCmd; static Tcl_ObjCmdProc FileAttrLinkStatCmd; static Tcl_ObjCmdProc FileAttrModifyTimeCmd; +static Tcl_ObjCmdProc FileAttrUTimeCmd; static Tcl_ObjCmdProc FileAttrSizeCmd; static Tcl_ObjCmdProc FileAttrStatCmd; static Tcl_ObjCmdProc FileAttrTypeCmd; @@ -981,6 +982,7 @@ TclInitFileCmd( {"tail", PathTailCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {"tempfile", TclFileTemporaryCmd, TclCompileBasic0To2ArgCmd, NULL, NULL, 0}, {"type", FileAttrTypeCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, + {"utime", FileAttrUTimeCmd, TclCompileBasic1Or2ArgCmd, NULL, NULL, 0}, {"volumes", FilesystemVolumesCmd, TclCompileBasic0ArgCmd, NULL, NULL, 0}, {"writable", FileAttrIsWritableCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {NULL, NULL, NULL, NULL, NULL, 0} @@ -1268,6 +1270,64 @@ FileAttrModifyTimeCmd( /* *---------------------------------------------------------------------- * + * FileAttrUTimeCmd -- + * + * This function is invoked to process the "file utime" Tcl command. See + * the user documentation for details on what it does. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * Update the access time and modification time on the file. + * + *---------------------------------------------------------------------- + */ + +static int +FileAttrUTimeCmd( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ + struct utimbuf tval; + long time; + /* + * Need separate variable for reading longs from an object on 64-bit + * platforms. [Bug 698146] + */ + + if (objc < 3 || objc > 4) { + Tcl_WrongNumArgs(interp, 1, objv, "name ?atime? mtime"); + return TCL_ERROR; + } + if (TclGetLongFromObj(interp, objv[2], &time) != TCL_OK) { + return TCL_ERROR; + } + tval.actime = time; + if (objc == 3) { + tval.modtime = time; + } else { + if (TclGetLongFromObj(interp, objv[3], &time) != TCL_OK) { + return TCL_ERROR; + } + tval.modtime = time; + } + + if (Tcl_FSUtime(objv[1], &tval) != 0) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "could not set time for file \"%s\": %s", + TclGetString(objv[1]), Tcl_PosixError(interp))); + return TCL_ERROR; + } + + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * FileAttrLinkStatCmd -- * * This function is invoked to process the "file lstat" Tcl command. See |