📄 openfilechnl.3
字号:
'\"'\" Copyright (c) 1996-1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\"'\" SCCS: @(#) OpenFileChnl.3 1.40 97/09/29 11:22:49.so man.macros.TH Tcl_OpenFileChannel 3 8.0 Tcl "Tcl Library Procedures".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMETcl_OpenFileChannel, Tcl_OpenCommandChannel, Tcl_MakeFileChannel, Tcl_GetChannel, Tcl_RegisterChannel, Tcl_UnregisterChannel, Tcl_Close, Tcl_Read, Tcl_Gets, Tcl_Write, Tcl_Flush, Tcl_Seek, Tcl_Tell, Tcl_Eof, Tcl_InputBlocked, Tcl_InputBuffered, Tcl_GetChannelOption, Tcl_SetChannelOption \- buffered I/O facilities using channels.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.sptypedef ... Tcl_Channel;.spTcl_Channel\fBTcl_OpenFileChannel\fR(\fIinterp, fileName, mode, permissions\fR).spTcl_Channel\fBTcl_OpenCommandChannel\fR(\fIinterp, argc, argv, flags\fR).VS.spTcl_Channel\fBTcl_MakeFileChannel\fR(\fIhandle, readOrWrite\fR).VE.spTcl_Channel\fBTcl_GetChannel\fR(\fIinterp, channelName, modePtr\fR).spvoid\fBTcl_RegisterChannel\fR(\fIinterp, channel\fR).spint\fBTcl_UnregisterChannel\fR(\fIinterp, channel\fR).spint\fBTcl_Close\fR(\fIinterp, channel\fR).spint\fBTcl_Read\fR(\fIchannel, buf, toRead\fR).spint\fBTcl_Gets\fR(\fIchannel, lineRead\fR).spint\fBTcl_GetsObj\fR(\fIchannel, lineObjPtr\fR).spint\fBTcl_Write\fR(\fIchannel, buf, toWrite\fR).spint\fBTcl_Flush\fR(\fIchannel\fR).spint\fBTcl_Seek\fR(\fIchannel, offset, seekMode\fR).spint\fBTcl_Tell\fR(\fIchannel\fR).spint\fBTcl_GetChannelOption\fR(\fIinterp, channel, optionName, optionValue\fR).spint\fBTcl_SetChannelOption\fR(\fIinterp, channel, optionName, newValue\fR).spint\fBTcl_Eof\fR(\fIchannel\fR).spint\fBTcl_InputBlocked\fR(\fIchannel\fR).spint\fBTcl_InputBuffered\fR(\fIchannel\fR).sp.SH ARGUMENTS.AS Tcl_ChannelType newClientProcPtr in.AP Tcl_Interp *interp inUsed for error reporting and to look up a channel registered in it..AP char *fileName inThe name of a local or network file..AP char *mode inSpecifies how the file is to be accessed. May have any of thevalues allowed for the \fImode\fR argument to the Tcl\fBopen\fR command.For \fBTcl_OpenCommandChannel\fR, may be NULL..AP int permissions inPOSIX-style permission flags such as 0644.If a new file is created, these permissions will be set on thecreated file..AP int argc inThe number of elements in \fIargv\fR..AP char **argv inArguments for constructing a command pipeline.These values have the same meaning as the non-switch argumentsto the Tcl \fBexec\fR command..AP int flags inSpecifies the disposition of the stdio handles in pipeline: OR-edcombination of \fBTCL_STDIN\fR, \fBTCL_STDOUT\fR, \fBTCL_STDERR\fR,and \fBTCL_ENFORCE_MODE\fR. If \fBTCL_STDIN\fR is set, stdin forthe first child in the pipe is the pipe channel, otherwise it is the sameas the standard input of the invoking process; likewise for\fBTCL_STDOUT\fR and \fBTCL_STDERR\fR. If \fBTCL_ENFORCE_MODE\fR is not set,then the pipe can redirect stdio handles to override the stdio handles forwhich \fBTCL_STDIN\fR, \fBTCL_STDOUT\fR and \fBTCL_STDERR\fR have been set.If it is set, then such redirections cause an error..VS.AP ClientData handle inOperating system specific handle for I/O to a file. For Unix this is afile descriptor, for Windows it is a HANDLE..AP int readOrWrite inOR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicatewhat operations are valid on \fIhandle\fR..VE.AP int *modePtr outPoints at an integer variable that will receive an OR-ed combination of\fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR denoting whether the channel isopen for reading and writing..AP Tcl_Channel channel inA Tcl channel for input or output. Must have been the return valuefrom a procedure such as \fBTcl_OpenFileChannel\fR..AP char *buf inAn array of bytes in which to store channel input, or from whichto read channel output..AP int len inThe length of the input or output..AP int atEnd inIf nonzero, store the input at the end of the input queue, otherwise storeit at the head of the input queue..AP int toRead inThe number of bytes to read from the channel..AP Tcl_DString *lineRead inA pointer to a Tcl dynamic string in which to store the line read from thechannel. Must have been initialized by the caller. The line readwill be appended to any data already in the dynamic string..AP Tcl_Obj *linePtrObj inA pointer to a Tcl object in which to store the line read from thechannel. The line read will be appended to the current value of theobject. .AP int toWrite inThe number of bytes to read from \fIbuf\fR and output to the channel..AP int offset inHow far to move the access point in the channel at which the next input oroutput operation will be applied, measured in bytes from the positiongiven by \fIseekMode\fR. May be either positive or negative..AP int seekMode inRelative to which point to seek; used with \fIoffset\fR to calculate the newaccess point for the channel. Legal values are \fBSEEK_SET\fR,\fBSEEK_CUR\fR, and \fBSEEK_END\fR..AP char *optionName inThe name of an option applicable to this channel, such as \fB\-blocking\fR.May have any of the values accepted by the \fBfconfigure\fR command..AP Tcl_DString *optionValue inWhere to store the value of an option or a list of all options and theirvalues. Must have been initialized by the caller..AP char *newValue inNew value for the option given by \fIoptionName\fR..BE.SH DESCRIPTION.PPThe Tcl channel mechanism provides a device-independent andplatform-independent mechanism for performing buffered inputand output operations on a variety of file, socket, and devicetypes.The channel mechanism is extensible to new channel types, byproviding a low level channel driver for the new type; the channel driverinterface is described in the manual entry for \fBTcl_CreateChannel\fR. Thechannel mechanism provides a buffering scheme modelled afterUnix's standard I/O, and it also allows for nonblocking I/O onchannels..PPThe procedures described in this manual entry comprise the C APIs of thegeneric layer of the channel architecture. For a description of the channeldriver architecture and how to implement channel drivers for new types ofchannels, see the manual entry for \fBTcl_CreateChannel\fR..SH TCL_OPENFILECHANNEL.PP\fBTcl_OpenFileChannel\fR opens a file specified by \fIfileName\fR andreturns a channel handle that can be used to perform input and output onthe file. This API is modelled after the \fBfopen\fR procedure ofthe Unix standard I/O library.The syntax and meaning of all arguments is similar to thosegiven in the Tcl \fBopen\fR command when opening a file.If an error occurs while opening the channel, \fBTcl_OpenFileChannel\fRreturns NULL and records a POSIX error code that can beretrieved with \fBTcl_GetErrno\fR.In addition, if \fIinterp\fR is non-NULL, \fBTcl_OpenFileChannel\fRleaves an error message in \fIinterp->result\fR after any error..PPThe newly created channel is not registered in the supplied interpreter; toregister it, use \fBTcl_RegisterChannel\fR, described below.If one of the standard channels, \fBstdin, stdout\fR or \fBstderr\fR waspreviously closed, the act of creating the new channel also assigns it as areplacement for the standard channel..SH TCL_OPENCOMMANDCHANNEL.PP\fBTcl_OpenCommandChannel\fR provides a C-level interface to thefunctions of the \fBexec\fR and \fBopen\fR commands.It creates a sequence of subprocesses specifiedby the \fIargv\fR and \fIargc\fR arguments and returns a channel that canbe used to communicate with these subprocesses.The \fIflags\fR argument indicates what sort of communication willexist with the command pipeline..PPIf the \fBTCL_STDIN\fR flag is set then the standard input for thefirst subprocess will be tied to the channel: writing to the channelwill provide input to the subprocess. If \fBTCL_STDIN\fR is not set,then standard input for the first subprocess will be the same as thisapplication's standard input. If \fBTCL_STDOUT\fR is set thenstandard output from the last subprocess can be read from the channel;otherwise it goes to this application's standard output. If\fBTCL_STDERR\fR is set, standard error output for all subprocesses isreturned to the channel and results in an error when the channel isclosed; otherwise it goes to this application's standard error. If\fBTCL_ENFORCE_MODE\fR is not set, then \fIargc\fR and \fIargv\fR canredirect the stdio handles to override \fBTCL_STDIN\fR,\fBTCL_STDOUT\fR, and \fBTCL_STDERR\fR; if it is set, then it is anerror for argc and argv to override stdio channels for which\fBTCL_STDIN\fR, \fBTCL_STDOUT\fR, and \fBTCL_STDERR\fR have been set..PPIf an error occurs while opening the channel, \fBTcl_OpenCommandChannel\fRreturns NULL and records a POSIX error code that can be retrieved with\fBTcl_GetErrno\fR.In addition, \fBTcl_OpenCommandChannel\fR leaves an error message in\fIinterp->result\fR if \fIinterp\fR is not NULL..PPThe newly created channel is not registered in the supplied interpreter; toregister it, use \fBTcl_RegisterChannel\fR, described below.If one of the standard channels, \fBstdin, stdout\fR or \fBstderr\fR waspreviously closed, the act of creating the new channel also assigns it as areplacement for the standard channel..SH TCL_MAKEFILECHANNEL.PP\fBTcl_MakeFileChannel\fR makes a \fBTcl_Channel\fR from an existing,platform-specific, file handle.The newly created channel is not registered in the supplied interpreter; toregister it, use \fBTcl_RegisterChannel\fR, described below.If one of the standard channels, \fBstdin, stdout\fR or \fBstderr\fR waspreviously closed, the act of creating the new channel also assigns it as areplacement for the standard channel..SH TCL_GETCHANNEL.PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -