input: move default bind handling to input core
[libpicofe.git] / linux / plat.c
index f5742b9..b7152b5 100644 (file)
@@ -1,6 +1,17 @@
-#define _GNU_SOURCE
+/*
+ * (C) GraÅžvydas "notaz" Ignotas, 2008-2010
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ *  - GNU GPL, version 2 or later.
+ *  - GNU LGPL, version 2.1 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#define _GNU_SOURCE 1
 #include <stdio.h>
 #include <string.h>
+#include <stdarg.h>
 #include <dirent.h>
 #include <sys/time.h>
 #include <time.h>
@@ -22,17 +33,22 @@ int plat_is_dir(const char *path)
 
 int plat_get_root_dir(char *dst, int len)
 {
-       extern char **g_argv;
-       int j;
+       int j, ret;
+
+       ret = readlink("/proc/self/exe", dst, len - 1);
+       if (ret < 0) {
+               perror("readlink");
+               ret = 0;
+       }
+       dst[ret] = 0;
 
-       strncpy(dst, g_argv[0], len);
-       len -= 32; // reserve
-       if (len < 0) len = 0;
-       dst[len] = 0;
        for (j = strlen(dst); j > 0; j--)
-               if (dst[j] == '/') { dst[j+1] = 0; break; }
+               if (dst[j] == '/') {
+                       dst[++j] = 0;
+                       break;
+               }
 
-       return j + 1;
+       return j;
 }
 
 #ifdef __GP2X__
@@ -142,3 +158,13 @@ void plat_munmap(void *ptr, size_t size)
        munmap(ptr, size);
 }
 
+/* lprintf */
+void lprintf(const char *fmt, ...)
+{
+       va_list vl;
+
+       va_start(vl, fmt);
+       vprintf(fmt, vl);
+       va_end(vl);
+}
+