Chinaunix首页 | 论坛 | 博客
  • 博客访问: 378544
  • 博文数量: 73
  • 博客积分: 2620
  • 博客等级: 少校
  • 技术积分: 1212
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-09 10:47
文章分类
文章存档

2011年(18)

2010年(50)

2009年(5)

我的朋友

分类: LINUX

2010-01-13 22:06:12

/*注:每个数据文件都有至少3个函数:get,set,end,其中get函数返回的是指向static的指针。
 *另外若文件支持关键字搜索,则还会有按照关键字:name,uid,gid搜索的函数
 *下面只介绍了3个文件:passwd,shadow,group的相关函数*/
/etc/passwd
struct passwd{
  char* pw_name;
  char* pw_passwd;
  uid_t uid;
  gid_t gid;
  char* pw_gecos;
  char* pw_dir;
  char* pw_shell;
}
#include
struct passwd* getpwuid(uid_t uid);
struct passwd* getpwnam(const char* name);
返回:错误NULL
struct passwd* getpwent(void); 返回:错误或文件尾null
void setpwent(void);
void endpwent(void);
 
/etc/shadow
struct spwd{
  char* sp_namp;
  char* sp_pwdp;
  int sp_lstchg;
  int sp_min;
  int sp_max;
  int sp_warn;
  int sp_inact;
  int sp_expire;
  unsigned long sp_flag; 
}
#include
struct spwd* getspnam(const char* name);
struct spwd* getspent(void);
返回:错误NULL
void setspent(void);
void endspent(void);
 
/etc/group
struct group{
  char* gr_name;
  char* gr_passwd;
  int gr_gid;
  char** gr_mem;
}
#include
struct group* getgrgid(gid_t gid);
struct group* getgrnam(const char* name);
返回:错误NULL
struct group* getgrent(void); 返回:错误或文件尾null
void setgrent(void);
void endgrent(void);
 
/*fetch and set supplementary Group IDs*/
int getgroups(int gidsetsize, gid_t grouplist[]); 返回:成功为增补的组ID数量,错误-1
#include
int setgroups(int ngroups, const gid_t grouplist[]); /*root*/
int initgroups(const char* username, gid_t basegid); /*root*/
返回:成功0,错误-1
 
 
UNIX系统维持2个数据文件:utmp,wtmp分别用于保存当前登录用户信息和所有用户登录/退出信息。
 
struct utsname{
  char sysname[];
  char nodename[];
  char release[];
  char version[];
  char mechine[];
}
#include
int uname(struct utsname* name); 返回:成功为非负值,错误-1
 
int gethostname(char* namebuf, int buflen); 返回:成功0,错误-1
 
#include
time_t time(time_t* calptr); 返回:成功为calendar time值,错误-1
 
struct timeval{
  time_t tv_sec; /*seconds*/
  time_t tv_usec; /*microsecondes*/
}
int gettimeofday(struct timeval* tp, void *tzp); 返回:总0 /*注:tzp必须为null*/
 
struct tm{ /*a broken-down time*/
  int tm_sec;
  int tm_min;
  int tm_hour;
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_wday;
  int tm_yday;
  int tm_isdst;
}
struct tm* gmtime(const time_t* calptr);
sturct tm* localtime(const time_t* calptr);
返回:总是broken-down指针
 
time_t mktime(struct tm* tmptr); 返回:成功calendar time,错误-1
 
char* asctime(const struct tm* tmptr);
char* ctime(const time_t* calptr);
返回:null-terminated string
 
size_t strftime(char* buf, size_t maxsize,
                const char* format, const struct tm* tmptr);
返回:存储在buf中的字符数量,buf以null结尾,错误0 /*format与printf类似*/
 
localtime,mktime,ctime,strftime受环境变量TZ影响。
 
 
阅读(2132) | 评论(0) | 转发(0) |
0

上一篇:chapter3 文件I/O

下一篇:chapter7 进程环境

给主人留下些什么吧!~~