summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixChan.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2005-06-06 23:45:37 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2005-06-06 23:45:37 (GMT)
commite9429305435f6edac06ba3dc914e5658705e160a (patch)
tree374c84c5df35cf33d6fe30319969eb01c100c078 /unix/tclUnixChan.c
parent6580b2352407aa1b0f314552899f301558bc3113 (diff)
downloadtcl-e9429305435f6edac06ba3dc914e5658705e160a.zip
tcl-e9429305435f6edac06ba3dc914e5658705e160a.tar.gz
tcl-e9429305435f6edac06ba3dc914e5658705e160a.tar.bz2
TIP#208 implementation
It's crude (especially in the tests and docs department) and incomplete (no truncation on non-POSIX platforms).
Diffstat (limited to 'unix/tclUnixChan.c')
-rw-r--r--unix/tclUnixChan.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c
index abc2edc..c055f83 100644
--- a/unix/tclUnixChan.c
+++ b/unix/tclUnixChan.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixChan.c,v 1.57 2005/05/14 20:46:48 das Exp $
+ * RCS: @(#) $Id: tclUnixChan.c,v 1.58 2005/06/06 23:45:46 dkf Exp $
*/
#include "tclInt.h" /* Internal definitions for Tcl. */
@@ -241,8 +241,10 @@ static int FileSeekProc _ANSI_ARGS_((ClientData instanceData,
long offset, int mode, int *errorCode));
#ifdef DEPRECATED
static void FileThreadActionProc _ANSI_ARGS_ ((
- ClientData instanceData, int action));
+ ClientData instanceData, int action));
#endif
+static int FileTruncateProc _ANSI_ARGS_ ((ClientData instanceData,
+ Tcl_WideInt length));
static Tcl_WideInt FileWideSeekProc _ANSI_ARGS_((ClientData instanceData,
Tcl_WideInt offset, int mode, int *errorCode));
static void FileWatchProc _ANSI_ARGS_((ClientData instanceData,
@@ -325,6 +327,7 @@ static Tcl_ChannelType fileChannelType = {
#else
NULL,
#endif
+ FileTruncateProc, /* truncate proc. */
};
#ifdef SUPPORTS_TTY
@@ -354,6 +357,7 @@ static Tcl_ChannelType ttyChannelType = {
NULL, /* handler proc. */
NULL, /* wide seek proc. */
NULL, /* thread action proc. */
+ NULL, /* truncate proc. */
};
#endif /* SUPPORTS_TTY */
@@ -379,6 +383,7 @@ static Tcl_ChannelType tcpChannelType = {
NULL, /* handler proc. */
NULL, /* wide seek proc. */
NULL, /* thread action proc. */
+ NULL, /* truncate proc. */
};
@@ -3318,3 +3323,45 @@ FileThreadActionProc (instanceData, action)
}
}
#endif
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * FileTruncateProc --
+ *
+ * Truncates a file to a given length.
+ *
+ * Results:
+ * 0 if the operation succeeded, and -1 if it failed (in which
+ * case *errorCodePtr will be set to errno).
+ *
+ * Side effects:
+ * The underlying file is potentially truncated. This can have a
+ * wide variety of side effects, including moving file pointers
+ * that point at places later in the file than the truncate
+ * point.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+FileTruncateProc(instanceData, length)
+ ClientData instanceData;
+ Tcl_WideInt length;
+{
+ FileState *fsPtr = (FileState *) instanceData;
+ int result;
+
+#ifdef HAVE_TYPE_OFF64_T
+ /*
+ * We assume this goes with the type for now...
+ */
+ result = ftruncate64(fsPtr->fd, (off64_t) length);
+#else
+ result = ftruncate(fsPtr->fd, (off_t) length);
+#endif
+ if (result) {
+ return errno;
+ }
+ return 0;
+}