summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAycanIrican <>2010-06-01 23:32:12 (GMT)
committerLuite Stegeman <luite@luite.com>2010-06-01 23:32:12 (GMT)
commita8e8a8fb032dea413bdf09fdf594d18f5b68faba (patch)
tree5abd1fbd266d82fd72b8246694034a27b6c7964b
parentc158324f764cbcab9263aac10db880aff8ee12bd (diff)
version 0.4HEAD0.4master
-rw-r--r--System/Syscall.hs32
-rw-r--r--hsyscall.cabal4
2 files changed, 25 insertions, 11 deletions
diff --git a/System/Syscall.hs b/System/Syscall.hs
index 08fa174..f49a0ef 100644
--- a/System/Syscall.hs
+++ b/System/Syscall.hs
@@ -13,7 +13,6 @@ import System.Posix.Types
import Foreign.C
import Foreign.Storable(poke)
import Foreign.Marshal (alloca)
-import Foreign.Ptr (Ptr, nullPtr)
#if defined(LINUX)
import System.Syscall.Linux
@@ -27,11 +26,19 @@ import System.Syscall.Darwin
import System.Syscall.FreeBSD
#endif
--- | A unified primitive signature for the sendfile syscall. The number of bytes written and the offset value
-c_sendfile :: Fd -> Fd -> COff -> CSize -> IO CSsize
+-- | A unified primitive signature for the sendfile syscall.
+c_sendfile :: Fd -> Fd -> COff -> CSize -> IO (Either Errno CSsize)
+c_sendfile ofd ifd o c = do
+ r <- _c_sendfile ofd ifd o c
+ if (r < 0)
+ then do e <- getErrno
+ return $ Left e
+ else return $ Right r
+
+_c_sendfile :: Fd -> Fd -> COff -> CSize -> IO CSsize
#if defined(LINUX)
-c_sendfile ofd ifd o c = do
+_c_sendfile ofd ifd o c = do
alloca $ \off -> do
poke off o
r <- c_sendfile_linux ofd ifd off c
@@ -39,15 +46,22 @@ c_sendfile ofd ifd o c = do
#endif
#if defined(DARWIN)
-c_sendfile ofd ifd o c = do
+_c_sendfile ofd ifd o c = do
alloca $ \sbytes ->
do poke sbytes c
- c_sendfile_darwin ifd ofd o sbytes 0 0
+ r <- c_sendfile_darwin ifd ofd o sbytes 0 0
+ sc <- peek $ ((castPtr sbytes)::Ptr CSsize)
+ if sc > 0
+ then return s
+ else return r
#endif
#if defined(FREEBSD)
-c_sendfile ofd ifd o c = do
+_c_sendfile ofd ifd o c = do
alloca $ \sbytes ->
- do poke sbytes c
- c_sendfile_freebsd ifd ofd o c 0 sbytes 0
+ do r <- c_sendfile_freebsd ifd ofd o c 0 sbytes 0
+ sc <- peek $ ((castPtr sbytes)::Ptr CSsize)
+ if sc > 0
+ then return s
+ else return r
#endif \ No newline at end of file
diff --git a/hsyscall.cabal b/hsyscall.cabal
index b5abccc..6408fb2 100644
--- a/hsyscall.cabal
+++ b/hsyscall.cabal
@@ -1,5 +1,5 @@
Name: hsyscall
-Version: 0.3
+Version: 0.4
Synopsis: FFI to syscalls
Description: FFI to OS syscalls (open, close, sendfile etc...).
Homepage: http://github.com/aycanirican/hsyscall
@@ -8,7 +8,7 @@ License-file: LICENSE
Author: Aycan iRiCAN
Maintainer: aycan.irican@core.gen.tr
Stability: Experimental
-Category: System
+Category: Foreign
Build-type: Simple
-- Extra files to be distributed with the package, such as examples or