diff options
author | hobbs <hobbs> | 1999-10-29 03:03:59 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 1999-10-29 03:03:59 (GMT) |
commit | 92efc11980dd19d497d47daca03f5082a28a63f4 (patch) | |
tree | 2550a48f32cd8d0e46db002b52b75fa1deff247a /generic/tclCmdAH.c | |
parent | bba32831be50692711739fc652d23c4d3e258c9e (diff) | |
download | tcl-92efc11980dd19d497d47daca03f5082a28a63f4.zip tcl-92efc11980dd19d497d47daca03f5082a28a63f4.tar.gz tcl-92efc11980dd19d497d47daca03f5082a28a63f4.tar.bz2 |
* generic/tclStringObj.c: fixed Tcl_AppendResultVA so it only
iterates once over the va_list (avoiding a memcpy of it,
which is not portable).
* generic/tclEnv.c: fixed possible ABR error in environ array
* tests/scan.test:
* generic/tclScan.c: added support for use of inline scan,
XPG3 currently not included
* tests/incr.test:
* tests/set.test:
* generic/tclCompCmds.c: fixed improper bytecode handling of
'eval {set array($unknownvar) 5}' (also for incr)
* win/tclWinTest.c: added testvolumetype command, as atime is
completely ignored for Windows FAT file systems
* win/tclWinPort.h: added sys/utime.h to includes
* unix/tclUnixPort.h: added utime.h to includes
* doc/file.n:
* tests/cmdAH.test:
* generic/tclCmdAH.c: added time arguments to atime and mtime
file command methods (support 'touch' functionality)
Diffstat (limited to 'generic/tclCmdAH.c')
-rw-r--r-- | generic/tclCmdAH.c | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index b86ea42..3e4de89 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdAH.c,v 1.9 1999/09/21 04:20:39 hobbs Exp $ + * RCS: @(#) $Id: tclCmdAH.c,v 1.10 1999/10/29 03:03:59 hobbs Exp $ */ #include "tclInt.h" @@ -827,13 +827,41 @@ Tcl_FileObjCmd(dummy, interp, objc, objv) switch ((enum options) index) { case FILE_ATIME: { struct stat buf; - - if (objc != 3) { - goto only3Args; + char *fileName; + struct utimbuf tval; + + if ((objc < 3) || (objc > 4)) { + Tcl_WrongNumArgs(interp, 2, objv, "name ?time?"); + return TCL_ERROR; } if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { return TCL_ERROR; } + if (objc == 4) { + if (Tcl_GetLongFromObj(interp, objv[3], + (long*)(&buf.st_atime)) != TCL_OK) { + return TCL_ERROR; + } + tval.actime = buf.st_atime; + tval.modtime = buf.st_mtime; + fileName = Tcl_GetString(objv[2]); + if (utime(fileName, &tval) != 0) { + Tcl_AppendStringsToObj(resultPtr, + "could not set access time for file \"", + fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + /* + * Do another stat to ensure that the we return the + * new recognized atime - hopefully the same as the + * one we sent in. However, fs's like FAT don't + * even know what atime is. + */ + if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { + return TCL_ERROR; + } + } Tcl_SetLongObj(resultPtr, (long) buf.st_atime); return TCL_OK; } @@ -986,13 +1014,41 @@ Tcl_FileObjCmd(dummy, interp, objc, objv) } case FILE_MTIME: { struct stat buf; - - if (objc != 3) { - goto only3Args; + char *fileName; + struct utimbuf tval; + + if ((objc < 3) || (objc > 4)) { + Tcl_WrongNumArgs(interp, 2, objv, "name ?time?"); + return TCL_ERROR; } if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { return TCL_ERROR; } + if (objc == 4) { + if (Tcl_GetLongFromObj(interp, objv[3], + (long*)(&buf.st_mtime)) != TCL_OK) { + return TCL_ERROR; + } + tval.actime = buf.st_atime; + tval.modtime = buf.st_mtime; + fileName = Tcl_GetString(objv[2]); + if (utime(fileName, &tval) != 0) { + Tcl_AppendStringsToObj(resultPtr, + "could not set modification time for file \"", + fileName, "\": ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + /* + * Do another stat to ensure that the we return the + * new recognized atime - hopefully the same as the + * one we sent in. However, fs's like FAT don't + * even know what atime is. + */ + if (GetStatBuf(interp, objv[2], TclStat, &buf) != TCL_OK) { + return TCL_ERROR; + } + } Tcl_SetLongObj(resultPtr, (long) buf.st_mtime); return TCL_OK; } |