filesystem.3
来自「tcl是工具命令语言」· 3 代码 · 共 1,350 行 · 第 1/4 页
3
1,350 行
directory for all files which match a given pattern. The appropriatefunction for the filesystem to which pathPtr belongs will be called..PPThe return value is a standard Tcl result indicating whether an erroroccurred in globbing. Error messages are placed in interp, but goodresults are placed in the resultPtr given. Note that the 'glob' code implements recursive patterns internally, sothis function will only ever be passed simple patterns, which can bematched using the logic of 'string match'. To handle recursion, Tclwill call this function frequently asking only for directories to bereturned..PP\fBTcl_FSLink\fR replaces the library version of readlink(), andextends it to support the creation of links. The appropriate function for the filesystem to which linkNamePtr belongs will be called..PPIf the \fItoPtr\fR is NULL, a readlink action is performed. The resultis a Tcl_Obj specifying the contents of the symbolic link given by\fIlinkNamePtr\fR, or NULL if the link could not be read. The result is ownedby the caller, which should call Tcl_DecrRefCount when the result is nolonger needed. If the \fItoPtr\fR is not NULL, Tcl should create a linkof one of the types passed in in the \fIlinkAction\fR flag. This flag isan or'd combination of TCL_CREATE_SYMBOLIC_LINK and TCL_CREATE_HARD_LINK.Where a choice exists (i.e. more than one flag is passed in), the Tclconvention is to prefer symbolic links. When a link is successfullycreated, the return value should be \fItoPtr\fR (which is thereforealready owned by the caller). If unsuccessful, NULL should bereturned..PP\fBTcl_FSLstat\fR fills the stat structure \fIstatPtr\fR with informationabout the specified file. You do not need any access rights to thefile to get this information but you need search rights to alldirectories named in the path leading to the file. The stat structureincludes info regarding device, inode (always 0 on Windows),privilege mode, nlink (always 1 on Windows), user id (always 0 onWindows), group id (always 0 on Windows), rdev (same as device onWindows), size, last access time, last modification time, and creationtime..PPIf \fIpath\fR exists, \fBTcl_FSLstat\fR returns 0 and the stat structureis filled with data. Otherwise, -1 is returned, and no stat info isgiven..PP\fBTcl_FSUtime\fR replaces the library version of utime. .PPFor results see 'utime' documentation. If successful, the functionwill update the 'atime' and 'mtime' values of the file given..PP\fBTcl_FSFileAttrsGet\fR implements read access for the hookable 'fileattributes' subcommand. The appropriate function for the filesystem towhich pathPtr belongs will be called..PPIf the result is TCL_OK, then an object was placed in objPtrRef, whichwill only be temporarily valid (unless Tcl_IncrRefCount is called)..PP\fBTcl_FSFileAttrsSet\fR implements write access for the hookable 'fileattributes' subcommand. The appropriate function for the filesystem towhich pathPtr belongs will be called..PP\fBTcl_FSFileAttrStrings\fR implements part of the hookable 'file attributes'subcommand. The appropriate function for the filesystem to whichpathPtr belongs will be called..PP The called procedure may either return an array of strings, or mayinstead return NULL and place a Tcl list into the given objPtrRef. Tclwill take that list and first increment its refCount before using it.On completion of that use, Tcl will decrement its refCount. Hence ifthe list should be disposed of by Tcl when done, it should have arefCount of zero, and if the list should not be disposed of, thefilesystem should ensure it retains a refCount on the object..PP\fBTcl_FSAccess\fR checks whether the process would be allowed to read,write or test for existence of the file (or other file system object)whose name is pathname. If pathname is a symbolic link on Unix,then permissions of the file referred by this symbolic link aretested..PPOn success (all requested permissions granted), zero is returned. Onerror (at least one bit in mode asked for a permission that is denied,or some other error occurred), -1 is returned..PP\fBTcl_FSStat\fR fills the stat structure \fIstatPtr\fR with informationabout the specified file. You do not need any access rights to thefile to get this information but you need search rights to alldirectories named in the path leading to the file. The stat structureincludes info regarding device, inode (always 0 on Windows),privilege mode, nlink (always 1 on Windows), user id (always 0 onWindows), group id (always 0 on Windows), rdev (same as device onWindows), size, last access time, last modification time, and creationtime..PPIf \fIpath\fR exists, \fBTcl_FSStat\fR returns 0 and the stat structureis filled with data. Otherwise, -1 is returned, and no stat info isgiven..PP\fBTcl_FSOpenFileChannel\fR opens a file specified by \fIpathPtr\fR andreturns a channel handle that can be used to perform input and output onthe file. This API is modeled 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_FSOpenFileChannel\fRreturns NULL and records a POSIX error code that can beretrieved with \fBTcl_GetErrno\fR.In addition, if \fIinterp\fR is non-NULL, \fBTcl_FSOpenFileChannel\fRleaves an error message in \fIinterp\fR's result 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..PP\fBTcl_FSGetCwd\fR replaces the library version of getcwd()..PPIt returns the Tcl library's current working directory. This may bedifferent to the native platform's working directory, in the case for which the cwd is not in the native filesystem..PPThe result is a pointer to a Tcl_Obj specifying the current directory,or NULL if the current directory could not be determined. If NULL isreturned, an error message is left in the interp's result. The result already has its refCount incremented for the caller. Whenit is no longer needed, that refCount should be decremented. This isneeded for thread-safety purposes, to allow multiple threads to accessthis and related functions, while ensuring the results are alwaysvalid..PP\fBTcl_FSChdir\fR replaces the library version of chdir(). The path isnormalized and then passed to the filesystem which claims it. If thatfilesystem does not implement this function, Tcl will fallback to a combination of stat and access to check whether the directory existsand has appropriate permissions..PP For results, see chdir() documentation. If successful, we keep arecord of the successful path in cwdPathPtr for subsequent calls togetcwd..PP\fBTcl_FSPathSeparator\fR returns the separator character to be used for most specific element of the path specified by pathPtr (i.e. the last part of the path)..PPThe separator is returned as a Tcl_Obj containing a string of length1. If the path is invalid, NULL is returned..PP\fBTcl_FSJoinPath\fR takes the given Tcl_Obj, which should be a valid list,and returns the path object given by considering the first 'elements'elements as valid path segments. If elements < 0, we use the entirelist..PPReturns object with refCount of zero, containing the joined path..PP\fBTcl_FSSplitPath\fR takes the given Tcl_Obj, which should be a valid path,and returns a Tcl List object containing each segment of that path asan element..PPReturns list object with refCount of zero. If the passed in lenPtr isnon-NULL, we use it to return the number of elements in the returnedlist..PP\fBTcl_FSEqualPaths\fR tests whether the two paths given represent the samefilesystem object.PPIt returns 1 if the paths are equal, and 0 if they are different. If either path is NULL, 0 is always returned..PP\fBTcl_FSGetNormalizedPath\fR this important function attempts to extractfrom the given Tcl_Obj a unique normalized path representation, whosestring value can be used as a unique identifier for the file..PPIt returns the normalized path object, with refCount of zero, or NULL if the path was invalid or could otherwise not be successfullyconverted. Extraction of absolute, normalized paths is veryefficient (because the filesystem operates on these representationsinternally), although the result when the filesystem containsnumerous symbolic links may not be the most user-friendlyversion of a path..PP\fBTcl_FSJoinToPath\fR takes the given object, which should usually be avalid path or NULL, and joins onto it the array of paths segmentsgiven..PPReturns object with refCount of zero, containing the joined path..PP\fBTcl_FSConvertToPathType\fR tries to convert the given Tcl_Obj to a validTcl path type, taking account of the fact that the cwd may have changedeven if this object is already supposedly of the correct type.The filename may begin with "~" (to indicate current user's homedirectory) or "~<user>" (to indicate any user's home directory)..PPIf the conversion succeeds (i.e. the object is a valid path in one of the current filesystems), then TCL_OK is returned. OtherwiseTCL_ERROR is returned, and an error message maybe left in the interpreter..PP\fBTcl_FSGetInternalRep\fR extracts the internal representation of a givenpath object, in the given filesystem. If the path object belongs to adifferent filesystem, we return NULL. If the internal representation iscurrently NULL, we attempt to generate it, by calling the filesystem's\fBTcl_FSCreateInternalRepProc\fR..PPReturns NULL or a valid internal path representation. This internalrepresentation is cached, so that repeated calls to this function willnot require additional conversions..PP\fBTcl_FSGetTranslatedPath\fR attempts to extract the translated pathfrom the given Tcl_Obj. .PPIf the translation succeeds (i.e. the object is a valid path), then itis returned. Otherwise NULL will be returned, and an error message maybe left in the interpreter. A "translated" path is one whichcontains no "~" or "~user" sequences (these have been expanded totheir current representation in the filesystem)..PP\fBTcl_FSGetTranslatedStringPath\fR does the same as \fBTcl_FSGetTranslatedPath\fR, but returns a character string or NULL..PP\fBTcl_FSNewNativePath\fR performs something like that reverse of theusual obj->path->nativerep conversions. If some code retrieves a pathin native form (from, e.g. readlink or a native dialog), and that pathis to be used at the Tcl level, then calling this function is anefficient way of creating the appropriate path object type..PPThe resulting object is a pure 'path' object, which will only receive a Utf-8 string representation if that is required by some Tcl code..PP\fBTcl_FSGetNativePath\fR is for use by the Win/Unix/MacOS nativefilesystems, so that they can easily retrieve the native (char* orTCHAR*) representation of a path. This function is a conveniencewrapper around \fBTcl_FSGetInternalRep\fR, and assumes the nativerepresentation is string-based. It may be desirable in the futureto have non-string-based native representations (for example, onMacOS, a representation using a fileSpec of FSRef structure wouldprobably be more efficient). On Windows a full Unicoderepresentation would allow for paths of unlimited length. Currentlythe representation is simply a character string containing thecomplete, absolute path in the native encoding..PPThe native representation is cached so that repeated calls to thisfunction will not require additional conversions..PP\fBTcl_FSFileSystemInfo\fR returns a list of two elements. The firstelement is the name of the filesystem (e.g. "native" or "vfs" or "zip"or "prowrap", perhaps), and the second is the particular type of thegiven path within that filesystem (which is filesystem dependent). Thesecond element may be empty if the filesystem does not provide afurther categorization of files..PPA valid list object is returned, unless the path object is notrecognized, when NULL will be returned..PP\fBTcl_FSGetFileSystemForPath\fR returns the a pointer to the\fBTcl_Filesystem\fR which accepts this path as valid..PPIf no filesystem will accept the path, NULL is returned..PP\fBTcl_FSGetPathType\fR determines whether the given path is relative to the current directory, relative to the current volume, orabsolute..PPIt returns one of TCL_PATH_ABSOLUTE, TCL_PATH_RELATIVE, orTCL_PATH_VOLUME_RELATIVE.PP\fBTcl_AllocStatBuf\fR allocates a \fITcl_StatBuf\fR on the systemheap (which may be deallocated by being passed to \fBckfree\fR.) Thisallows extensions to invoke \fBTcl_FSStat\fR and \fBTcl_FSLStat\fRwithout being dependent on the size of the buffer. That in turndepends on the flags used to build Tcl..PP.SH TCL_FILESYSTEM.PPA filesystem provides a \fBTcl_Filesystem\fR structure that containspointers to functions that implement the various operations on afilesystem; these operations are invoked as needed by the genericlayer, which generally occurs through the functions listed above. .PPThe \fBTcl_Filesystem\fR structures are manipulated using the followingmethods..PP\fBTcl_FSRegister\fR takes a pointer to a filesystem structure and anoptional piece of data to associated with that filesystem. On callingthis function, Tcl will attach the filesystem to the list of knownfilesystems, and it will become fully functional immediately. Tcl doesnot check if the same filesystem is registered multiple times (and ingeneral that is not a good thing to do). TCL_OK will be returned..PP\fBTcl_FSUnregister\fR removes the given filesystem structure fromthe list of known filesystems, if it is known, and returns TCL_OK. Ifthe filesystem is not currently registered, TCL_ERROR is returned..PP\fBTcl_FSData\fR will return the ClientData associated with the given filesystem, if that filesystem is registered. Otherwise it willreturn NULL..PP\fBTcl_FSMountsChanged\fR is used to inform the Tcl's core thatthe set of mount points for the given (already registered) filesystemhave changed, and that cached file representations may therefore nolonger be correct..PPThe \fBTcl_Filesystem\fR structure contains the following fields:.CStypedef struct Tcl_Filesystem { CONST char *\fItypeName\fR; int \fIstructureLength\fR; Tcl_FSVersion \fIversion\fR; Tcl_FSPathInFilesystemProc *\fIpathInFilesystemProc\fR; Tcl_FSDupInternalRepProc *\fIdupInternalRepProc\fR; Tcl_FSFreeInternalRepProc *\fIfreeInternalRepProc\fR; Tcl_FSInternalToNormalizedProc *\fIinternalToNormalizedProc\fR; Tcl_FSCreateInternalRepProc *\fIcreateInternalRepProc\fR; Tcl_FSNormalizePathProc *\fInormalizePathProc\fR; Tcl_FSFilesystemPathTypeProc *\fIfilesystemPathTypeProc\fR; Tcl_FSFilesystemSeparatorProc *\fIfilesystemSeparatorProc\fR; Tcl_FSStatProc *\fIstatProc\fR; Tcl_FSAccessProc *\fIaccessProc\fR; Tcl_FSOpenFileChannelProc *\fIopenFileChannelProc\fR; Tcl_FSMatchInDirectoryProc *\fImatchInDirectoryProc\fR; Tcl_FSUtimeProc *\fIutimeProc\fR; Tcl_FSLinkProc *\fIlinkProc\fR; Tcl_FSListVolumesProc *\fIlistVolumesProc\fR; Tcl_FSFileAttrStringsProc *\fIfileAttrStringsProc\fR; Tcl_FSFileAttrsGetProc *\fIfileAttrsGetProc\fR; Tcl_FSFileAttrsSetProc *\fIfileAttrsSetProc\fR; Tcl_FSCreateDirectoryProc *\fIcreateDirectoryProc\fR; Tcl_FSRemoveDirectoryProc *\fIremoveDirectoryProc\fR; Tcl_FSDeleteFileProc *\fIdeleteFileProc\fR; Tcl_FSCopyFileProc *\fIcopyFileProc\fR; Tcl_FSRenameFileProc *\fIrenameFileProc\fR; Tcl_FSCopyDirectoryProc *\fIcopyDirectoryProc\fR; Tcl_FSLstatProc *\fIlstatProc\fR; Tcl_FSLoadFileProc *\fIloadFileProc\fR; Tcl_FSGetCwdProc *\fIgetCwdProc\fR; Tcl_FSChdirProc *\fIchdirProc\fR; } Tcl_Filesystem;.CE.PP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?