頭檔案
#include <sys/types.h>
#include <pwd.h>
函式原型
struct passwd *getpwuid(uid_t uid);
函式說明
getpwuid函式是通過用戶的uid查找用戶的passwd數據。如果出錯時,它們都返回一個空指針並設定errno的值,用戶可以根據perror函式查看出錯的信息。
The passwd structure isdefined in<pwd.h>asfollows:
struct passwd {
char*pw_name; /*user name */
char*pw_passwd; /*user 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 <pwd.h>
#include <sys/types.h>
#include <stdio.h>
intmain()
{
uid_t my_uid;
my_uid =500;
structpasswd *my_info;
my_info =getpwuid( my_uid );
//my_info = getpwnam( "fflg" );
PRINTF( "my name = [%s]\n", my_info->pw_name );
printf( "my passwd = [%s]\n", my_info->pw_passwd );
printf( "my uid = [%d]\n", my_info->pw_uid );
printf( "my gid = [%d]\n", my_info->pw_gid );
printf( "my gecos = [%s]\n", my_info->pw_gecos );
printf( "my dir = [%s]\n", my_info->pw_dir );
printf( "my shell = [%s]\n", my_info->pw_shell );
return0;
}