X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=buildtools%2Fpmdinfogen%2Fpmdinfogen.c;h=dc0b6d5ff41e908f6f218c2f3454e0405d5383c1;hb=5d7b673d5fd6663b20c675dd382d9fb43b42af18;hp=b07dbcf4b17afc914a9feffce05ea007ef5dff3f;hpb=74d6c4a72eb2ba9025f25706227f4cf304fe0ba6;p=dpdk.git diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c index b07dbcf4b1..dc0b6d5ff4 100644 --- a/buildtools/pmdinfogen/pmdinfogen.c +++ b/buildtools/pmdinfogen/pmdinfogen.c @@ -8,7 +8,6 @@ * */ -#define _GNU_SOURCE #include #include #include @@ -26,6 +25,7 @@ #define ADDR_SIZE 32 #endif +static int use_stdin, use_stdout; static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) { @@ -39,11 +39,36 @@ static void *grab_file(const char *filename, unsigned long *size) { struct stat st; void *map = MAP_FAILED; - int fd; + 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)); + } + } - fd = open(filename, O_RDONLY); - if (fd < 0) - return NULL; if (fstat(fd, &st)) goto failed; @@ -358,10 +383,14 @@ static void output_pmd_info_string(struct elf_info *info, char *outfile) struct rte_pci_id *pci_ids; int idx = 0; - ofd = fopen(outfile, "w+"); - if (!ofd) { - fprintf(stderr, "Unable to open output file\n"); - return; + if (use_stdout) + ofd = stdout; + else { + ofd = fopen(outfile, "w+"); + if (!ofd) { + fprintf(stderr, "Unable to open output file\n"); + return; + } } drv = info->drivers; @@ -411,6 +440,8 @@ int main(int argc, char **argv) basename(argv[0])); exit(127); } + use_stdin = !strcmp(argv[1], "-"); + use_stdout = !strcmp(argv[2], "-"); parse_elf(&info, argv[1]); if (locate_pmd_entries(&info) < 0)