• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Converting POSIX to HFS names (was extended attributes?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Converting POSIX to HFS names (was extended attributes?)


  • Subject: Converting POSIX to HFS names (was extended attributes?)
  • From: James Bucanek <email@hidden>
  • Date: Wed, 2 Apr 2008 17:15:57 -0700

I was about to begin implementing this code ...

Quinn <mailto:email@hidden> wrote (Tuesday, February 19, 2008 3:22 AM -0000):
OTOH, converting an FSRef to a path isn't as expensive as you might think because you're getting the name of the file system object at this point anyway. For example:

i) Maintain the path to the parent directory as you iterate the hierarchy.
ii) Get the name of the file system object from FSGetCatalogInfoBulk.
iii) Convert that name to UTF-8 (and swap slashes to colons).
iv) Append it to the parent directory path.

... and it reminded me of a question that's been nagging me for some time. Is there any public API for converting file system name between the HFS style (that don't allow colons in names) and the POSIX style (that doesn't allow slashes in names)?


I wrote the following NSString category method sometime back:

- (NSString*)stringTranslatingHFSAndPOSIXPathSeparators
{
NSRange troubleRange = [self rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"/:"]];
if (troubleRange.length==0) // no problematic characters found
return (self); // return the untranslated string


// Allocate a buffer big enoungh to hold the Unicode representation of the string
unsigned int length = [self length];
NSMutableData* uniBuff = [[NSMutableData alloc] initWithLength:(length+2)*sizeof(unichar)];
unichar* s = (unichar*)[uniBuff bytes];
// Copy the unicode characters into the buffer so we can poke at them directly
[self getCharacters:s];
// Replace every / with a : and visa versa
int l = length;
unichar* c = s;
while (l--)
{
if (*c=='/')
*c = ':';
else if (*c==':')
*c = '/';
c++;
}
NSString* translatedString = [NSString stringWithCharacters:s length:length]; // turn char buffer back into an NSString
[uniBuff release]; // release the temporary buffer
return (translatedString);
}


But I thought I'd ask if there was a better/faster/approved way of doing this.



--
James Bucanek

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Converting POSIX to HFS names (was extended attributes?)
      • From: Eric Schlegel <email@hidden>
  • Prev by Date: Is there a way to identify the Time Machine backup folder?
  • Next by Date: Re: Converting POSIX to HFS names (was extended attributes?)
  • Previous by thread: Is there a way to identify the Time Machine backup folder?
  • Next by thread: Re: Converting POSIX to HFS names (was extended attributes?)
  • Index(es):
    • Date
    • Thread