+ int fd = -1;
+
+ if (!use_stdin) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+ } else {
+ /* from stdin, use a temporary file to mmap */
+ FILE *infile;
+ char buffer[1024];
+ int n;
+
+ infile = tmpfile();
+ if (infile == NULL) {
+ perror("tmpfile");
+ return NULL;
+ }
+ fd = dup(fileno(infile));
+ fclose(infile);
+ if (fd < 0)
+ return NULL;
+
+ n = read(STDIN_FILENO, buffer, sizeof(buffer));
+ while (n > 0) {
+ if (write(fd, buffer, n) != n)
+ goto failed;
+ n = read(STDIN_FILENO, buffer, sizeof(buffer));
+ }
+ }