aboutsummaryrefslogtreecommitdiff
path: root/jerry-libc
diff options
context:
space:
mode:
authorLászló Langó <llango.u-szeged@partner.samsung.com>2016-02-11 12:03:11 +0000
committerLászló Langó <llango.u-szeged@partner.samsung.com>2016-02-18 14:05:36 +0000
commit684ed7268c140ec52d2b711133280bbf98bae128 (patch)
tree710ac2f1c6b6ddffb1893c03dcdd586958f66a78 /jerry-libc
parenta7715a5d78dd5e685c61dedf77b55368bdd0a570 (diff)
Fix system call related date builtin functions
Related issues: #213, #691 * Fixed 'ecma_date_local_tza' and 'ecma_date_daylight_saving_ta' date builtin helper functions * Added syscall of gettimeofday function to get the current system time and timezone. * Fixed related regression test files. JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
Diffstat (limited to 'jerry-libc')
-rw-r--r--jerry-libc/include/time.h46
-rw-r--r--jerry-libc/target/darwin/jerry-libc-target.c15
-rw-r--r--jerry-libc/target/linux/jerry-libc-target.c16
-rw-r--r--jerry-libc/target/mcu-stubs/jerry-libc-target.c15
4 files changed, 89 insertions, 3 deletions
diff --git a/jerry-libc/include/time.h b/jerry-libc/include/time.h
new file mode 100644
index 00000000..b01e3d77
--- /dev/null
+++ b/jerry-libc/include/time.h
@@ -0,0 +1,46 @@
+/* Copyright 2016 Samsung Electronics Co., Ltd.
+ * Copyright 2016 University of Szeged
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef JERRY_LIBC_TIME_H
+#define JERRY_LIBC_TIME_H
+
+#ifdef __cplusplus
+# define EXTERN_C "C"
+#else /* !__cplusplus */
+# define EXTERN_C
+#endif /* !__cplusplus */
+
+/**
+ * Time value structure
+ */
+struct _timeval
+{
+ unsigned long tv_sec; /**< seconds */
+ unsigned long tv_usec; /**< microseconds */
+};
+
+/**
+ * Timezone structure
+ */
+struct timezone
+{
+ int tz_minuteswest; /**< minutes west of Greenwich */
+ int tz_dsttime; /**< type of DST correction */
+};
+
+extern EXTERN_C int gettimeofday (void *tp, void *tzp);
+
+#endif /* !JERRY_LIBC_TIME_H */
diff --git a/jerry-libc/target/darwin/jerry-libc-target.c b/jerry-libc/target/darwin/jerry-libc-target.c
index 8657c99b..02eaa6a0 100644
--- a/jerry-libc/target/darwin/jerry-libc-target.c
+++ b/jerry-libc/target/darwin/jerry-libc-target.c
@@ -1,4 +1,5 @@
-/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
+/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
+ * Copyright 2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +29,7 @@
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <time.h>
#include "jerry-libc-defs.h"
@@ -384,3 +386,14 @@ fwrite (const void *ptr, /**< data to write */
return bytes_written / size;
} /* fwrite */
+/**
+ * This function can get the time as well as a timezone.
+ *
+ * @return 0 if success, -1 otherwise
+ */
+int
+gettimeofday (void *tp, /**< struct timeval */
+ void *tzp) /**< struct timezone */
+{
+ return (int) syscall_2 (__NR_gettimeofday, (long int) tp, (long int) tzp);
+} /* gettimeofday */
diff --git a/jerry-libc/target/linux/jerry-libc-target.c b/jerry-libc/target/linux/jerry-libc-target.c
index c948a2db..67009d92 100644
--- a/jerry-libc/target/linux/jerry-libc-target.c
+++ b/jerry-libc/target/linux/jerry-libc-target.c
@@ -1,4 +1,5 @@
-/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
+/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
+ * Copyright 2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +29,7 @@
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <time.h>
#include "jerry-libc-defs.h"
@@ -384,6 +386,18 @@ fwrite (const void *ptr, /**< data to write */
return bytes_written / size;
} /* fwrite */
+/**
+ * This function can get the time as well as a timezone.
+ *
+ * @return 0 if success, -1 otherwise
+ */
+int
+gettimeofday (void *tp, /**< struct timeval */
+ void *tzp) /**< struct timezone */
+{
+ return (int) syscall_2 (__NR_gettimeofday, (long int) tp, (long int) tzp);
+} /* gettimeofday */
+
// FIXME
#if 0
/**
diff --git a/jerry-libc/target/mcu-stubs/jerry-libc-target.c b/jerry-libc/target/mcu-stubs/jerry-libc-target.c
index 893151f6..d1227ade 100644
--- a/jerry-libc/target/mcu-stubs/jerry-libc-target.c
+++ b/jerry-libc/target/mcu-stubs/jerry-libc-target.c
@@ -1,4 +1,5 @@
-/* Copyright 2015 Samsung Electronics Co., Ltd.
+/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
+ * Copyright 2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include "jerry-libc-defs.h"
@@ -61,3 +63,14 @@ fwrite (const void *ptr __attr_unused___, /**< data to write */
return size * nmemb;
} /* fwrite */
+/**
+ * This function can get the time as well as a timezone.
+ *
+ * @return 0 if success, -1 otherwise
+ */
+int
+gettimeofday (void *tp __attr_unused___, /**< struct timeval */
+ void *tzp __attr_unused___) /**< struct timezone */
+{
+ return 0;
+} /* gettimeofday */