词条 | getpwnam |
释义 | getpwnam() 函数功能:获取用户登录相关信息 原型定义: struct passwd *getpwnam(const char *name); 表头文件: #include <pwd.h> #include <sys/types.h> 信息存贮在如下的结构体之中 struct passwd { char * pw_name; /* Username. */ char * pw_passwd; /* Password. */ __uid_t -pw_uid; /* User ID. */ __gid_t -pw_gid; /* Group ID. */ char * pw_gecos; /* Real name. */ char * pw_dir; /* Home directory. -*/ char * pw_shell; /* Shell program. */ }; 例子: #include <stdio.h> #include <pwd.h> int main() { struct passwd * pw; char *username = "zxl"; pw = getpwnam(username); if (!pw) { printf("%s is not exist\", username); return -1; } printf("pw->pw_name = %s\", pw->pw_name); printf("pw->pw_passwd = %s\", pw->pw_passwd); printf("pw->pw_uid = %d\", pw->pw_uid); printf("pw->pw_gid = %d\", pw->pw_gid); printf("pw->pw_gecos = %s\", pw->pw_gecos); printf("pw->pw_dir = %s\", pw->pw_dir); printf("pw->pw_shell = %s\", pw->pw_shell); } |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。