Skip to contentSkip to conversation

Add Windows ctime_r implementation and empty ioctl.h header

PATCH In review Bruce Cran 2 participants 8 messages May 7, 2015 – May 8, 2015 Kbuild

lore
Share & tools
lore

Bruce Cran

author
#0 lore raw

PATCH 1/1 Add Windows ctime_r implementation and empty ioctl.h header

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.

Signature · 1 line
Bruce

From ca8693bb5af23fc0133fa3267f8d0cc5c8d25600 Mon Sep 17 00:00:00 2001
From: Bruce Cran <[email protected]>
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
os/windows/posix.c +24 -0
index d238c64..41fc480 100755
@@ -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;
os/windows/posix/include/sys/ioctl.h new file +7 -0
new file mode 100644
index 0000000..a42247d
@@ -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
Signature · 1 line
1.9.5.msysgit.1
#1 lore raw
Quoted 5 lines · Bruce Cran

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.

Added. Side note - your email consistently ends up in my gmail spam, for some reason...

What are the linker errors? I'm guessing you need to check and add your OS dependencies to T_OBJS in the Makefile, when targetos is Windows.

ifeq ($(CONFIG_TARGET_OS), Linux)
T_OBJS += whatever.o
endif

or something like that.

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 1 line · Jens Axboe

Added. Side note - your email consistently ends up in my gmail spam, for some reason...

Ugh, it's because DMARC doesn't work through mailing lists without jumping through hoops. I'll see if I can disable it for specified destinations.

Quoted 2 lines

What are the linker errors? I'm guessing you need to check and add your OS dependencies to T_OBJS in the Makefile, when targetos is Windows.

Got it - I'd forgotten that the Makefile is still checked in and it's not generated by the configure script! I've attached a patch which should make the build work a lot better on Windows.

--
Bruce

From 4a6ef95b40558b215c113a0260b891b36f376f83 Mon Sep 17 00:00:00 2001
From: Bruce Cran <[email protected]>
Date: Thu, 7 May 2015 14:56:58 -0600
Subject: [PATCH] Fix compiler warning and test progs linker errors on Windows

Add prototype for ctime_r to os-windows.h to avoid compiler warning. Link in os/windows/posix.o and lib/hweight.o to allow test progs to build on Windows.

---
 Makefile        | 6 ++++++
 os/os-windows.h | 1 +
 2 files changed, 7 insertions(+)
Makefile +6 -0
index 1b312cb..d9aedf5 100644
@@ -218,6 +218,12 @@ T_OBJS += $(T_LFSR_TEST_OBJS)
 T_OBJS += $(T_BTRACE_FIO_OBJS)
 T_OBJS += $(T_DEDUPE_OBJS)
 
+ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS)))
+    T_DEDUPE_OBJS += os/windows/posix.o lib/hweight.o
+    T_SMALLOC_OBJS += os/windows/posix.o lib/hweight.o
+    T_LFSR_TEST_OBJS += os/windows/posix.o lib/hweight.o
+endif
+
 T_TEST_PROGS = $(T_SMALLOC_PROGS)
 T_TEST_PROGS += $(T_IEEE_PROGS)
 T_PROGS += $(T_ZIPF_PROGS)
os/os-windows.h +1 -0
index 6603635..9e931c9 100644
@@ -105,6 +105,7 @@ int fcntl(int fildes, int cmd, ...);
 int fdatasync(int fildes);
 int lstat(const char * path, struct stat * buf);
 uid_t geteuid(void);
+char* ctime_r(const time_t *t, char *buf);
 int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
 ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
 ssize_t pwrite(int fildes, const void *buf, size_t nbyte,
Signature · 1 line
1.9.5.msysgit.1
#3 lore raw
Quoted 7 lines · Bruce Cran
Quoted 2 lines · Jens Axboe

Added. Side note - your email consistently ends up in my gmail spam, for some reason...

Ugh, it's because DMARC doesn't work through mailing lists without jumping through hoops. I'll see if I can disable it for specified destinations.

This one got through, but probably because it's a reply..

Quoted 7 lines
Quoted 2 lines

What are the linker errors? I'm guessing you need to check and add your OS dependencies to T_OBJS in the Makefile, when targetos is Windows.

Got it - I'd forgotten that the Makefile is still checked in and it's not generated by the configure script!
I've attached a patch which should make the build work a lot better on Windows.

Thanks, added.

Signature · 1 line
Jens Axboe
author
#4 lore raw
Quoted 2 lines · Jens Axboe

Thanks, added

And another patch, since my tree wasn't quite up-to-date: this time to add <limits.h> to eta.c and define _POSIX_HOST_NAME_MAX.

Signature · 1 line
Bruce

From eeb938efb2d79cd53fee8cd60f6d07033e37cbf1 Mon Sep 17 00:00:00 2001
From: Bruce Cran <[email protected]>
Date: Thu, 7 May 2015 15:24:45 -0600
Subject: [PATCH] Fix Windows build: add limits.h to eta.c and define
_POSIX_HOST_NAME_MAX

---
 eta.c              | 1 +
 os/windows/posix.h | 2 ++
 2 files changed, 3 insertions(+)
eta.c +1 -0
index e458457..a5a8f53 100644
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <limits.h>
 
 #include "fio.h"
 #include "lib/pow2.h"
os/windows/posix.h +2 -0
index 85640a2..3b4865f 100644
@@ -4,6 +4,8 @@
 typedef off_t off64_t;
 typedef int clockid_t;
 
+#define _POSIX_HOST_NAME_MAX 255
+
 extern int clock_gettime(clockid_t clock_id, struct timespec *tp);
 extern int inet_aton(const char *, struct in_addr *);
 extern int win_to_posix_error(DWORD winerr);
Signature · 1 line
1.9.5.msysgit.1
#5 lore raw
Quoted 6 lines · Bruce Cran
Quoted 2 lines · Jens Axboe

Thanks, added

And another patch, since my tree wasn't quite up-to-date: this time to add <limits.h> to eta.c and define _POSIX_HOST_NAME_MAX.

Honestly, that should just use PATH_MAX. I'll make that change instead of adding this patch.

Signature · 1 line
Jens Axboe
author
#6 lore raw
Quoted 1 line · Jens Axboe

Honestly, that should just use PATH_MAX. I'll make that change instead of adding this patch

Thanks. And one last patch, to fix the Windows installer build this time.

Signature · 1 line
Bruce

From 452f548cd17d13e6fe0047a82204f83202ea9fbe Mon Sep 17 00:00:00 2001
From: Bruce Cran <[email protected]>
Date: Thu, 7 May 2015 16:54:37 -0600
Subject: [PATCH] Fix Windows installer build: LICENSE is now MORAL-LICENSE

---
 os/windows/install.wxs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
os/windows/install.wxs +2 -2
index ba58b92..f392606 100755
@@ -40,7 +40,7 @@
 							<File Id="COPYING" Name="COPYING.txt" Source="..\..\COPYING"/>
 						</Component>
 						<Component>
-							<File Id="LICENSE" Name="LICENSE.txt" Source="..\..\LICENSE"/>
+							<File Id="MORAL_LICENSE" Name="MORAL-LICENSE.txt" Source="..\..\MORAL-LICENSE"/>
 						</Component>
 						<Directory Id="examples" Name="examples"/>
 					</Directory>
@@ -54,7 +54,7 @@
 		<ComponentRef Id="README"/>
 		<ComponentRef Id="REPORTING_BUGS"/>
 		<ComponentRef Id="COPYING"/>
-		<ComponentRef Id="LICENSE"/>
+		<ComponentRef Id="MORAL_LICENSE"/>
 		<ComponentGroupRef Id="examples"/>
 	</Feature>
 
Signature · 1 line
1.9.5.msysgit.1
#7 lore raw
Quoted 5 lines · Bruce Cran
Quoted 2 lines · Jens Axboe

Honestly, that should just use PATH_MAX. I'll make that change instead of adding this patch

Thanks. And one last patch, to fix the Windows installer build this time.

Great thanks, and with that, 2.2.8 has been tagged.

Signature · 1 line
Jens Axboe