build fixes and arm support.

Change-Id: I96fa6366c8bb1406d89f944f0fd1733bde565126
diff --git a/dedupe/Android.mk b/dedupe/Android.mk
index 45f1eb3..03c5de3 100644
--- a/dedupe/Android.mk
+++ b/dedupe/Android.mk
@@ -8,3 +8,16 @@
 LOCAL_MODULE := dedupe
 LOCAL_STATIC_LIBRARIES := libcrypto_static
 include $(BUILD_HOST_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := dedupe.c
+LOCAL_STATIC_LIBRARIES := libcrypto libcutils libc
+LOCAL_MODULE := utility_dedupe
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_STEM := dedupe
+LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
+LOCAL_C_INCLUDES := external/openssl/include
+LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+include $(BUILD_EXECUTABLE)
diff --git a/dedupe/dedupe.c b/dedupe/dedupe.c
index 8969fbc..d41b8ac 100644
--- a/dedupe/dedupe.c
+++ b/dedupe/dedupe.c
@@ -135,7 +135,7 @@
             return ret;
         }
         
-        if (ret = store_st(context->blob_dir, cst, full_path))
+        if (ret = store_st(context, cst, full_path))
             return ret;
     }
     closedir(dp);
@@ -150,6 +150,7 @@
         fprintf(stderr, "Error reading symlink\n");
         return errno;
     }
+    link[ret] = '\0';
     fprintf(context->output_manifest, "%s\t\n", link);
     return 0;
 }
@@ -184,7 +185,7 @@
 
 static char* tokenize(char *out, const char* line, const char sep) {
     while (*line != sep) {
-        if (*line == NULL) {
+        if (*line == '\0') {
             return NULL;
         }
         
@@ -193,9 +194,9 @@
         line++;
     }
     
-    *out = NULL;
+    *out = '\0';
     // resume at the next char
-    return line + 1;
+    return ++line;
 }
 
 static int dec_to_oct(int dec) {
@@ -227,7 +228,7 @@
         
         if (!S_ISDIR(st.st_mode)) {
             fprintf(stderr, "%s must be a directory.\n", argv[2]);
-            return;
+            return 1;
         }
         
         char blob_dir[PATH_MAX];
@@ -274,6 +275,8 @@
             token = tokenize(filename, token, '\t');
             
             int mode_oct = dec_to_oct(atoi(mode));
+            int uid_int = atoi(uid);
+            int gid_int = atoi(gid);
             int ret;
             printf("%s\t%s\t%s\t%s\t%s\t", type, mode, uid, gid, filename);
             if (strcmp(type, "f") == 0) {
@@ -289,7 +292,7 @@
                 }
                 
                 chmod(filename, mode_oct);
-                chown(filename, uid, gid);
+                chown(filename, uid_int, gid_int);
             }
             else if (strcmp(type, "l") == 0) {
                 char link[41];
@@ -299,7 +302,7 @@
                 symlink(link, filename);
 
                 chmod(filename, mode_oct);
-                lchown(filename, uid, gid);
+                lchown(filename, uid_int, gid_int);
             }
             else if (strcmp(type, "d") == 0) {
                 printf("\n");
@@ -307,7 +310,7 @@
                 mkdir(filename, mode_oct);
 
                 chmod(filename, mode_oct);
-                chown(filename, uid, gid);
+                chown(filename, uid_int, gid_int);
             }
         }