From c00e9e68d7f77cc3cf3475203860a66cafeba449 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 19 Aug 2010 16:54:30 +0000 Subject: [PATCH] Use already cached fp rather than constantly re-opening things on the fly. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1830 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 3 +++ urjtag/src/tap/cable/gpio.c | 18 ++---------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 01133be6..6ffc3432 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -4,6 +4,9 @@ src/tap/Makefile.am: Add vsllink cable driver to cable lists. * src/tap/cable/vsllink.c: New cable driver by Simon Qian. + * src/tap/cable/gpio.c (gpio_get_value): Use already cached fp rather than + constantly re-opening things on the fly. + 2010-08-18 Mike Frysinger * configure.ac (AC_CHECK_FUNCS): Check for _sleep. diff --git a/urjtag/src/tap/cable/gpio.c b/urjtag/src/tap/cable/gpio.c index 02472a11..6e4c2c73 100644 --- a/urjtag/src/tap/cable/gpio.c +++ b/urjtag/src/tap/cable/gpio.c @@ -127,26 +127,12 @@ static int gpio_set_value (FILE *fp, int value) return URJ_STATUS_OK; } -static int gpio_get_value (unsigned int gpio) +static int gpio_get_value (FILE *fp, unsigned int gpio) { int ret; int value; - char fname[50]; - FILE *fp; - - snprintf (fname, sizeof (fname), - "%sgpio%u/value", GPIO_PATH, gpio); - fname[sizeof (fname) - 1] = '\0'; - - fp = fopen (fname, "r"); - if (!fp) - { - urj_warning (_("%s: cannot open to read GPIO %u\n"), fname, gpio); - return URJ_STATUS_FAIL; - } ret = fscanf (fp, "%i", &value); - fclose (fp); if (ret != 1) { @@ -355,7 +341,7 @@ gpio_get_tdo ( urj_cable_t *cable ) urj_tap_cable_wait (cable); - return (gpio_get_value (p->jtag_gpios[GPIO_TDO])); + return gpio_get_value (p->fp_gpios[GPIO_TDO], p->jtag_gpios[GPIO_TDO]); } static int