#ifdef WITH_LIBGPIOD
static void
-init_libgpiod(char const *chip_name, char const *line_name, int line_num)
+init_libgpiod(char const *chip_name, char const *line_name,
+ unsigned int line_num)
{
struct gpiod_chip * chip;
outfn = &sysfs_out;
}
+static void
+usage()
+{
+
+ fprintf(stderr, "usage!\n");
+ exit(2);
+}
+
static void
init(int argc, char **argv)
{
char *statefile = NULL, *statestr = NULL;
#ifdef WITH_LIBGPIOD
char *gpiod_chip = NULL, *gpiod_line_name = NULL;
- int gpiod_line_num = -1;
+ unsigned int gpiod_line_num;
+ char *endptr;
+ bool have_gpiod_line_num = false;
#endif
int opt;
break;
#ifdef WITH_LIBGPIOD
case 'G':
+ if (gpiod_line_name != NULL)
+ usage();
gpiod_line_name = optarg;
break;
case 'C':
+ if (gpiod_chip != NULL)
+ usage();
gpiod_chip = optarg;
break;
case 'L':
- gpiod_line_num = atoi(optarg);
+ if (have_gpiod_line_num)
+ usage();
+ errno = 0;
+ gpiod_line_num = strtoul(optarg, &endptr, 0);
+ if (errno != 0) {
+ warn(NULL);
+ usage();
+ }
+ if (*endptr != '\0' || *optarg == '\0')
+ usage();
+ have_gpiod_line_num = true;
break;
#endif /* WITH_LIBGPIOD */
case 'Y':
init_sysfs(optarg);
break;
+ case '?':
+ usage();
+ break;
}
}
/* Default startup state is to assume the dial is correct. */