Retrieving user name with carbon.
Hi!
I'm a bit new on Mac development.
I would like to know if there is a way to retrieve the current user name with Carbon?
I'm porting an application from Windows to Mac, and so far I couldn't find a way to do it.
Thanks!
I'm a bit new on Mac development.
I would like to know if there is a way to retrieve the current user name with Carbon?
I'm porting an application from Windows to Mac, and so far I couldn't find a way to do it.
Thanks!
In the words of the wise OneSadCookie: Carbon is all but dead. Use Cocoa instead.
Are you looking for the user's short name, or their full name? If you just want short name, this appears to work:
See also whoami() in http://www.opensource.apple.com/darwinso.../who/who.c (requires ADC login).
Code:
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
struct passwd * passwd;
passwd = getpwuid(getuid());
printf("Name: %s\n", passwd->pw_name);
return EXIT_SUCCESS;
}See also whoami() in http://www.opensource.apple.com/darwinso.../who/who.c (requires ADC login).
NSUserName() / NSFullUserName() may also be useful. I thought there were CF equivalents but I can't see them :/
Thanks.
Now I'll have to code and try.
Now I'll have to code and try.
completeness, yeah, I would say ready for copy and paste ... thanks!
Here's the CF way:
Quote:char buffer[256];
Boolean success = CFStringGetCString(CSCopyUserName(true), buffer, sizeof(buffer), kCFStringEncodingUTF8);

