文件2
#Include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
1int stat(const char *path,struct stat *buf);
2int fstat(int fd,struct stat *buf);
3int lstat(const char *path,struct stat *buf);
#include <pwd.h>
4struct passwd *getpwuid(uid_t uid)//根据uid来获得用户信息
struct passwd
{
char *pw_name;//usrname
char *pw_passwd;//userword
uid_t pw_uid;// user ID
gid_t pw_gid; //group ID
char *pw_gecos; //user information
char *pw_dir;//home diectory
char *pw_shell;// shell
};
5struct group *getgrgid(gid_t gid)//根据组ID来获得信息
struct group
{
char *gr_name;
char *gr_passwd;
gid_t gr_gid;
char **gr_mem;
};
例子:
#include<stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
int main(int argc,char *argv[])
{
struct stat filestat;
lstat(argv[1],&filestat);
struct passwd *a=(struct passwd *)getpwuid(filestat.st_uid);
struct group *gp;
gp=getgrgid(filestat.st_gid);
printf("gid name is:%s\n",gp->gr_name);
printf("username :%s\n",a->pw_name);
printf("passwd :%s\n",a->pw_passwd);
printf("uid=%d\n",a->pw_uid);
printf("gid=%d\n",a->pw_gid);
printf("shell=%s\n",a->pw_shell);
printf("dir=%s\n",a->pw_dir);
return 0;
}
- 根文件系统的构建与分析(一)之流程分析
- oracle证明题:未提交的事务也可能被DBWn写进数据文件
- Winform中读写配置文件
- 可执行jar包怎么对包内的txt文件读写
- 忘记敲sudo又想保存文件的办法
- 在jsp和class文件中调用的相对路径不同。
- AMR 文件解析及编解码流程
- 算出两个文件的相对路径
- ubuntu 删除软件后,清理配置文件
- (*)hibernate映射文件配置
- c# 读取*.config文件指定节点的值
- 事物日志文件.
- linux文件和目录颜色不同代表不同语意
- C#备份及还原数据库的实现代码(粗略) // 利用C#还原数据库(SQL SERVER)备份文件到指定路径
- Android中Java根据文件头获取文件类型
- EasyPlat.net V5正式发布web.config配置文件内容
- 使用java NIO实现复制文件
- LINK 2005错误。*** 已经在*.obj文件中定义
- 使用dom4j将xml文件转换成project.properties文件
- PE文件结构详解(四)PE导入表