Mac People... how do you get the username on OSX?

Discussion in 'Game Development (Technical)' started by Raptisoft, Jun 28, 2011.

  1. Raptisoft

    Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    804
    Likes Received:
    0
    Hi all,
    Simple little question. In Windows there's GetUserName... what's the equivalent on Mac?

    Thanks,
    John
     
  2. FabianMatyas

    FabianMatyas New Member

    Joined:
    Mar 21, 2008
    Messages:
    34
    Likes Received:
    0
    You can just use NSUserName or NSFullUserName from the Foundation framework, or call [NSUserDefaults standardUserDefaults] for more extensive info.
     
  3. Pogacha

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    605
    Likes Received:
    0
    Something like this is what we are using:
    Code:
    	CFStringRef cfUserName = CSCopyUserName( false );
    		
    	if ( cfUserName != nil )
    	{
    		const char* buffer = CFStringGetCStringPtr( cfUserName, CFStringGetSystemEncoding()); 
    // do something with buffer 
    	}
     
  4. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Mac OS X is a Unix system so

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    int main(void)
    {
        printf("My username is %s\n", getenv("USER"));
        return 0;
    }
    
    tried it:
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer