-/* Postprocess pmd object files to export hw support
+/* SPDX-License-Identifier: GPL-2.0
+ * Postprocess pmd object files to export hw support
*
* Copyright 2016 Neil Horman <nhorman@tuxdriver.com>
* Based in part on modpost.c from the linux kernel
- *
- * This software may be used and distributed according to the terms
- * of the GNU General Public License V2, incorporated herein by reference.
- *
*/
-#define _GNU_SOURCE
#include <stdio.h>
#include <ctype.h>
#include <string.h>
/* from stdin, use a temporary file to mmap */
FILE *infile;
char buffer[1024];
- size_t n;
+ int n;
infile = tmpfile();
if (infile == NULL) {
perror("tmpfile");
return NULL;
}
- while (!feof(stdin)) {
- n = fread(buffer, 1, sizeof(buffer), stdin);
- if (fwrite(buffer, 1, n, infile) != n)
+ 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));
}
- fflush(infile);
- fd = fileno(infile);
}
if (fstat(fd, &st))