Posix.sync
Max A . K .
max630@mail.ru
Tue, 20 Nov 2001 08:07:45 +0600
--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Tue, Nov 20, 2001 at 12:04:47PM +1100, Manuel M. T. Chakravarty wrote:
> AFAIK no OS implements all of the Single Unix specification.
> Nevertheless, I think, Sigbjorn is right. Ideally, we
> should have a binding for Single Unix and on any particular
> OS, you will have a subset of it available (that's the same
> situation as you have with any other programming language).
>
> As is pointed out in the open(2) man page, O_SYNC, O_DSYNC,
> and O_RSYNC are synonymous in Linux 2.2. In 2.4, at least
> with some file systems (eg, XFS) you can choose which
> behaviour O_SYNC should have.
I understand. So, can the attached file be a "Single Unix
compatible" 'open' function binding?
The only difference I see is the *SYNC flags. Did I miss
anything?
Max.
--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sync.diff"
--- hslibs/posix/PosixFiles.lhs.orig Tue Nov 20 07:55:00 2001
+++ hslibs/posix/PosixFiles.lhs Tue Nov 20 07:52:57 2001
@@ -253,7 +253,10 @@
exclusive :: Bool,
noctty :: Bool,
nonBlock :: Bool,
- trunc :: Bool
+ trunc :: Bool,
+ sync :: Bool,
+ dSync :: Bool,
+ rSync :: Bool
}
defaultFileFlags :: OpenFileFlags
@@ -263,7 +266,10 @@
exclusive = False,
noctty = False,
nonBlock = False,
- trunc = False
+ trunc = False,
+ sync = False,
+ dSync = False,
+ rSync = False
}
openFd :: FilePath
@@ -271,7 +277,7 @@
-> Maybe FileMode -- Just x => O_CREAT, Nothing => must exist
-> OpenFileFlags
-> IO Fd
-openFd name how maybe_mode (OpenFileFlags append exclusive noctty nonBlock truncate) = do
+openFd name how maybe_mode (OpenFileFlags append exclusive noctty nonBlock truncate sync dSync rSync) = do
fd <- _ccall_ open (packString name) flags mode_w
if fdToInt fd /= ((-1)::Int)
then return fd
@@ -287,7 +293,10 @@
(if exclusive then ``O_EXCL'' else zero) `or`
(if noctty then ``O_NOCTTY'' else zero) `or`
(if nonBlock then ``O_NONBLOCK'' else zero) `or`
- (if truncate then ``O_TRUNC'' else zero)
+ (if truncate then ``O_TRUNC'' else zero) `or`
+ (if sync then ``O_SYNC'' else zero) `or`
+ (if dSync then ``O_DSYNC'' else zero) `or`
+ (if rSync then ``O_RSYNC'' else zero)
zero = W# (int2Word# 0#)
--- hslibs/posix/cbits/HsPosix.h.orig Tue Nov 20 07:40:04 2001
+++ hslibs/posix/cbits/HsPosix.h Tue Nov 20 07:48:39 2001
@@ -34,6 +34,15 @@
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
+ #ifndef O_SYNC
+ #define O_SYNC 0
+ #endif
+ #ifndef O_DSYNC
+ #define O_DSYNC O_SYNC
+ #endif
+ #ifndef O_RSYNC
+ #define O_RSYNC 0
+ #endif
#endif /* HAVE_FCNTL_H */
#ifdef HAVE_UNISTD_H
--X1bOJ3K7DJ5YkBrT--