第六章 系统数据文件和信息
2016-07-01 16:48
405 查看
1. 口令文件
获取口令文件项的函数:
struct passwd *getwuid(uid_t uid); //获取用户id
struct passwd *getpwnam(const char *name); //获取用户的登录名
获取的不仅仅是登录名和用户ID
struct passwd *getpwent(void); //获取一个记录项
void setpwent(void); //反绕它所使用的文件,使它定位到文件开始处
void endpwent(void); //关闭这些文件
2. 组文件
struct group *getgrid(gid_t gid);
struct group *getgrnam(const char* name);
如果要搜索整个组文件
struct group *getgrent(void);
void setgrent(void);
void endgrent(void);
3. 附属组ID
int getgroups(int gidsetsize, gid_t grouplist[]); //将进程所属用户的各附属组ID填写到grouplist中
int setgroups(int ngroups, const gid_t grouplist[]); //为调用进程设置附属组ID表
int initgroups(const char *username, gid_t basegid); //basegid是username在口令文件中的组ID
4. 其他数据文件
对这些文件都有跟组文件处理类似的函数,get函数,set函数,end函数。
5. 登陆账户记录
utmp文件记录当前登录到系统的各个用户;wtmp文件跟踪各个登陆和注销时间。
6. 系统标识
int unmae(struct utsname *name); //返回与主机和操作系统有关的信息,有sysname,nodename,release(操作系统的),version,machine。
int gethostname(char *name, int namelen); //得到主机名,就是TCP/IP网络上主机的名字。
7. 时间和日期
time_t time(time_t *calptr); //返回当前时间和日期
int clock_gettime(clockid_t clock_id, struct timespec *tsp); //clock_id是时钟类型标识符
int clock_getres(clockid_t clock_id, struct timespec *tsp);
int clock_settime(clockid_t clock_id, const struct timespec *tsp); //特定时钟设置时间
struct tm *gmtime(const time_t *calptr); //和下面的函数一样,返回tm结构的指针,出错返回NULL
struct tm *localtime(const time_t *calptr);
time_t mktime(struct tm *tmptr); //以本地时间的年月日作为参数,将其变换成time_t值
size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr);
size_t strftime_l(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr, locale_t locale);
char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tmptr); //这个函数与上两个相反,这个函数是字符串转化成时间输出,上两个是把时间转换成字符串进行输出#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
time_t t;
struct tm *tmp;
char buf1[16], buf2[64];
time(&t);
tmp = localtime(&t);
if(strftime(buf1, 16, "time and date: %r, %a %b %d, %Y", tmp) == 0)
printf("buffer length 16 is too small\n");
else
printf("%s\n", buf1);
if(strftime(buf2, 64, "time and date: %r, %a %b %d, %Y", tmp) == 0)
printf("buffer length 200 is too small\n");
else
printf("%s\n", buf2);
exit(0);
}
获取口令文件项的函数:
struct passwd *getwuid(uid_t uid); //获取用户id
struct passwd *getpwnam(const char *name); //获取用户的登录名
获取的不仅仅是登录名和用户ID
struct passwd *getpwent(void); //获取一个记录项
void setpwent(void); //反绕它所使用的文件,使它定位到文件开始处
void endpwent(void); //关闭这些文件
2. 组文件
struct group *getgrid(gid_t gid);
struct group *getgrnam(const char* name);
如果要搜索整个组文件
struct group *getgrent(void);
void setgrent(void);
void endgrent(void);
3. 附属组ID
int getgroups(int gidsetsize, gid_t grouplist[]); //将进程所属用户的各附属组ID填写到grouplist中
int setgroups(int ngroups, const gid_t grouplist[]); //为调用进程设置附属组ID表
int initgroups(const char *username, gid_t basegid); //basegid是username在口令文件中的组ID
4. 其他数据文件
对这些文件都有跟组文件处理类似的函数,get函数,set函数,end函数。
5. 登陆账户记录
utmp文件记录当前登录到系统的各个用户;wtmp文件跟踪各个登陆和注销时间。
6. 系统标识
int unmae(struct utsname *name); //返回与主机和操作系统有关的信息,有sysname,nodename,release(操作系统的),version,machine。
int gethostname(char *name, int namelen); //得到主机名,就是TCP/IP网络上主机的名字。
7. 时间和日期
time_t time(time_t *calptr); //返回当前时间和日期
int clock_gettime(clockid_t clock_id, struct timespec *tsp); //clock_id是时钟类型标识符
int clock_getres(clockid_t clock_id, struct timespec *tsp);
int clock_settime(clockid_t clock_id, const struct timespec *tsp); //特定时钟设置时间
struct tm *gmtime(const time_t *calptr); //和下面的函数一样,返回tm结构的指针,出错返回NULL
struct tm *localtime(const time_t *calptr);
time_t mktime(struct tm *tmptr); //以本地时间的年月日作为参数,将其变换成time_t值
size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr);
size_t strftime_l(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr, locale_t locale);
char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tmptr); //这个函数与上两个相反,这个函数是字符串转化成时间输出,上两个是把时间转换成字符串进行输出#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
time_t t;
struct tm *tmp;
char buf1[16], buf2[64];
time(&t);
tmp = localtime(&t);
if(strftime(buf1, 16, "time and date: %r, %a %b %d, %Y", tmp) == 0)
printf("buffer length 16 is too small\n");
else
printf("%s\n", buf1);
if(strftime(buf2, 64, "time and date: %r, %a %b %d, %Y", tmp) == 0)
printf("buffer length 200 is too small\n");
else
printf("%s\n", buf2);
exit(0);
}
相关文章推荐
- 新手必备的常用代码片段整理(一)
- 产生随机数的两种方法
- 6.2、Android Studio内存
- Linux编程-编译(gcc)与调试(gdb)
- 6.2、Android Studio内存
- 文字如果超出了自动 向左 横向 滚动
- chrome控制台
- Android之四大组件之一-Activity(五)扩展
- Linux的名利未发现
- c语言判断体重是否标准的一些问题处理
- Android使用摄像头,分别获取照片的缩略图与原图
- JS监听浏览器窗口关闭
- 51nod 1270 数组的最大代价 dp
- Android 一个程序多入口多icon多界面
- Linux下JDK、Tomcat的安装及配置
- 产品说明这样写,不知道领导会不会打死我
- jni-jni概述以及创建so库
- Chrome 插件: 起动本地应用 (Native messaging)
- 修改oracle用户密码永不过期
- pdf图片转换成jpg图片的两种方法