summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-15 05:32:02 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-15 05:32:02 +0000
commit866cee61626d6df0c41d02ff0e7ced8f940736f3 (patch)
treef291f7b00e706ea524e8f791fd1651e8886d535c /win32
parent3670ca436e55e227ab7ec4b912cf17200bd7fe22 (diff)
* include/ruby/win32.h, win32/Makefile.sub, win32/win32.c
(clock_gettime): [experimental] emulates clock_gettime(2) of posix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/Makefile.sub3
-rw-r--r--win32/win32.c41
2 files changed, 44 insertions, 0 deletions
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index 9926206708..cf0c743b8e 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -536,6 +536,8 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define TIMET2NUM(v) LONG2NUM(v)
#define NUM2TIMET(v) NUM2LONG(v)
!endif
+#define CLOCKID2NUM(v) INT2NUM(v)
+#define NUM2CLOCKID(v) NUM2INT(v)
#define SIZEOF_RLIM_T 0
!if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64"
#define SIZEOF_SIZE_T 8
@@ -638,6 +640,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define HAVE_MEMCMP 1
#define HAVE_MEMMOVE 1
#define HAVE_MKDIR 1
+#define HAVE_CLOCK_GETTIME 1
#define HAVE_SPAWNV 1
#define HAVE_STRCASECMP 1
#define HAVE_STRNCASECMP 1
diff --git a/win32/win32.c b/win32/win32.c
index fda9e36af7..95e201092b 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4310,6 +4310,47 @@ gettimeofday(struct timeval *tv, struct timezone *tz)
}
/* License: Ruby's */
+typedef int clockid_t;
+#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 1
+int
+clock_gettime(clockid_t clock_id, struct timespec *sp)
+{
+ switch (clock_id) {
+ case CLOCK_REALTIME:
+ {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ sp->tv_sec = tv.tv_sec;
+ sp->tv_nsec = tv.tv_usec * 1000;
+ return 0;
+ }
+ case CLOCK_MONOTONIC:
+ {
+ LARGE_INTEGER freq;
+ LARGE_INTEGER count;
+ if (!QueryPerformanceFrequency(&freq)) {
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+ if (!QueryPerformanceCounter(&count)) {
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+ sp->tv_sec = count.QuadPart / freq.QuadPart;
+ if (freq.QuadPart < 1000000000)
+ sp->tv_nsec = (count.QuadPart % freq.QuadPart) * (1000000000 / freq.QuadPart);
+ else
+ sp->tv_nsec = (long)((count.QuadPart % freq.QuadPart) * (1000000000.0 / freq.QuadPart));
+ return 0;
+ }
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+}
+
+/* License: Ruby's */
char *
rb_w32_getcwd(char *buffer, int size)
{