From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id B2D6F1BE0 for ; Thu, 25 Jan 2018 12:12:41 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 03:12:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,411,1511856000"; d="scan'208";a="22463968" Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.223.223]) by FMSMGA003.fm.intel.com with ESMTP; 25 Jan 2018 03:12:39 -0800 From: Bruce Richardson To: Neil Horman Cc: dev@dpdk.org, Bruce Richardson Date: Thu, 25 Jan 2018 11:12:25 +0000 Message-Id: <20180125111225.231897-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.14.3 Subject: [dpdk-dev] [PATCH] pmdinfogen: allow using stdin and stdout X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jan 2018 11:12:42 -0000 Rather than having to work off files all the time, allow stdin and stdout to be used as the source and destination for pmdinfogen. This will allow other possible usages from scripts, e.g. taking files from ar archive and building a single .pmd.c file from all the .o files in it. for f in `ar t librte_pmd_xyz.a` ; do ar p librte_pmd_xyz.a $f | pmdinfogen - - >> xyz_info.c done Signed-off-by: Bruce Richardson --- buildtools/pmdinfogen/pmdinfogen.c | 44 +++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c index b07dbcf4b..45b267346 100644 --- a/buildtools/pmdinfogen/pmdinfogen.c +++ b/buildtools/pmdinfogen/pmdinfogen.c @@ -26,6 +26,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 +40,32 @@ 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]; + size_t 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) + goto failed; + } + fflush(infile); + fd = fileno(infile); + } - fd = open(filename, O_RDONLY); - if (fd < 0) - return NULL; if (fstat(fd, &st)) goto failed; @@ -358,10 +380,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 +437,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) -- 2.14.3