*/
static void stabs_hash(const char *fname)
{
- FILE *f;
- char *s;
- static char *line;
-
- if (!line) line = malloc(MAX_LINE_SIZE);
- if (!line) {
- cc_log("Can't allocate in stabs hash!\n");
+ int fd;
+ struct stat st;
+ char *map;
+ int l_start, l_end;
+
+ fd = open(fname, O_RDONLY);
+ if (fd == -1 || fstat(fd, &st) != 0) {
+ cc_log("Failed to open preprocessor output %s\n", fname);
failed();
}
- line[MAX_LINE_SIZE-2] = 0;
-
- f = fopen(fname, "r");
- if (!f) {
- cc_log("Failed to open preprocessor output\n");
+ map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (map == (void *)-1) {
+ cc_log("Failed to mmap %s\n", fname);
failed();
}
-
- while ((s = fgets(line, MAX_LINE_SIZE, f))) {
- if (line[MAX_LINE_SIZE-2]) {
- cc_log("line too long in preprocessor output!\n");
- failed();
- }
+ close(fd);
- /* ignore debugging output */
- if (line[0] == '#' && line[1] == ' ' && isdigit(line[2])) {
+ l_start = 0;
+ while (l_start < st.st_size) {
+ l_end = l_start;
+ while (l_end < st.st_size && map[l_end] != '\n') {
+ l_end++;
+ }
+ if ((l_end - l_start) > 2 &&
+ map[l_start] == '#' && map[l_start+1] == ' ' &&
+ isdigit(map[l_start+2])) {
+ l_start = l_end+1;
continue;
}
-
- hash_string(s);
+ hash_buffer(&map[l_start], 1 + l_end - l_start);
+ l_start = l_end+1;
}
- fclose(f);
+ munmap(map, st.st_size);
}
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
void hash_int(int x);
void hash_file(const char *fname);
char *hash_result(void);
+void hash_buffer(const char *s, int len);
void cc_log(const char *format, ...);
void fatal(const char *msg);
mdfour_update(&md, s, strlen(s));
}
+void hash_buffer(const char *s, int len)
+{
+ mdfour_update(&md, s, len);
+}
+
void hash_int(int x)
{
mdfour_update(&md, (unsigned char *)&x, sizeof(x));