Some kernels reference USB ttys as tty/tty* instead of tty:tty*
authorKeith Packard <keithp@keithp.com>
Mon, 15 Jun 2009 00:25:34 +0000 (17:25 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 15 Jun 2009 00:25:34 +0000 (17:25 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
aoview/aoview_dev.c

index 2fabfe267b62c7af8636c2a4ce759fe25ba6f599..9b8cc19eae6bf61d31b3f902bc8fbc60bff10267 100644 (file)
@@ -60,11 +60,17 @@ load_hex(char *dir, char *file)
 }
 
 static int
-dir_filter_tty(const struct dirent *d)
+dir_filter_tty_colon(const struct dirent *d)
 {
        return strncmp(d->d_name, "tty:", 4) == 0;
 }
 
+static int
+dir_filter_tty(const struct dirent *d)
+{
+       return strncmp(d->d_name, "tty", 3) == 0;
+}
+
 static char *
 usb_tty(char *sys)
 {
@@ -76,6 +82,7 @@ usb_tty(char *sys)
        int num_interfaces;
        char endpoint_base[20];
        char *endpoint_full;
+       char *tty_dir;
        int ntty;
        char *tty;
 
@@ -87,15 +94,32 @@ usb_tty(char *sys)
                        sprintf(endpoint_base, "%s:%d.%d",
                                base, config, interface);
                        endpoint_full = aoview_fullname(sys, endpoint_base);
+
+                       /* Check for tty:ttyACMx style names
+                        */
                        ntty = scandir(endpoint_full, &namelist,
-                                      dir_filter_tty,
+                                      dir_filter_tty_colon,
                                       alphasort);
-                       free(endpoint_full);
                        if (ntty > 0) {
+                               free(endpoint_full);
                                tty = aoview_fullname("/dev", namelist[0]->d_name + 4);
                                free(namelist);
                                return tty;
                        }
+
+                       /* Check for tty/ttyACMx style names
+                        */
+                       tty_dir = aoview_fullname(endpoint_full, "tty");
+                       free(endpoint_full);
+                       ntty = scandir(tty_dir, &namelist,
+                                      dir_filter_tty,
+                                      alphasort);
+                       free (tty_dir);
+                       if (ntty > 0) {
+                               tty = aoview_fullname("/dev", namelist[0]->d_name);
+                               free(namelist);
+                               return tty;
+                       }
                }
        }
        return NULL;