From a6367a17d5f77848e8313b1e5e42698aec92908d Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 May 2013 15:43:17 +0000 Subject: [PATCH 1/3] on x86_64 use long instead of long long for 64bit posix types following glibc use the lowest rank 64bit integer type for ino_t etc. this is eg. useful for printf format compatibility --- arch/x86_64/bits/alltypes.h.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86_64/bits/alltypes.h.sh b/arch/x86_64/bits/alltypes.h.sh index c5e54aab..a6c90327 100755 --- a/arch/x86_64/bits/alltypes.h.sh +++ b/arch/x86_64/bits/alltypes.h.sh @@ -94,12 +94,12 @@ TYPEDEF long off_t; TYPEDEF unsigned int mode_t; TYPEDEF unsigned long nlink_t; -TYPEDEF unsigned long long ino_t; +TYPEDEF unsigned long ino_t; TYPEDEF unsigned long dev_t; TYPEDEF long blksize_t; -TYPEDEF long long blkcnt_t; -TYPEDEF unsigned long long fsblkcnt_t; -TYPEDEF unsigned long long fsfilcnt_t; +TYPEDEF long blkcnt_t; +TYPEDEF unsigned long fsblkcnt_t; +TYPEDEF unsigned long fsfilcnt_t; TYPEDEF void * timer_t; TYPEDEF int clockid_t; From 41c34d188a598b016d62e152735f8466fe9910a4 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 May 2013 15:49:08 +0000 Subject: [PATCH 2/3] fix ioctl _IOR, _IOW, etc macros to avoid signed overflow (2<<30) --- arch/arm/bits/ioctl.h | 6 +++--- arch/i386/bits/ioctl.h | 6 +++--- arch/microblaze/bits/ioctl.h | 6 +++--- arch/mips/bits/ioctl.h | 8 ++++---- arch/powerpc/bits/ioctl.h | 25 +++---------------------- arch/x86_64/bits/ioctl.h | 6 +++--- 6 files changed, 19 insertions(+), 38 deletions(-) diff --git a/arch/arm/bits/ioctl.h b/arch/arm/bits/ioctl.h index 336c71c3..9d75118e 100644 --- a/arch/arm/bits/ioctl.h +++ b/arch/arm/bits/ioctl.h @@ -4,9 +4,9 @@ #define _IOC_READ 2U #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(1,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(2,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(3,(a),(b),sizeof(c)) +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) #define TCGETS 0x5401 #define TCSETS 0x5402 diff --git a/arch/i386/bits/ioctl.h b/arch/i386/bits/ioctl.h index 336c71c3..9d75118e 100644 --- a/arch/i386/bits/ioctl.h +++ b/arch/i386/bits/ioctl.h @@ -4,9 +4,9 @@ #define _IOC_READ 2U #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(1,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(2,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(3,(a),(b),sizeof(c)) +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) #define TCGETS 0x5401 #define TCSETS 0x5402 diff --git a/arch/microblaze/bits/ioctl.h b/arch/microblaze/bits/ioctl.h index 336c71c3..9d75118e 100644 --- a/arch/microblaze/bits/ioctl.h +++ b/arch/microblaze/bits/ioctl.h @@ -4,9 +4,9 @@ #define _IOC_READ 2U #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(1,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(2,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(3,(a),(b),sizeof(c)) +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) #define TCGETS 0x5401 #define TCSETS 0x5402 diff --git a/arch/mips/bits/ioctl.h b/arch/mips/bits/ioctl.h index 5040226c..83fb1678 100644 --- a/arch/mips/bits/ioctl.h +++ b/arch/mips/bits/ioctl.h @@ -3,10 +3,10 @@ #define _IOC_READ 2U #define _IOC_WRITE 4U -#define _IO(a,b) _IOC(1U,(a),(b),0) -#define _IOW(a,b,c) _IOC(4U,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(2U,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(6U,(a),(b),sizeof(c)) +#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) #define TCGETA 0x5401 #define TCSETA 0x5402 diff --git a/arch/powerpc/bits/ioctl.h b/arch/powerpc/bits/ioctl.h index 15cd6c72..0c903dcb 100644 --- a/arch/powerpc/bits/ioctl.h +++ b/arch/powerpc/bits/ioctl.h @@ -1,31 +1,12 @@ -//#define _IOC(a,b,c,d) ( ((a)<<29) | ((b)<<8) | (c) | ((d)<<16) ) -// -#define _IOC_SIZEBITS 13 -#define _IOC_DIRBITS 3 - -#define _IOC_NRBITS 8 -#define _IOC_TYPEBITS 8 - -#define _IOC_NRSHIFT 0 -#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) -#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) -#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) - -#define _IOC(dir,type,nr,size) \ - (((dir) << _IOC_DIRSHIFT) | \ - ((type) << _IOC_TYPESHIFT) | \ - ((nr) << _IOC_NRSHIFT) | \ - ((size) << _IOC_SIZESHIFT)) - - +#define _IOC(a,b,c,d) ( ((a)<<29) | ((b)<<8) | (c) | ((d)<<16) ) #define _IOC_NONE 1U #define _IOC_WRITE 4U #define _IOC_READ 2U #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) #define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(_IOC_READ ,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(_IOC_READ | _IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) #define FIONCLEX _IO('f', 2) #define FIOCLEX _IO('f', 1) diff --git a/arch/x86_64/bits/ioctl.h b/arch/x86_64/bits/ioctl.h index 7f3c0380..77a94551 100644 --- a/arch/x86_64/bits/ioctl.h +++ b/arch/x86_64/bits/ioctl.h @@ -4,9 +4,9 @@ #define _IOC_READ 2U #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(1,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(2,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(3,(a),(b),sizeof(c)) +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) #define TCGETS 0x5401 #define TCSETS 0x5402 From 31ff797787d89bc01a69ca672fb2340ff21a827e Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 May 2013 16:01:38 +0000 Subject: [PATCH 3/3] fix the prototype of settimeofday to follow the original BSD declaration --- include/sys/time.h | 10 +++++----- src/linux/settimeofday.c | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/sys/time.h b/include/sys/time.h index 559e817e..3ce824e6 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -30,15 +30,15 @@ int utimes (const char *, const struct timeval [2]); #endif #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int futimes(int, const struct timeval [2]); -int futimesat(int, const char *, const struct timeval [2]); -int lutimes(const char *, const struct timeval [2]); -int settimeofday (const struct timeval *, void *); -int adjtime (const struct timeval *, struct timeval *); struct timezone { int tz_minuteswest; int tz_dsttime; }; +int futimes(int, const struct timeval [2]); +int futimesat(int, const char *, const struct timeval [2]); +int lutimes(const char *, const struct timeval [2]); +int settimeofday(const struct timeval *, const struct timezone *); +int adjtime (const struct timeval *, struct timeval *); #define timerisset(t) ((t)->tv_sec || (t)->tv_usec) #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ diff --git a/src/linux/settimeofday.c b/src/linux/settimeofday.c index d741f66b..15c18c63 100644 --- a/src/linux/settimeofday.c +++ b/src/linux/settimeofday.c @@ -1,7 +1,8 @@ +#define _BSD_SOURCE #include #include "syscall.h" -int settimeofday(const struct timeval *tv, void *tz) +int settimeofday(const struct timeval *tv, const struct timezone *tz) { return syscall(SYS_settimeofday, tv, 0); }