summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-28 16:10:01 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-28 16:10:01 (GMT)
commit0015fdd61a457d1292bd92f62ccdfad6bebb8e8a (patch)
treebdeb3a4349df7cbb36253f56248ae2ecc3f21ef7 /generic/tclIO.c
parentfe200c4760cb4f5b020a79716aec8f79e6fae099 (diff)
downloadtcl-0015fdd61a457d1292bd92f62ccdfad6bebb8e8a.zip
tcl-0015fdd61a457d1292bd92f62ccdfad6bebb8e8a.tar.gz
tcl-0015fdd61a457d1292bd92f62ccdfad6bebb8e8a.tar.bz2
Add "chan isbinary" command. Part of TIP #699, meant for 8.7
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index caf0e3a..cd925b5 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -7628,6 +7628,34 @@ CheckChannelErrors(
/*
*----------------------------------------------------------------------
*
+ * TclChanIsBinary --
+ *
+ * Returns 1 if the channel is a binary channel, 0 otherwise.
+ *
+ * Results:
+ * 1 or 0, always.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclChanIsBinary(
+ Tcl_Channel chan) /* Does this channel have EOF? */
+{
+ ChannelState *statePtr = ((Channel *) chan)->state;
+ /* State of real channel structure. */
+
+ return ((!statePtr->encoding || (statePtr->encoding == GetBinaryEncoding())) && !statePtr->inEofChar
+ && (!GotFlag(statePtr, TCL_READABLE) || (statePtr->inputTranslation == TCL_TRANSLATE_LF))
+ && (!GotFlag(statePtr, TCL_WRITABLE) || (statePtr->outputTranslation == TCL_TRANSLATE_LF)));
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_Eof --
*
* Returns 1 if the channel is at EOF, 0 otherwise.