avoid PATH_MAX/string copies usage
[libftdi] / src / ftdi.c
index 9630bfe..9740fca 100644 (file)
@@ -715,7 +715,6 @@ int ftdi_usb_open_string(struct ftdi_context *ftdi, const char* description)
     {
         struct usb_bus *bus;
         struct usb_device *dev;
-        char dev_name[PATH_MAX+1];
 
         usb_init();
 
@@ -728,9 +727,18 @@ int ftdi_usb_open_string(struct ftdi_context *ftdi, const char* description)
         {
             for (dev = bus->devices; dev; dev = dev->next)
             {
-                snprintf(dev_name, sizeof(dev_name), "%s/%s",bus->dirname,dev->filename);
-                if (strcmp(description+2,dev_name) == 0)
-                    return ftdi_usb_open_dev(ftdi, dev);
+                /* XXX: This doesn't handle symlinks/odd paths/etc... */
+                const char *desc = description + 2;
+                size_t len = strlen(bus->dirname);
+                if (strncmp(desc, bus->dirname, len))
+                    continue;
+                desc += len;
+                if (desc[0] != '/')
+                    continue;
+                ++desc;
+                if (strcmp(desc, dev->filename))
+                    continue;
+                return ftdi_usb_open_dev(ftdi, dev);
             }
         }
 
@@ -1599,7 +1607,7 @@ int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunks
 /**
     Enable bitbang mode.
 
-    For advanced bitbang modes of the FT2232C chip use ftdi_set_bitmode().
+    \deprecated use \ref ftdi_set_bitmode with mode BITMODE_BITBANG instead
 
     \param ftdi pointer to ftdi_context
     \param bitmask Bitmask to configure lines.
@@ -1648,7 +1656,7 @@ int ftdi_disable_bitbang(struct ftdi_context *ftdi)
     \param ftdi pointer to ftdi_context
     \param bitmask Bitmask to configure lines.
            HIGH/ON value configures a line as output.
-    \param mode Bitbang mode: use the values defined in \ref ftdi_mpsse_mode, use BITMODE_RESET to switch off bitbang
+    \param mode Bitbang mode: use the values defined in \ref ftdi_mpsse_mode
 
     \retval  0: all fine
     \retval -1: can't enable bitbang mode