Flexible I/O Tester development
 help / color / mirror / Atom feed
From: Bruce Cran <bruce@cran.org.uk>
To: "fio@vger.kernel.org" <fio@vger.kernel.org>
Subject: [PATCH] Add Windows ctime_r implementation and empty ioctl.h header
Date: Wed, 06 May 2015 21:31:19 -0600	[thread overview]
Message-ID: <554ADC87.2070605@cran.org.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

I've attached a patch that adds ctime_r to the Windows build and an 
empty ioctl.h header that the build appears to need now.   There are 
linker errors after building the fio binary - I guess the other programs 
need the Windows posix.c linked in?  I'm not sure how the 
configure/build system works now, so I wasn't able to update it.

-- 
Bruce

[-- Attachment #2: 0001-Add-Windows-ctime_r-implementation-and-add-empty-ioc.patch --]
[-- Type: text/plain, Size: 2442 bytes --]

From ca8693bb5af23fc0133fa3267f8d0cc5c8d25600 Mon Sep 17 00:00:00 2001
From: Bruce Cran <bruce.cran@gmail.com>
Date: Wed, 6 May 2015 16:30:46 -0600
Subject: [PATCH] Add Windows ctime_r implementation and add empty ioctl.h
 header

stat.c now uses ctime_r(), so add an implementation for Windows.
It's expected that ioctl.h exists on each platform, even if it's
not used: add an empty file on Windows.
---
 os/windows/posix.c                   | 24 ++++++++++++++++++++++++
 os/windows/posix/include/sys/ioctl.h |  7 +++++++
 2 files changed, 31 insertions(+)
 create mode 100644 os/windows/posix/include/sys/ioctl.h

diff --git a/os/windows/posix.c b/os/windows/posix.c
index d238c64..41fc480 100755
--- a/os/windows/posix.c
+++ b/os/windows/posix.c
@@ -229,6 +229,30 @@ char *dlerror(void)
 	return dl_error;
 }
 
+/* Copied from http://blogs.msdn.com/b/joshpoley/archive/2007/12/19/date-time-formats-and-conversions.aspx */
+void Time_tToSystemTime(time_t dosTime, SYSTEMTIME *systemTime)
+{
+    LARGE_INTEGER jan1970FT;
+    LARGE_INTEGER utcFT;
+    jan1970FT.QuadPart = 116444736000000000LL; // january 1st 1970
+    utcFT.QuadPart = ((unsigned __int64)dosTime) * 10000000 + jan1970FT.QuadPart;
+
+    FileTimeToSystemTime((FILETIME*)&utcFT, systemTime);
+}
+
+char* ctime_r(const time_t *t, char *buf)
+{
+    SYSTEMTIME systime;
+    const char * const dayOfWeek[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
+    const char * const monthOfYear[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+
+    Time_tToSystemTime(*t, &systime);
+    /* We don't know how long `buf` is, but assume it's rounded up from the minimum of 25 to 32 */
+    StringCchPrintfA(buf, 32, "%s %s %d %02d:%02d:%02d %04d", dayOfWeek[systime.wDayOfWeek - 1], monthOfYear[systime.wMonth - 1],
+										 systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wYear);
+    return buf;
+}
+
 int gettimeofday(struct timeval *restrict tp, void *restrict tzp)
 {
 	FILETIME fileTime;
diff --git a/os/windows/posix/include/sys/ioctl.h b/os/windows/posix/include/sys/ioctl.h
new file mode 100644
index 0000000..a42247d
--- /dev/null
+++ b/os/windows/posix/include/sys/ioctl.h
@@ -0,0 +1,7 @@
+#ifndef IOCTL_H
+#define IOCTL_H
+
+/* This file is empty since it only needs to exist on Windows
+   but isn't otherwise used */
+
+#endif /* IOCTL_H */
\ No newline at end of file
-- 
1.9.5.msysgit.1


             reply	other threads:[~2015-05-07  3:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-07  3:31 Bruce Cran [this message]
2015-05-07 16:59 ` [PATCH] Add Windows ctime_r implementation and empty ioctl.h header Jens Axboe
2015-05-07 21:04   ` Bruce Cran
2015-05-07 21:06     ` Jens Axboe
2015-05-07 21:27       ` Bruce Cran
2015-05-07 21:32         ` Jens Axboe
2015-05-07 22:56           ` Bruce Cran
2015-05-08  0:20             ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554ADC87.2070605@cran.org.uk \
    --to=bruce@cran.org.uk \
    --cc=fio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox