Add lseek to support GPIO read/write
GPIO api does not support repeat read(read multi times after one open).
A workaround is close and reopen the device before the second read.
The root cause is that the file descriptor is not moved to beginning of the file, this patch can fix this issue
Change-Id: I40e5602669c9ab6f0dddf5aa77040466cbfa3738
Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
diff --git a/libopenbmc_intf/gpio.c b/libopenbmc_intf/gpio.c
index 0dfb260..291f9c3 100644
--- a/libopenbmc_intf/gpio.c
+++ b/libopenbmc_intf/gpio.c
@@ -19,6 +19,12 @@
int rc = GPIO_OK;
char buf[1];
buf[0] = value;
+
+ if (lseek(gpio->fd, 0, SEEK_SET) == -1)
+ {
+ return GPIO_ERROR;
+ }
+
if (write(gpio->fd, buf, 1) != 1)
{
rc = GPIO_WRITE_ERROR;
@@ -36,6 +42,12 @@
{
buf[0]='1';
}
+
+ if (lseek(gpio->fd, 0, SEEK_SET) == -1)
+ {
+ return GPIO_ERROR;
+ }
+
if (write(gpio->fd, buf, 1) != 1)
{
rc = GPIO_WRITE_ERROR;
@@ -54,6 +66,11 @@
}
else
{
+ if (lseek(gpio->fd, 0, SEEK_SET) == -1)
+ {
+ return GPIO_ERROR;
+ }
+
if (read(gpio->fd,&buf,1) != 1)
{
r = GPIO_READ_ERROR;