예제 #1
0
static OSErr MacFSSpec2FullPathname(const FSSpec *inFSS, char **outPathname)
{
	OSErr err;
	Handle h;
	short fullPathLength;
	static char *fullPath = NULL;
	
	if (fullPath != NULL) {
		Nlm_Free(fullPath);
		fullPath = NULL;
	}
	err = FSpGetFullPath(inFSS, &fullPathLength, &h);
	if (err != noErr) return err;
	
	assert(fullPathLength >= 2);  /* An absolute pathname must be at least two chars long */
	fullPath = (char *)Nlm_Malloc(fullPathLength + 1);
	if (fullPath == NULL) {
		err = memFullErr;
	} else {
		strncpy(fullPath, *h, fullPathLength);
	}
	
	DisposeHandle(h);
	
	*outPathname = fullPath;
	return err;
}
예제 #2
0
extern char* vr_findVerRegName()
{
    FSSpec  regSpec;
    OSErr   err;
    short   foundVRefNum;
    long    foundDirID;
    int     bCreate = 0;
    
    /* quick exit if we have the info */
    if ( verRegName != NULL )
        return verRegName;

    err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);

    if (err == noErr)
    {
        err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_VERREG, &regSpec);

        if (err == -43) /* if file doesn't exist */
        {
            err = FSpCreate(&regSpec, 'MOSS', 'REGS', smSystemScript);
            bCreate = 1;
        }

        if (err == noErr)
        {
            Handle thePath;
            short pathLen;
            err = FSpGetFullPath(&regSpec, &pathLen, &thePath);
            if (err == noErr && thePath)
            {
                /* we have no idea if this moves memory, so better lock the handle */
             #if defined(STANDALONE_REGISTRY) || defined(USE_STDIO_MODES)
                HLock(thePath);
                verRegName = (char *)XP_ALLOC(pathLen + 1);
                XP_STRNCPY(verRegName, *thePath, pathLen);
                verRegName[pathLen] = '\0';
            #else
                /* Since we're now using NSPR, this HAS to be a unix path! */
                const char* src;
                char* dst;
                HLock(thePath);
                verRegName = (char*)XP_ALLOC(pathLen + 2);
                src = *(char**)thePath;
                dst = verRegName;
                *dst++ = '/';
                while (pathLen--)
                {
                    char c = *src++;
                    *dst++ = (c == ':') ? '/' : c;
                }
                *dst = '\0';
            #endif
            }
            DisposeHandle(thePath);
        }
    }

    return verRegName;
}
예제 #3
0
pascal OSErr AEOpenFiles(const AppleEvent * theAppleEvent,
                         AppleEvent * theReply, long Refcon)
{
    AEDescList docList;
    AEKeyword keywd;
    DescType returnedType;
    Size actualSize;
    long itemsInList;
    FSSpec theSpec;
    CInfoPBRec pb;
    Handle nameh;
    short namelen;
    OSErr err;
    short i;

    err =
        AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList,
                       &docList);
    if (err != noErr)
        return err;

    err = AECountItems(&docList, &itemsInList);
    if (err != noErr)
        return err;

    for (i = 1; i <= itemsInList; i++) {
        AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
                    (Ptr) & theSpec, sizeof(theSpec), &actualSize);

        if (noErr == FSpGetFullPath(&theSpec, &namelen, &nameh)) {
            HLock(nameh);
            char *str = new char[namelen + 1];
            memcpy(str, (char *) *nameh, namelen);
            str[namelen] = 0;
            HUnlock(nameh);
            DisposeHandle(nameh);

            AudacityProject *project = GetActiveProject();

            if (project == NULL || !project->GetTracks()->IsEmpty()) {
                project = CreateNewAudacityProject(gParentWindow);
            }
            project->OpenFile(str);

            delete[]str;
        }
    }

    return noErr;
}
예제 #4
0
static char* full_path_to(const FSSpec& file)
{
	short len = 0;
	Handle fullPath = NULL;
	if (FSpGetFullPath(&file, &len, &fullPath) == noErr && fullPath != NULL) {
		char* path = new char[1 + len];
		if (path != NULL) {
			BlockMoveData(*fullPath, path, len);
			path[len] = '\0';
		}
		DisposeHandle(fullPath);
		return path;
	}
	return NULL;
}
예제 #5
0
int PathToFile(char *pathName, int pathNameMax, FSSpec *where,UInt32 encoding) {
        OSErr	error;
        short 	pathLength;
        Handle fullPathHandle;
#pragma unused(encoding)
        
	error =  FSpGetFullPath(where, &pathLength, &fullPathHandle);
	if (fullPathHandle != 0) {
            pathLength = pathLength+1 > pathNameMax ? pathNameMax-1 : pathLength;
            strncpy((char *) pathName, (char *) *fullPathHandle, pathLength);
            pathName[pathLength] = 0x00;
            DisposeHandle(fullPathHandle);
        } else {
            *pathName = 0x00;
            pathLength = 0;
        }
	return pathLength;
}
예제 #6
0
pascal	OSErr	GetFullPath(short vRefNum,
							long dirID,
							ConstStr255Param name,
							short *fullPathLength,
							Handle *fullPath)
{
	OSErr		result;
	FSSpec		spec;
	
	*fullPathLength = 0;
	*fullPath = NULL;
	
	result = FSMakeFSSpecCompat(vRefNum, dirID, name, &spec);
	if ( (result == noErr) || (result == fnfErr) )
	{
		result = FSpGetFullPath(&spec, fullPathLength, fullPath);
	}
	
	return ( result );
}
예제 #7
0
extern XP_File VR_StubOpen (const char *mode)
{

    XP_File fh = NULL;
    FSSpec	regSpec;
    OSErr	err;
    short	foundVRefNum;
    long	foundDirID;
    short	pathLen;
    Handle	thePath;
    int     bCreate = 0;
	Ptr		finalPath;
	
	err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);

	if (!err) {

		err = FSMakeFSSpec(foundVRefNum, foundDirID, "\pNetscape Registry", &regSpec);

		if (err == -43) { /* if file doesn't exist */
			err = FSpCreate(&regSpec, '    ', '    ', smSystemScript);
            bCreate = 1;
		}

		if (err == noErr) {
			err = FSpGetFullPath(&regSpec, &pathLen, &thePath);
			
			finalPath = NewPtrClear(pathLen+1);
			BlockMoveData(*thePath, finalPath, pathLen);
						
            if (bCreate)
			    fh = fopen( finalPath, XP_FILE_WRITE_BIN );
            else 
                fh = fopen( finalPath, "w+b" ); /* this hack to support CW11 MSL C Lib fopen update mode */
             
            DisposePtr(finalPath);
		}
	}
예제 #8
0
int Zmacstat(const char *Fname, struct stat *buf)
{
    OSErr           err, rc;
    short           fullPathLength;
    Handle          hFullPath;
    char            path[NAME_MAX], path2[NAME_MAX];
    HVolumeParam    vpb;
    static unsigned long count_of_files = 0;

    AssertStr(Fname,Fname)
    Assert_it(buf,"","")

    UserStop();

    memset(buf, 0, sizeof(buf));    /* zero out all fields */

    RfDfFilen2Real(path2, Fname, MacZip.MacZipMode, MacZip.DataForkOnly,
                   &MacZip.CurrentFork);
    GetCompletePath(path, path2, &MacZip.fileSpec, &err);
    err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
    printerr("GetCompletePath:", err, err, __LINE__, __FILE__, path);

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

    /*  Collect here some more information, it's not related to Macstat.
        (note: filespec gets changed later in this function) */
    /* clear string-buffer */
    memset(MacZip.FullPath, 0x00, sizeof(MacZip.FullPath));
    rc = FSpGetFullPath(&MacZip.fileSpec, &fullPathLength, &hFullPath);
    strncpy(MacZip.FullPath, *hFullPath, fullPathLength);
    DisposeHandle(hFullPath);   /* we don't need it any more */
    /*  Collect some more information not related to Macstat */


    /*
     * Fill the fpb & vpb struct up with info about file or directory.
     */

    FSpGetDirectoryID(&MacZip.fileSpec, &MacZip.dirID, &MacZip.isDirectory);
    vpb.ioVRefNum = MacZip.fpb.hFileInfo.ioVRefNum =  MacZip.fileSpec.vRefNum;
    vpb.ioNamePtr = MacZip.fpb.hFileInfo.ioNamePtr =  MacZip.fileSpec.name;

    if (MacZip.isDirectory) {
        MacZip.fpb.hFileInfo.ioDirID =  MacZip.fileSpec.parID;
        /*
         * Directories are executable by everyone.
         */
        buf->st_mode |= UNX_IXUSR | UNX_IXGRP | UNX_IXOTH | UNX_IFDIR;
    } else {
        MacZip.fpb.hFileInfo.ioDirID = MacZip.dirID;
    }

    MacZip.fpb.hFileInfo.ioFDirIndex = 0;
    err = PBGetCatInfoSync((CInfoPBPtr)&MacZip.fpb);

    if (err == noErr) {
        vpb.ioVolIndex = 0;
        err = PBHGetVInfoSync((HParmBlkPtr)&vpb);
        if (err == noErr && buf != NULL) {
            /*
             * Files are always readable by everyone.
             */
            buf->st_mode |= UNX_IRUSR | UNX_IRGRP | UNX_IROTH;

            /*
             * Use the Volume Info & File Info to fill out stat buf.
             */
            if (MacZip.fpb.hFileInfo.ioFlAttrib & 0x10) {
                buf->st_mode |= UNX_IFDIR;
                buf->st_nlink = 2;
            } else {
                buf->st_nlink = 1;
                if (MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags & 0x8000) {
                    buf->st_mode |= UNX_IFLNK;
                } else {
                    buf->st_mode |= UNX_IFREG;
                }
            }

            if (MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType == 'APPL') {
                /*
                 * Applications are executable by everyone.
                 */
                buf->st_mode |= UNX_IXUSR | UNX_IXGRP | UNX_IXOTH;
            }
            if ((MacZip.fpb.hFileInfo.ioFlAttrib & 0x01) == 0){
                /*
                 * If not locked, then everyone has write acces.
                 */
                buf->st_mode |= UNX_IWUSR | UNX_IWGRP | UNX_IWOTH;
            }

            buf->st_ino = MacZip.fpb.hFileInfo.ioDirID;
            buf->st_dev = MacZip.fpb.hFileInfo.ioVRefNum;
            buf->st_uid = -1;
            buf->st_gid = -1;
            buf->st_rdev = 0;

            if (MacZip.CurrentFork == ResourceFork)
                buf->st_size = MacZip.fpb.hFileInfo.ioFlRLgLen;
            else
                buf->st_size = MacZip.fpb.hFileInfo.ioFlLgLen;

            buf->st_blksize = vpb.ioVAlBlkSiz;
            buf->st_blocks = (buf->st_size + buf->st_blksize - 1)
                            / buf->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".
             */
            if (!MacZip.isDirectory) {
                MacZip.CreatDate  = MacZip.fpb.hFileInfo.ioFlCrDat;
                MacZip.ModDate    = MacZip.fpb.hFileInfo.ioFlMdDat;
                MacZip.BackDate   = MacZip.fpb.hFileInfo.ioFlBkDat;
            } else {
                MacZip.CreatDate  = MacZip.fpb.dirInfo.ioDrCrDat;
                MacZip.ModDate    = MacZip.fpb.dirInfo.ioDrMdDat;
                MacZip.BackDate   = MacZip.fpb.dirInfo.ioDrBkDat;
            }

#ifdef IZ_CHECK_TZ
            if (!zp_tz_is_valid)
            {
                MacZip.HaveGMToffset = false;
                MacZip.Md_UTCoffs = 0L;
                MacZip.Cr_UTCoffs = 0L;
                MacZip.Bk_UTCoffs = 0L;
            }
            else
#endif
            {
                /* Do not use GMT offsets when Md_UTCoffs calculation
                 * fails, since this time stamp is used for time
                 * comparisons in Zip and UnZip operations.
                 * We do not bother when GMT offset calculation fails for
                 * any other time stamp value. Instead we simply assume
                 * a default value of 0.
                 */
                MacZip.HaveGMToffset =
                    GetGMToffsetMac(MacZip.ModDate, &MacZip.Md_UTCoffs);
                if (MacZip.HaveGMToffset) {
                    GetGMToffsetMac(MacZip.CreatDate, &MacZip.Cr_UTCoffs);
                    GetGMToffsetMac(MacZip.BackDate, &MacZip.Bk_UTCoffs);
                } else {
                    MacZip.Cr_UTCoffs = 0L;
                    MacZip.Bk_UTCoffs = 0L;
                }
            }
#ifdef DEBUG_TIME
            {
            printf("\nZmacstat:  MacZip.HaveGMToffset: %d",
               MacZip.HaveGMToffset);
            printf("\nZmacstat:  Mac modif: %lu local -> UTOffset: %d",
              MacZip.ModDate, MacZip.Md_UTCoffs);
            printf("\nZmacstat:  Mac creat: %lu local -> UTOffset: %d",
              MacZip.CreatDate, MacZip.Cr_UTCoffs);
            printf("\nZmacstat:  Mac  back: %lu local -> UTOffset: %d",
              MacZip.BackDate, MacZip.Bk_UTCoffs);
            }
#endif /* DEBUG_TIME */


            buf->st_mtime = MacFtime2UnixFtime(MacZip.ModDate);
            buf->st_ctime = MacFtime2UnixFtime(MacZip.CreatDate);
            buf->st_atime = buf->st_mtime;

#ifdef DEBUG_TIME
            {
            printf("\nZmacstat:  Unix modif: %lu UTC; Mac: %lu local",
              buf->st_mtime, MacZip.ModDate);
            printf("\nZmacstat:  Unix creat: %lu UTC; Mac: %lu local\n",
              buf->st_ctime, MacZip.CreatDate);
            }
#endif /* DEBUG_TIME */

            if (noisy)
            {
                if (MacZip.StatingProgress)
                {
                    count_of_files++;
                    InformProgress(MacZip.RawCountOfItems, count_of_files );
                }
                else
                    count_of_files = 0;
            }
        }
    }

    if (err != noErr) {
        errno = err;
    }

    MacZip.isMacStatValid = true;
    return (err == noErr ? 0 : -1);
}