Make get_my_path() safer

Adds maxLen parameter to get_my_path().
Some small cosmetic fixes.
diff --git a/adb/adb.c b/adb/adb.c
index c1646b8..7df3f7b 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -783,7 +783,7 @@
         fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno);
         return -1;
     }
-    get_my_path(path);
+    get_my_path(path, PATH_MAX);
     pid_t pid = fork();
     if(pid < 0) return -1;
 
diff --git a/adb/adb.h b/adb/adb.h
index b958682..a148019 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -236,7 +236,7 @@
 void handle_packet(apacket *p, atransport *t);
 void send_packet(apacket *p, atransport *t);
 
-void get_my_path(char s[PATH_MAX]);
+void get_my_path(char *s, size_t maxLen);
 int launch_server();
 int adb_main(int is_daemon);
 
diff --git a/adb/commandline.c b/adb/commandline.c
index 055aa10..52bcedc 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -50,7 +50,7 @@
 
 static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
 
-void get_my_path(char s[PATH_MAX]);
+void get_my_path(char *s, size_t maxLen);
 int find_sync_dirs(const char *srcarg,
         char **android_srcdir_out, char **data_srcdir_out);
 int install_app(transport_type transport, char* serial, int argc, char** argv);
@@ -673,7 +673,7 @@
         /* If the CWD isn't under a good-looking top, see if the
          * executable is.
          */
-        get_my_path(dir);
+        get_my_path(dir, PATH_MAX);
         top = find_top_from(dir, path_buf);
     }
     return top;
diff --git a/adb/get_my_path_darwin.c b/adb/get_my_path_darwin.c
index 6125cb4..5b95d15 100644
--- a/adb/get_my_path_darwin.c
+++ b/adb/get_my_path_darwin.c
@@ -17,7 +17,7 @@
 #import <Carbon/Carbon.h>
 #include <unistd.h>
 
-void get_my_path(char s[PATH_MAX])
+void get_my_path(char *s, size_t maxLen)
 {
     ProcessSerialNumber psn;
     GetCurrentProcess(&psn);
@@ -25,6 +25,6 @@
     dict = ProcessInformationCopyDictionary(&psn, 0xffffffff);
     CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict,
                 CFSTR("CFBundleExecutable"));
-    CFStringGetCString(value, s, PATH_MAX - 1, kCFStringEncodingUTF8);
+    CFStringGetCString(value, s, maxLen, kCFStringEncodingUTF8);
 }
 
diff --git a/adb/get_my_path_linux.c b/adb/get_my_path_linux.c
index f516e59..179c3dd 100644
--- a/adb/get_my_path_linux.c
+++ b/adb/get_my_path_linux.c
@@ -19,15 +19,15 @@
 #include <limits.h>
 #include <stdio.h>
 
-void get_my_path(char exe[PATH_MAX])
+void get_my_path(char *exe, size_t maxLen)
 {
     char proc[64];
     snprintf(proc, sizeof proc, "/proc/%d/exe", getpid());
-    int err = readlink(proc, exe, PATH_MAX - 1);
+    int err = readlink(proc, exe, maxLen - 1);
     if(err > 0) {
-        exe[err] = 0;
+        exe[err] = '\0';
     } else {
-        exe[0] = 0;
+        exe[0] = '\0';
     }
 }
 
diff --git a/adb/get_my_path_windows.c b/adb/get_my_path_windows.c
index fc7143c..ddf2816 100644
--- a/adb/get_my_path_windows.c
+++ b/adb/get_my_path_windows.c
@@ -18,14 +18,17 @@
 #include <assert.h>
 #include <windows.h>
 
-void get_my_path(char exe[PATH_MAX])
+void get_my_path(char *exe, size_t maxLen)
 {
-    char*  r;
+    char  *r;
 
-    GetModuleFileName( NULL, exe, PATH_MAX-1 );
-    exe[PATH_MAX-1] = 0;
-    r = strrchr( exe, '\\' );
-    if (r)
-        *r = 0;
+    /* XXX: should be GetModuleFileNameA */
+    if (GetModuleFileName(NULL, exe, maxLen) > 0) {
+        r = strrchr(exe, '\\');
+        if (r != NULL)
+            *r = '\0';
+    } else {
+        exe[0] = '\0';
+    }
 }