生手学UNIX高级环境编程图4-21出错!
新手学UNIX高级环境编程图4-21出错!!!
#include"apue.h"
#include<fcntl.h>
int main(int argc,char* argv[]){
struct stat buf;
struct timespec times[2];
int i,fd;
for(i=1;i<argc;i++){
if (stat(argv[i],&buf)<0){
err_sys("stat error");
continue;
}
fd=open(argv[i],O_RDWR|O_TRUNC);
if (fd<0){
err_sys("open error");
continue;
}
printf("%d",buf.st_atime);
times[0]=buf.st_atime;
times[1]=buf.st_mtime;
if (futimens(fd,times)<0)
err_sys("futimens error");
close(fd);//keyi shenglue
}
exit (0);
}
出现错误!!!
22:error :incompatible types when assigning to type 'struct timespec' from type '_time_t'
------解决思路----------------------
同学,类型不对啊!
struct timespec times[2];
===>
time_t times[2];
The structure stat contains at least the following members:
dev_t st_dev ID of device containing file
ino_t st_ino file serial number
mode_t st_mode mode of file (see below)
nlink_t st_nlink number of links to the file
uid_t st_uid user ID of file
gid_t st_gid group ID of file
dev_t st_rdev device ID (if file is character or block special)
off_t st_size file size in bytes (if file is a regular file)
time_t st_atime time of last access
time_t st_mtime time of last data modification
time_t st_ctime time of last status change
blksize_t st_blksize a filesystem-specific preferred I/O block size for
this object. In some filesystem types, this may
vary from file to file
blkcnt_t st_blocks number of blocks allocated for this object
#include"apue.h"
#include<fcntl.h>
int main(int argc,char* argv[]){
struct stat buf;
struct timespec times[2];
int i,fd;
for(i=1;i<argc;i++){
if (stat(argv[i],&buf)<0){
err_sys("stat error");
continue;
}
fd=open(argv[i],O_RDWR|O_TRUNC);
if (fd<0){
err_sys("open error");
continue;
}
printf("%d",buf.st_atime);
times[0]=buf.st_atime;
times[1]=buf.st_mtime;
if (futimens(fd,times)<0)
err_sys("futimens error");
close(fd);//keyi shenglue
}
exit (0);
}
出现错误!!!
22:error :incompatible types when assigning to type 'struct timespec' from type '_time_t'
------解决思路----------------------
同学,类型不对啊!
struct timespec times[2];
===>
time_t times[2];
The structure stat contains at least the following members:
dev_t st_dev ID of device containing file
ino_t st_ino file serial number
mode_t st_mode mode of file (see below)
nlink_t st_nlink number of links to the file
uid_t st_uid user ID of file
gid_t st_gid group ID of file
dev_t st_rdev device ID (if file is character or block special)
off_t st_size file size in bytes (if file is a regular file)
time_t st_atime time of last access
time_t st_mtime time of last data modification
time_t st_ctime time of last status change
blksize_t st_blksize a filesystem-specific preferred I/O block size for
this object. In some filesystem types, this may
vary from file to file
blkcnt_t st_blocks number of blocks allocated for this object