Seth Woolley's Man Viewer

Tcl_WriteRaw(3) - Tcl_Close, Tcl_DetachChannel, Tcl_Eof, Tcl_Flush, Tcl_GetChannel, Tcl_GetChannelNames, Tcl_GetChannelNamesEx, Tcl_GetChannelOption, Tcl_Gets, Tcl_GetsObj, Tcl_InputBlocked, Tcl_InputBuffered, Tcl_IsStandardChannel, Tcl_MakeFileChannel, Tcl_OpenCommandChannel, Tcl_OpenFileChannel, Tcl_OutputBuffered, Tcl_Read, Tcl_ReadChars, Tcl_ReadRaw, Tcl_RegisterChannel, Tcl_Seek, Tcl_SetChannelOption, Tcl_Tell, Tcl_Ungets, Tcl_UnregisterChannel, Tcl_Write, Tcl_WriteChars, Tcl_WriteObj, Tcl_WriteRaw - buffered I/O facilities using channels - man 3 Tcl_WriteRaw

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

Tcl_OpenFileChannel(3)      Tcl Library Procedures      Tcl_OpenFileChannel(3)



______________________________________________________________________________

NAME
       Tcl_OpenFileChannel,    Tcl_OpenCommandChannel,    Tcl_MakeFileChannel,
       Tcl_GetChannel, Tcl_GetChannelNames, Tcl_GetChannelNamesEx,  Tcl_Regis-
       terChannel,  Tcl_UnregisterChannel,  Tcl_DetachChannel, Tcl_IsStandard-
       Channel, Tcl_Close,  Tcl_ReadChars,  Tcl_Read,  Tcl_GetsObj,  Tcl_Gets,
       Tcl_WriteObj, Tcl_WriteChars, Tcl_Write, Tcl_Flush, Tcl_Seek, Tcl_Tell,
       Tcl_GetChannelOption, Tcl_SetChannelOption, Tcl_Eof,  Tcl_InputBlocked,
       Tcl_InputBuffered,    Tcl_OutputBuffered,    Tcl_Ungets,   Tcl_ReadRaw,
       Tcl_WriteRaw - buffered I/O facilities using channels

SYNOPSIS
       #include <tcl.h>

       Tcl_Channel
       Tcl_OpenFileChannel(interp, fileName, mode, permissions)

       Tcl_Channel
       Tcl_OpenCommandChannel(interp, argc, argv, flags)

       Tcl_Channel
       Tcl_MakeFileChannel(handle, readOrWrite)

       Tcl_Channel
       Tcl_GetChannel(interp, channelName, modePtr)

       int                                                                     |
       Tcl_GetChannelNames(interp)                                             |

       int                                                                     |
       Tcl_GetChannelNamesEx(interp, pattern)                                  |

       void
       Tcl_RegisterChannel(interp, channel)

       int
       Tcl_UnregisterChannel(interp, channel)

       int
       Tcl_DetachChannel(interp, channel)

       int
       Tcl_IsStandardChannel(channel)

       int
       Tcl_Close(interp, channel)

       int                                                                     |
       Tcl_ReadChars(channel, readObjPtr, charsToRead, appendFlag)             |

       int                                                                     |
       Tcl_Read(channel, readBuf, bytesToRead)                                 |

       int                                                                     |
       Tcl_GetsObj(channel, lineObjPtr)                                        |

       int                                                                     |
       Tcl_Gets(channel, lineRead)                                             |

       int                                                                     |
       Tcl_Ungets(channel, input, inputLen, addAtEnd)                          |

       int                                                                     |
       Tcl_WriteObj(channel, writeObjPtr)                                      |

       int                                                                     |
       Tcl_WriteChars(channel, charBuf, bytesToWrite)                          |

       int                                                                     |
       Tcl_Write(channel, byteBuf, bytesToWrite)                               |

       int                                                                     |
       Tcl_ReadRaw(channel, readBuf, bytesToRead)                              |

       int                                                                     |
       Tcl_WriteRaw(channel, byteBuf, bytesToWrite)                            |

       int
       Tcl_Eof(channel)

       int
       Tcl_Flush(channel)

       int
       Tcl_InputBlocked(channel)

       int
       Tcl_InputBuffered(channel)

       int                                                                     |
       Tcl_OutputBuffered(channel)                                             |

       Tcl_WideInt                                                             |
       Tcl_Seek(channel, offset, seekMode)                                     |

       Tcl_WideInt                                                             |
       Tcl_Tell(channel)                                                       |

       int
       Tcl_GetChannelOption(interp, channel, optionName, optionValue)

       int
       Tcl_SetChannelOption(interp, channel, optionName, newValue)


ARGUMENTS
       Tcl_Interp        *interp            (in(1,8))      Used for error(8,n) reporting
                                                      and to look(1,8,3 Search::Dict) up a channel
                                                      registered in(1,8) it.

       CONST char        *fileName          (in(1,8))      The name of a  local  or
                                                      network file.

       CONST char        *mode              (in(1,8))      Specifies  how  the file(1,n)
                                                      is to be accessed.   May
                                                      have  any  of the values
                                                      allowed  for  the   mode
                                                      argument to the Tcl open(2,3,n)
                                                      command.

       int               permissions        (in(1,8))      POSIX-style   permission
                                                      flags  such as 0644.  If
                                                      a new file(1,n)  is  created,
                                                      these  permissions  will
                                                      be set(7,n,1 builtins)  on  the  created
                                                      file.

       int               argc               (in(1,8))      The  number  of elements
                                                      in(1,8) argv.

       CONST char        **argv             (in(1,8))      Arguments for construct-
                                                      ing  a command pipeline.
                                                      These  values  have  the
                                                      same meaning as the non-
                                                      switch(1,n) arguments to  the
                                                      Tcl exec(3,n,1 builtins) command.

       int               flags              (in(1,8))      Specifies  the  disposi-
                                                      tion of the  stdio  han-
                                                      dles  in(1,8) pipeline: OR-ed
                                                      combination           of
                                                      TCL_STDIN,   TCL_STDOUT,
                                                      TCL_STDERR,          and
                                                      TCL_ENFORCE_MODE.     If
                                                      TCL_STDIN is set(7,n,1 builtins),  stdin
                                                      for  the  first child in(1,8)
                                                      the  pipe(2,8)  is  the  pipe(2,8)
                                                      channel, otherwise it is
                                                      the same as the standard
                                                      input  of  the  invoking
                                                      process;  likewise   for
                                                      TCL_STDOUT           and
                                                      TCL_STDERR.           If
                                                      TCL_ENFORCE_MODE  is not
                                                      set(7,n,1 builtins), then the  pipe(2,8)  can
                                                      redirect  stdio  handles
                                                      to  override  the  stdio
                                                      handles     for    which
                                                      TCL_STDIN,    TCL_STDOUT
                                                      and TCL_STDERR have been
                                                      set.  If it is set(7,n,1 builtins), then
                                                      such  redirections cause
                                                      an error.

       ClientData        handle             (in(1,8))      Operating  system   spe-
                                                      cific  handle for I/O to
                                                      a file. For Unix this is
                                                      a  file(1,n)  descriptor, for
                                                      Windows it is a  HANDLE.

       int               readOrWrite        (in(1,8))      OR-ed   combination   of
                                                      TCL_READABLE         and
                                                      TCL_WRITABLE to indicate
                                                      what   operations    are
                                                      valid on handle.

       CONST char        *channelName       (in(1,8))      The name of the channel.

       int               *modePtr           (out)     Points  at  an   integer
                                                      variable    that    will
                                                      receive an OR-ed  combi-
                                                      nation  of  TCL_READABLE
                                                      and TCL_WRITABLE  denot-
                                                      ing  whether the channel
                                                      is open(2,3,n) for reading  and
                                                      writing.                 |

       CONST char        *pat-                                                 |
       tern           (in(1,8))                               |                     |
                                                      The pattern to match on, |
                                                      passed   to  Tcl_String- |
                                                      Match, or NULL.

       Tcl_Channel       channel            (in(1,8))      A Tcl channel for  input
                                                      or  output.   Must  have
                                                      been  the  return  value
                                                      from a procedure such as
                                                      Tcl_OpenFileChannel.

       Tcl_Obj           *readOb-                                              |
       jPtr        (in(1,8)/out)                           |                        |
                                                      A   pointer   to  a  Tcl |
                                                      Object in(1,8) which to store |
                                                      the characters read(2,n,1 builtins) from |
                                                      the channel.             |

       int               char-                                                 |
       sToRead        (in(1,8))                               |                     |
                                                      The number of characters |
                                                      to read(2,n,1 builtins) from  the  chan- |
                                                      nel.   If  the channel's |
                                                      encoding(3,n) is binary, this |
                                                      is   equivalent  to  the |
                                                      number of bytes to  read(2,n,1 builtins) |
                                                      from the channel.        |

       int               append-                                               |
       Flag         (in(1,8))                               |                       |
                                                      If non-zero,  data  read(2,n,1 builtins) |
                                                      from the channel will be |
                                                      appended to the  object. |
                                                      Otherwise, the data will |
                                                      replace   the   existing |
                                                      contents  of the object. |

       char              *read-                                                |
       Buf           (out)                              |                      |
                                                      A  buffer  in(1,8)  which  to |
                                                      store  the  bytes   read(2,n,1 builtins) |
                                                      from the channel.        |

       int               byte-                                                 |
       sToRead        (in(1,8))                               |                     |
                                                      The number of  bytes  to |
                                                      read(2,n,1 builtins)  from  the channel. |
                                                      The buffer readBuf  must |
                                                      be  large enough to hold |
                                                      this many bytes.         |

       Tcl_Obj           *lineOb-                                              |
       jPtr        (in(1,8)/out)                           |                        |
                                                      A   pointer   to  a  Tcl |
                                                      object in(1,8) which to store |
                                                      the  line  read(2,n,1 builtins) from the |
                                                      channel.  The line  read(2,n,1 builtins) |
                                                      will  be appended to the |
                                                      current  value  of   the |
                                                      object.                  |

       Tcl_DString       *lineRead          (in(1,8)/out)                           ||
                                                      A  pointer  to   a   Tcl |
                                                      dynamic  string(3,n) in(1,8) which |
                                                      to store the  line  read(2,n,1 builtins) |
                                                      from  the channel.  Must |
                                                      have been initialized by |
                                                      the  caller.   The  line |
                                                      read(2,n,1 builtins) will be appended to |
                                                      any  data already in(1,8) the |
                                                      dynamic string.          |

       CONST                                                                   |
       char        *input             (in(1,8))                               |     |
                                                      The  input  to  add to a |
                                                      channel buffer.          |

       int               inputLen           (in(1,8))                               ||
                                                      Length of the input      |

       int               addA-                                                 |
       tEnd           (in(1,8))                               |                     |
                                                      Flag indicating  whether |
                                                      the   input   should  be |
                                                      added  to  the  end   or |
                                                      beginning of the channel |
                                                      buffer.

       Tcl_Obj           *writeObjPtr       (in(1,8))      A  pointer  to   a   Tcl
                                                      Object   whose  contents
                                                      will be  output  to  the
                                                      channel.

       CONST char        *charBuf           (in(1,8))      A  buffer containing the
                                                      characters to output  to
                                                      the channel.

       CONST char        *byteBuf           (in(1,8))      A  buffer containing the
                                                      bytes to output  to  the
                                                      channel.

       int               bytesToWrite       (in(1,8))      The  number  of bytes to
                                                      consume from charBuf  or
                                                      byteBuf  and  output  to
                                                      the channel.

       Tcl_WideInt       offset             (in(1,8))      How  far  to  move(3x,7,3x curs_move)   the
                                                      access(2,5)   point   in(1,8)  the
                                                      channel  at  which   the
                                                      next   input  or  output
                                                      operation    will     be
                                                      applied,   measured   in(1,8)
                                                      bytes from the  position
                                                      given  by seekMode.  May
                                                      be  either  positive  or
                                                      negative.

       int               seekMode           (in(1,8))      Relative  to which point
                                                      to seek; used with  off-
                                                      set(7,n,1 builtins) to calculate the new
                                                      access(2,5)  point  for   the
                                                      channel.   Legal  values
                                                      are SEEK_SET,  SEEK_CUR,
                                                      and SEEK_END.

       CONST char        *optionName        (in(1,8))      The  name  of  an option
                                                      applicable to this chan-
                                                      nel,  such as -blocking.
                                                      May have any of the val-
                                                      ues   accepted   by  the
                                                      fconfigure command.

       Tcl_DString       *optionValue       (in(1,8))      Where to store the value
                                                      of  an  option or a list
                                                      of all options and their
                                                      values.  Must  have been
                                                      initialized    by    the
                                                      caller.

       CONST char        *newValue          (in(1,8))      New value for the option
                                                      given by optionName.
_________________________________________________________________


DESCRIPTION
       The Tcl channel mechanism provides a device-independent  and  platform-
       independent  mechanism  for performing buffered input and output opera-
       tions on a variety of file(1,n), socket(2,7,n),  and  device  types.   The  channel
       mechanism  is extensible to new channel types, by providing a low level
       channel driver for the  new  type;  the  channel  driver  interface  is
       described in(1,8) the manual entry for Tcl_CreateChannel. The channel mecha-
       nism provides a buffering scheme modeled after Unix's standard I/O, and
       it also allows for nonblocking I/O on channels.

       The  procedures  described  in(1,8) this manual entry comprise the C APIs of
       the generic layer of the channel architecture. For a description of the
       channel  driver  architecture  and how to implement channel drivers for
       new types of channels, see the manual entry for Tcl_CreateChannel.


TCL_OPENFILECHANNEL
       Tcl_OpenFileChannel opens a file(1,n) specified by fileName  and  returns  a
       channel  handle  that  can  be  used to perform input and output on the
       file. This API is modeled after the fopen procedure of the  Unix  stan-
       dard  I/O  library.  The syntax and meaning of all arguments is similar
       to those given in(1,8) the Tcl open(2,3,n) command when  opening  a  file.   If  an
       error(8,n)  occurs  while  opening  the channel, Tcl_OpenFileChannel returns
       NULL and records  a  POSIX  error(8,n)  code  that  can  be  retrieved  with
       Tcl_GetErrno.   In addition, if(3,n) interp is non-NULL, Tcl_OpenFileChannel
       leaves an error(8,n) message in(1,8) interp's result after any error.  As of  Tcl
       8.4, the object-based API Tcl_FSOpenFileChannel should be used in(1,8) pref-
       erence to Tcl_OpenFileChannel wherever possible.



       The newly created channel is not  registered  in(1,8)  the  supplied  inter-
       preter;  to  register it, use Tcl_RegisterChannel, described below.  If
       one of the standard channels, stdin, stdout or  stderr  was  previously
       closed,  the  act  of  creating  the  new  channel also assigns it as a
       replacement for the standard channel.


TCL_OPENCOMMANDCHANNEL
       Tcl_OpenCommandChannel provides a C-level interface to the functions of
       the  exec(3,n,1 builtins)  and  open(2,3,n)  commands.   It creates a sequence of subprocesses
       specified by the argv and argc arguments and returns a channel that can
       be  used  to  communicate  with these subprocesses.  The flags argument
       indicates what sort(1,3) of communication will exist with the command  pipe-
       line.

       If the TCL_STDIN flag is set(7,n,1 builtins) then the standard input for the first sub-
       process will be tied to the channel: writing to the channel  will  pro-
       vide  input  to the subprocess.  If TCL_STDIN is not set(7,n,1 builtins), then standard
       input for the first subprocess will be the same as  this  application's
       standard  input.   If  TCL_STDOUT  is set(7,n,1 builtins) then standard output from the
       last subprocess can be read(2,n,1 builtins) from the channel; otherwise it goes to this
       application's  standard  output.   If TCL_STDERR is set(7,n,1 builtins), standard error(8,n)
       output for all subprocesses is returned to the channel and  results  in(1,8)
       an error(8,n) when the channel is closed; otherwise it goes to this applica-
       tion's standard error.  If TCL_ENFORCE_MODE is not set(7,n,1 builtins), then  argc  and
       argv  can redirect the stdio handles to override TCL_STDIN, TCL_STDOUT,
       and TCL_STDERR; if(3,n) it is set(7,n,1 builtins), then it is an error(8,n) for argc and argv  to
       override stdio channels for which TCL_STDIN, TCL_STDOUT, and TCL_STDERR
       have been set.

       If an error(8,n) occurs while opening  the  channel,  Tcl_OpenCommandChannel
       returns  NULL and records a POSIX error(8,n) code that can be retrieved with
       Tcl_GetErrno.  In addition, Tcl_OpenCommandChannel leaves an error(8,n) mes-
       sage in(1,8) the interpreter's result if(3,n) interp is not NULL.

       The  newly  created  channel  is  not registered in(1,8) the supplied inter-
       preter; to register it, use Tcl_RegisterChannel, described  below.   If
       one  of  the  standard channels, stdin, stdout or stderr was previously
       closed, the act of creating the  new  channel  also  assigns  it  as  a
       replacement for the standard channel.


TCL_MAKEFILECHANNEL
       Tcl_MakeFileChannel makes a Tcl_Channel from an existing, platform-spe-
       cific, file(1,n) handle.  The newly created channel is not registered in(1,8) the
       supplied   interpreter;   to   register  it,  use  Tcl_RegisterChannel,
       described below.  If one of the standard  channels,  stdin,  stdout  or
       stderr  was previously closed, the act of creating the new channel also
       assigns it as a replacement for the standard channel.


TCL_GETCHANNEL
       Tcl_GetChannel returns a channel given the channelName used  to  create
       it with Tcl_CreateChannel and a pointer to a Tcl interpreter in(1,8) interp.
       If a channel by that name is not registered in(1,8)  that  interpreter,  the
       procedure  returns NULL. If the modePtr argument is not NULL, it points
       at an integer variable  that  will  receive  an  OR-ed  combination  of
       TCL_READABLE  and  TCL_WRITABLE  describing whether the channel is open(2,3,n)
       for reading and writing.

       Tcl_GetChannelNames and Tcl_GetChannelNamesEx write(1,2) the  names  of  the
       registered  channels  to  the  interpreter's  result  as a list object.
       Tcl_GetChannelNamesEx will filter(1,3x,3x curs_util) these names according to the pattern.
       If  pattern  is  NULL,  then  it will not do any filtering.  The return
       value is TCL_OK if(3,n) no errors occurred writing to the result,  otherwise
       it  is  TCL_ERROR,  and  the error(8,n) message is left in(1,8) the interpreter's
       result.


TCL_REGISTERCHANNEL
       Tcl_RegisterChannel adds a channel to the set(7,n,1 builtins) of channels accessible in(1,8)
       interp. After this call, Tcl programs executing in(1,8) that interpreter can
       refer to the channel in(1,8) input or output operations using the name given
       in(1,8) the call to Tcl_CreateChannel.  After this call, the channel becomes
       the property of  the  interpreter,  and  the  caller  should  not  call
       Tcl_Close  for  the  channel;  the channel will be closed automatically
       when it is unregistered from the interpreter.

       Code executing outside of any Tcl interpreter  can  call  Tcl_Register-
       Channel  with interp as NULL, to indicate that it wishes to hold a ref-
       erence to this channel. Subsequently, the channel can be registered  in(1,8)
       a  Tcl  interpreter and it will only be closed when the matching number
       of calls to Tcl_UnregisterChannel have been  made.   This  allows  code
       executing  outside  of  any interpreter to safely hold a reference to a
       channel that is also registered in(1,8) a Tcl interpreter.

       This procedure interacts with the code managing the standard  channels.
       If  no  standard  channels  were  initialized  before the first call to
       Tcl_RegisterChannel  they  will  get  initialized  by  that  call.  See
       Tcl_StandardChannels for a general treatise about standard channels and
       the behaviour of the Tcl library with regard to them.


TCL_UNREGISTERCHANNEL
       Tcl_UnregisterChannel removes a channel from the set(7,n,1 builtins) of channels acces-
       sible  in(1,8)  interp. After this call, Tcl programs will no longer be able
       to use the channel's name to refer to the channel in(1,8) that  interpreter.
       If  this  operation removed the last registration of the channel in(1,8) any
       interpreter, the channel is also closed and destroyed.

       Code not associated with a Tcl interpreter can call Tcl_UnregisterChan-
       nel  with  interp as NULL, to indicate to Tcl that it no longer holds a
       reference to that channel. If this is the last reference to  the  chan-
       nel,  it  will now be closed.  Tcl_UnregisterChannel is very similar to
       Tcl_DetachChannel except that it will also close(2,7,n) the channel if(3,n) no fur-
       ther references to it exist.


TCL_DETACHCHANNEL
       Tcl_DetachChannel removes a channel from the set(7,n,1 builtins) of channels accessible
       in(1,8) interp. After this call, Tcl programs will no longer be able to  use
       the channel's name to refer to the channel in(1,8) that interpreter.  Beyond
       that, this command has no further effect.  It cannot  be  used  on  the
       standard channels (stdout, stderr, stdin), and will return TCL_ERROR if(3,n)
       passed one of those channels.

       Code not associated with a Tcl interpreter can  call  Tcl_DetachChannel
       with  interp as NULL, to indicate to Tcl that it no longer holds a ref-
       erence to that channel. If this is the last reference to  the  channel,
       unlike Tcl_UnregisterChannel, it will not be closed.


TCL_ISSTANDARDCHANNEL
       Tcl_IsStandardChannel tests whether a channel is one of the three stan-
       dard channels, stdin, stdout or stderr.  If so, it returns 1, otherwise
       0.

       No  attempt  is made to check whether the given channel or the standard
       channels are initialized or otherwise valid.


TCL_CLOSE
       Tcl_Close destroys the channel channel, which must denote  a  currently
       open(2,3,n)  channel.  The channel should not be registered in(1,8) any interpreter
       when Tcl_Close is called. Buffered output is flushed to  the  channel's
       output  device  prior to destroying the channel, and any buffered input
       is discarded.  If this is a blocking channel, the call does not  return
       until  all  buffered  data is successfully sent to the channel's output
       device.  If this is a nonblocking channel and there is buffered  output
       that  cannot be written without blocking, the call returns immediately;
       output is flushed in(1,8) the background and the channel will be closed once
       all  of  the buffered data has been output.  In this case errors during
       flushing are not reported.

       If the channel was closed successfully, Tcl_Close returns  TCL_OK.   If
       an  error(8,n) occurs, Tcl_Close returns TCL_ERROR and records a POSIX error(8,n)
       code that can be retrieved with Tcl_GetErrno.  If the channel is  being
       closed  synchronously and an error(8,n) occurs during closing of the channel
       and interp is not NULL, an error(8,n) message is left in(1,8)  the  interpreter's
       result.

       Note:  it is not safe to call Tcl_Close on a channel that has been reg-
       istered using Tcl_RegisterChannel; see the documentation for Tcl_Regis-
       terChannel,  above,  for details. If the channel has ever been given as
       the chan argument in(1,8) a call to Tcl_RegisterChannel, you should  instead
       use  Tcl_UnregisterChannel,  which  will internally call Tcl_Close when
       all calls to Tcl_RegisterChannel have  been  matched  by  corresponding
       calls to Tcl_UnregisterChannel.


TCL_READCHARS AND TCL_READ                                                     |
       Tcl_ReadChars  consumes  bytes  from  channel,  converting the bytes to |
       UTF-8 based on the channel's encoding(3,n) and storing the produced data  in(1,8) |
       readObjPtr's  string(3,n) representation.  The return value of Tcl_ReadChars |
       is the number of characters, up to charsToRead,  that  were  stored  in(1,8) |
       readObjPtr.   If  an error(8,n) occurs while reading, the return value is -1 |
       and Tcl_ReadChars records a POSIX error(8,n) code that can be retrieved with |
       Tcl_GetErrno.                                                           |

       Setting charsToRead to -1 will cause the command to read(2,n,1 builtins) all characters |
       currently available (non-blocking) or everything  until  eof  (blocking |
       mode).                                                                  |

       The return value may be smaller than the value to read(2,n,1 builtins), indicating that |
       less(1,3) data than requested was available.  This is called a  short  read(2,n,1 builtins). |
       In blocking mode, this can only happen on an end-of-file.  In nonblock- |
       ing mode, a short read(2,n,1 builtins) can also occur if(3,n) there is not enough input cur- |
       rently  available:   Tcl_ReadChars  returns  a  short count rather than |
       waiting for more data.                                                  |

       If the channel is in(1,8) blocking mode, a return value of zero indicates an |
       end-of-file condition.  If the channel is in(1,8) nonblocking mode, a return |
       value of zero indicates either that no input is currently available  or |
       an  end-of-file  condition.   Use  Tcl_Eof and Tcl_InputBlocked to tell |
       which of these conditions actually occurred.                            |

       Tcl_ReadChars translates the various end-of-line  representations  into |
       the  canonical \n internal representation according to the current end- |
       of-line recognition mode.   End-of-line  recognition  and  the  various |
       platform-specific  modes  are described in(1,8) the manual entry for the Tcl |
       fconfigure command.                                                     |

       As a performance optimization, when reading from  a  channel  with  the |
       encoding(3,n) binary, the bytes are not converted to UTF-8 as they are read. |
       Instead, they are stored in(1,8) readObjPtr's internal representation  as  a |
       byte-array  object.  The string(3,n) representation of this object will only |
       be constructed if(3,n) it is needed (e.g., because of  a  call  to  Tcl_Get- |
       StringFromObj).   In  this  way,  byte-oriented data can be read(2,n,1 builtins) from a |
       channel, manipulated by  calling  Tcl_GetByteArrayFromObj  and  related |
       functions,  and  then  written to a channel without the expense of ever |
       converting to or from UTF-8.                                            |

       Tcl_Read is similar to Tcl_ReadChars, except that it doesn't do  encod- |
       ing  conversions,  regardless  of the channel's encoding.  It is depre- |
       cated and exists for backwards compatibility with non-internationalized |
       Tcl  extensions.   It  consumes  bytes  from channel and stores them in(1,8) |
       readBuf, performing end-of-line translations on the  way.   The  return |
       value of Tcl_Read is the number of bytes, up to bytesToRead, written in(1,8) |
       readBuf.  The buffer produced by Tcl_Read is not null-terminated.   Its |
       contents  are  valid  from  the zeroth position up to and excluding the |
       position indicated by the return value.                                 |

       Tcl_ReadRaw is the same as Tcl_Read but does not compensate for  stack- |
       ing.  While  Tcl_Read  (and  the other functions in(1,8) the API) always get |
       their data from the topmost channel in(1,8) the stack the  supplied  channel |
       is part of, Tcl_ReadRaw does not. Thus this function is only usable for |
       transformational channel drivers, i.e. drivers used in(1,8) the middle of  a |
       stack  of channels, to move(3x,7,3x curs_move) data from the channel below into the trans- |
       formation.                                                              |


TCL_GETSOBJ AND TCL_GETS                                                       |
       Tcl_GetsObj consumes bytes from channel, converting the bytes to  UTF-8 |
       based  on  the  channel's encoding(3,n), until a full line of input has been |
       seen.  If the channel's encoding(3,n) is binary, each  byte  read(2,n,1 builtins)  from  the |
       channel  is  treated  as  an  individual Unicode character.  All of the |
       characters of the line except for the terminating  end-of-line  charac- |
       ter(s) are appended to lineObjPtr's string(3,n) representation.  The end-of- |
       line character(s) are read(2,n,1 builtins) and discarded.                               |

       If a line was successfully read(2,n,1 builtins), the return value is  greater  than  or |
       equal  to  zero and indicates the number of bytes stored in(1,8) lineObjPtr. |
       If an error(8,n) occurs, Tcl_GetsObj returns -1 and records  a  POSIX  error(8,n) |
       code that can be retrieved with Tcl_GetErrno.  Tcl_GetsObj also returns |
       -1 if(3,n) the end of the file(1,n) is reached; the Tcl_Eof procedure can be used |
       to distinguish an error(8,n) from an end-of-file condition.                  |

       If  the channel is in(1,8) nonblocking mode, the return value can also be -1 |
       if(3,n) no data was available or the data that was available did not contain |
       an  end-of-line  character.   When -1 is returned, the Tcl_InputBlocked |
       procedure may be invoked to determine if(3,n) the channel is blocked because |
       of input unavailability.                                                |

       Tcl_Gets is the same as Tcl_GetsObj except the resulting characters are |
       appended to the dynamic string(3,n) given by  lineRead  rather  than  a  Tcl |
       object.                                                                 |


TCL_UNGETS                                                                     |
       Tcl_Ungets  is  used  to  add  data to the input queue(1,3) of a channel, at |
       either the head or tail of the queue.  The pointer input points to  the |
       data  that  is to be added.  The length of the input to add is given by |
       inputLen.  A non-zero value of addAtEnd indicates that the data  is  to |
       be added at the end of queue(1,3); otherwise it will be added at the head of |
       the queue.  If channel has a "sticky" EOF set(7,n,1 builtins), no data will be added to |
       the input queue.  Tcl_Ungets returns inputLen or -1 if(3,n) an error(8,n) occurs. |


TCL_WRITECHARS, TCL_WRITEOBJ, AND TCL_WRITE                                    |
       Tcl_WriteChars accepts bytesToWrite bytes of character data at charBuf. |
       The  UTF-8  characters  in(1,8)  the  buffer  are converted to the channel's |
       encoding(3,n) and queued for output to channel.  If  bytesToWrite  is  nega- |
       tive,  Tcl_WriteChars expects charBuf to be null-terminated and it out- |
       puts(3,n) everything up to the null.                                         |

       Data queued for output may not appear on the output device immediately, |
       due to internal buffering.  If the data should appear immediately, call |
       Tcl_Flush after the call  to  Tcl_WriteChars,  or  set(7,n,1 builtins)  the  -buffering |
       option  on the channel to none.  If you wish the data to appear as soon |
       as a complete line is accepted for output, set(7,n,1 builtins) the -buffering option on |
       the channel to line mode.                                               |

       The  return  value  of Tcl_WriteChars is a count of how many bytes were |
       accepted for output to the channel.  This is either greater  than  zero |
       to  indicate  success  or -1 to indicate that an error(8,n) occurred.  If an |
       error(8,n) occurs, Tcl_WriteChars records a POSIX error(8,n)  code  that  may  be |
       retrieved with Tcl_GetErrno.                                            |

       Newline  characters  in(1,8) the output data are translated to platform-spe- |
       cific end-of-line sequences according to the  -translation  option  for |
       the channel.  This is done even if(3,n) the channel has no encoding.         |

       Tcl_WriteObj  is  similar  to  Tcl_WriteChars  except  it accepts a Tcl |
       object whose contents will be output to the channel.  The UTF-8 charac- |
       ters  in(1,8) writeObjPtr's string(3,n) representation are converted to the chan- |
       nel's encoding(3,n) and queued for output  to  channel.   As  a  performance |
       optimization, when writing to a channel with the encoding(3,n) binary, UTF-8 |
       characters are not converted as they are written.  Instead,  the  bytes |
       in(1,8)  writeObjPtr's  internal  representation  as a byte-array object are |
       written to the channel.  The byte-array representation  of  the  object |
       will  be  constructed if(3,n) it is needed.  In this way, byte-oriented data |
       can be read(2,n,1 builtins) from a channel, manipulated by calling Tcl_GetByteArrayFro- |
       mObj  and  related functions, and then written to a channel without the |
       expense of ever converting to or from UTF-8.                            |

       Tcl_Write is similar to Tcl_WriteChars except that it doesn't do encod- |
       ing  conversions,  regardless  of the channel's encoding.  It is depre- |
       cated and exists for backwards compatibility with non-internationalized |
       Tcl  extensions.   It accepts bytesToWrite bytes of data at byteBuf and |
       queues them for  output  to  channel.   If  bytesToWrite  is  negative, |
       Tcl_Write  expects  byteBuf to be null-terminated and it outputs every- |
       thing up to the null.                                                   |

       Tcl_WriteRaw is the same as  Tcl_Write  but  does  not  compensate  for |
       stacking.  While  Tcl_Write (and the other functions in(1,8) the API) always |
       feed their input to the topmost channel in(1,8) the stack the supplied chan- |
       nel  is  part  of,  Tcl_WriteRaw  does  not. Thus this function is only |
       usable for transformational channel drivers, i.e. drivers used  in(1,8)  the |
       middle  of  a  stack  of channels, to move(3x,7,3x curs_move) data from the transformation |
       into the channel below it.


TCL_FLUSH
       Tcl_Flush causes all of the buffered output  data  for  channel  to  be
       written  to  its underlying file(1,n) or device as soon as possible.  If the
       channel is in(1,8) blocking mode, the call does not  return  until  all  the
       buffered data has been sent to the channel or some error(8,n) occurred.  The
       call returns immediately if(3,n) the channel is  nonblocking;  it  starts  a
       background flush(8,n) that will write(1,2) the buffered data to the channel even-
       tually, as fast as the channel is able to absorb it.

       The return value is normally TCL_OK.  If  an  error(8,n)  occurs,  Tcl_Flush
       returns  TCL_ERROR and records a POSIX error(8,n) code that can be retrieved
       with Tcl_GetErrno.


TCL_SEEK
       Tcl_Seek moves the access(2,5) point in(1,8) channel where subsequent  data  will
       be  read(2,n,1 builtins)  or  written.  Buffered  output  is flushed to the channel and
       buffered input is discarded, prior to the seek operation.

       Tcl_Seek normally returns the new access(2,5) point.  If  an  error(8,n)  occurs,
       Tcl_Seek  returns  -1  and  records  a  POSIX  error(8,n)  code  that can be
       retrieved with Tcl_GetErrno.  After an error(8,n), the access(2,5) point  may  or
       may not have been moved.


TCL_TELL
       Tcl_Tell  returns  the current access(2,5) point for a channel. The returned
       value is -1 if(3,n) the channel does not support seeking.


TCL_GETCHANNELOPTION
       Tcl_GetChannelOption retrieves, in(1,8) optionValue, the value of one of the
       options currently in(1,8) effect for a channel, or a list of all options and
       their values.  The channel argument identifies the channel for which to
       query  an  option or retrieve all options and their values.  If option-
       Name is not NULL, it is the name of the option to query;  the  option's
       value  is  copied  to the Tcl dynamic string(3,n) denoted by optionValue. If
       optionName is NULL, the function stores an alternating list  of  option
       names  and  their  values  in(1,8)  optionValue,  using a series of calls to
       Tcl_DStringAppendElement. The various  preexisting  options  and  their
       possible  values are described in(1,8) the manual entry for the Tcl fconfig-
       ure command. Other options can be added by each  channel  type.   These
       channel type specific options are described in(1,8) the manual entry for the
       Tcl command that creates a channel of that type; for example, the addi-
       tional options for TCP based channels are described in(1,8) the manual entry
       for the Tcl socket(2,7,n) command.  The procedure normally returns TCL_OK.  If
       an  error(8,n)  occurs, it returns TCL_ERROR and calls Tcl_SetErrno to store
       an appropriate POSIX error(8,n) code.


TCL_SETCHANNELOPTION
       Tcl_SetChannelOption sets a new value newValue for an option optionName
       on  channel.   The  procedure  normally  returns  TCL_OK.   If an error(8,n)
       occurs, it returns TCL_ERROR;  in(1,8)  addition,  if(3,n)  interp  is  non-NULL,
       Tcl_SetChannelOption  leaves  an  error(8,n)  message  in(1,8)  the interpreter's
       result.


TCL_EOF
       Tcl_Eof returns a nonzero value if(3,n) channel encountered an end  of  file(1,n)
       during the last input operation.


TCL_INPUTBLOCKED
       Tcl_InputBlocked  returns  a nonzero value if(3,n) channel is in(1,8) nonblocking
       mode and the last input operation returned  less(1,3)  data  than  requested
       because there was insufficient data available.  The call always returns
       zero if(3,n) the channel is in(1,8) blocking mode.


TCL_INPUTBUFFERED
       Tcl_InputBuffered returns  the  number  of  bytes  of  input  currently
       buffered  in(1,8)  the internal buffers for a channel. If the channel is not
       open(2,3,n) for reading, this function always returns zero.


TCL_OUTPUTBUFFERED
       Tcl_OutputBuffered returns the number  of  bytes  of  output  currently |
       buffered  in(1,8)  the internal buffers for a channel. If the channel is not |
       open(2,3,n) for writing, this function always returns zero.


PLATFORM ISSUES
       The handles returned from Tcl_GetChannelHandle depend on  the  platform
       and  the  channel type.  On Unix platforms, the handle is always a Unix
       file(1,n) descriptor as returned from the  open(2,3,n)  system  call.   On  Windows
       platforms,  the  handle  is  a file(1,n) HANDLE when the channel was created
       with Tcl_OpenFileChannel, Tcl_OpenCommandChannel, or  Tcl_MakeFileChan-
       nel.  Other channel types may return a different type of handle on Win-
       dows platforms.  On the Macintosh platform, the handle is a file(1,n) refer-
       ence number as returned from HOpenDF.


SEE ALSO
       DString(3), fconfigure(n), filename(n), fopen(3), Tcl_CreateChannel(3)


KEYWORDS
       access(2,5)  point,  blocking, buffered I/O, channel, channel driver, end of
       file(1,n), flush(8,n), input, nonblocking, output, read(2,n,1 builtins), seek, write(1,2)



Tcl                                   8.3               Tcl_OpenFileChannel(3)

References for this manual (incoming links)