vi 1.0.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#define BUF 100
void print_time(time_t ct,char* s)
{
char st[BUF];
printf("%s: ",s);
strftime(st,BUF,"%Y %x %X",localtime(&ct));
printf("%s\n",st);
}
int main(int argc,char* argv[])
{
if (argc != 2)
{
printf("you need <pathname>\n");
exit(0);
}
struct stat statbuf;
if (lstat(argv[1],&statbuf) < 0)
{
printf("lstat error\n");
exit(0);
}
char *s = "文件最后访问时间为";
print_time(statbuf.st_atime,s);
s = "文件最后修改时间为";
print_time(statbuf.st_mtime,s);
s = "文件最后状态改变时间为";
print_time(statbuf.st_ctime,s);
}
运行:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。