Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/i2cscan Allow i2cdev to be specified with or withou...



details:   https://anonhg.NetBSD.org/src/rev/604a9142ef1b
branches:  trunk
changeset: 812007:604a9142ef1b
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Thu Nov 26 17:31:56 2015 +0000

description:
Allow i2cdev to be specified with or without the /dev prefix.
Inspired by and code borrowed from gpioctl(8).

diffstat:

 usr.sbin/i2cscan/i2cscan.8 |  15 ++++++++++++---
 usr.sbin/i2cscan/i2cscan.c |  18 ++++++++++++++----
 2 files changed, 26 insertions(+), 7 deletions(-)

diffs (104 lines):

diff -r fa4b979bb5e9 -r 604a9142ef1b usr.sbin/i2cscan/i2cscan.8
--- a/usr.sbin/i2cscan/i2cscan.8        Thu Nov 26 16:56:52 2015 +0000
+++ b/usr.sbin/i2cscan/i2cscan.8        Thu Nov 26 17:31:56 2015 +0000
@@ -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
diff -r fa4b979bb5e9 -r 604a9142ef1b usr.sbin/i2cscan/i2cscan.c
--- a/usr.sbin/i2cscan/i2cscan.c        Thu Nov 26 16:56:52 2015 +0000
+++ b/usr.sbin/i2cscan/i2cscan.c        Thu Nov 26 17:31:56 2015 +0000
@@ -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 @@
 #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 @@
 __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 @@
        int fd;
        int ch, rflag;
        int mode;
+       char *dev;
+       char devn[32];
 
        setprogname(*argv);
 
@@ -182,8 +186,14 @@
 
        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);
 



Home | Main Index | Thread Index | Old Index