getpwuid()
getpwuid函数是通过用户的uid查找用户的passwd数据。如果出错时,它们都返回一个空指针并设置errno的值,用户可以根据perror函数查看出错的信息。
- 外文名
- getpwuid()
- 头文件
- #include <sys/types.h>
- 原 型
- struct passwd *getpwuid
- 函数说明
- 查找用户的passwd数据
-
头文件
编辑12#include <sys/types.h>
#include <pwd.h>
函数原型
编辑1struct
passwd *getpwuid(uid_t uid);
函数说明
编辑12345678910The passwd structure is defined in <pwd.h> as follows:
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;
/*user real name */
char
*pw_dir;
/*home directory */
char
*pw_shell;
/*shell program */
};
范例
编辑12345678910111213141516171819#include <pwd.h>
#include <sys/types.h>
#include <stdio.h>
intmain()
{
uid_t my_uid;
//my_uid =500;
struct
passwd *my_info;
my_info =getpwuid( getuid() );
//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;
}
微信搜索“Kconfig”,获取支持...