系统数据文件
登录记帐
系统标识
时间和日期
===============================================================================
* 要获取口令文件的单个条目信息, 可利用 getpwuid 和 getpwnam, 分别以用户 ID 和
用户名作为参数, 这两个函数均返回 struct passwd 结构指针, 该结构的成员与
/etc/passwd 文件的字段一一对应.
* 要遍历口令文件, 可利用 setpwent, getpwent, endpwent 函数组.
* getpwent 每次调用时返回下一个条目.
===============================================================================
===============================================================================
#include <sys/utsname.h>
int uname (struct utsname *buf);
-------------------------------------------------------------------------------
struct utsname {
char sysname[SYS_NMLN];
char nodename[SYS_NMLN];
char release[SYS_NMLN];
char version[SYS_NMLN];
char machine[SYS_NMLN];
char domainname[SYS_NMLN];
};
===============================================================================
===============================================================================
#include <time.h>
time_t time(time_t *t);
-------------------------------------------------------------------------------
* time 返回日历时间, 即 1970 年 1 月 1 日 0:00:00 (UTC) 开始的秒数, 称为 Epoch.
===============================================================================
===============================================================================
#include <time.h>
struct tm *gmtime (const time_t *timep);
struct tm *localtime (const time_t *timep);
-------------------------------------------------------------------------------
struct tm
{
int tm_sec; /* seconds [0, 61]*/
int tm_min; /* minutes [0, 59]*/
int tm_hour; /* hours [0, 23]*/
int tm_mday; /* day of the month [1, 31]*/
int tm_mon; /* month [0, 11]*/
int tm_year; /* years since 1900*/
int tm_wday; /* day of the week [0, 6]*/
int tm_yday; /* day in the year [0, 365]*/
int tm_isdst; /* daylight saving time */
};
-------------------------------------------------------------------------------
* gmtime 不转换为本地时间, 即忽略系统的时区设置.
* localtime 转换为本地时间, 包括时区和夏时制.
===============================================================================
===============================================================================
#include <time.h>
time_t mktime(struct tm *timeptr);
-------------------------------------------------------------------------------
* 受 TZ 和 LC_TIME 的影响
===============================================================================
===============================================================================
#include <time.h>
char *asctime(const struct tm *timeptr);
char *ctime(const time_t *timep);
-------------------------------------------------------------------------------
* asctime 的参数是分解时间
* ctime 的参数是日历时间
* ctime 受 TZ 和 LC_TIME 的影响
===============================================================================
===============================================================================
#include <time.h>
size_t strftime (char *s, size_t max, const char *format,
const struct tm *tm);
-------------------------------------------------------------------------------
* format 指定格式信息
* 有将近 50 个格式化字符, 包括: %a (简写星期), %B (完整月份名称) 等等.
-------------------------------------------------------------------------------
===============================================================================
![]()