summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdAH.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclCmdAH.c')
-rw-r--r--generic/tclCmdAH.c70
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;
}