📄 tclioutil.c
字号:
{ char *id, *msg; msg = Tcl_ErrnoMsg(errno); id = Tcl_ErrnoId(); Tcl_SetErrorCode(interp, "POSIX", id, msg, (char *) NULL); return msg;}/* *---------------------------------------------------------------------- * * TclStat -- * * This procedure replaces the library version of stat and lsat. * The chain of functions that have been "inserted" into the * 'statProcList' will be called in succession until either * a value of zero is returned, or the entire list is visited. * * Results: * See stat documentation. * * Side effects: * See stat documentation. * *---------------------------------------------------------------------- */intTclStat(path, buf) CONST char *path; /* Path of file to stat (in current CP). */ TclStat_ *buf; /* Filled with results of stat call. */{ StatProc *statProcPtr = statProcList; int retVal = -1; /* * Call each of the "stat" function in succession. A non-return * value of -1 indicates the particular function has succeeded. */ while ((retVal == -1) && (statProcPtr != NULL)) { retVal = (*statProcPtr->proc)(path, buf); statProcPtr = statProcPtr->nextPtr; } return (retVal);}/* *---------------------------------------------------------------------- * * TclAccess -- * * This procedure replaces the library version of access. * The chain of functions that have been "inserted" into the * 'accessProcList' will be called in succession until either * a value of zero is returned, or the entire list is visited. * * Results: * See access documentation. * * Side effects: * See access documentation. * *---------------------------------------------------------------------- */intTclAccess(path, mode) CONST char *path; /* Path of file to access (in current CP). */ int mode; /* Permission setting. */{ AccessProc *accessProcPtr = accessProcList; int retVal = -1; /* * Call each of the "access" function in succession. A non-return * value of -1 indicates the particular function has succeeded. */ while ((retVal == -1) && (accessProcPtr != NULL)) { retVal = (*accessProcPtr->proc)(path, mode); accessProcPtr = accessProcPtr->nextPtr; } return (retVal);}/* *---------------------------------------------------------------------- * * Tcl_OpenFileChannel -- * * The chain of functions that have been "inserted" into the * 'openFileChannelProcList' will be called in succession until * either a valid file channel is returned, or the entire list is * visited. * * Results: * The new channel or NULL, if the named file could not be opened. * * Side effects: * May open the channel and may cause creation of a file on the * file system. * *---------------------------------------------------------------------- */ Tcl_ChannelTcl_OpenFileChannel(interp, fileName, modeString, permissions) Tcl_Interp *interp; /* Interpreter for error reporting; * can be NULL. */ char *fileName; /* Name of file to open. */ char *modeString; /* A list of POSIX open modes or * a string such as "rw". */ int permissions; /* If the open involves creating a * file, with what modes to create * it? */{ OpenFileChannelProc *openFileChannelProcPtr = openFileChannelProcList; Tcl_Channel retVal = NULL; /* * Call each of the "Tcl_OpenFileChannel" function in succession. * A non-NULL return value indicates the particular function has * succeeded. */ while ((retVal == NULL) && (openFileChannelProcPtr != NULL)) { retVal = (*openFileChannelProcPtr->proc)(interp, fileName, modeString, permissions); openFileChannelProcPtr = openFileChannelProcPtr->nextPtr; } return (retVal);}/* *---------------------------------------------------------------------- * * TclStatInsertProc -- * * Insert the passed procedure pointer at the head of the list of * functions which are used during a call to 'TclStat(...)'. The * passed function should be have exactly like 'TclStat' when called * during that time (see 'TclStat(...)' for more informatin). * The function will be added even if it already in the list. * * Results: * Normally TCL_OK; TCL_ERROR if memory for a new node in the list * could not be allocated. * * Side effects: * Memory allocataed and modifies the link list for 'TclStat' * functions. * *---------------------------------------------------------------------- */intTclStatInsertProc (proc) TclStatProc_ *proc;{ int retVal = TCL_ERROR; if (proc != NULL) { StatProc *newStatProcPtr; newStatProcPtr = (StatProc *)Tcl_Alloc(sizeof(StatProc));; if (newStatProcPtr != NULL) { newStatProcPtr->proc = proc; newStatProcPtr->nextPtr = statProcList; statProcList = newStatProcPtr; retVal = TCL_OK; } } return (retVal);}/* *---------------------------------------------------------------------- * * TclStatDeleteProc -- * * Removed the passed function pointer from the list of 'TclStat' * functions. Ensures that the built-in stat function is not * removvable. * * Results: * TCL_OK if the procedure pointer was successfully removed, * TCL_ERROR otherwise. * * Side effects: * Memory is deallocated and the respective list updated. * *---------------------------------------------------------------------- */intTclStatDeleteProc (proc) TclStatProc_ *proc;{ int retVal = TCL_ERROR; StatProc *tmpStatProcPtr = statProcList; StatProc *prevStatProcPtr = NULL; /* * Traverse the 'statProcList' looking for the particular node * whose 'proc' member matches 'proc' and remove that one from * the list. Ensure that the "default" node cannot be removed. */ while ((retVal == TCL_ERROR) && (tmpStatProcPtr != &defaultStatProc)) { if (tmpStatProcPtr->proc == proc) { if (prevStatProcPtr == NULL) { statProcList = tmpStatProcPtr->nextPtr; } else { prevStatProcPtr->nextPtr = tmpStatProcPtr->nextPtr; } Tcl_Free((char *)tmpStatProcPtr); retVal = TCL_OK; } else { prevStatProcPtr = tmpStatProcPtr; tmpStatProcPtr = tmpStatProcPtr->nextPtr; } } return (retVal);}/* *---------------------------------------------------------------------- * * TclAccessInsertProc -- * * Insert the passed procedure pointer at the head of the list of * functions which are used during a call to 'TclAccess(...)'. The * passed function should be have exactly like 'TclAccess' when * called during that time (see 'TclAccess(...)' for more informatin). * The function will be added even if it already in the list. * * Results: * Normally TCL_OK; TCL_ERROR if memory for a new node in the list * could not be allocated. * * Side effects: * Memory allocataed and modifies the link list for 'TclAccess' * functions. * *---------------------------------------------------------------------- */intTclAccessInsertProc(proc) TclAccessProc_ *proc;{ int retVal = TCL_ERROR; if (proc != NULL) { AccessProc *newAccessProcPtr; newAccessProcPtr = (AccessProc *)Tcl_Alloc(sizeof(AccessProc));; if (newAccessProcPtr != NULL) { newAccessProcPtr->proc = proc; newAccessProcPtr->nextPtr = accessProcList; accessProcList = newAccessProcPtr; retVal = TCL_OK; } } return (retVal);}/* *---------------------------------------------------------------------- * * TclAccessDeleteProc -- * * Removed the passed function pointer from the list of 'TclAccess' * functions. Ensures that the built-in access function is not * removvable. * * Results: * TCL_OK if the procedure pointer was successfully removed, * TCL_ERROR otherwise. * * Side effects: * Memory is deallocated and the respective list updated. * *---------------------------------------------------------------------- */intTclAccessDeleteProc(proc) TclAccessProc_ *proc;{ int retVal = TCL_ERROR; AccessProc *tmpAccessProcPtr = accessProcList; AccessProc *prevAccessProcPtr = NULL; /* * Traverse the 'accessProcList' looking for the particular node * whose 'proc' member matches 'proc' and remove that one from * the list. Ensure that the "default" node cannot be removed. */ while ((retVal == TCL_ERROR) && (tmpAccessProcPtr != &defaultAccessProc)) { if (tmpAccessProcPtr->proc == proc) { if (prevAccessProcPtr == NULL) { accessProcList = tmpAccessProcPtr->nextPtr; } else { prevAccessProcPtr->nextPtr = tmpAccessProcPtr->nextPtr; } Tcl_Free((char *)tmpAccessProcPtr); retVal = TCL_OK; } else { prevAccessProcPtr = tmpAccessProcPtr; tmpAccessProcPtr = tmpAccessProcPtr->nextPtr; } } return (retVal);}/* *---------------------------------------------------------------------- * * TclOpenFileChannelInsertProc -- * * Insert the passed procedure pointer at the head of the list of * functions which are used during a call to * 'Tcl_OpenFileChannel(...)'. The passed function should be have * exactly like 'Tcl_OpenFileChannel' when called during that time * (see 'Tcl_OpenFileChannel(...)' for more informatin). The * function will be added even if it already in the list. * * Results: * Normally TCL_OK; TCL_ERROR if memory for a new node in the list * could not be allocated. * * Side effects: * Memory allocataed and modifies the link list for * 'Tcl_OpenFileChannel' functions. * *---------------------------------------------------------------------- */intTclOpenFileChannelInsertProc(proc) TclOpenFileChannelProc_ *proc;{ int retVal = TCL_ERROR; if (proc != NULL) { OpenFileChannelProc *newOpenFileChannelProcPtr; newOpenFileChannelProcPtr = (OpenFileChannelProc *)Tcl_Alloc(sizeof(OpenFileChannelProc));; if (newOpenFileChannelProcPtr != NULL) { newOpenFileChannelProcPtr->proc = proc; newOpenFileChannelProcPtr->nextPtr = openFileChannelProcList; openFileChannelProcList = newOpenFileChannelProcPtr; retVal = TCL_OK; } } return (retVal);}/* *---------------------------------------------------------------------- * * TclOpenFileChannelDeleteProc -- * * Removed the passed function pointer from the list of * 'Tcl_OpenFileChannel' functions. Ensures that the built-in * open file channel function is not removvable. * * Results: * TCL_OK if the procedure pointer was successfully removed, * TCL_ERROR otherwise. * * Side effects: * Memory is deallocated and the respective list updated. * *---------------------------------------------------------------------- */intTclOpenFileChannelDeleteProc(proc) TclOpenFileChannelProc_ *proc;{ int retVal = TCL_ERROR; OpenFileChannelProc *tmpOpenFileChannelProcPtr = openFileChannelProcList; OpenFileChannelProc *prevOpenFileChannelProcPtr = NULL; /* * Traverse the 'openFileChannelProcList' looking for the particular * node whose 'proc' member matches 'proc' and remove that one from * the list. Ensure that the "default" node cannot be removed. */ while ((retVal == TCL_ERROR) && (tmpOpenFileChannelProcPtr != &defaultOpenFileChannelProc)) { if (tmpOpenFileChannelProcPtr->proc == proc) { if (prevOpenFileChannelProcPtr == NULL) { openFileChannelProcList = tmpOpenFileChannelProcPtr->nextPtr; } else { prevOpenFileChannelProcPtr->nextPtr = tmpOpenFileChannelProcPtr->nextPtr; } Tcl_Free((char *)tmpOpenFileChannelProcPtr); retVal = TCL_OK; } else { prevOpenFileChannelProcPtr = tmpOpenFileChannelProcPtr; tmpOpenFileChannelProcPtr = tmpOpenFileChannelProcPtr->nextPtr; } } return (retVal);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -