コード例 #1
0
ファイル: fdupes.c プロジェクト: MartinThoma/fdupes
void getfilestats(file_t *file)
{
  file->size = filesize(file->d_name);
  file->inode = getinode(file->d_name);
  file->device = getdevice(file->d_name);
  file->mtime = getmtime(file->d_name);
}
コード例 #2
0
ファイル: webmize.c プロジェクト: ploki/Not-So-Original
static int
setmtime(const char *dir, time_t time)
{
  struct stat st;
  int ret;
  ret = stat(dir, &st);
  if ( ret < 0 )
    {
      ERROR("stat(%s): %s", dir, strerror(errno));
      return ret;
    }
  struct utimbuf utim = {
    .actime = st.st_atim.tv_sec,
    .modtime = time,
  };
  
  ret = utime(dir, &utim);
  if ( ret < 0 )
    ERROR("utime(%s): %s", dir, strerror(errno));
  return ret;
}

static int
probe_setmtime(const char *dir, time_t *dt)
{
  int ret;
  ret = getmtime(dir, dt);
  if ( ret < 0 )
    return ret;
  ret = setmtime(dir, *dt + 1);
  if ( ret < 0 )
    return ret;
  ret = setmtime(dir, *dt);
  return ret;
}
コード例 #3
0
bool nr::csv::csv_table::init(std::string const& file, bool force_reload, bool* reloaded)
{
  if (reloaded) *reloaded = false;

  // Check if we need to reload the file.
  if (!force_reload && file == this->file_) {
    uint64_t ftime = getmtime(file);
    if (ftime == this->ftime_) {
      return true;
    }
    this->ftime_ = ftime;
  }
  else {
    this->file_ = file;
    this->ftime_ = getmtime(file);
  }

  // Flush and reload the CSV data.
  this->clear();
  FILE* fp = fopen(file.c_str(), "r");
  if (!fp) {
    return false;
  }
  auto callback = [this](csv_row const& row)
  {
    if (this->rowmin_ == 0 || row.size() < this->rowmin_)
      this->rowmin_ = row.size();
    if (this->rowmax_ == 0 || row.size() > this->rowmax_)
      this->rowmax_ = row.size();
    this->rows_.push_back(row);
    return true;
  };
  parse(fp, callback, this->delim_, this->quote_);

  if (reloaded) *reloaded = true;
  this->loaded_ = true;
  return true;
}
コード例 #4
0
/**
 * File's actual metadata
 */
xa_t getactualxa(FILE *f)
{
	xa_t actual;
	/*
	 * Must read mtime *before* file hash,
	 * if the file is being modified, hash will be invalid
	 * but timestamp will be outdated anyway
	 */
	actual=getmtime(f);

	/*
	 * Compute hash
	 */
	fhash(f,actual.sha256);

	return actual;
}
コード例 #5
0
ファイル: checkfunc.c プロジェクト: bycool/programming
static int __init checkfunc_init(void){
	getmtime();

	printk("checkfunc mod init\n");
	return 0;
}
コード例 #6
0
int main( int argc, const char* argv[] )
{
	char const * myname;
	myname=argv[0];

	if(argc != 2)
	{
		fprintf(stderr,"Usage: %s FILE\n",myname);
		exit(1);
	}

	char const * fn;
	fn=argv[1];

	FILE *f;
	f=fopen(fn,"r");
	if(!f)
	{
		fprintf(stderr,"Error: could not open file \"%s\": %s\n",fn,strerror(errno));
		exit(2);
	}

	xa_t s;
	s=getstoredxa(f);
	xa_t a;
	a=getactualxa(f);
	int needsupdate=0;
	int havecorrupt=0;

	if(s.s==a.s && s.ns==a.ns)
	{
		/*
		 * Times are the same, go ahead and compare the hash
		 */
		if(strcmp(s.sha256,a.sha256)!=0)
		{
			/*
			 * Hashes are different, but this may be because
			 * the file has been modified while we were computing the hash.
			 * So check if the mtime ist still the same.
			 */
			xa_t a2;
			a2=getmtime(f);
			if(s.s==a2.s && s.ns==a2.ns)
			{
				/*
				 * Now, this is either data corruption or somebody modified the file
				 * and reset the mtime to the last value (to hide the modification?)
				 */
				fprintf(stderr,"Error: corrupt file \"%s\"\n",fn);
				printf("<corrupt> %s\n",fn);
				printf(" stored: %s\n actual: %s\n",formatxa(s),formatxa(a));
				needsupdate=1;
				havecorrupt=1;
			}
		}
		else
			printf("<ok> %s\n",fn);
	}
	else
	{
		printf("<outdated> %s\n",fn);
		printf(" stored: %s\n actual: %s\n",formatxa(s),formatxa(a));
		needsupdate=1;
	}

	if(needsupdate && writexa(f,a)!=0)
	{
		fprintf(stderr,"Error: could not write extended attributes to file \"%s\": %s\n",fn,strerror(errno));
		exit(4);
	}

	if(havecorrupt)
		return 5;
	else
		return 0;
}
コード例 #7
0
ファイル: http.c プロジェクト: NTNcs631/NTN
int
clienthead(int clientsocket_fd, char *info[18], ReqInfo *req_info, char *pathname)
{
  char *gmt_str;
  char *mtime_str;
  char *file_type;
  char *file_length;
  char hostname[128];

  if (req_info->type != SIMPLE)
    if (write(clientsocket_fd, "HTTP/1.0 ", strlen("HTTP/1.0 ")) != 
        strlen("HTTP/1.0 ")) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
  if (write(clientsocket_fd, info[req_info->status], 
            strlen(info[req_info->status])) != strlen(info[req_info->status])) {
    fprintf(stderr, "Unable to write %s: %s\n",
            info[req_info->status], strerror(errno));
    return 1;
  }
  if (write(clientsocket_fd, "\n", 1) != 1) {
    fprintf(stderr, "Unable to write: %s\n", strerror(errno));
    return 1;
  }
  if (getgmttime(& gmt_str)) {
    fprintf(stderr, "Unable to get gmt time.\n");
    return 1;
  }
  if ((req_time = (char*)malloc((strlen(gmt_str)+1)*sizeof(char))) == NULL) {
      fprintf(stderr, "Unable to allocate memory: %s\n",
              strerror(errno));
      return 1;
  }
  strcpy(req_time, gmt_str);
  req_time[GMT_LENGTH] = '\0';
  if (req_info->type != SIMPLE) {
    if (write(clientsocket_fd, "Date: ", strlen("Date: ")) != strlen("Date: ")) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, gmt_str, strlen(gmt_str)) != strlen(gmt_str)) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (gethostname(hostname, sizeof(hostname)) < 0) {
      fprintf(stderr, "Unable to get hostname: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, "Server: ", strlen("Server: ")) != 
        strlen("Server: ")) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, hostname, strlen(hostname)) != 
        strlen(hostname)) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, "\n", 1) != 1) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
  }
  if (req_info->status != OK && req_info->status != SIMPLE_RESPONSE && 
      req_info->status != CREATED)
    return 0;
  if (req_info->type != SIMPLE) {
    if (getmtime(pathname, &mtime_str)) {
      fprintf(stderr, "Unable to get modify time.\n");
      return 1;
    }
    if (write(clientsocket_fd, "Last-Modified: ", strlen("Last-Modified: ")) != 
              strlen("Last-Modified: ")) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, mtime_str, strlen(mtime_str)) != 
        strlen(mtime_str)) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (gettype(& file_type, pathname)) {
      fprintf(stderr, "Unable to get type.\n");
      return 1;
    }
    if (write(clientsocket_fd, "Content-Type: ", strlen("Content-Type: ")) != 
        strlen("Content-Type: ")) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, file_type, strlen(file_type)) != 
        strlen(file_type)) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, "\n", 1) != 1) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
  }
  if ((file_length = getlength(pathname)) == NULL) {
    fprintf(stderr, "Unable to get type.\n");
    return 1;
  }
  if ((log_length = (char*)malloc((strlen(file_length)+1)*sizeof(char))) == NULL) {
      fprintf(stderr, "Unable to allocate memory: %s\n",
              strerror(errno));
      return 1;
  }
  strcpy(log_length, file_length);
  if (req_info->type != SIMPLE) {
    if (write(clientsocket_fd, "Content-Length: ", strlen("Content-Length: ")) != 
        strlen("Content-Length: ")) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, file_length, strlen(file_length)) != 
        strlen(file_length)) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, "\n", 1) != 1) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
    if (write(clientsocket_fd, "\n", 1) != 1) {
      fprintf(stderr, "Unable to write: %s\n", strerror(errno));
      return 1;
    }
  }
  return 0;
}