svn commit: r269879 - in stable/10: . share/examples share/examples/libusb20

Ed Maste emaste at FreeBSD.org
Tue Aug 12 14:53:04 UTC 2014


Author: emaste
Date: Tue Aug 12 14:53:02 2014
New Revision: 269879
URL: http://svnweb.freebsd.org/changeset/base/269879

Log:
  MFC cleanup of libusb20 example
  
  r257779 by hselasky:
  
    - Use libusb20_strerror() function instead of custom usb_error() one.
    - Rename "aux.[ch]" to "util.[ch]" which is a more common name for
    utility functions and allows checkout on some non-FreeBSD systems
    where the "aux.*" namespace is reserved.
    - Fix some compile warnings while at it.
  
  r257796 by glebius:
  
    Finish r257779.
  
  PR:		183728

Added:
  stable/10/share/examples/libusb20/util.c
     - copied unchanged from r257779, head/share/examples/libusb20/util.c
  stable/10/share/examples/libusb20/util.h
     - copied unchanged from r257779, head/share/examples/libusb20/util.h
Deleted:
  stable/10/share/examples/libusb20/aux.c
  stable/10/share/examples/libusb20/aux.h
Modified:
  stable/10/ObsoleteFiles.inc
  stable/10/share/examples/Makefile
  stable/10/share/examples/libusb20/Makefile
  stable/10/share/examples/libusb20/bulk.c
  stable/10/share/examples/libusb20/control.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/ObsoleteFiles.inc
==============================================================================
--- stable/10/ObsoleteFiles.inc	Tue Aug 12 14:37:33 2014	(r269878)
+++ stable/10/ObsoleteFiles.inc	Tue Aug 12 14:53:02 2014	(r269879)
@@ -38,6 +38,9 @@
 #   xargs -n1 | sort | uniq -d;
 # done
 
+# 20140812: example files removed
+OLD_FILES+=usr/share/examples/libusb20/aux.c
+OLD_FILES+=usr/share/examples/libusb20/aux.h
 # 20140728: Remove an obsolete man page
 OLD_FILES+=usr/share/man/man9/VOP_GETVOBJECT.9.gz
 OLD_FILES+=usr/share/man/man9/VOP_CREATEVOBJECT.9.gz

Modified: stable/10/share/examples/Makefile
==============================================================================
--- stable/10/share/examples/Makefile	Tue Aug 12 14:37:33 2014	(r269878)
+++ stable/10/share/examples/Makefile	Tue Aug 12 14:53:02 2014	(r269879)
@@ -107,8 +107,8 @@ XFILES=	BSD_daemon/FreeBSD.pfa \
 	kld/syscall/test/call.c \
 	libusb20/Makefile \
 	libusb20/README \
-	libusb20/aux.c \
-	libusb20/aux.h \
+	libusb20/util.c \
+	libusb20/util.h \
 	libusb20/bulk.c \
 	libusb20/control.c \
 	libvgl/Makefile \

Modified: stable/10/share/examples/libusb20/Makefile
==============================================================================
--- stable/10/share/examples/libusb20/Makefile	Tue Aug 12 14:37:33 2014	(r269878)
+++ stable/10/share/examples/libusb20/Makefile	Tue Aug 12 14:53:02 2014	(r269879)
@@ -1,13 +1,14 @@
 # $FreeBSD$
 TARGETS=	bulk control
+CFLAGS+=	-Wall
 
 all: $(TARGETS)
 
-bulk: bulk.o aux.o
-	$(CC) $(CFLAGS) -o bulk bulk.o aux.o -lusb
+bulk: bulk.o util.o
+	$(CC) $(CFLAGS) -o bulk bulk.o util.o -lusb
 
-control: control.o aux.o
-	$(CC) $(CFLAGS) -o control control.o aux.o -lusb
+control: control.o util.o
+	$(CC) $(CFLAGS) -o control control.o util.o -lusb
 
 clean:
 	rm -f $(TARGETS) *.o *~

Modified: stable/10/share/examples/libusb20/bulk.c
==============================================================================
--- stable/10/share/examples/libusb20/bulk.c	Tue Aug 12 14:37:33 2014	(r269878)
+++ stable/10/share/examples/libusb20/bulk.c	Tue Aug 12 14:53:02 2014	(r269879)
@@ -41,7 +41,7 @@
 #include <libusb20.h>
 #include <libusb20_desc.h>
 
-#include "aux.h"
+#include "util.h"
 
 /*
  * If you want to see the details of the internal datastructures
@@ -74,7 +74,7 @@ doit(struct libusb20_device *dev)
    */
   if ((rv = libusb20_dev_open(dev, 2)) != 0)
     {
-      fprintf(stderr, "libusb20_dev_open: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_dev_open: %s\n", libusb20_strerror(rv));
       return;
     }
 
@@ -84,7 +84,7 @@ doit(struct libusb20_device *dev)
    */
   if ((rv = libusb20_dev_set_config_index(dev, 0)) != 0)
     {
-      fprintf(stderr, "libusb20_dev_set_config_index: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_dev_set_config_index: %s\n", libusb20_strerror(rv));
       return;
     }
 
@@ -97,7 +97,7 @@ doit(struct libusb20_device *dev)
 
   if (xfr_in == NULL || xfr_out == NULL)
     {
-      fprintf(stderr, "libusb20_tr_get_pointer: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_tr_get_pointer: %s\n", libusb20_strerror(rv));
       return;
     }
 
@@ -107,12 +107,12 @@ doit(struct libusb20_device *dev)
    */
   if ((rv = libusb20_tr_open(xfr_out, 0, 1, out_ep)) != 0)
     {
-      fprintf(stderr, "libusb20_tr_open: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_tr_open: %s\n", libusb20_strerror(rv));
       return;
     }
   if ((rv = libusb20_tr_open(xfr_in, 0, 1, in_ep)) != 0)
     {
-      fprintf(stderr, "libusb20_tr_open: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_tr_open: %s\n", libusb20_strerror(rv));
       return;
     }
 
@@ -124,7 +124,7 @@ doit(struct libusb20_device *dev)
       if ((rv = libusb20_tr_bulk_intr_sync(xfr_out, out_buf, out_len, &rlen, TIMEOUT))
 	  != 0)
 	{
-	  fprintf(stderr, "libusb20_tr_bulk_intr_sync (OUT): %s\n", usb_error(rv));
+	  fprintf(stderr, "libusb20_tr_bulk_intr_sync (OUT): %s\n", libusb20_strerror(rv));
 	}
       printf("sent %d bytes\n", rlen);
     }
@@ -132,7 +132,7 @@ doit(struct libusb20_device *dev)
   if ((rv = libusb20_tr_bulk_intr_sync(xfr_in, in_buf, BUFLEN, &rlen, TIMEOUT))
       != 0)
     {
-      fprintf(stderr, "libusb20_tr_bulk_intr_sync: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_tr_bulk_intr_sync: %s\n", libusb20_strerror(rv));
     }
       printf("received %d bytes\n", rlen);
       if (rlen > 0)

Modified: stable/10/share/examples/libusb20/control.c
==============================================================================
--- stable/10/share/examples/libusb20/control.c	Tue Aug 12 14:37:33 2014	(r269878)
+++ stable/10/share/examples/libusb20/control.c	Tue Aug 12 14:53:02 2014	(r269879)
@@ -11,8 +11,6 @@
 /*
  * Simple demo program to illustrate the handling of FreeBSD's
  * libusb20.
- *
- * XXX
  */
 
 /*
@@ -38,12 +36,15 @@
 #include <stdlib.h>
 #include <sysexits.h>
 #include <unistd.h>
+#include <string.h>
 
 #include <libusb20.h>
 #include <libusb20_desc.h>
 
 #include <sys/queue.h>
 
+#include "util.h"
+
 /*
  * If you want to see the details of the internal datastructures
  * in the debugger, unifdef the following.
@@ -86,7 +87,7 @@ doit(struct libusb20_device *dev)
    */
   if ((rv = libusb20_dev_open(dev, 1)) != 0)
     {
-      fprintf(stderr, "libusb20_dev_open: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_dev_open: %s\n", libusb20_strerror(rv));
       return;
     }
 
@@ -96,7 +97,7 @@ doit(struct libusb20_device *dev)
    */
   if ((rv = libusb20_dev_set_config_index(dev, 0)) != 0)
     {
-      fprintf(stderr, "libusb20_dev_set_config_index: %s\n", usb_error(rv));
+      fprintf(stderr, "libusb20_dev_set_config_index: %s\n", libusb20_strerror(rv));
       return;
     }
 
@@ -126,7 +127,7 @@ doit(struct libusb20_device *dev)
 					  0 /* flags */)) != 0)
 	{
 	  fprintf(stderr,
-		  "libusb20_dev_request_sync: %s\n", usb_error(rv));
+		  "libusb20_dev_request_sync: %s\n", libusb20_strerror(rv));
 	}
       printf("sent %d bytes\n", actlen);
       if ((setup.bmRequestType & 0x80) != 0)
@@ -146,7 +147,7 @@ doit(struct libusb20_device *dev)
 
       if (xfr_intr == NULL)
 	{
-	  fprintf(stderr, "libusb20_tr_get_pointer: %s\n", usb_error(rv));
+	  fprintf(stderr, "libusb20_tr_get_pointer: %s\n", libusb20_strerror(rv));
 	  return;
 	}
 
@@ -155,7 +156,7 @@ doit(struct libusb20_device *dev)
        */
       if ((rv = libusb20_tr_open(xfr_intr, 0, 1, intr_ep)) != 0)
 	{
-	  fprintf(stderr, "libusb20_tr_open: %s\n", usb_error(rv));
+	  fprintf(stderr, "libusb20_tr_open: %s\n", libusb20_strerror(rv));
 	  return;
 	}
 
@@ -165,7 +166,7 @@ doit(struct libusb20_device *dev)
       if ((rv = libusb20_tr_bulk_intr_sync(xfr_intr, in_buf, BUFLEN, &rlen, TIMEOUT))
 	  != 0)
 	{
-	  fprintf(stderr, "libusb20_tr_bulk_intr_sync: %s\n", usb_error(rv));
+	  fprintf(stderr, "libusb20_tr_bulk_intr_sync: %s\n", libusb20_strerror(rv));
 	}
       printf("received %d bytes\n", rlen);
       if (rlen > 0)

Copied: stable/10/share/examples/libusb20/util.c (from r257779, head/share/examples/libusb20/util.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/10/share/examples/libusb20/util.c	Tue Aug 12 14:53:02 2014	(r269879, copy of r257779, head/share/examples/libusb20/util.c)
@@ -0,0 +1,50 @@
+/* ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42) (by Poul-Henning Kamp):
+ * <joerg at FreeBSD.ORG> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.        Joerg Wunsch
+ * ----------------------------------------------------------------------------
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Helper functions common to all examples
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <libusb20.h>
+#include <libusb20_desc.h>
+
+#include "util.h"
+
+/*
+ * Print "len" bytes from "buf" in hex, followed by an ASCII
+ * representation (somewhat resembling the output of hd(1)).
+ */
+void
+print_formatted(uint8_t *buf, uint32_t len)
+{
+  int i, j;
+
+  for (j = 0; j < len; j += 16)
+    {
+      printf("%02x: ", j);
+
+      for (i = 0; i < 16 && i + j < len; i++)
+	printf("%02x ", buf[i + j]);
+      printf("  ");
+      for (i = 0; i < 16 && i + j < len; i++)
+	{
+	  uint8_t c = buf[i + j];
+	  if(c >= ' ' && c <= '~')
+	    printf("%c", (char)c);
+	  else
+	    putchar('.');
+	}
+      putchar('\n');
+    }
+}

Copied: stable/10/share/examples/libusb20/util.h (from r257779, head/share/examples/libusb20/util.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/10/share/examples/libusb20/util.h	Tue Aug 12 14:53:02 2014	(r269879, copy of r257779, head/share/examples/libusb20/util.h)
@@ -0,0 +1,14 @@
+/* ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42) (by Poul-Henning Kamp):
+ * <joerg at FreeBSD.ORG> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.        Joerg Wunsch
+ * ----------------------------------------------------------------------------
+ *
+ * $FreeBSD$
+ */
+
+#include <stdint.h>
+#include <libusb20.h>
+
+void print_formatted(uint8_t *buf, uint32_t len);


More information about the svn-src-all mailing list