Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
- Subject: Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
- From: Jim Correia <email@hidden>
- Date: Mon, 2 Jun 2003 15:43:00 -0400
On Monday, June 2, 2003, at 03:00 PM, Rolf wrote:
I have found the solution. Thanks for pointing me in the right
direction. Here is a class method that returns the Machine Name:
+(NSString * )machineName {
SInt32 gestaltReturnValue;
// Fetch machine name as pointer to PStr255 (Pascal String:
Byte0=length, Byte1..255=Characters)
if (!Gestalt(gestaltUserVisibleMachineName, &gestaltReturnValue)) {
return [NSString stringWithCString: (char *)gestaltReturnValue
+ 1];
} else {
return @"Unknown";
}
}
Pascal strings are not guaranteed to be null terminated, so you cannot
treat pascalString+1 as a cstring.
You should be using CFStringCreateWithPascalString, or wrapping the
bytes in an NSData and using the data initializer for NSString.
Jim
_______________________________________________
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.