Tcl_FSCopyFile attempts to copy the file given by srcPathPtr to the path name given by destPathPtr. If the two paths given lie in the same filesystem (according to Tcl_FSGetFileSystemForPath) then that filesystem'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').
Tcl_FSCopyDirectory attempts to copy the directory given by srcPathPtr to the path name given by destPathPtr. If the two paths given lie in the same filesystem (according to Tcl_FSGetFileSystemForPath) then that filesystem'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').
Tcl_FSCreateDirectory attempts to create the directory given by pathPtr by calling the owning filesystem's 'create directory' function.
Tcl_FSDeleteFile attempts to delete the file given by pathPtr by calling the owning filesystem's 'delete file' function.
Tcl_FSRemoveDirectory attempts to remove the directory given by pathPtr by calling the owning filesystem's 'remove directory' function.
Tcl_FSRenameFile attempts to rename the file or directory given by srcPathPtr to the path name given by destPathPtr. If the two paths given lie in the same filesystem (according to Tcl_FSGetFileSystemForPath) then that filesystem's 'rename 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').
Tcl_FSListVolumes calls each filesystem which has a non-NULL 'list volumes' function and asks those to append their root volumes to the list in the interpreters result.
Tcl_FSEvalFile reads the file given by pathPtr and evaluates its contents as a Tcl script. It returns the same information as Tcl_EvalObjEx. If the file couldn't be read then a Tcl error is returned to describe why 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 Tcl interpreter into ``^Z''.
Tcl_FSLoadFile dynamically loads a binary code file into memory and returns the addresses of two procedures within that file, if they are defined. The appropriate function for the filesystem to which pathPtr belongs will be called. If that filesystem does not implement this function (most virtual filesystems will not, because of OS limitations in dynamically loading binary code), Tcl will attempt to copy the file to a temporary directory and load that temporary file.
Returns a standard Tcl completion code. If an error occurs, an error message is left in the interp's result.
Tcl_FSMatchInDirectory is used by the globbing code to search a directory for all files which match a given pattern. The appropriate function for the filesystem to which pathPtr belongs will be called.
The return value is a standard Tcl result indicating whether an error occurred in globbing. Error messages are placed in interp, but good results are placed in the resultPtr given. Note that the 'glob' code implements recursive patterns internally, so this function will only ever be passed simple patterns, which can be matched using the logic of 'string match'. To handle recursion, Tcl will call this function frequently asking only for directories to be returned.
Tcl_FSReadlink replaces the library version of readlink(). The appropriate function for the filesystem to which pathPtr belongs will be called.
The result is a Tcl_Obj specifying the contents of the symbolic link given by 'path', or NULL if the symbolic link could not be read. The result is owned by the caller, which should call Tcl_DecrRefCount when the result is no longer needed.
Tcl_FSLstat fills the stat structure statPtr with information about the specified file. You do not need any access rights to the file to get this information but you need search rights to all directories named in the path leading to the file. The stat structure includes info regarding device, inode (always 0 on Windows), privilege mode, nlink (always 1 on Windows), user id (always 0 on Windows), group id (always 0 on Windows), rdev (same as device on Windows), size, last access time, last modification time, and creation time.
If path exists, Tcl_FSLstat returns 0 and the stat structure is filled with data. Otherwise, -1 is returned, and no stat info is given.
Tcl_FSUtime replaces the library version of utime.
For results see 'utime' documentation. If successful, the function will update the 'atime' and 'mtime' values of the file given.
Tcl_FSFileAttrsGet implements read access for the hookable 'file attributes' subcommand. The appropriate function for the filesystem to which pathPtr belongs will be called.
If the result is TCL_OK, then an object was placed in objPtrRef, which will only be temporarily valid (unless Tcl_IncrRefCount is called).
Tcl_FSFileAttrsSet implements write access for the hookable 'file attributes' subcommand. The appropriate function for the filesystem to which pathPtr belongs will be called.
Tcl_FSFileAttrStrings implements part of the hookable 'file attributes' subcommand. The appropriate function for the filesystem to which pathPtr belongs will be called.
The called procedure may either return an array of strings, or may instead return NULL and place a Tcl list into the given objPtrRef. Tcl will take that list and first increment its refCount before using it. On completion of that use, Tcl will decrement its refCount. Hence if the list should be disposed of by Tcl when done, it should have a refCount of zero, and if the list should not be disposed of, the filesystem should ensure it retains a refCount on the object.
Tcl_FSAccess 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 are tested.
On success (all requested permissions granted), zero is returned. On error (at least one bit in mode asked for a permission that is denied, or some other error occurred), -1 is returned.
Tcl_FSStat fills the stat structure statPtr with information about the specified file. You do not need any access rights to the file to get this information but you need search rights to all directories named in the path leading to the file. The stat structure includes info regarding device, inode (always 0 on Windows), privilege mode, nlink (always 1 on Windows), user id (always 0 on Windows), group id (always 0 on Windows), rdev (same as device on Windows), size, last access time, last modification time, and creation time.
If path exists, Tcl_FSStat returns 0 and the stat structure is filled with data. Otherwise, -1 is returned, and no stat info is given.
Tcl_FSOpenFileChannel 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 fopen procedure of the Unix standard I/O library. The syntax and meaning of all arguments is similar to those given in the Tcl open command when opening a file. If an error occurs while opening the channel, Tcl_OpenFileChannel returns NULL and records a POSIX error code that can be retrieved with Tcl_GetErrno. In addition, if interp is non-NULL, Tcl_OpenFileChannel leaves an error message in interp's result after any error.
The newly created channel is not registered in 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_FSGetCwd replaces the library version of getcwd().
It returns the Tcl library's current working directory. This may be different to the native platform's working directory, in the case for which the cwd is not in the native filesystem.
The result is a pointer to a Tcl_Obj specifying the current directory, or NULL if the current directory could not be determined. If NULL is returned, an error message is left in the interp's result. The result already has its refCount incremented for the caller. When it is no longer needed, that refCount should be decremented. This is needed for thread-safety purposes, to allow multiple threads to access this and related functions, while ensuring the results are always valid.
Tcl_FSChdir replaces the library version of chdir(). The path is normalized and then passed to the filesystem which claims it. If that filesystem does not implement this function, Tcl will fallback to a combination of stat and access to check whether the directory exists and has appropriate permissions.
For results, see chdir() documentation. If successful, we keep a record of the successful path in cwdPathPtr for subsequent calls to getcwd.
Tcl_FSPathSeparator 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).
The separator is returned as a Tcl_Obj containing a string of length 1. If the path is invalid, NULL is returned.
Tcl_FSJoinPath 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 entire list.
Returns object with refCount of zero, containing the joined path.
Tcl_FSSplitPath takes the given Tcl_Obj, which should be a valid path, and returns a Tcl List object containing each segment of that path as an element.
Returns list object with refCount of zero. If the passed in lenPtr is non-NULL, we use it to return the number of elements in the returned list.
Tcl_FSEqualPaths tests whether the two paths given represent the same filesystem object
It returns 1 if the paths are equal, and 0 if they are different. If either path is NULL, 0 is always returned.
Tcl_FSGetNormalizedPath this important function attempts to extract from the given Tcl_Obj a unique normalized path representation, whose string value can be used as a unique identifier for the file.
It returns the normalized path object, with refCount of zero, or NULL if the path was invalid or could otherwise not be successfully converted.
Tcl_FSJoinToPath takes the given object, which should usually be a valid path or NULL, and joins onto it the array of paths segments given.
Returns object with refCount of zero, containing the joined path.
Tcl_FSConvertToPathType tries to convert the given Tcl_Obj to a valid Tcl path type, taking account of the fact that the cwd may have changed even if this object is already supposedly of the correct type. The filename may begin with "~" (to indicate current user's home directory) or "~<user>" (to indicate any user's home directory).
If the conversion succeeds (i.e. the object is a valid path in one of the current filesystems), then TCL_OK is returned. Otherwise TCL_ERROR is returned, and an error message may be left in the interpreter.
Tcl_FSGetInternalRep extracts the internal representation of a given path object, in the given filesystem. If the path object belongs to a different filesystem, we return NULL. If the internal representation is currently NULL, we attempt to generate it, by calling the filesystem's 'TclfsConvertToInternalProc_'.
Returns NULL or a valid internal path representation. This internal representation is cached, so that repeated calls to this function will not require additional conversions.
Tcl_FSGetTranslatedPath attempts to extract the translated path string from the given Tcl_Obj.
If the translation succeeds (i.e. the object is a valid path), then it is returned. Otherwise NULL will be returned, and an error message may be left in the interpreter.
Tcl_FSNewNativePath performs the something like that reverse of the usual obj->path->nativerep conversions. If some code retrieves a path in native form (from, e.g. readlink or a native dialog), and that path is to be used at the Tcl level, then calling this function is an efficient way of creating the appropriate path object type.
The resulting object is a pure 'path' object, which will only receive a Utf-8 string representation if that is required by some Tcl code.
Tcl_FSGetNativePath is for use by the Win/Unix/MacOS native filesystems, so that they can easily retrieve the native (char* or TCHAR*) representation of a path.
The native representation is cached so that repeated calls to this function will not require additional conversions.
Tcl_FSFileSystemInfo returns a list of two elements. The first element is the name of the filesystem (e.g. "native" or "vfs" or "zip" or "prowrap", perhaps), and the second is the particular type of the given path within that filesystem (which is filesystem dependent). The second element may be empty if the filesystem does not provide a further categorization of files.
A valid list object is returned, unless the path object is not recognized, when NULL will be returned.
The Tcl_Filesystem structures are manipulated using the following methods.
Tcl_FSRegister takes a pointer to a filesystem structure and an optional piece of data to associated with that filesystem. On calling this function, Tcl will attach the filesystem to the list of known filesystems, and it will become fully functional immediately. Tcl does not check if the same filesystem is registered multiple times (and in general that is not a good thing to do). TCL_OK will be returned.
Tcl_FSUnregister removes the given filesystem structure from the list of known filesystems, if it is known, and returns TCL_OK. If the filesystem is not currently registered, TCL_ERROR is returned.
Tcl_FSData will return the ClientData associated with the given filesystem, if that filesystem is registered. Otherwise it will return NULL.
The Tcl_Filesystem structure contains the following fields:
typedef struct Tcl_Filesystem { CONST char *typeName; int structureLength; Tcl_FSVersion version; Tcl_FSPathInFilesystemProc *pathInFilesystemProc; Tcl_FSDupInternalRepProc *dupInternalRepProc; Tcl_FSFreeInternalRepProc *freeInternalRepProc; Tcl_FSInternalToNormalizedProc *internalToNormalizedProc; Tcl_FSCreateInternalRepProc *createInternalRepProc; Tcl_FSNormalizePathProc *normalizePathProc; Tcl_FSFilesystemPathTypeProc *filesystemPathTypeProc; Tcl_FSFilesystemSeparatorProc *filesystemSeparatorProc; Tcl_FSStatProc *statProc; Tcl_FSAccessProc *accessProc; Tcl_FSOpenFileChannelProc *openFileChannelProc; Tcl_FSMatchInDirectoryProc *matchInDirectoryProc; Tcl_FSUtimeProc *utimeProc; Tcl_FSReadlinkProc *readlinkProc; Tcl_FSListVolumesProc *listVolumesProc; Tcl_FSFileAttrStringsProc *fileAttrStringsProc; Tcl_FSFileAttrsGetProc *fileAttrsGetProc; Tcl_FSFileAttrsSetProc *fileAttrsSetProc; Tcl_FSCreateDirectoryProc *createDirectoryProc; Tcl_FSRemoveDirectoryProc *removeDirectoryProc; Tcl_FSDeleteFileProc *deleteFileProc; Tcl_FSCopyFileProc *copyFileProc; Tcl_FSRenameFileProc *renameFileProc; Tcl_FSCopyDirectoryProc *copyDirectoryProc; Tcl_FSLstatProc *lstatProc; Tcl_FSLoadFileProc *loadFileProc; Tcl_FSUnloadFileProc *unloadFileProc; Tcl_FSGetCwdProc *getCwdProc; Tcl_FSChdirProc *chdirProc; } Tcl_Filesystem;
Except for the first three fields in this structure which contain simple data elements, all entries contain addresses of functions called by the generic filesystem layer to perform the complete range of filesystem related actions.
The many functions in this structure are broken down into three categories: infrastructure functions (almost all of which must be implemented), operational functions (which must be implemented if a complete filesystem is provided), and efficiency functions (which need only be implemented if they can be done so efficiently, or if they have side-effects which are required by the filesystem; Tcl has less efficient emulations it can fall back on). It is important to note that, in the current version of Tcl, most of these fallbacks are only used to handle commands initiated in Tcl, not in C. What this means is, that if a 'file rename' command is issued in Tcl, and the relevant filesystem(s) do not implement their Tcl_FSRenameFileProc, Tcl's core will instead fallback on a combination of other filesystem functions (it will use Tcl_FSCopyFileProc followed by Tcl_FSDeleteFileProc, and if Tcl_FSCopyFileProc is not implemented there is a further fallback). However, if a Tcl_FSRenameFile command is issued at the C level, no such fallbacks occur. This is true except for the last five entries in the filesystem table (lstat, load, unload, getcwd and chdir) for which fallbacks do in fact occur at the C level.
Any functions which take path names in Tcl_Obj form take those names in UTF-8 form. The filesystem infrastructure API is designed to support efficient, cached conversion of these UTF-8 paths to other native representations.
typedef int Tcl_FSPathInFilesystemProc( Tcl_Obj *pathPtr, ClientData *clientDataPtr);
typedef ClientData Tcl_FSDupInternalRepProc( ClientData clientData);
typedef void Tcl_FSFreeInternalRepProc( ClientData clientData);
typedef Tcl_Obj* Tcl_FSInternalToNormalizedProc( ClientData clientData);
typedef ClientData Tcl_FSCreateInternalRepProc( Tcl_Obj *pathPtr);
typedef int Tcl_FSNormalizePathProc( Tcl_Interp *interp, Tcl_Obj *pathPtr, int nextCheckpoint);
typedef Tcl_Obj* Tcl_FSFilesystemPathTypeProc( Tcl_Obj *pathPtr);
typedef Tcl_Obj* Tcl_FSFilesystemSeparatorProc( Tcl_Obj *pathPtr);
typedef int Tcl_FSStatProc( Tcl_Obj *pathPtr, struct stat *statPtr);
The Tcl_FSStatProc fills the stat structure statPtr with information about the specified file. You do not need any access rights to the file to get this information but you need search rights to all directories named in the path leading to the file. The stat structure includes info regarding device, inode (always 0 on Windows), privilege mode, nlink (always 1 on Windows), user id (always 0 on Windows), group id (always 0 on Windows), rdev (same as device on Windows), size, last access time, last modification time, and creation time.
If the file represented by pathPtr exists, the Tcl_FSStatProc returns 0 and the stat structure is filled with data. Otherwise, -1 is returned, and no stat info is given.
typedef int Tcl_FSAccessProc( Tcl_Obj *pathPtr, int mode);
The Tcl_FSAccessProc 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, then permissions of the file referred by this symbolic link should be tested.
On success (all requested permissions granted), zero is returned. On error (at least one bit in mode asked for a permission that is denied, or some other error occurred), -1 is returned.
typedef Tcl_Channel Tcl_FSOpenFileChannelProc( Tcl_Interp *interp, Tcl_Obj *pathPtr, char *modeString, int permissions);
The Tcl_FSOpenFileChannelProc opens a file specified by pathPtr 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 standard I/O library. The syntax and meaning of all arguments is similar to those given in the Tcl open command when opening a file. If an error occurs while opening the channel, the Tcl_FSOpenFileChannelProc returns NULL and records a POSIX error code that can be retrieved with Tcl_GetErrno. In addition, if interp is non-NULL, the Tcl_FSOpenFileChannelProc leaves an error message in interp's result after any error.
The newly created channel is not registered in the supplied interpreter; to register it, use Tcl_RegisterChannel. 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.
typedef int Tcl_FSMatchInDirectoryProc( Tcl_Interp* interp, Tcl_Obj *result, Tcl_Obj *pathPtr, char *pattern, Tcl_GlobTypeData * types);
The function should return all files or directories (or other filesystem objects) which match the given pattern and accord with the types specification given. The directory pathPtr, in which the function should search, can be assumed to be both non-NULL and non-empty.
The return value is a standard Tcl result indicating whether an error occurred in the matching process. Error messages are placed in interp, but on a TCL_OK result, the interpreter should not be modified, but rather results should be added to the result object given (which can be assumed to be a valid Tcl list). The matches added to result should include any path prefix given in pathPtr (this usually means they will be absolute path specifications). .PP
typedef int Tcl_FSUtimeProc( Tcl_Obj *pathPtr, struct utimbuf *tval);
The access and modification times of the file specified by pathPtr should be changed to the values given in the tval structure.
The return value is a standard Tcl result indicating whether an error occurred in the process.
typedef Tcl_Obj* Tcl_FSReadlinkProc( Tcl_Obj *pathPtr);
The result is a Tcl_Obj specifying the contents of the symbolic link given by 'path', or NULL if the symbolic link could not be read. The result is owned by the caller, which should call Tcl_DecrRefCount when the result is no longer needed.
typedef int Tcl_FSListVolumesProc( Tcl_Interp *interp);
The result should be TCL_OK, since there is no way this function can fail. The function should add the known volumes to the list object contained in the Tcl interpreter's result.
typedef char** Tcl_FSFileAttrStringsProc( Tcl_Obj *pathPtr, Tcl_Obj** objPtrRef);
The called function may either return an array of strings, or may instead return NULL and place a Tcl list into the given objPtrRef. Tcl will take that list and first increment its refCount before using it. On completion of that use, Tcl will decrement its refCount. Hence if the list should be disposed of by Tcl when done, it should have a refCount of zero, and if the list should not be disposed of, the filesystem should ensure it retains a refCount on the object.
typedef int Tcl_FSFileAttrsGetProc( Tcl_Interp *interp, int index, Tcl_Obj *pathPtr, Tcl_Obj **objPtrRef);
Returns a standard Tcl return code. The attribute value retrieved, which corresponds to the index'th element in the list returned by the Tcl_FSFileAttrStringsProc, is a Tcl_Obj placed in objPtrRef (if TCL_OK was returned) and is likely to have a refCount of zero. Either way we must either store it somewhere (e.g. the Tcl result), or Incr/Decr its refCount to ensure it is properly freed.
typedef int Tcl_FSFileAttrsSetProc( Tcl_Interp *interp, int index, Tcl_Obj *pathPtr, Tcl_Obj *objPtr);
The attribute value of the index'th element in the list returned by the Tcl_FSFileAttrStringsProc should be set to the objPtr given.
typedef int Tcl_FSCreateDirectoryProc( Tcl_Obj *pathPtr);
The return value is a standard Tcl result indicating whether an error occurred in the process. If successful, a new directory should have been added to the filesystem in the location specified by pathPtr.
typedef int Tcl_FSRemoveDirectoryProc( Tcl_Obj *pathPtr, int recursive, Tcl_Obj **errorPtr);
The return value is a standard Tcl result indicating whether an error occurred in the process. If successful, the directory specified by pathPtr should have been removed from the filesystem. If the recursive flag is given, then a non-empty directory should be deleted without error. If an error does occur, the name of the file or directory which caused the error should be placed in errorPtr.
typedef int Tcl_FSDeleteFileProc( Tcl_Obj *pathPtr);
The return value is a standard Tcl result indicating whether an error occurred in the process. If successful, the file specified by pathPtr should have been removed from the filesystem.
typedef int Tcl_FSLstatProc( Tcl_Obj *pathPtr, struct stat *statPtr);
The behavior of this function is very similar to that of the Tcl_FSStatProc defined above, except that if it is applied to a symbolic link, it returns information about the link, not about the target file.
typedef int Tcl_FSCopyFileProc( Tcl_Obj *srcPathPtr, Tcl_Obj *destPathPtr);
The return value is a standard Tcl result indicating whether an error occurred in the copying process. Note that, destPathPtr is the name of the file which should become the copy of srcPathPtr. It is never the name of a directory into which srcPathPtr could be copied (i.e. the function is much simpler than the Tcl level 'file copy' subcommand).
typedef int Tcl_FSRenameFileProc( Tcl_Obj *srcPathPtr, Tcl_Obj *destPathPtr);
The return value is a standard Tcl result indicating whether an error occurred in the renaming process.
typedef int Tcl_FSCopyDirectoryProc( Tcl_Obj *srcPathPtr, Tcl_Obj *destPathPtr, Tcl_Obj **errorPtr);
The return value is a standard Tcl result indicating whether an error occurred in the copying process. If an error does occur, the name of the file or directory which caused the error should be placed in errorPtr. Note that, destPathPtr is the name of the directory-name which should become the mirror-image of srcPathPtr. It is not the name of a directory into which srcPathPtr should be copied (i.e. the function is much simpler than the Tcl level 'file copy' subcommand).
typedef int Tcl_FSLoadFileProc( Tcl_Interp * interp, Tcl_Obj *pathPtr, char * sym1, char * sym2, Tcl_PackageInitProc ** proc1Ptr, Tcl_PackageInitProc ** proc2Ptr, ClientData * clientDataPtr);
Returns a standard Tcl completion code. If an error occurs, an error message is left in the interp's result. The function dynamically loads a binary code file into memory and returns the addresses of two procedures within that file, if they are defined. On a successful load, the clientDataPtr should be filled with a token for the dynamically loaded file which will be passed back to the Tcl_FSUnloadFileProc to unload the file.
typedef void Tcl_FSUnloadFileProc( ClientData clientData);
typedef Tcl_Obj* Tcl_FSGetCwdProc( Tcl_Interp *interp);
If the filesystem supports a native notion of a current working directory (which might perhaps change independent of Tcl), this function should return that cwd as the result, or NULL if the current directory could not be determined (e.g. the user does not have appropriate permissions on the cwd directory). If NULL is returned, an error message is left in the interp's result.
typedef int Tcl_FSChdirProc( Tcl_Obj *pathPtr);
The Tcl_FSChdirProc changes the applications current working directory to the value specified in pathPtr. The function returns -1 on error or 0 on success.
Copyright © 2001 Vincent Darley Copyright © 1995-1997 Roger E. Critchlow Jr.