Linux getpw、getpwend、setpwent和endpwent函数
来源:互联网 发布:java中的注释 编辑:程序博客网 时间:2024/06/16 15:42
getpw、getpwend、setpwent和endpwent
头文件
1. #include <pwd.h>
#include <sys/types.h>
#define _GNU_SOURCE
2. #incldue <pwd.h>
#include <sys/types.h>
3. #include <pwd.h>
#include <sys/types.h>
4. #include <pwd.h>
#include <sys/types.h>
函数原型
int getpw(uid_t uid, char *buf);
struct passwd *getpwent(void);
void setpwent(void);
void endpwent(void);
功能
getpw函数取得uid_t为uid的用户的密码文件的相关数据。
getpwent函数返回下一条记录项,此记录项是一个由它填写好的password结构的指针。
setpwent函数能从密码文件中取得帐号的数据,setpwent()用来将getpwent()的读写地址指回密码文件开头
endpwent函数一般用来关闭用getpwent打开的密码文件。
参数
struct passwd{char *pw_name; /*用户帐号*/char *pw_passwd; /*用户密码*/uid_t pw_uid; /*用户识别码*/gid_t pw_gid; /*组识别码*/char *pw_gecos; /*用户全名*/char *pw_dir; /*家目录*/char *pw_shell; /*所使用的shell的路径*/};
例子
getpw
#include <pwd.h>#include <stdio.h>#include <stdlib.h>#include <sys/types.h>int main(){char buffer[80];getpw(0, buffer);printf("%s\n", buffer);exit(0);}
getpwent和endpwent
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <pwd.h>#include <unistd.h>int main(void){struct passwd *user;while((user = getpwent()) != 0){printf("%s:%d:%d:%s:%s:%s\n", user->pw_name,user->pw_uid, user->pw_gid, user->pw_gecos, user->pw_dir, user->pw_shell);}endpwent();exit(0);}
来自unix环境高级编程的例子
#include <pwd.h> /*getpwnam函数的实现*/#include <stddef.h>#include <string.h>#include <sys/types.h>struct passwd *getpwnam(const char *name){struct passwd *ptr;setpwent();while((ptr = getpwent()) != NULL){if(strcmp(name, ptr->pw_name) == 0){break;}}endpwent();return(ptr);}
0 0
- Linux getpw、getpwend、setpwent和endpwent函数
- setpwent函数
- getpw()函数的使用
- endpwent
- endpwent()
- getpw
- setpwent
- setpwent()
- C语言setpwent()函数:从头读取密码文件中的账号数据
- undefined reference to `setpwent'
- (standard c libraries translation )getpw
- Linux中send()函数和recv()函数
- linux下open函数和creat函数
- linux access()函数和readdir()函数
- linux access()函数和readdir()函数
- linux access()函数和readdir()函数
- Unix/Linux时间函数和日历函数
- Linux内核 指针函数和函数指针
- oracle 常用的数据字典----转自“七仔”
- 获取string 省略号
- 电商----货品组合(详情页展示)
- spring事务传播特性和事务隔离级别
- IT修炼道路-贵在坚持
- Linux getpw、getpwend、setpwent和endpwent函数
- 在 CentOS 6.4上安装rabbitmq
- Hadoop2.4.1集群安装
- CLR、泛型、委托简介及简单使用
- Android实现计时以及倒计时的几种方法
- java BigInteger
- recyclerview item动画
- C语言 求1000以内的回文素数
- Hibernate级联查询(多对一)