00001__文件操作

00001__文件操作

一、简介

在编程的时候,有时候免不了要操作文件,例如覆盖或者重新编译之类的。假如要被操作的文件已经是最新的了,那就没有必要做接下来的动作了。

二、代码如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>

void exit_if_need_not_update(const char* in, const char* out) {
  struct stat st_in;
  struct stat st_out;

  memset(&st_in, 0x00, sizeof(st_in));
  memset(&st_out, 0x00, sizeof(st_out));

  if (in == NULL || out == NULL) {
    printf("param error!")
    exit(-1);
  }

  if (stat(in, &st_in) < 0) {
    printf("%s not exist\n", in);
    exit(-1);
  }

  if (stat(out, &st_out) < 0) {
    printf("%s not exist\n", out);
    return;
  }

  if (st_in.st_mtime < st_out.st_mtime) {
    printf("Skip because: %s is newer than %s\n", out, in);
    exit(0);
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值