/*
* Copyright 2013 Samsung Electronics Co., Ltd
*
- * Licensed under the Flora License, Version 1.0 (the "License");
+ * Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.tizenopensource.org/license
+ * http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
+#include <time.h>
#include <dlog.h>
#include <livebox-errno.h> /* For error code */
#include "util.h"
int errno;
+#if defined(_USE_ECORE_TIME_GET)
+static struct {
+ clockid_t type;
+} s_info = {
+ .type = CLOCK_MONOTONIC,
+};
+#endif
int util_check_extension(const char *filename, const char *check_ptr)
{
name_len = strlen(filename);
while (--name_len >= 0 && *check_ptr) {
- if (filename[name_len] != *check_ptr)
+ if (filename[name_len] != *check_ptr) {
return LB_STATUS_ERROR_INVALID;
+ }
check_ptr ++;
}
double util_timestamp(void)
{
+#if defined(_USE_ECORE_TIME_GET)
+ struct timespec ts;
+
+ do {
+ if (clock_gettime(s_info.type, &ts) == 0) {
+ return ts.tv_sec + ts.tv_nsec / 1000000000.0f;
+ }
+
+ ErrPrint("%d: %s\n", s_info.type, strerror(errno));
+ if (s_info.type == CLOCK_MONOTONIC) {
+ s_info.type = CLOCK_REALTIME;
+ } else if (s_info.type == CLOCK_REALTIME) {
+ 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);
+
+ return 0.0f;
+#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
}
const char *util_basename(const char *name)
{
int length;
length = name ? strlen(name) : 0;
- if (!length)
+ if (!length) {
return ".";
+ }
while (--length > 0 && name[length] != '/');
return LB_STATUS_ERROR_INVALID;
}
- if (!check_native_livebox(pkgname) || !check_web_livebox(pkgname))
+ if (!check_native_livebox(pkgname) || !check_web_livebox(pkgname)) {
return 0;
+ }
return LB_STATUS_ERROR_INVALID;
}
int len;
len = strlen(SCHEMA_FILE);
- if (strncasecmp(uri, SCHEMA_FILE, len))
+ if (strncasecmp(uri, SCHEMA_FILE, len)) {
return NULL;
+ }
return uri + len;
}
int desclen;
int ret;
- if (!filename)
+ if (!filename) {
return LB_STATUS_ERROR_INVALID;
+ }
desclen = strlen(filename) + 6; /* .desc */
descfile = malloc(desclen);