aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/IO.hsc
diff options
context:
space:
mode:
authorGravatar sof <unknown>2003-10-23 23:32:43 +0000
committerGravatar sof <unknown>2003-10-23 23:32:43 +0000
commit54162131ecf4e303fb3cdb1b3953d1d1875c985f (patch)
treed8bfc6958ae96ba62fddb5cb6356e4c3709135eb /System/Posix/IO.hsc
parent91399425157428e5a6171b50eeb810d927d8f977 (diff)
[project @ 2003-10-23 23:32:43 by sof]
fdRead: drop superfluous array copying merge to stable
Diffstat (limited to 'System/Posix/IO.hsc')
-rw-r--r--System/Posix/IO.hsc18
1 files changed, 4 insertions, 14 deletions
diff --git a/System/Posix/IO.hsc b/System/Posix/IO.hsc
index 00e56af..c4468eb 100644
--- a/System/Posix/IO.hsc
+++ b/System/Posix/IO.hsc
@@ -328,22 +328,12 @@ fdRead (Fd fd) nbytes = do
allocaBytes (fromIntegral nbytes) $ \ bytes -> do
rc <- throwErrnoIfMinus1Retry "fdRead" (c_read fd bytes nbytes)
case fromIntegral rc of
- 0 -> ioError (IOError Nothing EOF "fdRead" "EOF" Nothing)
- n | n == nbytes -> do
- s <- peekCStringLen (bytes, fromIntegral n)
- return (s, n)
- | otherwise -> do
- -- Let go of the excessively long ByteArray# by copying to a
- -- shorter one. Maybe we need a new primitive, shrinkCharArray#?
- allocaBytes (fromIntegral n) $ \ bytes' -> do
- c_memcpy bytes' bytes n
- s <- peekCStringLen (bytes', fromIntegral n)
- return (s, n)
+ 0 -> ioError (IOError Nothing EOF "fdRead" "EOF" Nothing)
+ n -> do
+ s <- peekCStringLen (bytes, fromIntegral n)
+ return (s, n)
fdWrite :: Fd -> String -> IO ByteCount
fdWrite (Fd fd) str = withCStringLen str $ \ (strPtr,len) -> do
rc <- throwErrnoIfMinus1Retry "fdWrite" (c_write fd strPtr (fromIntegral len))
return (fromIntegral rc)
-
-foreign import ccall unsafe "memcpy"
- c_memcpy :: Ptr dst -> Ptr src -> CSize -> IO (Ptr dst)