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);
}
运行:
原文链接:https://www.f2er.com/bash/391023.html