Linux C 函数参考(用户组)[1]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 ming6 的 blog

 



endgrent(关闭组文件)
相关函数
getgrent,setgrent
表头文件
#include<grp.h>
#include<sys/types.h>
定义函数
void endgrent(void);
函数说明
endgrent()用来关闭由getgrent()所打开的密码文件。
返回值

附加说明

范例
请参考getgrent()与setgrent()。
 



endpwent(关闭密码文件)
相关函数
getpwent,setpwent
表头文件
#include<pwd.h>
#include<sys/types.h>
定义函数
void endpwent(void);
函数说明
endpwent()用来关闭由getpwent()所打开的密码文件。
返回值

附加说明

范例
请参考getpwent()与setpwent()。
 



endutent(关闭utmp 文件)
相关函数
getutent,setutent
表头文件
#include<utmp.h>
定义函数
void endutent(void);
函数说明
endutent()用来关闭由getutent所打开的utmp文件。
返回值

附加说明

范例
请参考getutent()。
 



fgetgrent(从指定的文件来读取组格式)
相关函数
fgetpwent
表头文件
#include<grp.h>
#include<stdio.h>
#include<sys/types.h>
定义函数
struct group * getgrent(file * stream);
函数说明
fgetgrent()会从参数stream指定的文件读取一行数据,然后以group结构将该数据返回。参数stream所指定的文件必须和、etc/group相同的格式。group结构定义请参考getgrent()。
返回值
返回group结构数据,如果返回null则表示已无数据,或有错误发生。
范例
#include <grp.h>
#include<sys/types.h>
#include<stdio.h>
main()
{
struct group *data;
file *stream;
int i;
stream = fopen("/etc/group", "r");
while((data = fgetgrent(stream))!=0){
i=0;
printf("%s :%s:%d :", data->gr_name,data->gr_passwd,data->gr_gid);
while (data->gr_mem[i])printf("%s,",data->gr_mem[i++]);
printf("\n");
}
fclose(stream);
}
执行
root:x:0:root,
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5
disk:x:6:root
lp:x:7:daemon,lp
mem:x:8
kmem:x:9
wheel:x:10:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15
games:x:20
gopher:x:30
dip:x:40:
ftp:x:50
nobody:x:99:
 



fgetpwent(从指定的文件来读取密码格式)
相关函数
fgetgrent
表头文件
#include<pwd.h>
#include<stdio.h>
#include<sys/types.h>
定义函数
struct passwd * fgetpwent(file *stream);
函数说明
fgetpwent()会从参数stream指定的文件读取一行数据,然后以passwd结构将该数据返回。参数stream所指定的文件必须和/etc/passwd相同的格式。passwd结构定义请参考getpwent()。
返回值
返回passwd结构数据,如果返回null则表示已无数据,或有错误发生。
范例
#include<pwd.h>
#include<sys/types.h>
main()
{
struct passwd *user;
file *stream;
stream = fopen("/etc/passwd", "r");
while((user = fgetpwent(stream))!=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);
}
}
执行
root:0:0:root:/root:/bin/bash
bin:1:1:bin:/bin:
daemon:2:2:daemon:/sbin:
adm:3:4:adm:/var/adm:
lp:4:7:lp:/var/spool/lpd:
sync:5:0:sync:/sbin:/bin/sync
shutdown:6:0:shutdown:/sbin:/sbin/shutdown
halt:7:0:halt:/sbin:/sbin/halt
mail:8:12:mail:/var/spool/mail:
news:9:13:news:var/spool/news
uucp:10:14:uucp:/var/spool/uucp:
operator:11:0:operator :/root:
games:12:100:games:/usr/games:
gopher:13:30:gopher:/usr/lib/gopher-data:
ftp:14:50:ftp user:/home/ftp:
nobody:99:99:nobody:/:

本文关键:Linux C 函数参考(用户组)
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top