Esempio n. 1
0
void LoadImportPLUG( MADLibrary		*inMADDriver, short	No, FSSpec	*theSpec)
{
	Handle		theRes;
	short		fileID;
	Str255		tStr;

	
	inMADDriver->ThePlug[ No].file = *theSpec;
	
	{
		Boolean		targetIsFolder, wasAliased;
		
		ResolveAliasFile( &inMADDriver->ThePlug[ No].file, true, &targetIsFolder, &wasAliased);
	}

	pStrCpy( inMADDriver->ThePlug[ No].filename, inMADDriver->ThePlug[ No].file.name);
	
	fileID = FSpOpenResFile( theSpec, fsCurPerm);
	
	/** CODE du Plug-in **/
	
	GetIndString( tStr, 1000, 1);
	BlockMoveData( tStr + 1, &inMADDriver->ThePlug[ No].type, 4);
	inMADDriver->ThePlug[ No].type[ 4] = 0;
	
	GetIndString( tStr, 1000, 2);
	BlockMoveData( tStr + 1, &inMADDriver->ThePlug[ No].mode, 4);
	
	GetIndString( inMADDriver->ThePlug[ No].MenuName, 1000, 3);
	GetIndString( inMADDriver->ThePlug[ No].AuthorString, 1000, 4);
	
	CloseResFile( fileID);
}
Esempio n. 2
0
static pascal void
GetSharedLibraryFilterProc(const CInfoPBRec* const inCpb, Boolean* inWantQuit, void *inFilterData)
{
	GetSharedLibraryFilterProcData* pFilterData = (GetSharedLibraryFilterProcData*) inFilterData;

	if ((inCpb->hFileInfo.ioFlAttrib & (1 << ioDirFlg)) == 0)
	{
		FSSpec	fragSpec;
		OSErr	tempErr;
		Str255	errName;
		Boolean	crap;
		UInt32	codeOffset;
		UInt32	codeLength;
		
		// it's a file
		
		// ¥ fix-me do we really want to allow all 'APPL's' for in which to find this library?
		switch (inCpb->hFileInfo.ioFlFndrInfo.fdType)
		{
			case kCFragLibraryFileType:
			case 'APPL':
				tempErr = FSMakeFSSpec(inCpb->hFileInfo.ioVRefNum, inCpb->hFileInfo.ioFlParID, inCpb->hFileInfo.ioNamePtr, &fragSpec);

				// this shouldn't fail
				if (noErr != tempErr)
				{
					return;
				}
				
				// resolve an alias if this was one
				tempErr = ResolveAliasFile(&fragSpec, true, &crap, &crap);

				// if got here we have a shlb (or app-like shlb)
				if (noErr != tempErr)
				{
					// probably couldn't resolve an alias
					return;
				}
		
				break;
			default:
				return;
		}
	
		// see if this symbol is in this fragment
		if (LibInPefContainer(&fragSpec, pFilterData->inName, &codeOffset, &codeLength))
			tempErr = GetDiskFragment(&fragSpec, codeOffset, codeLength, fragSpec.name, kLoadCFrag, &pFilterData->outID, &pFilterData->outAddress, errName);
		else
			return;
				
		// stop if we found a library by that name
		if (noErr == tempErr)
		{			
			*inWantQuit = true;
			pFilterData->outFound = true;
			pFilterData->outError = tempErr;
		}
	}
	// FSpIterateDirectory will automagically call us for subsequent sub-dirs if necessary
}
Esempio n. 3
0
DIR *
opendir (const char *name)           /* Open a directory stream on NAME. */
/* Return a DIR stream on the directory, or NULL if it could not be opened.  */
{
	CInfoPBRec cat_info;
	FSSpec spec;
	Boolean targetIsFolder, wasAliased;

	if (indx) {											// We don't support more than one dir open at a time
		closedir((DIR *)1);								// Fail hard
		return((DIR *)0);
		}
	dir_volume=0;										// Default to the application directory
	dir_ID=0;
	while (name[0]=='.') ++name;						// Don't allow leading '.', avoids device names
		CToPCpy(fname,name);
		if (!FSMakeFSSpec(0,0,fname,&spec)) {			// Figure out where user is pointing
			ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
			cat_info.dirInfo.ioCompletion=(IOCompletionUPP)0;
			cat_info.dirInfo.ioNamePtr=spec.name;
			cat_info.dirInfo.ioVRefNum=spec.vRefNum;
			cat_info.dirInfo.ioFDirIndex = 0;			// Use full spec
			cat_info.dirInfo.ioDrDirID=spec.parID;
			cat_info.dirInfo.ioFVersNum=0;
			if (!PBGetCatInfoSync(&cat_info) && (cat_info.dirInfo.ioFlAttrib&16)) 
				spec.parID=cat_info.dirInfo.ioDrDirID;	// Found it, save it's volume and dirID
			dir_volume=spec.vRefNum;
			dir_ID=spec.parID;
			}
		else return ((DIR *)0);
	indx=1;
	return((DIR *)1);
	}
Esempio n. 4
0
/* This function is an adaptation of the function FSpLocationFromPath in
   tclMacUtils.c in the Tcl 8.0 distribution */
OSErr FSMakeFSSpecFromPath(ConstStr255Param fileName, FSSpecPtr spec)
{
  Boolean isDir, wasAlias;
  int pos, end;
  OSErr err;
  Str255 Name;
  short vRefNum;
  long dirID;
  
  /* get the initial directory information and set up first path component */
  CopyNamePart(Name, fileName, 1);
  if (Name[0] < fileName[0] && Name[1] != ':') { /* absolute path */
    Name[0]++;
    Name[Name[0]] = ':';
    if ((err = FSMakeFSSpec(0, 0, Name, spec)) != noErr)
      return err;
    if ((err = FSpGetDirectoryID(spec, &dirID, &isDir)) != noErr)
      return err;
    if (! isDir)
      return dirNFErr;
    vRefNum = spec->vRefNum;
    pos = Name[0] + 1;
    CopyNamePart(Name, fileName, pos);
  }
  else {
    dirID = 0;
    vRefNum = 0;
    pos = 1;
    isDir = true;
  }
  
  /* process remaining path parts */
  end = fileName[0] + 1;
  while (true) {
    if ((err = FSMakeFSSpec(vRefNum, dirID, Name[0] == 0 ? NULL : Name,
                            spec)) != noErr ||
        (err = ResolveAliasFile(spec, true, &isDir, &wasAlias)) != noErr)
      return err;
    pos += Name[0];
    if (pos < end) {
      if ((err = FSpGetDirectoryID(spec, &dirID, &isDir)) != noErr)
        return err;
      if (! isDir)
        return dirNFErr;
      vRefNum = spec->vRefNum;
      CopyNamePart(Name, fileName, pos);
    }
    else
      return noErr;
  }
}
Esempio n. 5
0
void SaveGlobalMacros(NewMacroInfo *macrost)
{
	OSErr err;
	FSSpec macroFile;
	Boolean dummy1, dummy2;
	Str255 tempString;

	GetIndString(tempString, MISC_STRINGS, MACROS_FILE_NAME);
	err = FSMakeFSSpec(TelInfo->PrefFolder.vRefNum, TelInfo->PrefFolder.parID, tempString, &macroFile);
	if ((!err) || (err == -43)) {
		ResolveAliasFile(&macroFile, FALSE, &dummy1, &dummy2);
		saveMacros(macrost, &macroFile);
	}
}
Esempio n. 6
0
static int fetchFileSpec(FSSpec *spec,unsigned char *name,long *parentDirectory) {
    long        aliasGestaltInfo;
    CInfoPBRec  pb;
    Boolean     result,ignore;
    FSSpec      spec2;
    OSErr       err;
        
    pb.hFileInfo.ioNamePtr = name;
    pb.hFileInfo.ioFVersNum = 0;
    pb.hFileInfo.ioFDirIndex = 0;
    pb.hFileInfo.ioVRefNum = spec->vRefNum;
    pb.hFileInfo.ioDirID = spec->parID;

    if (PBGetCatInfoSync(&pb) == noErr) {
    	if (pb.hFileInfo.ioFlFndrInfo.fdFlags & kIsAlias) {     	   
    	   err = FSMakeFSSpecCompat(spec->vRefNum, spec->parID, name,&spec2);
    #if TARGET_CPU_PPC
           if ((Gestalt(gestaltAliasMgrAttr, &aliasGestaltInfo) == noErr) &&
                aliasGestaltInfo & (1<<gestaltAliasMgrResolveAliasFileWithMountOptions)  &&
                ((Ptr) ResolveAliasFileWithMountFlags != (Ptr)kUnresolvedCFragSymbolAddress)) {
                err = ResolveAliasFileWithMountFlags(&spec2,false,&ignore,&ignore,kResolveAliasFileNoUI);
            } 
            else 
    #endif
    			err = ResolveAliasFile(&spec2,false,&ignore,&ignore);
                if (err == noErr) {
             	    fetchFileSpec(&spec2,spec2.name,parentDirectory);
            	    *spec = spec2;
                    result = true;
                    goto done;
    		    }
    	}
        spec->parID = pb.hFileInfo.ioDirID;
        result = true;
        goto done;
    }
    result = false;
    
    done:
        if (parentDirectory != nil)
            *parentDirectory = pb.dirInfo.ioDrParID;
        return result;
}
Esempio n. 7
0
void CheckGlobalMacros(void)
{
	OSErr err;
	FSSpec macroFile;
	Boolean dummy1, dummy2;
	Str255 tempString;

// RAB BetterTelnet 2.0b5
// if there's no global file, we have to get our default from the resource fork...
// we load them first just in case we have OLD macros in the macros file, in which case
// we have to add them to the defaults rather than replace the default

	GetDefaultMacros();

	GetIndString(tempString, MISC_STRINGS, MACROS_FILE_NAME);
	err = FSMakeFSSpec(TelInfo->PrefFolder.vRefNum, TelInfo->PrefFolder.parID, tempString, &macroFile);
	if (!err) {
		ResolveAliasFile(&macroFile, FALSE, &dummy1, &dummy2);
		loadMacros(&TelInfo->newMacros, &macroFile);
	}
}
Esempio n. 8
0
	uint16_t AliasDispatch(uint16_t trap)
	{

		uint16_t selector = cpuGetDReg(0);

		Log("%04x AliasDispatch($%04x)\n", trap, selector);

		switch (selector)
		{

			case 0x000c:
				return ResolveAliasFile();
				break;

			default:
					fprintf(stderr, "AliasDispatch: selector $%04x not implemented\n", 
					selector);
				exit(1);		
		}


		return 0;
	}
int	__open_file(const char * name, __file_modes mode, __file_handle * handle)
{
	FSSpec					spec;
	OSErr						ioResult;
	HParamBlockRec	pb;
	
	ioResult = __path2fss(name, &spec);
	
	if (ioResult) 
		gSqueakFileLastError = ioResult;
		
	if (__system7present())												/* mm 980424 */
	{																	/* mm 980424 */
		Boolean targetIsFolder, wasAliased;								/* mm 980424 */
		ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);	/* mm 980424 */
	}																	/* mm 980424 */
	
	if (ioResult && (ioResult != fnfErr || mode.open_mode == __must_exist))
		return(__io_error);
	
	
#if TARGET_API_MAC_CARBON
	if (ioResult) {
        CFStringRef 	filePath;
        CFURLRef 	    sillyThing, sillyThing2;
        FSRef	        parentFSRef;
    	short int       fileRefNum;
        OSErr           err;
        UniChar         buffer[1024];
        long            tokenLength;
        
		
        filePath   = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)name,strlen(name),gCurrentVMEncoding,false);
        if (filePath == nil) 
            return __io_error;
        sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false);
        CFRelease(filePath);
        sillyThing2 = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault,sillyThing);
        err = CFURLGetFSRef(sillyThing2,&parentFSRef);
        if (err == 0) {
            CFRelease(sillyThing);
            CFRelease(sillyThing2);
            return fnfErr;  
        }
        filePath = CFURLCopyLastPathComponent(sillyThing);
        tokenLength = CFStringGetLength(filePath);
        if (tokenLength > 1024) {
            CFRelease(filePath);
            CFRelease(sillyThing);
            CFRelease(sillyThing2);
            return(__io_error);
        }
            
        CFStringGetCharacters(filePath,CFRangeMake(0,tokenLength),buffer);

        CFRelease(filePath);
        CFRelease(sillyThing);
        CFRelease(sillyThing2);

		ioResult = FSCreateFileUnicode(&parentFSRef,tokenLength,buffer,kFSCatInfoNone,NULL,NULL,&spec);  
    	if (ioResult)
			gSqueakFileLastError = ioResult;
    	if (ioResult)
	    	return(__io_error);
	    	
        pb.ioParam.ioNamePtr    = spec.name;
    	pb.ioParam.ioVRefNum    = spec.vRefNum;
    	pb.ioParam.ioPermssn    = (mode.io_mode == __read) ? fsRdPerm : fsRdWrPerm;
    	pb.ioParam.ioMisc       = 0;
    	pb.fileParam.ioFVersNum = 0;
    	pb.fileParam.ioDirID    = spec.parID;
		set_file_type(&spec, mode.binary_io);
		ioResult = PBHOpenDFSync(&pb);  /* HH 10/25/97  was PBHOpenSync */
    	    	
    	if (ioResult)
    		return(__io_error);
    	
    	*handle = pb.ioParam.ioRefNum;
	
	    return(__no_io_error);
	}
#endif
    pb.ioParam.ioNamePtr    = spec.name;
	pb.ioParam.ioVRefNum    = spec.vRefNum;
	pb.ioParam.ioPermssn    = (mode.io_mode == __read) ? fsRdPerm : fsRdWrPerm;
	pb.ioParam.ioMisc       = 0;
	pb.fileParam.ioFVersNum = 0;
	pb.fileParam.ioDirID    = spec.parID;
	
	if (ioResult)
	{
		if (!(ioResult = PBHCreateSync(&pb)))
		{
			if (ioResult) 
				gSqueakFileLastError = ioResult;
			set_file_type(&spec, mode.binary_io);
			ioResult = PBHOpenDFSync(&pb);  /* HH 10/25/97  was PBHOpenSync */
			if (ioResult) 
				gSqueakFileLastError = ioResult;
		}
	}
	else
	{
		if (!(ioResult = PBHOpenDFSync(&pb)) && mode.open_mode == __create_or_truncate)  
		                                  /* HH 10/25/97  was PBHOpenSync */
		{
			pb.ioParam.ioMisc = 0;
			
			ioResult = PBSetEOFSync((ParmBlkPtr) &pb);
			
			if (ioResult)
				gSqueakFileLastError = ioResult;

			if (ioResult)
				PBCloseSync((ParmBlkPtr) &pb);
		} else {
			if (ioResult) 
				gSqueakFileLastError = ioResult;

		}
	}
	
	if (ioResult)
		return(__io_error);
	
	*handle = pb.ioParam.ioRefNum;
	
	return(__no_io_error);
}
Esempio n. 10
0
/*Get the file ID that unique IDs this file or directory, also resolve any alias if required */
int fetchFileInfo(int dirIndex,FSSpec *spec,unsigned char *name,Boolean doAlias,long *parentDirectory,
 int *isFolder,int *createDateStorage,int *modificationDateStorage,squeakFileOffsetType *sizeOfFile,Str255 *longFileName) {
    long        aliasGestaltInfo;
    CInfoPBRec pb;
    Boolean     isFolder2;
    OSErr	error,result;
    
    *isFolder = false;
        
    pb.hFileInfo.ioNamePtr = name;
    pb.hFileInfo.ioFVersNum = 0;
    pb.hFileInfo.ioFDirIndex = dirIndex;
    pb.hFileInfo.ioVRefNum = spec->vRefNum;
    pb.hFileInfo.ioDirID = spec->parID;

    if ((error = PBGetCatInfoSync(&pb)) == noErr) {
    	if ((pb.hFileInfo.ioFlFndrInfo.fdFlags & kIsAlias) && doAlias) {
		    FSSpec spec2,spec3;
		    Boolean isAlias;
		    OSErr   err;
		    
		   
		   err = FSMakeFSSpecCompat(spec->vRefNum, spec->parID, name,&spec2);
           spec3 = spec2;
#if TARGET_CPU_PPC
           if ((Gestalt(gestaltAliasMgrAttr, &aliasGestaltInfo) == noErr) &&
                aliasGestaltInfo & (1<<gestaltAliasMgrResolveAliasFileWithMountOptions)  &&
                ((Ptr) ResolveAliasFileWithMountFlags != (Ptr)kUnresolvedCFragSymbolAddress)) {
                err = ResolveAliasFileWithMountFlags(&spec2,false,&isFolder2,&isAlias,kResolveAliasFileNoUI);
            } else {
                err = ResolveAliasFile(&spec2,false,&isFolder2,&isAlias);
            }
#else
			err = ResolveAliasFile(&spec2,false,&isFolder2,&isAlias);
#endif         
			*isFolder = isFolder2;
            if (err == noErr) {
                resolveLongName(0,0,nil,&spec3,*isFolder,longFileName,sizeOfFile);
                result = noErr;
                goto done;
		    }
    	}
    	
    	if ((pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0)
    	    *sizeOfFile = 0;
    	else
            *sizeOfFile =  pb.hFileInfo.ioFlLgLen;
            
        resolveLongName(pb.hFileInfo.ioVRefNum,pb.hFileInfo.ioFlParID,name,nil,((pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) > 0),longFileName,sizeOfFile);
        spec->parID = pb.hFileInfo.ioDirID;
        result = noErr;
        goto done;
    }
    result = error;
    memcpy(longFileName,name,sizeof(StrFileName));
    
    done:
    *isFolder = ((pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) > 0) || *isFolder;
    *createDateStorage =  pb.hFileInfo.ioFlCrDat;
    *modificationDateStorage =  pb.hFileInfo.ioFlMdDat;
    *parentDirectory = pb.dirInfo.ioDrParID;
    return result;
}
Esempio n. 11
0
sqInt	ioFilenamefromStringofLengthresolveAliases(char* dst, char* src, sqInt num, sqInt resolveAlias) {
        FSRef		theFSRef;
        FSSpec		convertFileNameSpec,failureRetry;
        OSErr		err;
        Boolean		isFolder=false,isAlias=false;
        CFURLRef 	sillyThing,appendedSillyThing;
        CFStringRef 	lastPartOfPath,filePath2;
		CFMutableStringRef filePath;
        
        *dst = 0x00;
        err = quicklyMakePath((char *) src,num,dst,resolveAlias);
        if (err == noErr) 
            return;
            
        err = lookupPath((char *) src,num,&convertFileNameSpec,true,false);
        if ((err == noErr) && resolveAlias) {
            err = ResolveAliasFile(&convertFileNameSpec,true,&isFolder,&isAlias);
            if (err == fnfErr) {
				err = lookupPath((char *) src,num,&convertFileNameSpec,false,false);
	            err = ResolveAliasFile(&convertFileNameSpec,true,&isFolder,&isAlias);
            }
        }
        
        if (err == fnfErr) {
            failureRetry = convertFileNameSpec;
            CopyCStringToPascal("::",failureRetry.name);
            err = FSpMakeFSRef(&failureRetry,&theFSRef);
            if (err != noErr) 
                return;
//            filePath   = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)src,num,gCurrentVMEncoding,false);
			CFStringRef tmpStrRef = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)src,num,gCurrentVMEncoding,false);
            if (tmpStrRef == nil) 
                return;
			filePath = CFStringCreateMutableCopy(NULL, 0, tmpStrRef);
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(filePath, kCFStringNormalizationFormKD); // canonical decomposition

            sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false);
            CFRelease(filePath);
			if (sillyThing == NULL) 
					return;

            lastPartOfPath = CFURLCopyLastPathComponent(sillyThing);
            CFRelease(sillyThing);
            sillyThing = CFURLCreateFromFSRef(kCFAllocatorDefault,&theFSRef);
            appendedSillyThing = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,sillyThing,lastPartOfPath,false);
#if defined(__MWERKS__) && !defined(__APPLE__) && !defined(__MACH__)
            filePath2 = CFURLCopyFileSystemPath (appendedSillyThing, kCFURLHFSPathStyle);
#else
            filePath2 = CFURLCopyFileSystemPath (appendedSillyThing, kCFURLPOSIXPathStyle);
#endif
            CFStringGetCString (filePath2,dst,1000, gCurrentVMEncoding);
            CFRelease(sillyThing);
            CFRelease(appendedSillyThing);
            CFRelease(lastPartOfPath);
            CFRelease(filePath2);        
            return; 
        }
        	
        err = FSpMakeFSRef(&convertFileNameSpec,&theFSRef);
#if defined(__MWERKS__) && !defined(__APPLE__) && !defined(__MACH__)
		sillyThing = CFURLCreateFromFSRef(kCFAllocatorDefault,&theFSRef);
        filePath = CFURLCopyFileSystemPath (sillyThing, kCFURLHFSPathStyle);
        CFStringGetCString (filePath,dst,1000, gCurrentVMEncoding);
		CFRelease(sillyThing);
        CFRelease(filePath);        
        return;
 #else
        err = FSRefMakePath(&theFSRef,(UInt8 *)dst,1000); 
 #endif
}
/*
 *  int open(const char *path, int oflag)
 *
 *      Opens a file stream.
 */
int my_open(char *path, int oflag)
{
    FSSpec          spec;
    char            permission;
    HParamBlockRec  hpb;
    OSErr           err, errno;
    Boolean targetIsFolder, wasAliased;

    AssertStr(path,path)

    /* Setup permission */
    if ((oflag & 0x03) == O_RDWR)
        permission = fsRdWrPerm;
    else
        permission = (oflag & O_RDONLY) ? fsRdPerm : 0 + (oflag & O_WRONLY) ? fsWrPerm : 0;

        FSpLocationFromFullPath(strlen(path),path, &spec);
        if ((oflag & (O_ALIAS | O_NRESOLVE)) == 0)
            ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
        hpb.fileParam.ioNamePtr = spec.name;
        hpb.fileParam.ioVRefNum = spec.vRefNum;
        hpb.fileParam.ioDirID = spec.parID;
        hpb.ioParam.ioPermssn = permission;

        if (oflag & O_RSRC)         /* open the resource fork of the file */
            err = PBHOpenRFSync(&hpb);
        else                        /* open the data fork of the file */
            err = PBHOpenDFSync(&hpb);

    if ((err == fnfErr) && (oflag & O_CREAT)) {
        hpb.fileParam.ioFlVersNum = 0;
        err = PBHCreateSync(&hpb);
        if (err == noErr) {
            /* Set the finder info */
            unsigned long secs;
            unsigned long isbinary = oflag & O_BINARY;

            hpb.fileParam.ioFlFndrInfo.fdType = '\?\?\?\?';
            hpb.fileParam.ioFlFndrInfo.fdCreator = '\?\?\?\?';
            hpb.fileParam.ioFlFndrInfo.fdFlags = 0;
            if (oflag & O_ALIAS)        /* set the alias bit */
                hpb.fileParam.ioFlFndrInfo.fdFlags = kIsAlias;
            else                                        /* clear all flags */
                hpb.fileParam.ioFlFndrInfo.fdFlags = 0;

            GetDateTime(&secs);
            hpb.fileParam.ioFlCrDat = hpb.fileParam.ioFlMdDat = secs;
            PBHSetFInfoSync(&hpb);
        }

        if (err && (err != dupFNErr)) {
            errno = err; return -1;
        }

            if (oflag & O_RSRC)         /* open the resource fork of the file */
                err = PBHOpenRFSync(&hpb);
            else                        /* open the data fork of the file */
                err = PBHOpenDFSync(&hpb);
    }

    if (err && (err != dupFNErr) && (err != opWrErr)) {
        errno = err; return -1;
    }

    if (oflag & O_TRUNC) {
        IOParam pb;

        pb.ioRefNum = hpb.ioParam.ioRefNum;
        pb.ioMisc = 0L;
        err = PBSetEOFSync((ParmBlkPtr)&pb);
        if (err != noErr) {
            errno = err; return -1;
        }
    }

    if (oflag & O_APPEND) lseek(hpb.ioParam.ioRefNum,0,SEEK_END);

    return (hpb.ioParam.ioRefNum);
}
Esempio n. 13
0
void NScanDirImportPlug( MADLibrary		*inMADDriver, long dirID, short VRefNum, Str255	Fname)
{
	CInfoPBRec		info;
	Str255			tempStr;
	short			i;
	Boolean			targetIsFolder, wasAliased;
	FSSpec			theSpec;
	FInfo			fndrInfo;

	info.hFileInfo.ioNamePtr = tempStr;
	info.hFileInfo.ioVRefNum = VRefNum;
	
	for (i = 1; true; i ++)
	{
		info.hFileInfo.ioDirID			= dirID;
		info.hFileInfo.ioFDirIndex		= i;
		
		if (PBGetCatInfoSync( &info) != noErr) break;
		
		FSMakeFSSpec( info.hFileInfo.ioVRefNum, dirID, info.hFileInfo.ioNamePtr, &theSpec);
		ResolveAliasFile( &theSpec, true, &targetIsFolder, &wasAliased);
		FSpGetFInfo( &theSpec, &fndrInfo);
		
		if( targetIsFolder)			//if((info.hFileInfo.ioFlAttrib & 16))
		{
			if( Fname[ 0] > 0)
			{
				if( EqualString( info.hFileInfo.ioNamePtr, Fname, false, false) || PlugsFolderOK > 0)	// == true ||
				//	EqualString( theSpec.name, Fname, false, false) == true)
				{
					CInfoPBRec		ci;

					ci.hFileInfo.ioNamePtr 		= theSpec.name;
					ci.hFileInfo.ioVRefNum 		= theSpec.vRefNum;
					ci.hFileInfo.ioDirID  		= theSpec.parID;
					ci.hFileInfo.ioFDirIndex	= 0;
					
					PBGetCatInfoSync( &ci);
					
					PlugsFolderOK++;
					
					NScanDirImportPlug( inMADDriver, ci.hFileInfo.ioDirID, ci.hFileInfo.ioVRefNum, Fname);
					
					PlugsFolderOK--;
				}
			}
		}
		
#if CALL_NOT_IN_CARBON
		
		else if( fndrInfo.fdType == 'IMPL')
		
#else
		
		else if( fndrInfo.fdType == 'shlb')
		
#endif
		
		{
			if( inMADDriver->TotalPlug < MAXPLUG)
			{
				LoadImportPLUG( inMADDriver, inMADDriver->TotalPlug, &theSpec);
				inMADDriver->TotalPlug++;
			}
		}
	}
}
Esempio n. 14
0
static int
FSpLocationFromPathAlias(
    int length,			/* Length of path. */
    CONST char *path,		/* The path to convert. */
    FSSpecPtr fileSpecPtr,	/* On return the spec for the path. */
    Boolean resolveLink)	/* Resolve the last path component? */
{
    Str255 fileName;
    OSErr err;
    short vRefNum;
    long dirID;
    int pos, cur;
    Boolean isDirectory;
    Boolean wasAlias=FALSE;
    FSSpec lastFileSpec;

    /*
     * Check to see if this is a full path.  If partial
     * we assume that path starts with the current working
     * directory.  (Ie. volume & dir = 0)
     */
    vRefNum = 0;
    dirID = 0;
    cur = 0;
    if (length == 0) {
        return fnfErr;
    }
    if (path[cur] == ':') {
	cur++;
	if (cur >= length) {
	    /*
	     * If path = ":", just return current directory.
	     */
	    FSMakeFSSpecCompat(0, 0, NULL, fileSpecPtr);
	    return noErr;
	}
    } else {
	while (path[cur] != ':' && cur < length) {
	    cur++;
	}
	if (cur > 255) {
	    return bdNamErr;
	}
	if (cur < length) {
	    /*
	     * This is a full path
	     */
	    cur++;
	    strncpy((char *) fileName + 1, path, cur);
	    fileName[0] = cur;
	    err = FSMakeFSSpecCompat(0, 0, fileName, fileSpecPtr);
	    if (err != noErr) return err;
	    FSpGetDirectoryID(fileSpecPtr, &dirID, &isDirectory);
	    vRefNum = fileSpecPtr->vRefNum;
	} else {
	    cur = 0;
	}
    }
    
    isDirectory = 1;
    while (cur < length) {
	if (!isDirectory) {
	    return dirNFErr;
	}
	pos = cur;
	while (path[pos] != ':' && pos < length) {
	    pos++;
	}
	if (pos == cur) {
	    /* Move up one dir */
	    /* cur++; */
	    strcpy((char *) fileName + 1, "::");
	    fileName[0] = 2;
	} else if (pos - cur > 255) {
	    return bdNamErr;
	} else {
	    strncpy((char *) fileName + 1, &path[cur], pos - cur);
	    fileName[0] = pos - cur;
	}
	err = FSMakeFSSpecCompat(vRefNum, dirID, fileName, fileSpecPtr);
	if (err != noErr) return err;
	lastFileSpec=*fileSpecPtr;
	err = ResolveAliasFile(fileSpecPtr, true, &isDirectory, &wasAlias);
	if (err != noErr) {
	    /* ignore alias resolve errors on last path component */
	    if (pos < length) return err;
	    else *fileSpecPtr=lastFileSpec;
	}
	FSpGetDirectoryID(fileSpecPtr, &dirID, &isDirectory);
	vRefNum = fileSpecPtr->vRefNum;
	cur = pos;
	if (path[cur] == ':') {
	    cur++;
	}
    }
    
    if(!resolveLink && wasAlias)
    	*fileSpecPtr=lastFileSpec;
    
    return noErr;
}