CFStringCreateWithCharacters and unicode ":" chars
CFStringCreateWithCharacters and unicode ":" chars
- Subject: CFStringCreateWithCharacters and unicode ":" chars
- From: Ken Hawkins <email@hidden>
- Date: Tue, 11 May 2004 10:16:45 -0700
how can i correctly retrieve a volumes name and ensure that the special
chars do not get munged?
in this bit of code from the AudioCDSample:
for (volumeIndex = 1; result == noErr || result != nsvErr;
volumeIndex++)
{
FSVolumeRefNum actualVolume;
HFSUniStr255 volumeName;
FSVolumeInfo volumeInfo;
bzero((void *) &volumeInfo, sizeof(volumeInfo));
result = FSGetVolumeInfo(kFSInvalidVolumeRefNum,
volumeIndex,
&actualVolume,
kFSVolInfoFSInfo,
&volumeInfo,
&volumeName,
NULL);
if (result == noErr)
{
// Work around a bug in Mac OS X 10.0.x where the filesystem ID and
signature bytes were
// erroneously swapped. This was fixed in Mac OS X 10.1 (r.
2653443).
if ((systemVersion >= 0x00001000 && systemVersion < 0x00001010 &&
volumeInfo.signature == kAudioCDFilesystemID) ||
volumeInfo.filesystemID == kAudioCDFilesystemID) // It's an audio
CD
{
GetVolParmsInfoBuffer volumeParms;
HParamBlockRec pb;
// Use the volume reference number to retrieve the volume
parameters. See the documentation
// on PBHGetVolParmsSync for other possible ways to specify a
volume.
pb.ioParam.ioNamePtr = NULL;
pb.ioParam.ioVRefNum = actualVolume;
pb.ioParam.ioBuffer = (Ptr) &volumeParms;
pb.ioParam.ioReqCount = sizeof(volumeParms);
// A version 4 GetVolParmsInfoBuffer contains the BSD node name in
the vMDeviceID field.
// It is actually a char * value. This is mentioned in the header
CoreServices/CarbonCore/Files.h.
result = PBHGetVolParmsSync(&pb);
// This code is just to convert the volume name from a
HFSUniCharStr to
// a plain C string so we can print it with printf. It'd be
preferable to
// use CoreFoundation to work with the volume name in its Unicode
form.
CFStringRef volNameAsCFString;
char volNameAsCString[256];
volNameAsCFString =
CFStringCreateWithCharacters(kCFAllocatorDefault,
volumeName.unicode,
volumeName.length);
// If the conversion to a C string fails, just treat it as a null
string.
if (!CFStringGetCString(volNameAsCFString,
volNameAsCString,
sizeof(volNameAsCString),
kCFStringEncodingUTF8))
{
volNameAsCString[0] = 0;
}
...
everything works great but except when i happen to insert a CD that has
special chars in it, ':' for example. i can only find docs on using
'CDStringCreateWithCharacters using the kCDAllocatorDefault (or pass
NULL). this munges chars like ':' and they come out as '/' char's.
thanks,
ken;
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.