static void
remember_include_file(char *path, size_t path_len, struct mdfour *cpp_hash)
{
- struct file_hash *h;
struct mdfour fhash;
struct stat st;
char *source = NULL;
size_t size;
int result;
+ bool is_pch;
if (path_len >= 2 && (path[0] == '<' && path[path_len - 1] == '>')) {
/* Typically <built-in> or <command-line>. */
hash_start(&fhash);
- if (is_precompiled_header(path)) {
- hash_file2(&fhash, cpp_hash, path);
+ is_pch = is_precompiled_header(path);
+ if (is_pch) {
+ struct file_hash pch_hash;
+ if (!hash_file(&fhash, path)) {
+ goto failure;
+ }
+ hash_result_as_bytes(&fhash, pch_hash.hash);
+ pch_hash.size = fhash.totalN;
+ hash_delimiter(cpp_hash, "pch_hash");
+ hash_buffer(cpp_hash, pch_hash.hash, sizeof(pch_hash.hash));
}
-
if (enable_direct) {
- if (!is_precompiled_header(path)) {
+ struct file_hash *h;
+
+ if (!is_pch) { /* else: the file has already been hashed. */
if (st.st_size > 0) {
if (!read_file(path, st.st_size, &source, &size)) {
goto failure;
void hash_string(struct mdfour *md, const char *s);
void hash_int(struct mdfour *md, int x);
bool hash_fd(struct mdfour *md, int fd);
-bool hash_fd2(struct mdfour *md1, struct mdfour *md2, int fd);
bool hash_file(struct mdfour *md, const char *fname);
-bool hash_file2(struct mdfour *md1, struct mdfour *md2, const char *fname);
/* ------------------------------------------------------------------------- */
/* util.c */
*/
bool
hash_fd(struct mdfour *md, int fd)
-{
- return hash_fd2(md, NULL, fd);
-}
-
-/*
- * Add contents of an open file to the hash. Returns true on success, otherwise
- * false.
- */
-bool
-hash_fd2(struct mdfour *md1, struct mdfour *md2, int fd)
{
char buf[16384];
ssize_t n;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
- if (md1) {
- hash_buffer(md1, buf, n);
- }
- if (md2) {
- hash_buffer(md2, buf, n);
- }
+ hash_buffer(md, buf, n);
}
return n == 0;
}
*/
bool
hash_file(struct mdfour *md, const char *fname)
-{
- return hash_file2(md, NULL, fname);
-}
-
-/*
- * Add contents of a file to two hash sums. Returns true on success, otherwise
- * false.
- */
-bool
-hash_file2(struct mdfour *md1, struct mdfour *md2, const char *fname)
{
int fd;
bool ret;
return false;
}
- ret = hash_fd2(md1, md2, fd);
+ ret = hash_fd(md, fd);
close(fd);
return ret;
}