Module Name: src Committed By: hubertf Date: Thu Nov 26 17:31:57 UTC 2015
Modified Files: src/usr.sbin/i2cscan: i2cscan.8 i2cscan.c Log Message: Allow i2cdev to be specified with or without the /dev prefix. Inspired by and code borrowed from gpioctl(8). To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/i2cscan/i2cscan.8 \ src/usr.sbin/i2cscan/i2cscan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/i2cscan/i2cscan.8 diff -u src/usr.sbin/i2cscan/i2cscan.8:1.4 src/usr.sbin/i2cscan/i2cscan.8:1.5 --- src/usr.sbin/i2cscan/i2cscan.8:1.4 Thu Nov 26 16:56:52 2015 +++ src/usr.sbin/i2cscan/i2cscan.8 Thu Nov 26 17:31:56 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: i2cscan.8,v 1.4 2015/11/26 16:56:52 hubertf Exp $ +.\" $NetBSD: i2cscan.8,v 1.5 2015/11/26 17:31:56 hubertf Exp $ .\" .\" Copyright (c) 2011, 2013 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd July 10, 2013 +.Dd November 26, 2015 .Dt I2CSCAN 8 .Os .Sh NAME @@ -40,12 +40,21 @@ .Sh DESCRIPTION The .Nm -utility scans the IIC bus +utility scans the Inter-Integrated Circuit bus .Pq Xr iic 4 specified by .Ar i2cdev to determine which addresses respond. .Pp +.Ar i2cdev +can be specified with or without the +.Pa /dev +prefix. +For example, +.Pa /dev/iic0 +or +.Pa iic0 . +.Pp Available options: .Bl -tag -width Ds .It Fl r Index: src/usr.sbin/i2cscan/i2cscan.c diff -u src/usr.sbin/i2cscan/i2cscan.c:1.4 src/usr.sbin/i2cscan/i2cscan.c:1.5 --- src/usr.sbin/i2cscan/i2cscan.c:1.4 Wed Jul 10 15:18:54 2013 +++ src/usr.sbin/i2cscan/i2cscan.c Thu Nov 26 17:31:56 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: i2cscan.c,v 1.4 2013/07/10 15:18:54 tcort Exp $ */ +/* $NetBSD: i2cscan.c,v 1.5 2015/11/26 17:31:56 hubertf Exp $ */ /*- * Copyright (c) 2011, 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: i2cscan.c,v 1.4 2013/07/10 15:18:54 tcort Exp $"); +__RCSID("$NetBSD: i2cscan.c,v 1.5 2015/11/26 17:31:56 hubertf Exp $"); #include <sys/types.h> #include <sys/ioctl.h> @@ -38,8 +38,10 @@ __RCSID("$NetBSD: i2cscan.c,v 1.4 2013/0 #include <err.h> #include <errno.h> #include <fcntl.h> +#include <paths.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include <dev/i2c/i2c_io.h> @@ -50,7 +52,7 @@ __RCSID("$NetBSD: i2cscan.c,v 1.4 2013/0 __dead static void usage(void) { - fprintf(stderr, "usage: %s [-r] <i2cdev>\n", getprogname()); + fprintf(stderr, "usage: %s [-r] i2cdev\n", getprogname()); exit(EXIT_FAILURE); } @@ -159,6 +161,8 @@ main(int argc, char *argv[]) int fd; int ch, rflag; int mode; + char *dev; + char devn[32]; setprogname(*argv); @@ -182,8 +186,14 @@ main(int argc, char *argv[]) if (*argv == NULL) usage(); + dev = argv[0]; - fd = open(*argv, O_RDWR); + if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { + (void)snprintf(devn, sizeof(devn), "%s%s", _PATH_DEV, dev); + dev = devn; + } + + fd = open(dev, O_RDWR); if (fd == -1) err(EXIT_FAILURE, "couldn't open %s", *argv);