⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tclunixfcmd.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 3 页
字号:
static intTraversalDelete(src, ignore, sbPtr, type, errorPtr)     char *src;			/* Source pathname. */    char *ignore;		/* Destination pathname (not used). */    struct stat *sbPtr;		/* Stat info for file specified by src. */    int type;                   /* Reason for call - see TraverseUnixTree(). */    Tcl_DString *errorPtr;	/* If non-NULL, initialized DString for				 * error return. */{    switch (type) {        case DOTREE_F:	    if (unlink(src) == 0) {		return TCL_OK;	    }	    break;        case DOTREE_PRED:	    return TCL_OK;        case DOTREE_POSTD:	    if (rmdir(src) == 0) {		return TCL_OK;	    }	    break;	        }    if (errorPtr != NULL) {	Tcl_DStringAppend(errorPtr, src, -1);    }    return TCL_ERROR;}/* *---------------------------------------------------------------------- * * CopyFileAtts * *      Copy the file attributes such as owner, group, permissions, and *      modification date from one file to another. * * Results: *      Standard Tcl result. * * Side effects: *      user id, group id, permission bits, last modification time, and  *      last access time are updated in the new file to reflect the old *      file. *       *---------------------------------------------------------------------- */static intCopyFileAtts(src, dst, statBufPtr)     char *src;                 /* Path name of source file */    char *dst;                 /* Path name of target file */    struct stat *statBufPtr;   /* ptr to stat info for source file */{    struct utimbuf tval;    mode_t newMode;        newMode = statBufPtr->st_mode	    & (S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO);	    /*      * Note that if you copy a setuid file that is owned by someone     * else, and you are not root, then the copy will be setuid to you.     * The most correct implementation would probably be to have the     * copy not setuid to anyone if the original file was owned by      * someone else, but this corner case isn't currently handled.     * It would require another lstat(), or getuid().     */        if (chmod(dst, newMode)) {	newMode &= ~(S_ISUID | S_ISGID);	if (chmod(dst, newMode)) {	    return TCL_ERROR;	}    }    tval.actime = statBufPtr->st_atime;     tval.modtime = statBufPtr->st_mtime;     if (utime(dst, &tval)) {	return TCL_ERROR;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * GetGroupAttribute * *      Gets the group attribute of a file. * * Results: *      Standard TCL result. Returns a new Tcl_Obj in attributePtrPtr *	if there is no error. * * Side effects: *      A new object is allocated. *       *---------------------------------------------------------------------- */static intGetGroupAttribute(interp, objIndex, fileName, attributePtrPtr)    Tcl_Interp *interp;		/* The interp we are using for errors. */    int objIndex;		/* The index of the attribute. */    char *fileName;		/* The name of the file. */    Tcl_Obj **attributePtrPtr;	/* A pointer to return the object with. */{    struct stat statBuf;    struct group *groupPtr;    if (TclStat(fileName, &statBuf) != 0) {	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"could not stat file \"", fileName, "\": ",		Tcl_PosixError(interp), (char *) NULL);	return TCL_ERROR;    }    groupPtr = getgrgid(statBuf.st_gid);    if (groupPtr == NULL) {	*attributePtrPtr = Tcl_NewIntObj(statBuf.st_gid);    } else {	*attributePtrPtr = Tcl_NewStringObj(groupPtr->gr_name, -1);    }    endgrent();    return TCL_OK;}/* *---------------------------------------------------------------------- * * GetOwnerAttribute * *      Gets the owner attribute of a file. * * Results: *      Standard TCL result. Returns a new Tcl_Obj in attributePtrPtr *	if there is no error. * * Side effects: *      A new object is allocated. *       *---------------------------------------------------------------------- */static intGetOwnerAttribute(interp, objIndex, fileName, attributePtrPtr)    Tcl_Interp *interp;		/* The interp we are using for errors. */    int objIndex;		/* The index of the attribute. */    char *fileName;		/* The name of the file. */    Tcl_Obj **attributePtrPtr;	/* A pointer to return the object with. */{    struct stat statBuf;    struct passwd *pwPtr;    if (TclStat(fileName, &statBuf) != 0) {	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"could not stat file \"", fileName, "\": ",		Tcl_PosixError(interp), (char *) NULL);	return TCL_ERROR;    }    pwPtr = getpwuid(statBuf.st_uid);    if (pwPtr == NULL) {	*attributePtrPtr = Tcl_NewIntObj(statBuf.st_uid);    } else {	*attributePtrPtr = Tcl_NewStringObj(pwPtr->pw_name, -1);    }    endpwent();    return TCL_OK;}/* *---------------------------------------------------------------------- * * GetPermissionsAttribute * *      Gets the group attribute of a file. * * Results: *      Standard TCL result. Returns a new Tcl_Obj in attributePtrPtr *	if there is no error. The object will have ref count 0. * * Side effects: *      A new object is allocated. *       *---------------------------------------------------------------------- */static intGetPermissionsAttribute(interp, objIndex, fileName, attributePtrPtr)    Tcl_Interp *interp;		    /* The interp we are using for errors. */    int objIndex;		    /* The index of the attribute. */    char *fileName;		    /* The name of the file. */    Tcl_Obj **attributePtrPtr;	    /* A pointer to return the object with. */{    struct stat statBuf;    char returnString[6];    if (TclStat(fileName, &statBuf) != 0) {	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"could not stat file \"", fileName, "\": ",		Tcl_PosixError(interp), (char *) NULL);	return TCL_ERROR;    }    sprintf(returnString, "%0#5lo", (statBuf.st_mode & 0x00007FFF));    *attributePtrPtr = Tcl_NewStringObj(returnString, -1);        return TCL_OK;}/* *---------------------------------------------------------------------- * * SetGroupAttribute * *      Sets the file to the given group. * * Results: *      Standard TCL result. * * Side effects: *      The group of the file is changed. *       *---------------------------------------------------------------------- */static intSetGroupAttribute(interp, objIndex, fileName, attributePtr)    Tcl_Interp *interp;		    /* The interp we are using for errors. */    int objIndex;		    /* The index of the attribute. */    char *fileName;		    /* The name of the file. */    Tcl_Obj *attributePtr;	    /* The attribute to set. */{    gid_t groupNumber;    long placeHolder;    if (Tcl_GetLongFromObj(interp, attributePtr, &placeHolder) != TCL_OK) {	struct group *groupPtr;	char *groupString = Tcl_GetStringFromObj(attributePtr, NULL);	Tcl_ResetResult(interp);	groupPtr = getgrnam(groupString);	if (groupPtr == NULL) {	    endgrent();	    Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		    "could not set group for file \"", fileName,		    "\": group \"", groupString, "\" does not exist",		    (char *) NULL);	    return TCL_ERROR;	}	groupNumber = groupPtr->gr_gid;    } else {	groupNumber = (gid_t) placeHolder;    }    if (chown(fileName, -1, groupNumber) != 0) {	endgrent();	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"could not set group for file \"", fileName, "\": ",		Tcl_PosixError(interp), (char *) NULL);	return TCL_ERROR;    }        endgrent();    return TCL_OK;}/* *---------------------------------------------------------------------- * * SetOwnerAttribute * *      Sets the file to the given owner. * * Results: *      Standard TCL result. * * Side effects: *      The group of the file is changed. *       *---------------------------------------------------------------------- */static intSetOwnerAttribute(interp, objIndex, fileName, attributePtr)    Tcl_Interp *interp;		    /* The interp we are using for errors. */    int objIndex;		    /* The index of the attribute. */    char *fileName;		    /* The name of the file. */    Tcl_Obj *attributePtr;	    /* The attribute to set. */{    uid_t userNumber;    long placeHolder;    if (Tcl_GetLongFromObj(interp, attributePtr, &placeHolder) != TCL_OK) {	struct passwd *pwPtr;	char *ownerString = Tcl_GetStringFromObj(attributePtr, NULL);	Tcl_ResetResult(interp);	pwPtr = getpwnam(ownerString);	if (pwPtr == NULL) {	    Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		    "could not set owner for file \"", fileName,		    "\": user \"", ownerString, "\" does not exist",		    (char *) NULL);	    return TCL_ERROR;	}	userNumber = pwPtr->pw_uid;    } else {	userNumber = (uid_t) placeHolder;    }    if (chown(fileName, userNumber, -1) != 0) {	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"could not set owner for file \"", fileName, "\": ",		Tcl_PosixError(interp), (char *) NULL);	return TCL_ERROR;    }    	    return TCL_OK;}/* *---------------------------------------------------------------------- * * SetPermissionsAttribute * *      Sets the file to the given group. * * Results: *      Standard TCL result. * * Side effects: *      The group of the file is changed. *       *---------------------------------------------------------------------- */static intSetPermissionsAttribute(interp, objIndex, fileName, attributePtr)    Tcl_Interp *interp;		    /* The interp we are using for errors. */    int objIndex;		    /* The index of the attribute. */    char *fileName;		    /* The name of the file. */    Tcl_Obj *attributePtr;	    /* The attribute to set. */{    long modeInt;    mode_t newMode;    /*     * mode_t is a long under SPARC; an int under SunOS. Since we do not     * know how big it really is, we get the long and then cast it     * down to a mode_t.     */        if (Tcl_GetLongFromObj(interp, attributePtr, &modeInt)	    != TCL_OK) {	return TCL_ERROR;    }    newMode = (mode_t) modeInt;    if (chmod(fileName, newMode) != 0) {	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),		"could not set permissions for file \"", fileName, "\": ",		Tcl_PosixError(interp), (char *) NULL);	return TCL_ERROR;    }    return TCL_OK;}/* *--------------------------------------------------------------------------- * * TclpListVolumes -- * *	Lists the currently mounted volumes, which on UNIX is just /. * * Results: *	A standard Tcl result.  Will always be TCL_OK, since there is no way *	that this command can fail.  Also, the interpreter's result is set to  *	the list of volumes. * * Side effects: *	None. * *--------------------------------------------------------------------------- */intTclpListVolumes(interp)    Tcl_Interp *interp;			/* Interpreter to which to pass					 * the volume list. */{    Tcl_Obj *resultPtr;        resultPtr = Tcl_GetObjResult(interp);    Tcl_SetStringObj(resultPtr, "/", 1);    return TCL_OK;	}

⌨️ 快捷键说明

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