コード例 #1
0
int dir_Lookup(char *pathString, int pathStringLength, int index,
  /* outputs: */
  char *name, int *nameLength, int *creationDate, int *modificationDate,
  int *isDirectory, squeakFileOffsetType *sizeIfFile) {
	/* Lookup the index-th entry of the directory with the given path, starting
	   at the root of the file system. Set the name, name length, creation date,
	   creation time, directory flag, and file size (if the entry is a file).
	   Return:	0 	if a entry is found at the given index
	   			1	if the directory has fewer than index entries
	   			2	if the given path has bad syntax or does not reach a directory
	*/

	int okay;
    FSSpec      spec;
    long        parentDirectory;
    OSErr       err;
    Str255      longFileName;
		FSVolumeInfoParam fsVolumeParam;
		HFSUniStr255 uniStr;
		FSVolumeInfo volumeInfo;
    
	/* default return values */
	*name             = 0;
	*nameLength       = 0;
	*creationDate     = 0;
	*modificationDate = 0;
	*isDirectory      = false;
	*sizeIfFile       = 0;

	if ((pathStringLength == 0)) {
		/* get volume info */
		fsVolumeParam.volumeName = &uniStr;
		fsVolumeParam.ioVRefNum = kFSInvalidVolumeRefNum;
		fsVolumeParam.volumeIndex = index;
		fsVolumeParam.whichInfo = 0;
		fsVolumeParam.volumeInfo = &volumeInfo;
		fsVolumeParam.ref = NULL;
		fsVolumeParam.whichInfo = kFSVolInfoCreateDate + kFSVolInfoModDate; 
		okay = PBGetVolumeInfoSync( &fsVolumeParam) == noErr;
/*
		FSGetVolumeInfo (kFSInvalidVolumeRefNum,
			index,
			NULL,
			)
*/
		if (okay) {
			CFStringRef strRef = CFStringCreateWithCharacters( kCFAllocatorDefault, uniStr.unicode, uniStr.length );
			CFMutableStringRef mStr = CFStringCreateMutableCopy(NULL, 0, strRef);
			// HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined
			Boolean result = CFStringGetCString(mStr, name, 256, gCurrentVMEncoding); // buffer size is to see primitiveDirectoryLookup
			CFRelease(strRef);
			CFRelease(mStr);
			if (result == true) {
				// strncpy(name, &(uniStr.unicode), uniStr.length);
				// *nameLength       = uniStr.length;
				*nameLength       = strlen(name);
				{	
					LocalDateTime local;
					
					ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->createDate,&local);
					*creationDate     = convertToSqueakTime(local.lowSeconds);
				}
				{	
					LocalDateTime local;
					
					ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->modifyDate,&local);
					*modificationDate     = convertToSqueakTime(local.lowSeconds);
				}
				*isDirectory      = true;
				*sizeIfFile       = 0;
				return ENTRY_FOUND;
			} else {
				return NO_MORE_ENTRIES;
			}
		} else {
			return NO_MORE_ENTRIES;
		}
	} else {
		/* get file or directory info */
		if (!equalsLastPath(pathString, pathStringLength)) {
 			/* lookup and cache the refNum for this path */
			err = lookupPath(pathString, pathStringLength, &spec,false,true);
 			if (err == noErr) 
				recordPath(pathString, pathStringLength, &spec);
			else 
				return BAD_PATH;
		}
	    spec = lastSpec;
		*sizeIfFile   = 0;
		okay = fetchFileInfo(index,&spec,(unsigned char *) name,true,
							&parentDirectory,isDirectory,creationDate,
							modificationDate,sizeIfFile,&longFileName);
		if (okay == noErr) {
			CFStringRef cfs= CFStringCreateWithPascalString(NULL, longFileName, gCurrentVMEncoding);
			CFMutableStringRef mStr= CFStringCreateMutableCopy(NULL, 0, cfs);
			CFRelease(cfs);
			// HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined
			CFStringGetCString(mStr, name, 256, gCurrentVMEncoding);
			CFRelease(mStr);

			*nameLength       = strlen(name);
			*creationDate     = convertToSqueakTime(*creationDate);
			*modificationDate = convertToSqueakTime(*modificationDate);
			return ENTRY_FOUND;
		} else
			return okay == fnfErr ? NO_MORE_ENTRIES : BAD_PATH;
	}
}
コード例 #2
0
ファイル: getfpn.c プロジェクト: EvilMcJerkface/iODBC
char *
get_full_pathname (long dirID, short volID)
{
  FSVolumeInfoParam vol;
  HFSUniStr255 volname;
  CInfoPBRec pb;
  OSErr result;
  Str255 dir;
  char *pathname = NULL;
  char *prov = NULL;
  SInt16 vdefNum; 
  SInt32 dummy;

  pb.dirInfo.ioNamePtr = dir;
  pb.dirInfo.ioVRefNum = volID;
  pb.dirInfo.ioDrParID = dirID;
  pb.dirInfo.ioFDirIndex = -1;

  do
    {
      pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
      result = PBGetCatInfo (&pb, false);
      if (result != noErr)
	return NULL;
      if (pb.dirInfo.ioDrDirID != fsRtDirID)
	{
	  prov = pathname;
	  pathname =
	      (char *) malloc ((pathname ? strlen (pathname) : 0) +
	      (unsigned char) dir[0] + 2);
	  strcpy (pathname, PATH_SEPARATOR);
	  strncat (pathname, (char *) dir + 1, (unsigned char) dir[0]);
	}
#ifdef macintosh
      else
	{
	  prov = pathname;
	  pathname =
	      (char *) malloc ((pathname ? strlen (pathname) : 0) +
	      (unsigned char) dir[0] + 1);
	  pathname[0] = 0;
	  strncat (pathname, (char *) dir + 1, (unsigned char) dir[0]);
	}
#endif

      if (prov)
	{
	  strcat (pathname, prov);
	  free (prov);
         prov = NULL;
	}
    }
  while (pb.dirInfo.ioDrDirID != fsRtDirID);

#ifdef __APPLE__
  /* Get also the volume name */
  FindFolder (kOnSystemDisk, kSystemFolderType, FALSE, &vdefNum, &dummy);
  if(vdefNum != volID)
    {
      vol.ioVRefNum = volID;
      vol.volumeIndex = 0;
      vol.whichInfo = kFSVolInfoNone;
      vol.volumeName = &volname;
      vol.ref = NULL;

      PBGetVolumeInfoSync(&vol);
      if(volname.length)
        {
          wchar_t volwchar[1024];
          char *volutf8 = NULL;

          /* Convert the UniString255 to wchar */
          for(dummy = 0 ; dummy < volname.length ; dummy++)
            volwchar[dummy] = volname.unicode[dummy];
          volwchar[dummy] = L'\0';

          /* Then transform it in UTF8 */
          volutf8 = dm_SQL_WtoU8 (volwchar, SQL_NTS);
          if(volutf8)
            {
              prov = pathname;
              pathname =
                (char*) malloc ((pathname ? strlen (pathname) : 0) +
                volname.length + strlen("/Volumes/") + 2);
              strcpy(pathname, "/Volumes/");
              strcat(pathname, volutf8);
              if(prov)
                {
                  strcat(pathname, prov);
                  free(prov);
                }
              free(volutf8);
            }
        }
    }
#endif

  return pathname;
}