Merge "Add a missing include."
diff --git a/adb/Android.mk b/adb/Android.mk
index 3828ed3..3cadee3 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -63,7 +63,6 @@
 	file_sync_client.c \
 	$(EXTRA_SRCS) \
 	$(USB_SRCS) \
-	usb_vendors.c
 
 LOCAL_C_INCLUDES += external/openssl/include
 
@@ -157,7 +156,6 @@
 	file_sync_client.c \
 	get_my_path_linux.c \
 	usb_linux.c \
-	usb_vendors.c \
 	fdevent.c
 
 LOCAL_CFLAGS := \
diff --git a/adb/adb.c b/adb/adb.c
index 68a6026..a6a4636 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -41,8 +41,6 @@
 #include <sys/prctl.h>
 #include <getopt.h>
 #include <selinux/selinux.h>
-#else
-#include "usb_vendors.h"
 #endif
 
 #if ADB_TRACE
@@ -1320,7 +1318,6 @@
 #ifdef WORKAROUND_BUG6558362
     if(is_daemon) adb_set_affinity();
 #endif
-    usb_vendors_init();
     usb_init();
     local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
     adb_auth_init();
diff --git a/adb/get_my_path_darwin.c b/adb/get_my_path_darwin.c
index 65dd226..ff1396c 100644
--- a/adb/get_my_path_darwin.c
+++ b/adb/get_my_path_darwin.c
@@ -24,7 +24,7 @@
     CFStringRef executablePathString = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle);
     CFRelease(executableURL);
 
-    CFStringGetCString(executablePathString, s, maxLen, kCFStringEncodingASCII);
+    CFStringGetFileSystemRepresentation(executablePathString, s, maxLen);
     CFRelease(executablePathString);
 }
 
diff --git a/adb/usb_osx.c b/adb/usb_osx.c
index ee893f5..ba157f1 100644
--- a/adb/usb_osx.c
+++ b/adb/usb_osx.c
@@ -28,12 +28,11 @@
 
 #define TRACE_TAG   TRACE_USB
 #include "adb.h"
-#include "usb_vendors.h"
 
 #define  DBG   D
 
 static IONotificationPortRef    notificationPort = 0;
-static io_iterator_t*           notificationIterators;
+static io_iterator_t            notificationIterator;
 
 struct usb_handle
 {
@@ -61,8 +60,6 @@
 {
     CFMutableDictionaryRef  matchingDict;
     CFRunLoopSourceRef      runLoopSource;
-    SInt32                  vendor, if_subclass, if_protocol;
-    unsigned                i;
 
     //* To set up asynchronous notifications, create a notification port and
     //* add its run loop event source to the program's run loop
@@ -70,47 +67,33 @@
     runLoopSource = IONotificationPortGetRunLoopSource(notificationPort);
     CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
 
-    memset(notificationIterators, 0, sizeof(notificationIterators));
+    //* Create our matching dictionary to find the Android device's
+    //* adb interface
+    //* IOServiceAddMatchingNotification consumes the reference, so we do
+    //* not need to release this
+    matchingDict = IOServiceMatching(kIOUSBInterfaceClassName);
 
-    //* loop through all supported vendors
-    for (i = 0; i < vendorIdCount; i++) {
-        //* Create our matching dictionary to find the Android device's
-        //* adb interface
-        //* IOServiceAddMatchingNotification consumes the reference, so we do
-        //* not need to release this
-        matchingDict = IOServiceMatching(kIOUSBInterfaceClassName);
-
-        if (!matchingDict) {
-            DBG("ERR: Couldn't create USB matching dictionary.\n");
-            return -1;
-        }
-
-        //* Match based on vendor id, interface subclass and protocol
-        vendor = vendorIds[i];
-        if_subclass = ADB_SUBCLASS;
-        if_protocol = ADB_PROTOCOL;
-        CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID),
-                             CFNumberCreate(kCFAllocatorDefault,
-                                            kCFNumberSInt32Type, &vendor));
-        CFDictionarySetValue(matchingDict, CFSTR(kUSBInterfaceSubClass),
-                             CFNumberCreate(kCFAllocatorDefault,
-                                            kCFNumberSInt32Type, &if_subclass));
-        CFDictionarySetValue(matchingDict, CFSTR(kUSBInterfaceProtocol),
-                             CFNumberCreate(kCFAllocatorDefault,
-                                            kCFNumberSInt32Type, &if_protocol));
-        IOServiceAddMatchingNotification(
-                notificationPort,
-                kIOFirstMatchNotification,
-                matchingDict,
-                AndroidInterfaceAdded,
-                NULL,
-                &notificationIterators[i]);
-
-        //* Iterate over set of matching interfaces to access already-present
-        //* devices and to arm the notification
-        AndroidInterfaceAdded(NULL, notificationIterators[i]);
+    if (!matchingDict) {
+        DBG("ERR: Couldn't create USB matching dictionary.\n");
+        return -1;
     }
 
+    //* We have to get notifications for all potential candidates and test them
+    //* at connection time because the matching rules don't allow for a
+    //* USB interface class of 0xff for class+subclass+protocol matches
+    //* See https://developer.apple.com/library/mac/qa/qa1076/_index.html
+    IOServiceAddMatchingNotification(
+            notificationPort,
+            kIOFirstMatchNotification,
+            matchingDict,
+            AndroidInterfaceAdded,
+            NULL,
+            &notificationIterator);
+
+    //* Iterate over set of matching interfaces to access already-present
+    //* devices and to arm the notification
+    AndroidInterfaceAdded(NULL, notificationIterator);
+
     return 0;
 }
 
@@ -126,6 +109,7 @@
     HRESULT                  result;
     SInt32                   score;
     UInt32                   locationId;
+    UInt8                    class, subclass, protocol;
     UInt16                   vendor;
     UInt16                   product;
     UInt8                    serialIndex;
@@ -156,6 +140,16 @@
             continue;
         }
 
+        kr = (*iface)->GetInterfaceClass(iface, &class);
+        kr = (*iface)->GetInterfaceSubClass(iface, &subclass);
+        kr = (*iface)->GetInterfaceProtocol(iface, &protocol);
+        if(class != ADB_CLASS || subclass != ADB_SUBCLASS || protocol != ADB_PROTOCOL) {
+            // Ignore non-ADB devices.
+            DBG("Ignoring interface with incorrect class/subclass/protocol - %d, %d, %d\n", class, subclass, protocol);
+            (*iface)->Release(iface);
+            continue;
+        }
+
         //* this gets us an ioservice, with which we will find the actual
         //* device; after getting a plugin, and querying the interface, of
         //* course.
@@ -192,7 +186,6 @@
 
         //* Now after all that, we actually have a ref to the device and
         //* the interface that matched our criteria
-
         kr = (*dev)->GetDeviceVendor(dev, &vendor);
         kr = (*dev)->GetDeviceProduct(dev, &product);
         kr = (*dev)->GetLocationID(dev, &locationId);
@@ -385,8 +378,6 @@
 
 void* RunLoopThread(void* unused)
 {
-    unsigned i;
-
     InitUSB();
 
     currentRunLoop = CFRunLoopGetCurrent();
@@ -399,9 +390,7 @@
     CFRunLoopRun();
     currentRunLoop = 0;
 
-    for (i = 0; i < vendorIdCount; i++) {
-        IOObjectRelease(notificationIterators[i]);
-    }
+    IOObjectRelease(notificationIterator);
     IONotificationPortDestroy(notificationPort);
 
     DBG("RunLoopThread done\n");
@@ -416,9 +405,6 @@
     {
         adb_thread_t    tid;
 
-        notificationIterators = (io_iterator_t*)malloc(
-            vendorIdCount * sizeof(io_iterator_t));
-
         adb_mutex_init(&start_lock, NULL);
         adb_cond_init(&start_cond, NULL);
 
@@ -443,11 +429,6 @@
     close_usb_devices();
     if (currentRunLoop)
         CFRunLoopStop(currentRunLoop);
-
-    if (notificationIterators != NULL) {
-        free(notificationIterators);
-        notificationIterators = NULL;
-    }
 }
 
 int usb_write(usb_handle *handle, const void *buf, int len)
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c
deleted file mode 100755
index 1b73521..0000000
--- a/adb/usb_vendors.c
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "usb_vendors.h"
-
-#include <stdio.h>
-
-#ifdef _WIN32
-#  define WIN32_LEAN_AND_MEAN
-#  include "windows.h"
-#  include "shlobj.h"
-#else
-#  include <unistd.h>
-#  include <sys/stat.h>
-#endif
-
-#include "sysdeps.h"
-#include "adb.h"
-
-#define ANDROID_PATH            ".android"
-#define ANDROID_ADB_INI         "adb_usb.ini"
-
-#define TRACE_TAG               TRACE_USB
-
-/* Keep the list below sorted alphabetically by #define name */
-// Acer's USB Vendor ID
-#define VENDOR_ID_ACER          0x0502
-// Alco's  USB Vendor ID
-#define VENDOR_ID_ALCO          0x1914
-// Allwinner's USB Vendor ID
-#define VENDOR_ID_ALLWINNER     0x1F3A
-// Amlogic's USB Vendor ID
-#define VENDOR_ID_AMLOGIC       0x1b8e
-// AnyDATA's USB Vendor ID
-#define VENDOR_ID_ANYDATA       0x16D5
-// Archos's USB Vendor ID
-#define VENDOR_ID_ARCHOS        0x0E79
-// Asus's USB Vendor ID
-#define VENDOR_ID_ASUS          0x0b05
-// BYD's USB Vendor ID
-#define VENDOR_ID_BYD           0x1D91
-// Compal's USB Vendor ID
-#define VENDOR_ID_COMPAL        0x04B7
-// Compalcomm's USB Vendor ID
-#define VENDOR_ID_COMPALCOMM    0x1219
-// Dell's USB Vendor ID
-#define VENDOR_ID_DELL          0x413c
-// ECS's USB Vendor ID
-#define VENDOR_ID_ECS           0x03fc
-// EMERGING_TECH's USB Vendor ID
-#define VENDOR_ID_EMERGING_TECH 0x297F
-// Emerson's USB Vendor ID
-#define VENDOR_ID_EMERSON       0x2207
-// Foxconn's USB Vendor ID
-#define VENDOR_ID_FOXCONN       0x0489
-// Fujitsu's USB Vendor ID
-#define VENDOR_ID_FUJITSU       0x04C5
-// Funai's USB Vendor ID
-#define VENDOR_ID_FUNAI         0x0F1C
-// Garmin-Asus's USB Vendor ID
-#define VENDOR_ID_GARMIN_ASUS   0x091E
-// Gigabyte's USB Vendor ID
-#define VENDOR_ID_GIGABYTE      0x0414
-// Gigaset's USB Vendor ID
-#define VENDOR_ID_GIGASET       0x1E85
-// GIONEE's USB Vendor ID
-#define VENDOR_ID_GIONEE        0x271D
-// Google's USB Vendor ID
-#define VENDOR_ID_GOOGLE        0x18d1
-// Haier's USB Vendor ID
-#define VENDOR_ID_HAIER         0x201E
-// Harris's USB Vendor ID
-#define VENDOR_ID_HARRIS        0x19A5
-// Hisense's USB Vendor ID
-#define VENDOR_ID_HISENSE       0x109b
-// HP's USB Vendor ID
-#define VENDOR_ID_HP            0x03f0
-// HTC's USB Vendor ID
-#define VENDOR_ID_HTC           0x0bb4
-// Huawei's USB Vendor ID
-#define VENDOR_ID_HUAWEI        0x12D1
-// INQ Mobile's USB Vendor ID
-#define VENDOR_ID_INQ_MOBILE    0x2314
-// Intel's USB Vendor ID
-#define VENDOR_ID_INTEL         0x8087
-// Intermec's USB Vendor ID
-#define VENDOR_ID_INTERMEC      0x067e
-// IRiver's USB Vendor ID
-#define VENDOR_ID_IRIVER        0x2420
-// K-Touch's USB Vendor ID
-#define VENDOR_ID_K_TOUCH       0x24E3
-// KT Tech's USB Vendor ID
-#define VENDOR_ID_KT_TECH       0x2116
-// Kobo's USB Vendor ID
-#define VENDOR_ID_KOBO          0x2237
-// Kyocera's USB Vendor ID
-#define VENDOR_ID_KYOCERA       0x0482
-// Lab126's USB Vendor ID
-#define VENDOR_ID_LAB126        0x1949
-// Lenovo's USB Vendor ID
-#define VENDOR_ID_LENOVO        0x17EF
-// LenovoMobile's USB Vendor ID
-#define VENDOR_ID_LENOVOMOBILE  0x2006
-// LG's USB Vendor ID
-#define VENDOR_ID_LGE           0x1004
-// Lumigon's USB Vendor ID
-#define VENDOR_ID_LUMIGON       0x25E3
-// Micromax's USB Vendor ID
-#define VENDOR_ID_MICROMAX      0x2A96
-// Motorola's USB Vendor ID
-#define VENDOR_ID_MOTOROLA      0x22b8
-// MSI's USB Vendor ID
-#define VENDOR_ID_MSI           0x0DB0
-// MTK's USB Vendor ID
-#define VENDOR_ID_MTK           0x0e8d
-// NEC's USB Vendor ID
-#define VENDOR_ID_NEC           0x0409
-// B&N Nook's USB Vendor ID
-#define VENDOR_ID_NOOK          0x2080
-// Nvidia's USB Vendor ID
-#define VENDOR_ID_NVIDIA        0x0955
-// OPPO's USB Vendor ID
-#define VENDOR_ID_OPPO          0x22D9
-// On-The-Go-Video's USB Vendor ID
-#define VENDOR_ID_OTGV          0x2257
-// OUYA's USB Vendor ID
-#define VENDOR_ID_OUYA          0x2836
-// Pantech's USB Vendor ID
-#define VENDOR_ID_PANTECH       0x10A9
-// Pegatron's USB Vendor ID
-#define VENDOR_ID_PEGATRON      0x1D4D
-// Philips's USB Vendor ID
-#define VENDOR_ID_PHILIPS       0x0471
-// Panasonic Mobile Communication's USB Vendor ID
-#define VENDOR_ID_PMC           0x04DA
-// Positivo's USB Vendor ID
-#define VENDOR_ID_POSITIVO      0x1662
-// Prestigio's USB Vendor ID
-#define VENDOR_ID_PRESTIGIO     0x29e4
-// Qisda's USB Vendor ID
-#define VENDOR_ID_QISDA         0x1D45
-// Qualcomm's USB Vendor ID
-#define VENDOR_ID_QUALCOMM      0x05c6
-// Quanta's USB Vendor ID
-#define VENDOR_ID_QUANTA        0x0408
-// Razer's USB Vendor ID
-#define VENDOR_ID_RAZER         0x1532
-// Rockchip's USB Vendor ID
-#define VENDOR_ID_ROCKCHIP      0x2207
-// Samsung's USB Vendor ID
-#define VENDOR_ID_SAMSUNG       0x04e8
-// Sharp's USB Vendor ID
-#define VENDOR_ID_SHARP         0x04dd
-// SK Telesys's USB Vendor ID
-#define VENDOR_ID_SK_TELESYS    0x1F53
-// Smartisan's USB Vendor ID
-#define VENDOR_ID_SMARTISAN     0x29a9
-// Sonim Tech's USB Vendor ID
-#define VENDOR_ID_SONIM_TECH    0x1d9c
-// Sony's USB Vendor ID
-#define VENDOR_ID_SONY          0x054C
-// Sony Ericsson's USB Vendor ID
-#define VENDOR_ID_SONY_ERICSSON 0x0FCE
-// T & A Mobile Phones' USB Vendor ID
-#define VENDOR_ID_T_AND_A       0x1BBB
-// TechFaith's USB Vendor ID
-#define VENDOR_ID_TECHFAITH     0x1d09
-// Teleepoch's USB Vendor ID
-#define VENDOR_ID_TELEEPOCH     0x2340
-// Texas Instruments's USB Vendor ID
-#define VENDOR_ID_TI            0x0451
-// Toshiba's USB Vendor ID
-#define VENDOR_ID_TOSHIBA       0x0930
-// TrekStor's USB Vendor ID
-#define VENDOR_ID_TREKSTOR      0x1E68
-// Unowhy's USB Vendor ID
-#define VENDOR_ID_UNOWHY        0x2A49
-// Vizio's USB Vendor ID
-#define VENDOR_ID_VIZIO         0xE040
-// Wacom's USB Vendor ID
-#define VENDOR_ID_WACOM         0x0531
-// Xiaomi's USB Vendor ID
-#define VENDOR_ID_XIAOMI        0x2717
-// YotaDevices's USB Vendor ID
-#define VENDOR_ID_YOTADEVICES   0x2916
-// Yulong Coolpad's USB Vendor ID
-#define VENDOR_ID_YULONG_COOLPAD 0x1EBF
-// ZTE's USB Vendor ID
-#define VENDOR_ID_ZTE           0x19D2
-/* Keep the list above sorted alphabetically by #define name */
-
-/** built-in vendor list */
-/* Keep the list below sorted alphabetically */
-int builtInVendorIds[] = {
-    VENDOR_ID_ACER,
-    VENDOR_ID_ALCO,
-    VENDOR_ID_ALLWINNER,
-    VENDOR_ID_AMLOGIC,
-    VENDOR_ID_ANYDATA,
-    VENDOR_ID_ARCHOS,
-    VENDOR_ID_ASUS,
-    VENDOR_ID_BYD,
-    VENDOR_ID_COMPAL,
-    VENDOR_ID_COMPALCOMM,
-    VENDOR_ID_DELL,
-    VENDOR_ID_ECS,
-    VENDOR_ID_EMERGING_TECH,
-    VENDOR_ID_EMERSON,
-    VENDOR_ID_FOXCONN,
-    VENDOR_ID_FUJITSU,
-    VENDOR_ID_FUNAI,
-    VENDOR_ID_GARMIN_ASUS,
-    VENDOR_ID_GIGABYTE,
-    VENDOR_ID_GIGASET,
-    VENDOR_ID_GIONEE,
-    VENDOR_ID_GOOGLE,
-    VENDOR_ID_HAIER,
-    VENDOR_ID_HARRIS,
-    VENDOR_ID_HISENSE,
-    VENDOR_ID_HP,
-    VENDOR_ID_HTC,
-    VENDOR_ID_HUAWEI,
-    VENDOR_ID_INQ_MOBILE,
-    VENDOR_ID_INTEL,
-    VENDOR_ID_INTERMEC,
-    VENDOR_ID_IRIVER,
-    VENDOR_ID_KOBO,
-    VENDOR_ID_K_TOUCH,
-    VENDOR_ID_KT_TECH,
-    VENDOR_ID_KYOCERA,
-    VENDOR_ID_LAB126,
-    VENDOR_ID_LENOVO,
-    VENDOR_ID_LENOVOMOBILE,
-    VENDOR_ID_LGE,
-    VENDOR_ID_LUMIGON,
-    VENDOR_ID_MICROMAX,
-    VENDOR_ID_MOTOROLA,
-    VENDOR_ID_MSI,
-    VENDOR_ID_MTK,
-    VENDOR_ID_NEC,
-    VENDOR_ID_NOOK,
-    VENDOR_ID_NVIDIA,
-    VENDOR_ID_OPPO,
-    VENDOR_ID_OTGV,
-    VENDOR_ID_OUYA,
-    VENDOR_ID_PANTECH,
-    VENDOR_ID_PEGATRON,
-    VENDOR_ID_PHILIPS,
-    VENDOR_ID_PMC,
-    VENDOR_ID_POSITIVO,
-    VENDOR_ID_PRESTIGIO,
-    VENDOR_ID_QISDA,
-    VENDOR_ID_QUALCOMM,
-    VENDOR_ID_QUANTA,
-    VENDOR_ID_RAZER,
-    VENDOR_ID_ROCKCHIP,
-    VENDOR_ID_SAMSUNG,
-    VENDOR_ID_SHARP,
-    VENDOR_ID_SK_TELESYS,
-    VENDOR_ID_SMARTISAN,
-    VENDOR_ID_SONIM_TECH,
-    VENDOR_ID_SONY,
-    VENDOR_ID_SONY_ERICSSON,
-    VENDOR_ID_T_AND_A,
-    VENDOR_ID_TECHFAITH,
-    VENDOR_ID_TELEEPOCH,
-    VENDOR_ID_TI,
-    VENDOR_ID_TOSHIBA,
-    VENDOR_ID_TREKSTOR,
-    VENDOR_ID_UNOWHY,
-    VENDOR_ID_VIZIO,
-    VENDOR_ID_WACOM,
-    VENDOR_ID_XIAOMI,
-    VENDOR_ID_YOTADEVICES,
-    VENDOR_ID_YULONG_COOLPAD,
-    VENDOR_ID_ZTE,
-};
-/* Keep the list above sorted alphabetically */
-
-#define BUILT_IN_VENDOR_COUNT    (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
-
-/* max number of supported vendor ids (built-in + 3rd party). increase as needed */
-#define VENDOR_COUNT_MAX         128
-
-int vendorIds[VENDOR_COUNT_MAX];
-unsigned vendorIdCount = 0;
-
-static int get_adb_usb_ini(char* buff, size_t len);
-
-void usb_vendors_init(void)
-{
-    if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) {
-        fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n");
-        exit(2);
-    }
-
-    /* add the built-in vendors at the beginning of the array */
-    memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds));
-
-    /* default array size is the number of built-in vendors */
-    vendorIdCount = BUILT_IN_VENDOR_COUNT;
-
-    if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT)
-        return;
-
-    char temp[PATH_MAX];
-    if (get_adb_usb_ini(temp, sizeof(temp)) == 0) {
-        FILE * f = fopen(temp, "rt");
-
-        if (f != NULL) {
-            /* The vendor id file is pretty basic. 1 vendor id per line.
-               Lines starting with # are comments */
-            while (fgets(temp, sizeof(temp), f) != NULL) {
-                if (temp[0] == '#')
-                    continue;
-
-                long value = strtol(temp, NULL, 0);
-                if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) {
-                    fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI);
-                    exit(2);
-                }
-
-                vendorIds[vendorIdCount++] = (int)value;
-
-                /* make sure we don't go beyond the array */
-                if (vendorIdCount == VENDOR_COUNT_MAX) {
-                    break;
-                }
-            }
-            fclose(f);
-        }
-    }
-}
-
-/* Utils methods */
-
-/* builds the path to the adb vendor id file. returns 0 if success */
-static int build_path(char* buff, size_t len, const char* format, const char* home)
-{
-    if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= (signed)len) {
-        return 1;
-    }
-
-    return 0;
-}
-
-/* fills buff with the path to the adb vendor id file. returns 0 if success */
-static int get_adb_usb_ini(char* buff, size_t len)
-{
-#ifdef _WIN32
-    const char* home = getenv("ANDROID_SDK_HOME");
-    if (home != NULL) {
-        return build_path(buff, len, "%s\\%s\\%s", home);
-    } else {
-        char path[MAX_PATH];
-        SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path);
-        return build_path(buff, len, "%s\\%s\\%s", path);
-    }
-#else
-    const char* home = getenv("HOME");
-    if (home == NULL)
-        home = "/tmp";
-
-    return build_path(buff, len, "%s/%s/%s", home);
-#endif
-}
diff --git a/adb/usb_vendors.h b/adb/usb_vendors.h
deleted file mode 100644
index cee23a1..0000000
--- a/adb/usb_vendors.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __USB_VENDORS_H
-#define __USB_VENDORS_H
-
-extern int vendorIds[];
-extern unsigned  vendorIdCount;
-
-void usb_vendors_init(void);
-
-#endif
diff --git a/fastboot/util_osx.c b/fastboot/util_osx.c
index a8f5c31..e718562 100644
--- a/fastboot/util_osx.c
+++ b/fastboot/util_osx.c
@@ -36,7 +36,7 @@
     CFStringRef executablePathString = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle);
     CFRelease(executableURL);
 
-    CFStringGetCString(executablePathString, s, PATH_MAX-1, kCFStringEncodingASCII);
+    CFStringGetFileSystemRepresentation(executablePathString, s, PATH_MAX-1);
     CFRelease(executablePathString);
 
 	char *x;
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index 49f5903..4b09f24 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -20,6 +20,7 @@
 #include <assert.h>
 #include <dirent.h>
 #include <fcntl.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -100,7 +101,7 @@
 
     ctx->buf_len += ret;
     ctx->buf[ctx->buf_len] = 0;
-    SLOGV("Read %d to buffer: %s", ret, ctx->buf);
+    SLOGV("Read %zd to buffer: %s", ret, ctx->buf);
 
     assert(ctx->buf_len <= sizeof(ctx->buf));
 
@@ -251,7 +252,7 @@
 {
     int processes;
     int sleep_us = 100;
-    long startTime = android::uptimeMillis();
+    int64_t startTime = android::uptimeMillis();
 
     while ((processes = killProcessGroupOnce(uid, initialPid, signal)) > 0) {
         SLOGV("killed %d processes for processgroup %d\n", processes, initialPid);
@@ -265,7 +266,7 @@
         }
     }
 
-    SLOGV("Killed process group uid %d pid %d in %ldms, %d procs remain", uid, initialPid,
+    SLOGV("Killed process group uid %d pid %d in %" PRId64 "ms, %d procs remain", uid, initialPid,
             android::uptimeMillis()-startTime, processes);
 
     if (processes == 0) {
@@ -279,12 +280,12 @@
 {
     int ret;
 
-    ret = mkdir(path, 0750);
+    ret = mkdir(path, mode);
     if (ret < 0 && errno != EEXIST) {
         return -errno;
     }
 
-    ret = chown(path, AID_SYSTEM, AID_SYSTEM);
+    ret = chown(path, uid, gid);
     if (ret < 0) {
         ret = -errno;
         rmdir(path);
diff --git a/toolbox/notify.c b/toolbox/notify.c
index c983ed5..8ce346c 100644
--- a/toolbox/notify.c
+++ b/toolbox/notify.c
@@ -101,14 +101,17 @@
 			else if(verbose >= 1)
 		        printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
 			if(print_files && (event->mask & IN_MODIFY)) {
-				char filename[512];
+				char* filename = file_names[event->wd + id_offset];
+				char* alloc_buf = NULL;
 				ssize_t read_len;
 				char *display_name;
 				int buflen;
-				strcpy(filename, file_names[event->wd + id_offset]);
 				if(event->len) {
-					strcat(filename, "/");
-					strcat(filename, event->name);
+					if(asprintf(&alloc_buf, "%s/%s", filename, event->name) < 0) {
+						fprintf(stderr, "asprintf failed, %s\n", strerror(errno));
+						return 1;
+					}
+					filename = alloc_buf;
 				}
 				ffd = open(filename, O_RDONLY);
 				display_name = (verbose >= 2 || event->len == 0) ? filename : event->name;
@@ -132,6 +135,7 @@
 					printf("%s: %s", display_name, buf);
 				}
 				close(ffd);
+				free(alloc_buf);
 			}
 	        if(event_count && --event_count == 0)
 	            return 0;