Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/linux-sunxi/sunxi-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/pio.c
diff options
context:
space:
mode:
authorHenrik Nordstrom <henrik@henriknordstrom.net>2012-08-01 02:29:07 +0400
committerHenrik Nordstrom <henrik@henriknordstrom.net>2012-08-01 02:29:07 +0400
commit1690132c1c24f1e082388463d54d25789d6d7d48 (patch)
tree21da71db4ebbf24309d008b91f8abf757e9f1de5 /pio.c
parente9f338bb6bf5a14b411c2c5034606150b5d7e52f (diff)
pio: Correct parsing of pin values
Diffstat (limited to 'pio.c')
-rw-r--r--pio.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/pio.c b/pio.c
index 3474544..d2ccbf4 100644
--- a/pio.c
+++ b/pio.c
@@ -7,6 +7,7 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
+#include <errno.h>
#include <endian.h>
@@ -174,6 +175,19 @@ static void cmd_show_pin(char *buf, const char *pin)
pio_print(port, port_nr, &pio);
}
+static int parse_int(int *dst, const char *in)
+{
+ int value;
+ char *next;
+ errno = 0;
+ value = strtol(in, &next, 0);
+ if (!errno && next != in) {
+ *dst = value;
+ return 0;
+ }
+ return -1;
+}
+
static void cmd_set_pin(char *buf, const char *pin)
{
int port, port_nr;
@@ -182,29 +196,29 @@ static void cmd_set_pin(char *buf, const char *pin)
parse_pin(&port, &port_nr, pin);
if (!pio_get(buf, port, port_nr, &pio))
usage(1);
- t = strchr(t, '<');
+ if (t)
+ t = strchr(t, '<');
if (t) {
t++;
- if (*t && *t != '>')
- pio.mul_sel = atoi(t);
+ parse_int(&pio.mul_sel, t);
}
- t = strchr(t, '<');
+ if (t)
+ t = strchr(t, '<');
if (t) {
t++;
- if (*t && *t != '>')
- pio.pull = atoi(t);
+ parse_int(&pio.pull, t);
}
- t = strchr(t, '<');
+ if (t)
+ t = strchr(t, '<');
if (t) {
t++;
- if (*t && *t != '>')
- pio.drv_level = atoi(t);
+ parse_int(&pio.drv_level, t);
}
- t = strchr(t, '<');
+ if (t)
+ t = strchr(t, '<');
if (t) {
t++;
- if (*t && *t != '>')
- pio.data = atoi(t);
+ parse_int(&pio.data, t);
}
pio_set(buf, port, port_nr, &pio);
}