• 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
Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED] (From: Rolf <email@hidden>)

  • Prev by Date: Bad solution for RTF template?
  • Next by Date: Re: Static linking with the Mach-O linker in PB
  • Previous by thread: Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
  • Next by thread: Re: User friendly machine name (gestaltUserVisibleMachineName?) [SOLVED]
  • Index(es):
    • Date
    • Thread