Beispiel #1
0
void cache_write(const char *path)
{
	int vmajor, vminor;
	FILE *f;
	HDR *h;

	if (check_cache_file(path, &vmajor, &vminor) == CACHE_BAD)
		return;

	if (!(f = fopen(path, "w")))
		return;

	fprintf(f, magic, DEPS_MAJOR, DEPS_MINOR);
	fputc('\n', f);

	for (h = hdrlist; h; h = h->next)
	{
		LIST *l;
		fprintf(f, "%ld %s\n", h->time, h->file);
		for (l = h->includes; l; l = list_next (l))
		{
			fprintf(f, "\t%s\n", l->string);
		}
		fprintf(f, "\n");
	}

	fclose(f);
}
Beispiel #2
0
void cache_read(const char *path)
{
	FILE *f;
	char buf[1024];
	int vmajor, vminor;
	HDR *h = 0;
	int n;
	time_t timeval;

	if (check_cache_file(path, &vmajor, &vminor) != CACHE_OK)
		return;

	if ((vmajor != DEPS_MAJOR) || (vminor != DEPS_MINOR))
		return;

	if (!(f = fopen(path, "r")))
		return;

	/* Skip magic */
	fgets(buf, sizeof(buf), f);

	while (fgets(buf, sizeof (buf), f))
	{
		buf[strlen(buf) - 1] = '\0'; /* zap newline */

		if (!buf[0])
			continue;

		if (buf[0] == '\t')
		{
			h->includes = list_new(h->includes, buf + 1, 0);
			continue;
		}
		
		sscanf(buf, "%ld %n", &timeval, &n);
		h = hdr_enter (buf + n);
		h->time = timeval;
	}

	fclose(f);
}
Beispiel #3
0
int load_cache(const Config *c, Data *d) {
  FILE *cf;
  long cflen;

  if(check_cache_file(c) != 0)
    return  -1;

  if((cf = fopen(c->cache_file, "rb")) == NULL) {
    LERROR(0, errno, "fopen()");
    return -1;
  }

  fseek(cf, 0, SEEK_END);
  cflen = ftell(cf);
  fseek(cf, 0, SEEK_SET);

  d->data = malloc(cflen + 1);
  GUARD_MALLOC(d->data);
  d->datalen = cflen;
  fread(d->data, cflen, 1, cf);
  fclose(cf);

  return 0;
}