summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSung-jae Park <nicesj.park@samsung.com>2013-09-26 12:36:29 +0900
committerSung-jae Park <nicesj.park@samsung.com>2013-09-26 12:36:29 +0900
commitb1eb30b5f03c00852f478fa67bd5f03470060a24 (patch)
treed459a50ea32002874afcb1b582af0f05702fdbeb
parenta71e6a98823a96ef14ab8ab130a40aa543c12ba9 (diff)
downloadprovider-tizen_2.2.tar.gz
provider-tizen_2.2.tar.bz2
provider-tizen_2.2.zip
Replace gettimeofday with clock_gettimesubmit/tizen_2.2/20131107.0609452.2.1_releasetizen_2.2
Change-Id: Iae2ae47b53a5ade1c0d058665a9eb8e0d882d0c0
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/util.h2
-rw-r--r--packaging/libprovider.spec2
-rw-r--r--src/provider.c10
-rw-r--r--src/util.c45
5 files changed, 56 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 48d38c7..966ea8a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,8 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
#ADD_DEFINITIONS("-ansi")
#ADD_DEFINITIONS("-pedantic")
+ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET")
+
ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
ADD_DEFINITIONS("-DLOG_TAG=\"PROVIDER\"")
ADD_DEFINITIONS("-DNDEBUG")
diff --git a/include/util.h b/include/util.h
index d84474e..7fef2eb 100644
--- a/include/util.h
+++ b/include/util.h
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-extern double util_get_timestamp(void);
+extern double util_timestamp(void);
extern const char *util_basename(const char *name);
extern const char *util_uri_to_path(const char *uri);
diff --git a/packaging/libprovider.spec b/packaging/libprovider.spec
index eeeb6ed..0125f3d 100644
--- a/packaging/libprovider.spec
+++ b/packaging/libprovider.spec
@@ -1,6 +1,6 @@
Name: libprovider
Summary: Library for developing the livebox service provider.
-Version: 0.9.11
+Version: 0.9.12
Release: 1
Group: HomeTF/Livebox
License: Flora License
diff --git a/src/provider.c b/src/provider.c
index 443d509..eb5154e 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -1101,7 +1101,6 @@ static char *keep_file_in_safe(const char *id, int uri)
int len;
int base_idx;
char *new_path;
- struct timeval tv;
path = uri ? util_uri_to_path(id) : id;
if (!path) {
@@ -1139,6 +1138,14 @@ static char *keep_file_in_safe(const char *id, int uri)
strncpy(new_path, path, base_idx);
+#if defined(_USE_ECORE_TIME_GET)
+ double tval;
+
+ tval = util_timestamp();
+
+ snprintf(new_path + base_idx, len + 10 - base_idx + 30, "reader/%lf.%s", tval, path + base_idx);
+#else
+ struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) {
ErrPrint("gettimeofday: %s\n", strerror(errno));
tv.tv_sec = rand();
@@ -1146,6 +1153,7 @@ static char *keep_file_in_safe(const char *id, int uri)
}
snprintf(new_path + base_idx, len + 10 - base_idx + 30, "reader/%lu.%lu.%s", tv.tv_sec, tv.tv_usec, path + base_idx);
+#endif
if (unlink(new_path) < 0) {
ErrPrint("Unlink(%s): %s\n", new_path, strerror(errno));
diff --git a/src/util.c b/src/util.c
index defbdb0..714217f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -18,19 +18,60 @@
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
#include <dlog.h>
#include "util.h"
#include "debug.h"
-double util_get_timestamp(void)
+int errno;
+#if defined(_USE_ECORE_TIME_GET)
+static struct {
+ clockid_t type;
+} s_info = {
+ .type = CLOCK_MONOTONIC,
+};
+#endif
+
+double util_timestamp(void)
{
+#ifdef _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 (double)tv.tv_sec + (double)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)