emulator-ui: Remove dependencies from qemu sources.

This change removes some QEMU-specifics that crept into the UI code.

Change-Id: Ib1974dc64e54a35dc0cd01aec1eb547a9263a0c8
diff --git a/android/charmap.c b/android/charmap.c
index 1d200e6..81c866a 100644
--- a/android/charmap.c
+++ b/android/charmap.c
@@ -9,11 +9,13 @@
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 */
-#include "qemu-common.h"
 #include "android/utils/path.h"
 #include "android/utils/misc.h"
 #include "android/utils/debug.h"
+#include "android/utils/system.h"
 #include "android/charmap.h"
+#include <stdio.h>
+#include <errno.h>
 
 /* Parses .kcm file producing key characters map.
  * .kcm file parsed by this module is expected to contain 4 types of
@@ -636,7 +638,7 @@
 
     // Preallocate map.
     char_map->num_entries = 0;
-    char_map->entries = qemu_malloc(sizeof(AKeyEntry) * map_size);
+    AARRAY_NEW0(char_map->entries, map_size);
 
     // Line by line parse the file.
     for (; 0 != fgets(line, sizeof(line), kcm_file); cur_line++) {
@@ -651,13 +653,10 @@
             // Key information has been extracted. Add it to the map.
             // Lets see if we need to reallocate map.
             if (map_size == char_map->num_entries) {
-                void* new_map;
+                AKeyEntry* entries = (AKeyEntry*)char_map->entries;
                 map_size += 10;
-                new_map = qemu_malloc(sizeof(AKeyEntry) * map_size);
-                memcpy(new_map, char_map->entries,
-                       char_map->num_entries * sizeof(AKeyEntry));
-                qemu_free((void*)char_map->entries);
-                char_map->entries = new_map;
+                AARRAY_RENEW(entries, map_size);
+                char_map->entries = (const AKeyEntry*)entries;
             }
             entries = (AKeyEntry*)char_map->entries;
             entries[char_map->num_entries] = key_entry;
@@ -682,7 +681,7 @@
     if (err) {
         // Cleanup on failure.
         if (0 != char_map->entries) {
-            qemu_free((void*)char_map->entries);
+            AFREE((void*)char_map->entries);
             char_map->entries = 0;
         }
         char_map->num_entries = 0;
@@ -704,8 +703,7 @@
         if (!parse_kcm_file(kcm_file_path, &android_custom_charmap)) {
             // Here we have two default charmaps and the custom one.
             android_charmap_count = 3;
-            android_charmaps = qemu_malloc(sizeof(AKeyCharmap*) *
-                                           android_charmap_count);
+            AARRAY_NEW(android_charmaps, android_charmap_count);
             android_charmaps[0] = &android_custom_charmap;
             android_charmaps[1] = &_qwerty_charmap;
             android_charmaps[2] = &_qwerty2_charmap;
@@ -716,8 +714,7 @@
     } else {
         // Here we have only two default charmaps.
         android_charmap_count = 2;
-        android_charmaps = qemu_malloc(sizeof(AKeyCharmap*) *
-                           android_charmap_count);
+        AARRAY_NEW(android_charmaps, android_charmap_count);
         android_charmaps[0] = &_qwerty_charmap;
         android_charmaps[1] = &_qwerty2_charmap;
     }
@@ -734,10 +731,10 @@
           // static entries defined in charmap.c
           if ((_qwerty_charmap.entries != android_charmaps[n]->entries) &&
               (_qwerty2_charmap.entries != android_charmaps[n]->entries)) {
-              qemu_free((void*)android_charmaps[n]->entries);
+              AFREE((void*)android_charmaps[n]->entries);
           }
       }
-      qemu_free(android_charmaps);
+      AFREE(android_charmaps);
   }
 }
 
diff --git a/android/display.c b/android/display.c
index 0cfd98d..d7c261a 100644
--- a/android/display.c
+++ b/android/display.c
@@ -15,6 +15,7 @@
  * is supposed to do.
  */
 #include "android/display.h"
+#include "android/utils/system.h"
 
 /*
 
@@ -92,7 +93,7 @@
                                                     qf->pixels);
 
     /* Register a change listener for it */
-    dcl = (DisplayChangeListener *) qemu_mallocz(sizeof(DisplayChangeListener));
+    ANEW0(dcl);
     dcl->dpy_update      = android_display_update;
     dcl->dpy_resize      = android_display_resize;
     dcl->dpy_refresh     = android_display_refresh;
diff --git a/android/main.c b/android/main.c
index c5dc899..b88fb5e 100644
--- a/android/main.c
+++ b/android/main.c
@@ -657,7 +657,7 @@
 
 FOUND_IT:
     //D("image auto-detection: %s/%s", temp, fileName);
-    return qemu_strdup(temp);
+    return android_strdup(temp);
 }
 
 static char*
@@ -670,7 +670,7 @@
     if (p >= end || !path_exists(temp))
         return NULL;
 
-    return qemu_strdup(temp);
+    return android_strdup(temp);
 }
 
 static char*
@@ -968,7 +968,7 @@
 
         /* if no data directory is specified, use the system directory */
         if (!opts->datadir) {
-            opts->datadir   = qemu_strdup(opts->sysdir);
+            opts->datadir   = android_strdup(opts->sysdir);
             dataDirIsSystem = 1;
             D("autoconfig: -datadir %s", opts->sysdir);
         }
@@ -987,14 +987,14 @@
                 exit(2);
             }
 
-            opts->data = qemu_strdup(tmp);
+            opts->data = android_strdup(tmp);
             D("autoconfig: -data %s", opts->data);
         }
 
         if (!opts->sdcard && opts->datadir) {
             bufprint(tmp, tmpend, "%s/sdcard.img", opts->datadir);
             if (path_exists(tmp)) {
-                opts->sdcard = qemu_strdup(tmp);
+                opts->sdcard = android_strdup(tmp);
                 D("autoconfig: -sdcard %s", opts->sdcard);
             }
         }
@@ -1466,7 +1466,7 @@
     }
     if (!opts->memory) {
         bufprint(tmp, tmpend, "%d", hw->hw_ramSize);
-        opts->memory = qemu_strdup(tmp);
+        opts->memory = android_strdup(tmp);
     }
 
     if (opts->trace) {
diff --git a/android/skin/window.c b/android/skin/window.c
index 9aa7ec9..b1d98af 100644
--- a/android/skin/window.c
+++ b/android/skin/window.c
@@ -722,13 +722,13 @@
     for (nn = 0; nn < layout->num_displays; nn++)
         display_done( &layout->displays[nn] );
 
-    qemu_free( layout->buttons );
+    AFREE( layout->buttons );
     layout->buttons = NULL;
 
-    qemu_free( layout->backgrounds );
+    AFREE( layout->backgrounds );
     layout->backgrounds = NULL;
 
-    qemu_free( layout->displays );
+    AFREE( layout->displays );
     layout->displays = NULL;
 
     layout->num_buttons     = 0;
@@ -1100,7 +1100,7 @@
     }
 
     if (window->shrink_pixels) {
-        qemu_free(window->shrink_pixels);
+        AFREE(window->shrink_pixels);
         window->shrink_pixels = NULL;
     }
 
@@ -1267,7 +1267,7 @@
             window->shrink_surface = NULL;
         }
         if (window->shrink_pixels) {
-            qemu_free(window->shrink_pixels);
+            AFREE(window->shrink_pixels);
             window->shrink_pixels = NULL;
         }
         if (window->onion) {
@@ -1279,7 +1279,7 @@
             window->scaler = NULL;
         }
         layout_done( &window->layout );
-        qemu_free(window);
+        AFREE(window);
     }
 }
 
diff --git a/android/utils/dirscanner.c b/android/utils/dirscanner.c
index fc63ef0..9c6a39c 100644
--- a/android/utils/dirscanner.c
+++ b/android/utils/dirscanner.c
@@ -11,7 +11,8 @@
 */
 #include "android/utils/dirscanner.h"
 #include "android/utils/bufprint.h"
-#include "qemu-common.h"
+#include "android/utils/system.h"
+#include "android/utils/path.h"
 #include <stddef.h>
 
 #define  DIRSCANNER_BASE     \
@@ -149,7 +150,7 @@
 DirScanner*
 dirScanner_new ( const char*  rootPath )
 {
-    DirScanner*  s   = qemu_mallocz(sizeof *s);
+    DirScanner*  s   = android_alloc0(sizeof *s);
     char*        p   = s->root;
     char*        end = p + sizeof s->root;
 
@@ -177,7 +178,7 @@
         return;
 
     _dirScanner_done(s);
-    qemu_free(s);
+    AFREE(s);
 }
 
 
diff --git a/android/utils/system.c b/android/utils/system.c
index e09fd6b..8443877 100644
--- a/android/utils/system.c
+++ b/android/utils/system.c
@@ -122,7 +122,7 @@
             q++;
         }
     }
-Exit:	
+Exit:
     *pline = p;
     return line;
 }
diff --git a/android/utils/timezone.c b/android/utils/timezone.c
index f4b78db..2707e2e 100644
--- a/android/utils/timezone.c
+++ b/android/utils/timezone.c
@@ -131,7 +131,7 @@
                 return NULL;
             }
         }
-        pstrcpy( android_timezone0, sizeof(android_timezone0), tz );
+        snprintf(android_timezone0, sizeof(android_timezone0), "%s", tz );
         android_timezone = android_timezone0;
     }
     D( "found timezone %s", android_timezone );
@@ -402,7 +402,7 @@
             if (tz == NULL)
                 return NULL;
 
-            pstrcpy( android_timezone0, sizeof(android_timezone0), tz );
+            snprintf(android_timezone0, sizeof(android_timezone0), "%s", tz);
             android_timezone = android_timezone0;
         }
         D( "found timezone %s\n", android_timezone );