p4-11.c

来自「SUN Solaris8平台下进程间通信」· C语言 代码 · 共 28 行

C
28
字号
#include <sys/types.h>#include <utime.h>#include <sys/stat.h>#include <fcntl.h>#include "err_exit.h"int main(int argc, char *argv[]){    int i;    struct  stat statbuf;    struct utimbuf times;    if (argc != 2) {       printf("Usage: a.out filename\n");       exit(1);    }    if (stat(argv[1],&statbuf) < 0)       /* 获得文件的当前时间 */       err_exit(argv[1]);if (open(argv[1],O_RDWR|O_TRUNC) < 0)      /* 截断文件 */       err_exit(argv[1]);    printf("%s is truncated now.\n", argv[1] );    times.actime = statbuf.st_atime;          /* 恢复文件时间至原时间 */    times.modtime = statbuf.st_mtime;       if (utime(argv[1], &times) == 0)                   printf ("utime() call successful\n");    else       printf ("ERROR: utime() call failed. %s\n",strerror(errno));    exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?