| 133 | } |
| 134 | |
| 135 | void AddFile(CSHA512& hasher, const char *path) |
| 136 | { |
| 137 | struct stat sb = {}; |
| 138 | int f = open(path, O_RDONLY); |
| 139 | size_t total = 0; |
| 140 | if (f != -1) { |
| 141 | unsigned char fbuf[4096]; |
| 142 | int n; |
| 143 | hasher.Write((const unsigned char*)&f, sizeof(f)); |
| 144 | if (fstat(f, &sb) == 0) hasher << sb; |
| 145 | do { |
| 146 | n = read(f, fbuf, sizeof(fbuf)); |
| 147 | if (n > 0) hasher.Write(fbuf, n); |
| 148 | total += n; |
| 149 | /* not bothering with EINTR handling. */ |
| 150 | } while (n == sizeof(fbuf) && total < 1048576); // Read only the first 1 Mbyte |
| 151 | close(f); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void AddPath(CSHA512& hasher, const char *path) |
| 156 | { |
no test coverage detected