filesystem.3

来自「tcl是工具命令语言」· 3 代码 · 共 1,350 行 · 第 1/4 页

3
1,350
字号
'\"'\" Copyright (c) 2001 Vincent Darley'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: FileSystem.3,v 1.32 2003/02/10 12:50:31 vincentdarley Exp $'\" .so man.macros.TH Filesystem 3 8.4 Tcl "Tcl Library Procedures".BS.SH NAMETcl_FSRegister, Tcl_FSUnregister, Tcl_FSData, Tcl_FSMountsChanged, Tcl_FSGetFileSystemForPath, Tcl_FSGetPathType, Tcl_FSCopyFile, Tcl_FSCopyDirectory, Tcl_FSCreateDirectory, Tcl_FSDeleteFile, Tcl_FSRemoveDirectory, Tcl_FSRenameFile, Tcl_FSListVolumes, Tcl_FSEvalFile, Tcl_FSLoadFile, Tcl_FSMatchInDirectory, Tcl_FSLink, Tcl_FSLstat, Tcl_FSUtime, Tcl_FSFileAttrsGet, Tcl_FSFileAttrsSet, Tcl_FSFileAttrStrings, Tcl_FSStat, Tcl_FSAccess, Tcl_FSOpenFileChannel, Tcl_FSGetCwd, Tcl_FSChdir, Tcl_FSPathSeparator, Tcl_FSJoinPath, Tcl_FSSplitPath, Tcl_FSEqualPaths, Tcl_FSGetNormalizedPath, Tcl_FSJoinToPath, Tcl_FSConvertToPathType, Tcl_FSGetInternalRep, Tcl_FSGetTranslatedPath, Tcl_FSGetTranslatedStringPath, Tcl_FSNewNativePath, Tcl_FSGetNativePath, Tcl_FSFileSystemInfo, Tcl_AllocStatBuf \- procedures to interact with any filesystem.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spint\fBTcl_FSRegister\fR(\fIclientData, fsPtr\fR).spint\fBTcl_FSUnregister\fR(\fIfsPtr\fR).spClientData\fBTcl_FSData\fR(\fIfsPtr\fR).spvoid\fBTcl_FSMountsChanged\fR(\fIfsPtr\fR).spTcl_Filesystem*\fBTcl_FSGetFileSystemForPath\fR(\fIpathObjPtr\fR).spTcl_PathType\fBTcl_FSGetPathType\fR(\fIpathObjPtr\fR).spint\fBTcl_FSCopyFile\fR(\fIsrcPathPtr, destPathPtr\fR).spint\fBTcl_FSCopyDirectory\fR(\fIsrcPathPtr, destPathPtr, errorPtr\fR).spint\fBTcl_FSCreateDirectory\fR(\fIpathPtr\fR).spint\fBTcl_FSDeleteFile\fR(\fIpathPtr\fR).spint\fBTcl_FSRemoveDirectory\fR(\fIpathPtr, int recursive, errorPtr\fR).spint\fBTcl_FSRenameFile\fR(\fIsrcPathPtr, destPathPtr\fR).spTcl_Obj*\fBTcl_FSListVolumes\fR(\fIvoid\fR).spint\fBTcl_FSEvalFile\fR(\fIinterp, pathPtr\fR).spint\fBTcl_FSLoadFile\fR(\fIinterp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr, handlePtr, unloadProcPtr\fR).spint\fBTcl_FSMatchInDirectory\fR(\fIinterp, result, pathPtr, pattern, types\fR).spTcl_Obj*\fBTcl_FSLink\fR(\fIlinkNamePtr, toPtr, linkAction\fR).spint\fBTcl_FSLstat\fR(\fIpathPtr, statPtr\fR).spint\fBTcl_FSUtime\fR(\fIpathPtr, tval\fR).spint\fBTcl_FSFileAttrsGet\fR(\fIinterp, int index, pathPtr, objPtrRef\fR).spint\fBTcl_FSFileAttrsSet\fR(\fIinterp, int index, pathPtr, Tcl_Obj *objPtr\fR).spCONST char**      \fBTcl_FSFileAttrStrings\fR(\fIpathPtr, objPtrRef\fR).spint\fBTcl_FSStat\fR(\fIpathPtr, statPtr\fR).spint\fBTcl_FSAccess\fR(\fIpathPtr, mode\fR).spTcl_Channel \fBTcl_FSOpenFileChannel\fR(\fIinterp, pathPtr, modeString, permissions\fR).spTcl_Obj*\fBTcl_FSGetCwd\fR(\fIinterp\fR).spint\fBTcl_FSChdir\fR(\fIpathPtr\fR).spTcl_Obj*\fBTcl_FSPathSeparator\fR(\fIpathPtr\fR).spTcl_Obj*\fBTcl_FSJoinPath\fR(\fIlistObj, elements\fR).spTcl_Obj*\fBTcl_FSSplitPath\fR(\fIpathPtr, lenPtr\fR).spint\fBTcl_FSEqualPaths\fR(\fIfirstPtr, secondPtr\fR).spTcl_Obj*\fBTcl_FSGetNormalizedPath\fR(\fIinterp, pathPtr\fR).spTcl_Obj*\fBTcl_FSJoinToPath\fR(\fIbasePtr, objc, objv\fR).spint\fBTcl_FSConvertToPathType\fR(\fIinterp, pathPtr\fR).spClientData \fBTcl_FSGetInternalRep\fR(\fIpathPtr, fsPtr\fR).spTcl_Obj* \fBTcl_FSGetTranslatedPath\fR(\fIinterp, pathPtr\fR).spCONST char* \fBTcl_FSGetTranslatedStringPath\fR(\fIinterp, pathPtr\fR).spTcl_Obj*\fBTcl_FSNewNativePath\fR(\fIfsPtr, clientData\fR).spCONST char* \fBTcl_FSGetNativePath\fR(\fIpathPtr\fR).spTcl_Obj*\fBTcl_FSFileSystemInfo\fR(\fIpathPtr\fR).spTcl_StatBuf*\fBTcl_AllocStatBuf\fR().SH ARGUMENTS.AS Tcl_Filesystem *fsPtr in.AP Tcl_Filesystem *fsPtr inPoints to a structure containing the addresses of procedures thatcan be called to perform the various filesystem operations..AP Tcl_Obj *pathPtr inThe path represented by this object is used for the operation inquestion.  If the object does not already have an internal \fBpath\fRrepresentation, it will be converted to have one..AP Tcl_Obj *srcPathPtr inAs for \fBpathPtr\fR, but used for the source file for a copy orrename operation..AP Tcl_Obj *destPathPtr inAs for \fBpathPtr\fR, but used for the destination filename for a copy orrename operation..AP "CONST char" *pattern inOnly files or directories matching this pattern will be returned by\fBTcl_FSMatchInDirectory\fR..AP GlobTypeData *types inOnly files or directories matching the type descriptions contained inthis structure will be returned by \fBTcl_FSMatchInDirectory\fR.  Itis very important that the 'directory' flag is properly handled.This parameter may be NULL..AP Tcl_Interp *interp inInterpreter to use either for results, evaluation, or reporting error messages..AP ClientData clientData inThe native description of the path object to create..AP Tcl_Obj *firstPtr inThe first of two path objects to compare.  The object may be convertedto \fBpath\fR type..AP Tcl_Obj *secondPtr inThe second of two path objects to compare.  The object may be convertedto \fBpath\fR type..AP Tcl_Obj *listObj inThe list of path elements to operate on with a \fBjoin\fR operation..AP int elements inIf non-negative, the number of elements in the listObj which shouldbe joined together.  If negative, then all elements are joined..AP Tcl_Obj **errorPtr outIn the case of an error, filled with an object containing the name ofthe file which caused an error in the various copy/rename operations..AP Tcl_Obj **objPtrRef outFilled with an object containing the result of the operation..AP Tcl_Obj *result outPre-allocated object in which to store (by lappending) the list offiles or directories which are successfully matched in\fBTcl_FSMatchInDirectory\fR..AP int mode inMask consisting of one or more of R_OK, W_OK, X_OK and F_OK.  R_OK,W_OK and X_OK request checking whether the file exists and  has  read,write and  execute  permissions, respectively.  F_OK just requestschecking for the existence of the file..AP Tcl_StatBuf *statPtr outThe structure that contains the result of a stat or lstat operation..AP "CONST char" *sym1 inName of a procedure to look up in the file's symbol table.AP "CONST char" *sym2 inName of a procedure to look up in the file's symbol table.AP Tcl_PackageInitProc **proc1Ptr outFilled with the init function for this code..AP Tcl_PackageInitProc **proc2Ptr outFilled with the safe-init function for this code..AP ClientData *clientDataPtr outFilled with the clientData value to pass to this code's unloadfunction when it is called..AP TclfsUnloadFileProc_ **unloadProcPtr outFilled with the function to use to unload this piece of code..AP utimbuf *tval inThe access and modification times in this structure are read and used to set those values for a given file..AP "CONST char" *modeString inSpecifies how the file is to be accessed.  May have any of the valuesallowed for the \fImode\fR argument to the Tcl \fBopen\fR command..AP int permissions inPOSIX-style permission flags such as 0644.  If a new file is created, thesepermissions will be set on the created file..AP int *lenPtr outIf non-NULL, filled with the number of elements in the split path..AP Tcl_Obj *basePtr inThe base path on to which to join the given elements.  May be NULL..AP int objc inThe number of elements in \fIobjv\fR..AP "Tcl_Obj *CONST" objv[] inThe elements to join to the given base path..BE.SH DESCRIPTION.PPThere are several reasons for calling the \fBTcl_FS...\fR functionsrather than calling system level functions like \fBaccess\fR and\fBstat\fR directly.  First, they will work cross-platform, so anextension which calls them should work unmodified on Unix, MacOS andWindows.  Second, the Windows implementation of some of these functionsfixes some bugs in the system level calls.  Third, these function callsdeal with any 'Utf to platform-native' path conversions which may berequired (and may cache the results of such conversions for greaterefficiency on subsequent calls).  Fourth, and perhaps most importantly,all of these functions are 'virtual filesystem aware'.  Any virtualfilesystem which has been registered (through\fBTcl_FSRegister\fR) may reroute file access to alternativemedia or access methods.  This means that all of these functions (andtherefore the corresponding \fBfile\fR, \fBglob\fR, \fBpwd\fR, \fBcd\fR,\fBopen\fR, etc.  Tcl commands) may be operate on 'files' which are notnative files in the native filesystem.  This also means that any Tclextension which accesses the filesystem through this API isautomatically 'virtual filesystem aware'.  Of course, if an extensionaccesses the native filesystem directly (through platform-specificAPIs, for example), then Tcl cannot intercept such calls.  .PPIf appropriate vfs's have been registered, the 'files' may, to give twoexamples, be remote (e.g. situated on a remote ftp server) or archived(e.g. lying inside a .zip archive).  Such registered filesystems providea lookup table of functions to implement all or some of the functionalitylisted here.  Finally, the \fBTcl_FSStat\fR and \fBTcl_FSLstat\fR callsabstract away from what the 'struct stat' buffer buffer is actuallydeclared to be, allowing the same code to be used both on systems withand systems without support for files larger than 2GB in size..PPThe \fBTcl_FS...\fR are objectified and may cache internalrepresentations and other path-related strings (e.g. the current workingdirectory).  One side-effect of this is that one must not pass in objectswith a refCount of zero to any of these functions.  If such calls were handled, they might resultin memory leaks (under some circumstances, the filesystem code may wishto retain a reference to the passed in object, and so one must not assumethat after any of these calls return, the object still has a refCount ofzero - it may have been incremented), or in a direct segfaultdue to the object being freed part way through the complex objectmanipulation required to ensure that the path is fully normalized andabsolute for filesystem determination.  The practical lesson to learnfrom this is that \fBTcl_Obj *path = Tcl_NewStringObj(...)  ;Tcl_FS...(path) ; Tcl_DecrRefCount(path)\fR is wrong, and may segfault.The 'path' must have its refCount incremented before passing it in, ordecrementing it.  For this reason, objects with a refCount of zero areconsidered not to be valid filesystem paths and calling any Tcl_FS APIwith such an object will result in no action being taken..PP\fBTcl_FSCopyFile\fR attempts to copy the file given by srcPathPtr to thepath name given by destPathPtr.  If the two paths given lie in the samefilesystem (according to \fBTcl_FSGetFileSystemForPath\fR) then thatfilesystem's 'copy file' function is called (if it is non-NULL).Otherwise the function returns -1 and sets Tcl's errno to the 'EXDEV'posix error code (which signifies a 'cross-domain link')..PP\fBTcl_FSCopyDirectory\fR attempts to copy the directory given by srcPathPtr to thepath name given by destPathPtr.  If the two paths given lie in the samefilesystem (according to \fBTcl_FSGetFileSystemForPath\fR) then thatfilesystem's 'copy file' function is called (if it is non-NULL).Otherwise the function returns -1 and sets Tcl's errno to the 'EXDEV'posix error code (which signifies a 'cross-domain link')..PP\fBTcl_FSCreateDirectory\fR attempts to create the directory given bypathPtr by calling the owning filesystem's 'create directory'function..PP\fBTcl_FSDeleteFile\fR attempts to delete the file given bypathPtr by calling the owning filesystem's 'delete file'function..PP\fBTcl_FSRemoveDirectory\fR attempts to remove the directory given bypathPtr by calling the owning filesystem's 'remove directory'function..PP\fBTcl_FSRenameFile\fR attempts to rename the file or directory given bysrcPathPtr to the path name given by destPathPtr.  If the two pathsgiven lie in the same filesystem (according to\fBTcl_FSGetFileSystemForPath\fR) then that filesystem's 'rename file'function is called (if it is non-NULL).  Otherwise the function returns -1and sets Tcl's errno to the 'EXDEV' posix error code (which signifiesa ``cross-domain link'')..PP\fBTcl_FSListVolumes\fR calls each filesystem which has a non-NULL 'listvolumes' function and asks them to return their list of root volumes.  Itaccumulates the return values in a list which is returned to thecaller (with a refCount of 0)..PP\fBTcl_FSEvalFile\fR reads the file given by \fIpathPtr\fR and evaluatesits contents as a Tcl script.  It returns the same information as\fBTcl_EvalObjEx\fR.If the file couldn't be read then a Tcl error is returned to describewhy the file couldn't be read.The eofchar for files is '\\32' (^Z) for all platforms.If you require a ``^Z'' in code for string comparison, you can use``\\032'' or ``\\u001a'', which will be safely substituted by the Tclinterpreter into ``^Z''..PP\fBTcl_FSLoadFile\fR dynamically loads a binary code file into memory andreturns the addresses of two procedures within that file, if they aredefined.  The appropriate function for the filesystem to which pathPtrbelongs will be called.  If that filesystem does not implement thisfunction (most virtual filesystems will not, because of OS limitationsin dynamically loading binary code), Tcl will attempt to copy the fileto a temporary directory and load that temporary file..PPReturns a standard Tcl completion code.  If an error occurs, an errormessage is left in the interp's result..PP\fBTcl_FSMatchInDirectory\fR is used by the globbing code to search a

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?