Linux服务器编程之:utime()函数
1.依賴的頭文件
#include<sys/types.h>
#include<utime.h>
2函數(shù)聲明
int utime(const char *filename, const struct utimbuf *times);
#include<sys/time.h>
int utimes(const char *filename,const struct timeval times[2]);
函數(shù)說明:
The? utime()? system? call changes the access and modification times of
?????? the inode specified by filename to the actime? and? modtime? fields? of
?????? times respectively.
???????翻譯:調(diào)用utime來修改inode中的信息,傳遞的值有:文件名,訪問時間和更改時間。
If? times? is? NULL, then the access and modification times of the file
?????? are set to the current time.
??????翻譯:如果時間為NULL,訪問時間和修改時間默認(rèn)設(shè)置成了當(dāng)前時間。
??????成功放回0,失敗返回1
3.下面是????utimbuf這個結(jié)構(gòu)體:
?????struct utimbuf
???? {
????????????? time_t atime;????????? /*access time :訪問時間*/
??????????????time_t modtime;???? /*modification time :?更改時間*/
?????};
4.utimes()調(diào)用也
The utimes() system call is similar, but the times argument? refers? to
?????? an? array? rather? than? a? structure.?? The elements of this array are
?????? timeval structures, which allow a precision of 1 microsecond for speci‐
?????? fying timestamps.? The timeval structure is:
?????????? struct timeval {
?????????????? long tv_sec;??????? /* seconds */
?????????????? long tv_usec;?????? /* microseconds */
?????????? };
?????? times[0]? specifies the new access time, and times[1] specifies the new
?????? modification time.? If times is NULL, then analogously to utime(),? the
?????? access and modification times of the file are set to the current time.
utimes()的調(diào)用也相似,但是這個時間指定的是一個數(shù)組,而不是一個結(jié)構(gòu)體,數(shù)組的每個元素師一個timeval結(jié)構(gòu)體
這個結(jié)構(gòu)體中允許一個為timestamps所用的精確的微秒值(微秒,百萬分之一秒),其中timeval結(jié)構(gòu)體如下:
???????struct timeval
?????? {
???????????? long tv_sec;????????? /*seconds?秒*/
?????????????long tv_usec;????????/*microseconds?微秒,百萬分之一秒*/
?????? }
times[0]這個元素指定的是訪問時間,times[1]指定的是修改時間。如果時間為NULL,那么,類似(analogously)utime(),
訪問時間和修改時間被設(shè)置成當(dāng)前時間。
總結(jié)
以上是生活随笔為你收集整理的Linux服务器编程之:utime()函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux服务器编程之:chown()函
- 下一篇: Linux服务器编程之:truncate