static uint32_t get_file_hash_index(struct manifest *mf, char *path, struct file_hash *file_hash, struct hashtable *mf_files, struct hashtable *mf_file_infos) { struct file_info fi; uint32_t *fi_index; uint32_t n; fi.index = get_include_file_index(mf, path, mf_files); memcpy(fi.hash, file_hash->hash, sizeof(fi.hash)); fi.size = file_hash->size; fi_index = hashtable_search(mf_file_infos, &fi); if (fi_index) { return *fi_index; } n = mf->n_file_infos; mf->file_infos = x_realloc(mf->file_infos, (n + 1) * sizeof(*mf->file_infos)); mf->n_file_infos++; mf->file_infos[n] = fi; return n; }
static uint32_t get_file_hash_index(struct manifest *mf, char *path, struct file_hash *file_hash, struct hashtable *mf_files, struct hashtable *mf_file_infos) { struct file_info fi; uint32_t *fi_index; uint32_t n; struct stat file_stat; fi.index = get_include_file_index(mf, path, mf_files); memcpy(fi.hash, file_hash->hash, sizeof(fi.hash)); fi.size = file_hash->size; /* * file_stat.st_{m,c}time has a resolution of 1 second, so we can cache the * file's mtime and ctime only if they're at least one second older than * time_of_compilation. * * st->ctime may be 0, so we have to check time_of_compilation against * MAX(mtime, ctime). */ if (stat(path, &file_stat) != -1 && time_of_compilation > MAX(file_stat.st_mtime, file_stat.st_ctime)) { fi.mtime = file_stat.st_mtime; fi.ctime = file_stat.st_ctime; } else { fi.mtime = -1; fi.ctime = -1; } fi_index = hashtable_search(mf_file_infos, &fi); if (fi_index) { return *fi_index; } n = mf->n_file_infos; mf->file_infos = x_realloc(mf->file_infos, (n + 1) * sizeof(*mf->file_infos)); mf->n_file_infos++; mf->file_infos[n] = fi; return n; }