--- dz099i/AUTHORS	2003-08-27 11:48:32.000000000 -0700
+++ dz099i-kees/AUTHORS	2005-08-25 16:51:37.000000000 -0700
@@ -31,3 +31,6 @@
    Made it IRQ sharing and now trying to move it to multi-platform
    status.
 
+   Kees Cook (kees@outflux.net).
+   Fix for USB serial devices.
+
--- dz099i/configure.in	2002-04-03 12:58:46.000000000 -0800
+++ dz099i-kees/configure.in	2005-08-25 09:44:16.000000000 -0700
@@ -263,21 +263,27 @@
   AC_DEFINE(MAP_FAILED, [(void *)-1])
 fi
 
-dnl Some miscellaneous defines.
 DZCOMM_MAYBE_LINUX_FILES=DZCOMM_EMPTY_LIST
 
-dzcomm_system=`uname -s | tr A-Z a-z`
-case "$dzcomm_system" in
+if test "$dzcomm_support_linux" = yes; then
+  AC_MSG_CHECKING([whether we are using Linux])
 
-*linux*)
-  if test "$dzcomm_support_linux" = yes; then
+  dzcomm_system=`uname -s | tr A-Z a-z`
+  case "$dzcomm_system" in
+
+  *linux*)
+    AC_MSG_RESULT([yes])
     AC_DEFINE(DZCOMM_LINUX)
+    AC_SUBST(DZCOMM_LINUX)
     DZCOMM_MAYBE_LINUX_FILES=DZCOMM_SRC_LINUX_FILES
+    ;;
 
-  fi
-  ;;
+  *)
+    AC_MSG_RESULT([no])
+    ;;
 
-esac
+  esac
+fi
 
 AC_SUBST(DZCOMM_MAYBE_LINUX_FILES)
 
--- dz099i/include/dzcomm/dzconfig.h	2003-03-26 10:18:26.000000000 -0800
+++ dz099i-kees/include/dzcomm/dzconfig.h	2005-08-25 10:54:29.000000000 -0700
@@ -50,7 +50,9 @@
 
    #define CONSTRUCTOR_FUNCTION(func)              func __attribute__ ((constructor))
 
-   #define INLINE          inline
+   #ifndef INLINE
+   # define INLINE          inline
+   #endif
 
    #ifndef ZERO_SIZE
       #define ZERO_SIZE    0
diff -uNr dz099i/src/comm.c dz099i-kees/src/comm.c
--- dz099i/src/comm.c	2003-09-09 12:11:54.000000000 -0700
+++ dz099i-kees/src/comm.c	2005-08-25 16:42:17.000000000 -0700
@@ -448,7 +448,10 @@
 
    /* And call the Machine/OS appropriate installer */
    if (comm_port_funcs->install_handler) {
-      if (comm_port_funcs->install_handler(port) == 0) return 0;
+      if (comm_port_funcs->install_handler(port) == 0) {
+         dz_make_comm_err("OS handler failed.");
+         return 0;
+      }
    }
 
    switch(port->nData) {
@@ -650,8 +653,8 @@
        (port->installed == PORT_NOT_INSTALLED) || (comm_port_funcs->out == NULL)) return 0;
 
    /* Make sure it is being sent in a machine/OS correct way */
-   c = comm_port_funcs->out(port, s);
-   for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, &s[i]);
+   c = comm_port_funcs->out(port, (unsigned char *)s);
+   for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, (unsigned char *)&s[i]);
 
    return c;
 }
@@ -668,9 +671,9 @@
        (port->installed == PORT_NOT_INSTALLED) || (comm_port_funcs->out == NULL)) return 0;
 
    /* Make sure it is being sent in a machine/OS correct way */
-   c = comm_port_funcs->out(port, s);
-   for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, &s[i]);
-   if (c==i) c += comm_port_funcs->out(port, &r);
+   c = comm_port_funcs->out(port, (unsigned char *)s);
+   for (i=1; ((s[i]!=0) && (c==i)); i++) c += comm_port_funcs->out(port, (unsigned char *)&s[i]);
+   if (c==i) c += comm_port_funcs->out(port, (unsigned char *)&r);
 
    return c;
 }
diff -uNr dz099i/src/linux/lcomm.c dz099i-kees/src/linux/lcomm.c
--- dz099i/src/linux/lcomm.c	2003-09-10 15:25:30.000000000 -0700
+++ dz099i-kees/src/linux/lcomm.c	2005-08-25 16:37:56.000000000 -0700
@@ -90,6 +90,7 @@
    if (port->fd == -1) return NULL;
 
    if (tcgetattr(port->fd, &tio) == -1)        tio_avail = 0;
+   /* USB serial ports don't have this information */
    if (ioctl(port->fd, TIOCGSERIAL, &sio) < 0) sio_avail = 0;
 
    if (tio_avail == 1) {
@@ -189,6 +190,10 @@
    struct serial_struct sio;
    struct termios       tio;
    speed_t              speed;
+   int                  sio_avail = 1;
+
+   /* USB serial ports don't have this information */
+   if (ioctl(port->fd, TIOCGSERIAL, &sio) < 0) sio_avail = 0;
 
    sio.type = (int) PORT_UNKNOWN; /* Want it to work it out */
    sio.flags = ASYNC_CALLOUT_NOHUP | ASYNC_LOW_LATENCY | ASYNC_SKIP_TEST;
@@ -256,8 +261,10 @@
    cfsetospeed(&tio, speed);
    cfsetispeed(&tio, speed);
 
-   if (ioctl(port->fd, TIOCSSERIAL, &sio) < 0) return 0;
-   if (ioctl(port->fd, TIOCSERCONFIG) < 0) return 0;
+   if (sio_avail) {
+      if (ioctl(port->fd, TIOCSSERIAL, &sio) < 0) return 0;
+      if (ioctl(port->fd, TIOCSERCONFIG) < 0) return 0;
+   }
    tcsetattr(port->fd, TCSANOW, &tio);
 
    return 1;
@@ -312,7 +319,7 @@
 /*-------------- LINUX COMM SET LINE STATUS ------------------------------*/
 int linux_comm_set_line_status(comm_port *port, dzcomm_line line, int value)
 {
-   int flag;
+   int flag=0;
 
    if ((line == DZCOMM_CTS) || (line == DZCOMM_DSR)) return -1;
 
