函 數 接 口
1.time
time_t time(time_t *t);
功能:
獲得1970年到現在所過的秒數
參數:
t:要存放秒數空間的指針
返回值:
成功返回所過的秒數
失敗返回(time_t *)(-1)
2.localtime
struct tm *localtime(const time_t *timep);
功能:
將從1970年到現在的秒數轉化成日曆時間
參數:
timep:秒數存放空間的首地址
返回值:
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
文件IO
1.文件描述符
很小的非負的整數
int
內核每打開一個文件就會獲得一個文件
描述符
2.函數接口
1.open
int open(const char *pathname, int flags);
功能:
獲得一個文件描述符
參數:
pathname:文件名
flags:
O_RDONLY
O_WRONLY
O_RDWR
返回值:
成功返回文件描述符
失敗返回-1
2.write
ssize_t write(int fd, const void *buf, size_t count);
功能:
通過文件描述符向文件中寫一串數據
參數:
fd:文件描述符
buf:要寫入文件的字符串的首地址
count:要寫入字符的個數
返回值:
成功返回實際寫入的個數
失敗返回-1
3.read
ssize_t read(int fd, void *buf, size_t count);
功能:
通過文件描述符讀取文件中的數據
參數:
fd:文件描述符
buf:存放數據空間的首地址
count:要讀到數據的個數
返回值:
成功返回讀到數據的個數
失敗返回-1
讀到文件結尾返回0
4.lseek
off_t lseek(int fd, off_t offset, int whence);
功能:
定位光標的位置
參數:
fd:文件描述符
offset:偏移量
正:向後偏移
負:向前偏移
零:不偏移
whence:
SEEK_SET
SEEK_CUR
SEEK_END
返回值:
成功返回偏移量
失敗返回-1