Ami*_*Sri 9 macos cocoa objective-c
请告诉我如何在objective-c中获取当前登录用户的名称或mac机器名称(如果可能).谢谢
小智 6
C函数:getpwuid()返回struct passwd:
struct passwd {
char *pw_name; /* username */
char *pw_passwd; /* user password */
uid_t pw_uid; /* user ID */
gid_t pw_gid; /* group ID */
char *pw_gecos; /* user information */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};
Run Code Online (Sandbox Code Playgroud)
- - - - - - - - - - - 码 - - - - - - - -
#include <pwd.h>
register uid_t uid;
struct passwd *uid_pw;
uid = geteuid ();
uid_pw = getpwuid (uid);
strcpy(uname,uid_pw->pw_name)
Run Code Online (Sandbox Code Playgroud)
//类似的其他信息