2025年《Linux系统调用:getgrent,setgrent,endgrent》

《Linux系统调用:getgrent,setgrent,endgrent》一 介绍 getgrent setgrent endgrent 组合起来使用按顺序扫描密码文件 etc group 中的所有的各项记录 include sys types h include grp h 调用会自动打开组文件 不需要执行 open 打开 每次调用会按顺序读取各项 grp h sys

大家好,我是讯享网,很高兴认识大家。

一、介绍

getgrent(),setgrent(),endgrent() 组合起来使用按顺序扫描密码文件(/etc/group)中的所有的各项记录。


讯享网

#include <sys/types.h> #include <grp.h> // 调用会自动打开组文件,不需要执行open打开 // 每次调用会按顺序读取各项,有点类似文件操作的lseek struct group *getgrent(void); // 调用重返文件的起始处 void setgrent(void); // 调用相当于关闭组文件,不需要执行close关闭 void endgrent(void);

讯享网

二、实例

讯享网#include <sys/stat.h> #include <sys/types.h> #include <grp.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> #include <stdio.h> void print_grp(struct group *grp) { printf("grp->gr_name : [%s]
小讯
上一篇 2025-02-06 15:56
下一篇 2025-03-02 21:11

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/130404.html