Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
- Subject: Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
- From: "M. Uli Kusterer" <email@hidden>
- Date: Tue, 3 Jun 2003 05:08:14 +0200
At 21:00 Uhr +0200 02.06.2003, Rolf wrote:
+(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";
}
}
Rolf,
don't assume the string is terminated. It's a P-String, and if it's
been used for anything else by the OS before that, it might not
contain zero bytes beyond the machine name. Make that:
return [NSString stringWithCString: (char *)gestaltReturnValue + 1
length: ((char*)gestaltReturnValue[0])];
just to be on the safe side.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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.