📄 tclmacfile.c
字号:
bufPtr->st_mode |= S_IXUSR | S_IXGRP | S_IXOTH; } if ((fpb.ioFlAttrib & 0x01) == 0){ /* * If not locked, then everyone has write acces. */ bufPtr->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; } bufPtr->st_ino = fpb.ioDirID; bufPtr->st_dev = fpb.ioVRefNum; bufPtr->st_uid = -1; bufPtr->st_gid = -1; bufPtr->st_rdev = 0; bufPtr->st_size = fpb.ioFlLgLen; bufPtr->st_blksize = vpb.ioVAlBlkSiz; bufPtr->st_blocks = (bufPtr->st_size + bufPtr->st_blksize - 1) / bufPtr->st_blksize; /* * The times returned by the Mac file system are in the * local time zone. We convert them to GMT so that the * epoch starts from GMT. This is also consistent with * what is returned from "clock seconds". */ bufPtr->st_atime = bufPtr->st_mtime = fpb.ioFlMdDat - TclpGetGMTOffset() + tcl_mac_epoch_offset; bufPtr->st_ctime = fpb.ioFlCrDat - TclpGetGMTOffset() + tcl_mac_epoch_offset; } } if (err != noErr) { errno = TclMacOSErrorToPosixError(err); } return (err == noErr ? 0 : -1);}/* *---------------------------------------------------------------------- * * Tcl_WaitPid -- * * Fakes a call to wait pid. * * Results: * Always returns -1. * * Side effects: * None. * *---------------------------------------------------------------------- */Tcl_PidTcl_WaitPid( Tcl_Pid pid, int *statPtr, int options){ return (Tcl_Pid) -1;}/* *---------------------------------------------------------------------- * * TclMacFOpenHack -- * * This function replaces fopen. It supports paths with alises. * Note, remember to undefine the fopen macro! * * Results: * See fopen documentation. * * Side effects: * See fopen documentation. * *---------------------------------------------------------------------- */#undef fopenFILE *TclMacFOpenHack( CONST char *path, CONST char *mode){ OSErr err; FSSpec fileSpec; Handle pathString = NULL; int size; FILE * f; err = FSpLocationFromPath(strlen(path), path, &fileSpec); if ((err != noErr) && (err != fnfErr)) { return NULL; } err = FSpPathFromLocation(&fileSpec, &size, &pathString); if ((err != noErr) && (err != fnfErr)) { return NULL; } HLock(pathString); f = fopen(*pathString, mode); HUnlock(pathString); DisposeHandle(pathString); return f;}/* *--------------------------------------------------------------------------- * * TclpGetUserHome -- * * This function takes the specified user name and finds their * home directory. * * Results: * The result is a pointer to a string specifying the user's home * directory, or NULL if the user's home directory could not be * determined. Storage for the result string is allocated in * bufferPtr; the caller must call Tcl_DStringFree() when the result * is no longer needed. * * Side effects: * None. * *---------------------------------------------------------------------- */char *TclpGetUserHome(name, bufferPtr) CONST char *name; /* User name for desired home directory. */ Tcl_DString *bufferPtr; /* Uninitialized or free DString filled * with name of user's home directory. */{ return NULL;}/* *---------------------------------------------------------------------- * * TclMacOSErrorToPosixError -- * * Given a Macintosh OSErr return the appropiate POSIX error. * * Results: * A Posix error. * * Side effects: * None. * *---------------------------------------------------------------------- */intTclMacOSErrorToPosixError( int error) /* A Macintosh error. */{ switch (error) { case noErr: return 0; case bdNamErr: return ENAMETOOLONG; case afpObjectTypeErr: return ENOTDIR; case fnfErr: case dirNFErr: return ENOENT; case dupFNErr: return EEXIST; case dirFulErr: case dskFulErr: return ENOSPC; case fBsyErr: return EBUSY; case tmfoErr: return ENFILE; case fLckdErr: case permErr: case afpAccessDenied: return EACCES; case wPrErr: case vLckdErr: return EROFS; case badMovErr: return EINVAL; case diffVolErr: return EXDEV; default: return EINVAL; }}intTclMacChmod( CONST char *path, int mode){ HParamBlockRec hpb; OSErr err; Str255 pathName; strcpy((char *) pathName + 1, path); pathName[0] = strlen(path); hpb.fileParam.ioNamePtr = pathName; hpb.fileParam.ioVRefNum = 0; hpb.fileParam.ioDirID = 0; if (mode & 0200) { err = PBHRstFLockSync(&hpb); } else { err = PBHSetFLockSync(&hpb); } if (err != noErr) { errno = TclMacOSErrorToPosixError(err); return -1; } return 0;}/* *---------------------------------------------------------------------- * * TclpTempFileName -- * * This function returns a unique filename. * * Results: * Returns a valid Tcl_Obj* with refCount 0, or NULL on failure. * * Side effects: * None. * *---------------------------------------------------------------------- */Tcl_Obj* TclpTempFileName(){ char fileName[L_tmpnam]; if (tmpnam(fileName) == NULL) { /* INTL: Native. */ return NULL; } return TclpNativeToNormalized((ClientData) fileName);}#ifdef S_IFLNKTcl_Obj* TclpObjLink(pathPtr, toPtr, linkAction) Tcl_Obj *pathPtr; Tcl_Obj *toPtr; int linkAction;{ Tcl_Obj* link = NULL; if (toPtr != NULL) { if (TclpObjAccess(pathPtr, F_OK) != -1) { /* src exists */ errno = EEXIST; return NULL; } if (TclpObjAccess(toPtr, F_OK) == -1) { /* target doesn't exist */ errno = ENOENT; return NULL; } if (linkAction & TCL_CREATE_SYMBOLIC_LINK) { /* Needs to create a new link */ FSSpec spec; FSSpec linkSpec; OSErr err; CONST char *path; err = FspLocationFromFsPath(toPtr, &spec); if (err != noErr) { errno = ENOENT; return NULL; } path = Tcl_FSGetNativePath(pathPtr); err = FSpLocationFromPath(strlen(path), path, &linkSpec); if (err == noErr) { err = dupFNErr; /* EEXIST. */ } else { err = CreateAliasFile(&linkSpec, &spec); } if (err != noErr) { errno = TclMacOSErrorToPosixError(err); return NULL; } return toPtr; } else { errno = ENODEV; return NULL; } } else { Tcl_DString ds; Tcl_Obj *transPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr); if (transPtr == NULL) { return NULL; } if (TclpReadlink(Tcl_GetString(transPtr), &ds) != NULL) { link = Tcl_NewStringObj(Tcl_DStringValue(&ds), -1); Tcl_IncrRefCount(link); Tcl_DStringFree(&ds); } } return link;}#endif/* *--------------------------------------------------------------------------- * * TclpFilesystemPathType -- * * This function is part of the native filesystem support, and * returns the path type of the given path. Right now it simply * returns NULL. In the future it could return specific path * types, like 'HFS', 'HFS+', 'nfs', 'samba', 'FAT32', etc. * * Results: * NULL at present. * * Side effects: * None. * *--------------------------------------------------------------------------- */Tcl_Obj*TclpFilesystemPathType(pathObjPtr) Tcl_Obj* pathObjPtr;{ /* All native paths are of the same type */ return NULL;}/* *--------------------------------------------------------------------------- * * TclpUtime -- * * Set the modification date for a file. * * Results: * 0 on success, -1 on error. * * Side effects: * None. * *--------------------------------------------------------------------------- */int TclpUtime(pathPtr, tval) Tcl_Obj *pathPtr; /* File to modify */ struct utimbuf *tval; /* New modification date structure */{ long gmt_offset=TclpGetGMTOffset(); struct utimbuf local_tval; local_tval.actime=tval->actime+gmt_offset; local_tval.modtime=tval->modtime+gmt_offset; return utime(Tcl_FSGetNativePath(Tcl_FSGetNormalizedPath(NULL,pathPtr)), &local_tval);}/* *--------------------------------------------------------------------------- * * CreateAliasFile -- * * Creates an alias file located at aliasDest referring to the targetFile. * * Results: * 0 on success, OS error code on error. * * Side effects: * None. * *--------------------------------------------------------------------------- */static OSErrCreateAliasFile(FSSpec *theAliasFile, FSSpec *targetFile){ CInfoPBRec cat; FInfo fndrInfo; AliasHandle theAlias; short saveRef, rsrc = -1; OSErr err; saveRef = CurResFile(); /* set up the Finder information record for the alias file */ cat.dirInfo.ioNamePtr = targetFile->name; cat.dirInfo.ioVRefNum = targetFile->vRefNum; cat.dirInfo.ioFDirIndex = 0; cat.dirInfo.ioDrDirID = targetFile->parID; err = PBGetCatInfoSync(&cat); if (err != noErr) goto bail; if ((cat.dirInfo.ioFlAttrib & 16) == 0) { /* file alias */ switch (cat.hFileInfo.ioFlFndrInfo.fdType) { case 'APPL': fndrInfo.fdType = kApplicationAliasType; break; case 'APPC': fndrInfo.fdType = kApplicationCPAliasType; break; case 'APPD': fndrInfo.fdType = kApplicationDAAliasType; break; default: fndrInfo.fdType = cat.hFileInfo.ioFlFndrInfo.fdType; break; } fndrInfo.fdCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator; } else { /* folder alias */ fndrInfo.fdType = kContainerFolderAliasType; fndrInfo.fdCreator = 'MACS'; } fndrInfo.fdFlags = kIsAlias; fndrInfo.fdLocation.v = 0; fndrInfo.fdLocation.h = 0; fndrInfo.fdFldr = 0; /* create new file and set the file information */ FSpCreateResFile( theAliasFile, fndrInfo.fdCreator, fndrInfo.fdType, smSystemScript); if ((err = ResError()) != noErr) goto bail; err = FSpSetFInfo( theAliasFile, &fndrInfo); if (err != noErr) goto bail; /* save the alias resource */ rsrc = FSpOpenResFile(theAliasFile, fsRdWrPerm); if (rsrc == -1) { err = ResError(); goto bail; } UseResFile(rsrc); err = NewAlias(theAliasFile, targetFile, &theAlias); if (err != noErr) goto bail; AddResource((Handle) theAlias, rAliasType, 0, theAliasFile->name); if ((err = ResError()) != noErr) goto bail; CloseResFile(rsrc); rsrc = -1; /* done */ bail: if (rsrc != -1) CloseResFile(rsrc); UseResFile(saveRef); return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -