Remove hardcoded path for multiuser support
[platform/framework/web/livebox-viewer.git] / src / util.c
index c58b4f2..beffe34 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <dlog.h>
 #include <livebox-errno.h> /* For error code */
+#include <tzplatform_config.h>
 
 #include "debug.h"
 #include "util.h"
@@ -67,7 +68,13 @@ double util_timestamp(void)
                if (s_info.type == CLOCK_MONOTONIC) {
                        s_info.type = CLOCK_REALTIME;
                } else if (s_info.type == CLOCK_REALTIME) {
-                       break;
+                       struct timeval tv;
+                       if (gettimeofday(&tv, NULL) < 0) {
+                               ErrPrint("gettimeofday: %s\n", strerror(errno));
+                               break;
+                       }
+
+                       return tv.tv_sec + tv.tv_usec / 1000000.0f;
                }
        } while (1);
 
@@ -75,7 +82,12 @@ double util_timestamp(void)
 #else
        struct timeval tv;
 
-       gettimeofday(&tv, NULL);
+       if (gettimeofday(&tv, NULL) < 0) {
+               ErrPrint("gettimeofday: %s\n", strerror(errno));
+               tv.tv_sec = 0;
+               tv.tv_usec = 0;
+       }
+
        return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
 #endif
 }
@@ -98,8 +110,8 @@ static inline int check_native_livebox(const char *pkgname)
        int len;
        char *path;
 
-       len = strlen(pkgname) * 2;
-       len += strlen("/opt/usr/live/%s/libexec/liblive-%s.so");
+       /* get lenght of path */
+       len = snprintf(NULL, 0, "%s/%s/libexec/liblive-%s.so",tzplatform_getenv(TZ_USER_LIVE),pkgname, pkgname);
 
        path = malloc(len + 1);
        if (!path) {
@@ -107,7 +119,7 @@ static inline int check_native_livebox(const char *pkgname)
                return LB_STATUS_ERROR_MEMORY;
        }
 
-       snprintf(path, len, "/opt/usr/live/%s/libexec/liblive-%s.so", pkgname, pkgname);
+       snprintf(path, len, "%s/%s/libexec/liblive-%s.so",tzplatform_getenv(TZ_USER_LIVE),pkgname, pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);
@@ -123,8 +135,8 @@ static inline int check_web_livebox(const char *pkgname)
        int len;
        char *path;
 
-       len = strlen(pkgname) * 2;
-       len += strlen("/opt/usr/apps/%s/res/wgt/livebox/index.html");
+       /* get lenght of path*/
+       len = snprintf(NULL, 0, "%s/%s/res/wgt/livebox/index.html",tzplatform_getenv(TZ_USER_APP),pkgname);
 
        path = malloc(len + 1);
        if (!path) {
@@ -132,7 +144,7 @@ static inline int check_web_livebox(const char *pkgname)
                return LB_STATUS_ERROR_MEMORY;
        }
 
-       snprintf(path, len, "/opt/usr/apps/%s/res/wgt/livebox/index.html", pkgname);
+       snprintf(path, len, "%s/%s/res/wgt/livebox/index.html",tzplatform_getenv(TZ_USER_APP) ,pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);