名稱,頭檔案,相關函式,描述,返回值,返回的錯誤類型,
名稱
utimensat, futimens:以納秒級的精度改變檔案的時間戳
頭檔案
#include <sys/stat.h>
相關函式
int utimensat(int dirfd, const char *pathname,const struct timespectimes[2], intflags);
int futimens(int fd, const struct timespectimes[2]);
描述
utimensat()通過檔案的路徑(pathname)獲得檔案,futimens()通過獲得檔案的句柄(fd)獲得檔案。
這兩個系統調用函式都是通過一個時間數組times來改變時間戳的,times[0]修改最後一次訪問的時間,times[1]修改最後修改的時間。該時間數組是由秒和納秒兩個部分組成,數據結構如下:
struct timespec {
time_t tv_sec; /* 秒 */
long tv_nsec; /* 納秒 */
};
返回值
調用成功,utimensat()和futimens()返回0,調用失敗返回-1,並設定errno
返回的錯誤類型
EACCES : 時間為空
EBADF:futimens()的檔案句柄無效
EFAULT:times所指的地址空間無效
EINVAL:flags無效
EINVAL:pathname是空
ELOOP:utimensat()在需找pathname所指的路勁過程中有太多符號連結
ENAMETOOLONG:pathname太長
ENOENT:pathname指向了一個不存在的檔案或者目錄
EPERM:時間戳沒有改為當前時間
EROFS:檔案時唯讀檔案
ESRCH:utimensat()的查找請求被拒絕