Manual Pages for UNIX Darwin command on man Tcl_Close
MyWebUniversity

Manual Pages for UNIX Darwin command on man Tcl_Close

TclOpenFileChannel(3) Tcl Library Procedures TclOpenFileChannel(3)

NAME

TclOpenFileChannel, TclOpenCommandChannel, TclMakeFileChannel,

TclGetChannel, TclGetChannelNames, TclGetChannelNamesEx, TclRegis-

terChannel, TclUnregisterChannel, TclDetachChannel, TclIsStandard-

Channel, TclClose, TclReadChars, TclRead, TclGetsObj, TclGets, TclWriteObj, TclWriteChars, TclWrite, TclFlush, TclSeek, TclTell, TclGetChannelOption, TclSetChannelOption, TclEof, TclInputBlocked, TclInputBuffered, TclOutputBuffered, TclUngets, TclReadRaw,

TclWriteRaw - buffered I/O facilities using channels

SYNOPSIS

##iinncclluuddee <>

TclChannel TTccllOOppeennFFiilleeCChhaannnneell(interp, fileName, mode, permissions) TclChannel TTccllOOppeennCCoommmmaannddCChhaannnneell(interp, argc, argv, flags) TclChannel TTccllMMaakkeeFFiilleeCChhaannnneell(handle, readOrWrite) TclChannel TTccllGGeettCChhaannnneell(interp, channelName, modePtr) int | TTccllGGeettCChhaannnneellNNaammeess(interp) | int | TTccllGGeettCChhaannnneellNNaammeessEExx(interp, pattern) | void TTccllRReeggiisstteerrCChhaannnneell(interp, channel) int TTccllUUnnrreeggiisstteerrCChhaannnneell(interp, channel) int TTccllDDeettaacchhCChhaannnneell(interp, channel) int TTccllIIssSSttaannddaarrddCChhaannnneell(channel) int TTccllCClloossee(interp, channel) int | TTccllRReeaaddCChhaarrss(channel, readObjPtr, charsToRead, appendFlag) | int | TTccllRReeaadd(channel, readBuf, bytesToRead) | int | TTccllGGeettssOObbjj(channel, lineObjPtr) | int | TTccllGGeettss(channel, lineRead) | int | TTccllUUnnggeettss(channel, input, inputLen, addAtEnd) | int | TTccllWWrriitteeOObbjj(channel, writeObjPtr) | int | TTccllWWrriitteeCChhaarrss(channel, charBuf, bytesToWrite) | int | TTccllWWrriittee(channel, byteBuf, bytesToWrite) | int | TTccllRReeaaddRRaaww(channel, readBuf, bytesToRead) | int | TTccllWWrriitteeRRaaww(channel, byteBuf, bytesToWrite) | int TTccllEEooff(channel) int TTccllFFlluusshh(channel) int TTccllIInnppuuttBBlloocckkeedd(channel) int TTccllIInnppuuttBBuuffffeerreedd(channel) int | TTccllOOuuttppuuttBBuuffffeerreedd(channel) | TclWideInt | TTccllSSeeeekk(channel, offset, seekMode) | TclWideInt | TTccllTTeellll(channel) | int TclGetChannelOptionitr, hne, pinae otoVle int TclSetChannelOptionitr, hne, pinae nwau) AARRGGUUMMEENNTTSS TclInterp *interp (in) Used for error reporting and to look up a channel registered in it. CONST char *fileName (in) The name of a local or network file. CONST char *mode (in) Specifies how the file is to be accessed. May have any of the values allowed for the mode argument to the Tcl ooppeenn command.

int permissions (in) POSIX-style permission

flags such as 0644. If a new file is created, these permissions will be set on the created file. int argc (in) The number of elements in argv.

CONST char **argv (in) Arguments for construct-

ing a command pipeline. These values have the

same meaning as the non-

switch arguments to the Tcl eexxeecc command.

int flags (in) Specifies the disposi-

tion of the stdio han-

dles in pipeline: OR-ed

combination of TTCCLLSSTTDDIINN, TTCCLLSSTTDDOOUUTT, TTCCLLSSTTDDEERRRR, and TTCCLLEENNFFOORRCCEEMMOODDEE. If TTCCLLSSTTDDIINN is set, stdin for the first child in the pipe is the pipe channel, otherwise it is the same as the standard input of the invoking process; likewise for TTCCLLSSTTDDOOUUTT and TTCCLLSSTTDDEERRRR. If TTCCLLEENNFFOORRCCEEMMOODDEE is not set, then the pipe can redirect stdio handles to override the stdio handles for which TTCCLLSSTTDDIINN, TTCCLLSSTTDDOOUUTT and TTCCLLSSTTDDEERRRR have been set. If it is set, then such redirections cause an error.

ClientData handle (in) Operating system spe-

cific handle for I/O to a file. For Unix this is a file descriptor, for Windows it is a HANDLE.

int readOrWrite (in) OR-ed combination of

TTCCLLRREEAADDAABBLLEE and TTCCLLWWRRIITTAABBLLEE to indicate what operations are valid on handle. CONST char *channelName (in) The name of the channel. int *modePtr (out) Points at an integer variable that will

receive an OR-ed combi-

nation of TTCCLLRREEAADDAABBLLEE

and TTCCLLWWRRIITTAABBLLEE denot-

ing whether the channel is open for reading and writing. |

CONST char *pat- |

tern (in) | | The pattern to match on, |

passed to TclString- |

Match, or NULL. TclChannel channel (in) A Tcl channel for input or output. Must have been the return value from a procedure such as TTccllOOppeennFFiilleeCChhaannnneell.

TclObj *readOb- |

jPtr (in/out) | | A pointer to a Tcl | Object in which to store | the characters read from | the channel. |

int char- |

sToRead (in) | | The number of characters |

to read from the chan- |

nel. If the channel's | encoding is bbiinnaarryy, this | is equivalent to the | number of bytes to read | from the channel. |

int append- |

Flag (in) | |

If non-zero, data read |

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 which to | store the bytes read | from the channel. |

int byte- |

sToRead (in) | | The number of bytes to | read from the channel. | The buffer readBuf must | be large enough to hold | this many bytes. |

TclObj *lineOb- |

jPtr (in/out) | | A pointer to a Tcl | object in which to store | the line read from the | channel. The line read | will be appended to the | current value of the | object. | TclDString *lineRead (in/out) || A pointer to a Tcl | dynamic string in which | to store the line read | from the channel. Must | have been initialized by | the caller. The line | read will be appended to | any data already in the | dynamic string. | CONST | char *input (in) | | The input to add to a | channel buffer. | int inputLen (in) || Length of the input |

int addA- |

tEnd (in) | | Flag indicating whether | the input should be | added to the end or | beginning of the channel | buffer. TclObj *writeObjPtr (in) A pointer to a Tcl Object whose contents will be output to the channel. CONST char *charBuf (in) A buffer containing the characters to output to the channel. CONST char *byteBuf (in) A buffer containing the bytes to output to the channel. int bytesToWrite (in) The number of bytes to consume from charBuf or byteBuf and output to the channel. TclWideInt offset (in) How far to move the access point in the channel at which the next input or output operation will be applied, measured in bytes from the position given by seekMode. May be either positive or negative. int seekMode (in) Relative to which point

to seek; used with off-

set to calculate the new access point for the channel. Legal values are SSEEEEKKSSEETT, SSEEEEKKCCUURR, and SSEEEEKKEENNDD. CONST char *optionName (in) The name of an option

applicable to this chan-

nel, such as -bblloocckkiinngg.

May have any of the val-

ues accepted by the ffccoonnffiigguurree command. TclDString *optionValue (in) 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) 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, socket, 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 the manual entry for TTccllCCrreeaatteeCChhaannnneell. 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 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 TTccllCCrreeaatteeCChhaannnneell. TTCCLLOOPPEENNFFIILLEECCHHAANNNNEELL TTccllOOppeennFFiilleeCChhaannnneell opens a file 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 ffooppeenn procedure of the Unix stan-

dard I/O library. The syntax and meaning of all arguments is similar to those given in the Tcl ooppeenn command when opening a file. If an error occurs while opening the channel, TTccllOOppeennFFiilleeCChhaannnneell returns NULL and records a POSIX error code that can be retrieved with

TTccllGGeettEErrrrnnoo. In addition, if interp is non-NULL, TTccllOOppeennFFiilleeCChhaannnneell

leaves an error message in interp's result after any error. As of Tcl

8.4, the object-based API TTccllFFSSOOppeennFFiilleeCChhaannnneell should be used in pref-

erence to TTccllOOppeennFFiilleeCChhaannnneell wherever possible.

The newly created channel is not registered in the supplied inter-

preter; to register it, use TTccllRReeggiisstteerrCChhaannnneell, described below. If one of the standard channels, ssttddiinn,, ssttddoouutt or ssttddeerrrr was previously closed, the act of creating the new channel also assigns it as a replacement for the standard channel. TTCCLLOOPPEENNCCOOMMMMAANNDDCCHHAANNNNEELL

TTccllOOppeennCCoommmmaannddCChhaannnneell provides a C-level interface to the functions of

the eexxeecc and ooppeenn 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 of communication will exist with the command pipe-

line.

If the TTCCLLSSTTDDIINN flag is set 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 TTCCLLSSTTDDIINN is not set, then standard input for the first subprocess will be the same as this application's standard input. If TTCCLLSSTTDDOOUUTT is set then standard output from the last subprocess can be read from the channel; otherwise it goes to this application's standard output. If TTCCLLSSTTDDEERRRR is set, standard error output for all subprocesses is returned to the channel and results in

an error when the channel is closed; otherwise it goes to this applica-

tion's standard error. If TTCCLLEENNFFOORRCCEEMMOODDEE is not set, then argc and argv can redirect the stdio handles to override TTCCLLSSTTDDIINN, TTCCLLSSTTDDOOUUTT, and TTCCLLSSTTDDEERRRR; if it is set, then it is an error for argc and argv to override stdio channels for which TTCCLLSSTTDDIINN, TTCCLLSSTTDDOOUUTT, and TTCCLLSSTTDDEERRRR have been set. If an error occurs while opening the channel, TTccllOOppeennCCoommmmaannddCChhaannnneell returns NULL and records a POSIX error code that can be retrieved with

TTccllGGeettEErrrrnnoo. In addition, TTccllOOppeennCCoommmmaannddCChhaannnneell leaves an error mes-

sage in the interpreter's result if interp is not NULL.

The newly created channel is not registered in the supplied inter-

preter; to register it, use TTccllRReeggiisstteerrCChhaannnneell, described below. If one of the standard channels, ssttddiinn,, ssttddoouutt or ssttddeerrrr was previously closed, the act of creating the new channel also assigns it as a replacement for the standard channel. TTCCLLMMAAKKEEFFIILLEECCHHAANNNNEELL

TTccllMMaakkeeFFiilleeCChhaannnneell makes a TTccllCChhaannnneell from an existing, platform-spe-

cific, file handle. The newly created channel is not registered in the supplied interpreter; to register it, use TTccllRReeggiisstteerrCChhaannnneell, described below. If one of the standard channels, ssttddiinn,, ssttddoouutt or ssttddeerrrr was previously closed, the act of creating the new channel also assigns it as a replacement for the standard channel. TTCCLLGGEETTCCHHAANNNNEELL TTccllGGeettCChhaannnneell returns a channel given the channelName used to create it with TTccllCCrreeaatteeCChhaannnneell and a pointer to a Tcl interpreter in interp. If a channel by that name is not registered in 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

TTCCLLRREEAADDAABBLLEE and TTCCLLWWRRIITTAABBLLEE describing whether the channel is open for reading and writing. TTccllGGeettCChhaannnneellNNaammeess and TTccllGGeettCChhaannnneellNNaammeessEExx write the names of the registered channels to the interpreter's result as a list object. TTccllGGeettCChhaannnneellNNaammeessEExx will filter these names according to the pattern. If pattern is NULL, then it will not do any filtering. The return value is TTCCLLOOKK if no errors occurred writing to the result, otherwise it is TTCCLLEERRRROORR, and the error message is left in the interpreter's result. TTCCLLRREEGGIISSTTEERRCCHHAANNNNEELL TTccllRReeggiisstteerrCChhaannnneell adds a channel to the set of channels accessible in interp. After this call, Tcl programs executing in that interpreter can refer to the channel in input or output operations using the name given in the call to TTccllCCrreeaatteeCChhaannnneell. After this call, the channel becomes the property of the interpreter, and the caller should not call TTccllCClloossee 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 TTccllRReeggiisstteerr-

CChhaannnneell with interp as NULL, to indicate that it wishes to hold a ref-

erence to this channel. Subsequently, the channel can be registered in a Tcl interpreter and it will only be closed when the matching number of calls to TTccllUUnnrreeggiisstteerrCChhaannnneell have been made. This allows code executing outside of any interpreter to safely hold a reference to a channel that is also registered in a Tcl interpreter. This procedure interacts with the code managing the standard channels. If no standard channels were initialized before the first call to TTccllRReeggiisstteerrCChhaannnneell they will get initialized by that call. See TTccllSSttaannddaarrddCChhaannnneellss for a general treatise about standard channels and the behaviour of the Tcl library with regard to them. TTCCLLUUNNRREEGGIISSTTEERRCCHHAANNNNEELL

TTccllUUnnrreeggiisstteerrCChhaannnneell removes a channel from the set of channels acces-

sible in interp. After this call, Tcl programs will no longer be able to use the channel's name to refer to the channel in that interpreter. If this operation removed the last registration of the channel in any interpreter, the channel is also closed and destroyed.

Code not associated with a Tcl interpreter can call TTccllUUnnrreeggiisstteerrCChhaann-

nneell 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. TTccllUUnnrreeggiisstteerrCChhaannnneell is very similar to

TTccllDDeettaacchhCChhaannnneell except that it will also close the channel if no fur-

ther references to it exist. TTCCLLDDEETTAACCHHCCHHAANNNNEELL TTccllDDeettaacchhCChhaannnneell removes a channel from the set of channels accessible in interp. After this call, Tcl programs will no longer be able to use the channel's name to refer to the channel in that interpreter. Beyond that, this command has no further effect. It cannot be used on the

standard channels (stdout, stderr, stdin), and will return TCLERROR if

passed one of those channels. Code not associated with a Tcl interpreter can call TTccllDDeettaacchhCChhaannnneell

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 TTccllUUnnrreeggiisstteerrCChhaannnneell, it will not be closed. TTCCLLIISSSSTTAANNDDAARRDDCCHHAANNNNEELL

TTccllIIssSSttaannddaarrddCChhaannnneell 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. TTCCLLCCLLOOSSEE TTccllCClloossee destroys the channel channel, which must denote a currently open channel. The channel should not be registered in any interpreter when TTccllCClloossee 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 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, TTccllCClloossee returns TTCCLLOOKK. If an error occurs, TTccllCClloossee returns TTCCLLEERRRROORR and records a POSIX error code that can be retrieved with TTccllGGeettEErrrrnnoo. If the channel is being closed synchronously and an error occurs during closing of the channel and interp is not NULL, an error message is left in the interpreter's result.

Note: it is not safe to call TTccllCClloossee on a channel that has been reg-

istered using TTccllRReeggiisstteerrCChhaannnneell; see the documentation for TTccllRReeggiiss-

tteerrCChhaannnneell, above, for details. If the channel has ever been given as the cchhaann argument in a call to TTccllRReeggiisstteerrCChhaannnneell, you should instead use TTccllUUnnrreeggiisstteerrCChhaannnneell, which will internally call TTccllCClloossee when all calls to TTccllRReeggiisstteerrCChhaannnneell have been matched by corresponding calls to TTccllUUnnrreeggiisstteerrCChhaannnneell. TTCCLLRREEAADDCCHHAARRSS AANNDD TTCCLLRREEAADD | TTccllRReeaaddCChhaarrss consumes bytes from channel, converting the bytes to |

UTF-8 based on the channel's encoding and storing the produced data in |

readObjPtr's string representation. The return value of TTccllRReeaaddCChhaarrss | is the number of characters, up to charsToRead, that were stored in |

readObjPtr. If an error occurs while reading, the return value is -1 |

and TTccllRReeaaddCChhaarrss records a POSIX error code that can be retrieved with | TTccllGGeettEErrrrnnoo. |

Setting charsToRead to -11 will cause the command to read all characters |

currently available (non-blocking) or everything until eof (blocking |

mode). | The return value may be smaller than the value to read, indicating that | less data than requested was available. This is called a short read. |

In blocking mode, this can only happen on an end-of-file. In nonblock- |

ing mode, a short read can also occur if there is not enough input cur- |

rently available: TTccllRReeaaddCChhaarrss returns a short count rather than | waiting for more data. | If the channel is in blocking mode, a return value of zero indicates an |

end-of-file condition. If the channel is in nonblocking mode, a return |

value of zero indicates either that no input is currently available or |

an end-of-file condition. Use TTccllEEooff and TTccllIInnppuuttBBlloocckkeedd to tell |

which of these conditions actually occurred. |

TTccllRReeaaddCChhaarrss translates the various end-of-line representations into |

the canonical \\nn internal representation according to the current end- |

of-line recognition mode. End-of-line recognition and the various |

platform-specific modes are described in the manual entry for the Tcl |

ffccoonnffiigguurree command. | As a performance optimization, when reading from a channel with the |

encoding bbiinnaarryy, the bytes are not converted to UTF-8 as they are read. |

Instead, they are stored in readObjPtr's internal representation as a |

byte-array object. The string representation of this object will only |

be constructed if it is needed (e.g., because of a call to TTccllGGeett- |

SSttrriinnggFFrroommOObbjj). In this way, byte-oriented data can be read from a |

channel, manipulated by calling TTccllGGeettBByytteeAArrrraayyFFrroommOObbjj and related | functions, and then written to a channel without the expense of ever |

converting to or from UTF-8. |

TTccllRReeaadd is similar to TTccllRReeaaddCChhaarrss, 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 |

readBuf, performing end-of-line translations on the way. The return |

value of TTccllRReeaadd is the number of bytes, up to bytesToRead, written in |

readBuf. The buffer produced by TTccllRReeaadd is not null-terminated. Its |

contents are valid from the zeroth position up to and excluding the | position indicated by the return value. |

TTccllRReeaaddRRaaww is the same as TTccllRReeaadd but does not compensate for stack- |

ing. While TTccllRReeaadd (and the other functions in the API) always get | their data from the topmost channel in the stack the supplied channel | is part of, TTccllRReeaaddRRaaww does not. Thus this function is oonnllyy usable for | transformational channel drivers, i.e. drivers used in the middle of a |

stack of channels, to move data from the channel below into the trans- |

formation. | TTCCLLGGEETTSSOOBBJJ AANNDD TTCCLLGGEETTSS |

TTccllGGeettssOObbjj consumes bytes from channel, converting the bytes to UTF-8 |

based on the channel's encoding, until a full line of input has been | seen. If the channel's encoding is bbiinnaarryy, each byte read 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 representation. The end-of- |

line character(s) are read and discarded. | If a line was successfully read, the return value is greater than or | equal to zero and indicates the number of bytes stored in lineObjPtr. |

If an error occurs, TTccllGGeettssOObbjj returns -1 and records a POSIX error |

code that can be retrieved with TTccllGGeettEErrrrnnoo. TTccllGGeettssOObbjj also returns |

-1 if the end of the file is reached; the TTccllEEooff procedure can be used |

to distinguish an error from an end-of-file condition. |

If the channel is in nonblocking mode, the return value can also be -1 |

if no data was available or the data that was available did not contain |

an end-of-line character. When -1 is returned, the TTccllIInnppuuttBBlloocckkeedd |

procedure may be invoked to determine if the channel is blocked because | of input unavailability. | TTccllGGeettss is the same as TTccllGGeettssOObbjj except the resulting characters are | appended to the dynamic string given by lineRead rather than a Tcl | object. | TTCCLLUUNNGGEETTSS | TTccllUUnnggeettss is used to add data to the input queue 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; otherwise it will be added at the head of | the queue. If channel has a "sticky" EOF set, no data will be added to |

the input queue. TTccllUUnnggeettss returns inputLen or -1 if an error occurs. |

TTCCLLWWRRIITTEECCHHAARRSS,, TTCCLLWWRRIITTEEOOBBJJ,, AANNDD TTCCLLWWRRIITTEE | TTccllWWrriitteeCChhaarrss accepts bytesToWrite bytes of character data at charBuf. |

The UTF-8 characters in the buffer are converted to the channel's |

encoding and queued for output to channel. If bytesToWrite is nega- |

tive, TTccllWWrriitteeCChhaarrss expects charBuf to be null-terminated and it out- |

puts 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 |

TTccllFFlluusshh after the call to TTccllWWrriitteeCChhaarrss, or set the -bbuuffffeerriinngg |

option on the channel to nnoonnee. If you wish the data to appear as soon |

as a complete line is accepted for output, set the -bbuuffffeerriinngg option on |

the channel to lliinnee mode. | The return value of TTccllWWrriitteeCChhaarrss 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 occurred. If an |

error occurs, TTccllWWrriitteeCChhaarrss records a POSIX error code that may be | retrieved with TTccllGGeettEErrrrnnoo. |

Newline characters in the output data are translated to platform-spe- |

cific end-of-line sequences according to the -ttrraannssllaattiioonn option for |

the channel. This is done even if the channel has no encoding. | TTccllWWrriitteeOObbjj is similar to TTccllWWrriitteeCChhaarrss except it accepts a Tcl |

object whose contents will be output to the channel. The UTF-8 charac- |

ters in writeObjPtr's string representation are converted to the chan- |

nel's encoding and queued for output to channel. As a performance |

optimization, when writing to a channel with the encoding bbiinnaarryy, UTF-8 |

characters are not converted as they are written. Instead, the bytes |

in 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 it is needed. In this way, byte-oriented data |

can be read from a channel, manipulated by calling TTccllGGeettBByytteeAArrrraayyFFrroo- |

mmOObbjj and related functions, and then written to a channel without the |

expense of ever converting to or from UTF-8. |

TTccllWWrriittee is similar to TTccllWWrriitteeCChhaarrss 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, |

TTccllWWrriittee expects byteBuf to be null-terminated and it outputs every- |

thing up to the null. | TTccllWWrriitteeRRaaww is the same as TTccllWWrriittee but does not compensate for | stacking. While TTccllWWrriittee (and the other functions in the API) always |

feed their input to the topmost channel in the stack the supplied chan- |

nel is part of, TTccllWWrriitteeRRaaww does not. Thus this function is oonnllyy | usable for transformational channel drivers, i.e. drivers used in the | middle of a stack of channels, to move data from the transformation | into the channel below it. TTCCLLFFLLUUSSHH TTccllFFlluusshh causes all of the buffered output data for channel to be written to its underlying file or device as soon as possible. If the channel is in blocking mode, the call does not return until all the buffered data has been sent to the channel or some error occurred. The call returns immediately if the channel is nonblocking; it starts a

background flush that will write the buffered data to the channel even-

tually, as fast as the channel is able to absorb it. The return value is normally TTCCLLOOKK. If an error occurs, TTccllFFlluusshh returns TTCCLLEERRRROORR and records a POSIX error code that can be retrieved with TTccllGGeettEErrrrnnoo. TTCCLLSSEEEEKK TTccllSSeeeekk moves the access point in channel where subsequent data will be read or written. Buffered output is flushed to the channel and buffered input is discarded, prior to the seek operation. TTccllSSeeeekk normally returns the new access point. If an error occurs,

TTccllSSeeeekk returns -1 and records a POSIX error code that can be

retrieved with TTccllGGeettEErrrrnnoo. After an error, the access point may or may not have been moved. TTCCLLTTEELLLL TTccllTTeellll returns the current access point for a channel. The returned

value is -1 if the channel does not support seeking.

TTCCLLGGEETTCCHHAANNNNEELLOOPPTTIIOONN TclGetChannelOption eree, n pinau, h vle f n o te options currently in 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 denoted by optionValue. If optionName is NULL, the function stores an alternating list of option names and their values in optionValue, using a series of calls to TTccllDDSSttrriinnggAAppppeennddEElleemmeenntt. The various preexisting options and their

possible values are described in the manual entry for the Tcl ffccoonnffiigg-

uurree command. Other options can be added by each channel type. These channel type specific options are described in 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 the manual entry for the Tcl ssoocckkeett command. The procedure normally returns TTCCLLOOKK. If an error occurs, it returns TTCCLLEERRRROORR and calls TTccllSSeettEErrrrnnoo to store an appropriate POSIX error code. TTCCLLSSEETTCCHHAANNNNEELLOOPPTTIIOONN TclSetChannelOption es nw au nwau fr n pin pinae on channel. The procedure normally returns TTCCLLOOKK. If an error

occurs, it returns TTCCLLEERRRROORR; in addition, if interp is non-NULL,

TclSetChannelOption evs n ro msae n h itrrtrs result. TTCCLLEEOOFF TTccllEEooff returns a nonzero value if channel encountered an end of file during the last input operation. TTCCLLIINNPPUUTTBBLLOOCCKKEEDD TTccllIInnppuuttBBlloocckkeedd returns a nonzero value if channel is in nonblocking mode and the last input operation returned less data than requested because there was insufficient data available. The call always returns zero if the channel is in blocking mode. TTCCLLIINNPPUUTTBBUUFFFFEERREEDD TTccllIInnppuuttBBuuffffeerreedd returns the number of bytes of input currently buffered in the internal buffers for a channel. If the channel is not open for reading, this function always returns zero. TTCCLLOOUUTTPPUUTTBBUUFFFFEERREEDD TTccllOOuuttppuuttBBuuffffeerreedd returns the number of bytes of output currently | buffered in the internal buffers for a channel. If the channel is not | open for writing, this function always returns zero. PPLLAATTFFOORRMM IISSSSUUEESS The handles returned from TTccllGGeettCChhaannnneellHHaannddllee depend on the platform and the channel type. On Unix platforms, the handle is always a Unix file descriptor as returned from the ooppeenn system call. On Windows platforms, the handle is a file HHAANNDDLLEE when the channel was created

with TTccllOOppeennFFiilleeCChhaannnneell, TTccllOOppeennCCoommmmaannddCChhaannnneell, or TTccllMMaakkeeFFiilleeCChhaann-

nneell. Other channel types may return a different type of handle on Win-

dows platforms. On the Macintosh platform, the handle is a file refer-

ence number as returned from HHOOppeennDDFF.

SEE ALSO

DString(3), fconfigure(n), filename(n), fopen(3), TclCreateChannel(3) KKEEYYWWOORRDDSS access point, blocking, buffered I/O, channel, channel driver, end of file, flush, input, nonblocking, output, read, seek, write Tcl 8.3 TclOpenFileChannel(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™