diff options
author | John Goerzen <jgoerzen@complete.org> | 2006-08-30 13:45:17 +0000 |
---|---|---|
committer | John Goerzen <jgoerzen@complete.org> | 2006-08-30 13:45:17 +0000 |
commit | f001cc60987ca1d02d515c955fb47acf5017d10a (patch) | |
tree | e2d39f25b90a32ad6aac72fe1f28cdb3c09dc5da | |
parent | 23dffda7855bfac1e72f302184f3950de10f22cb (diff) |
Fix compilation issues with new getgrent/getpwent code
-rw-r--r-- | System/Posix/User.hsc | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/System/Posix/User.hsc b/System/Posix/User.hsc index f98b30e..5c6d8db 100644 --- a/System/Posix/User.hsc +++ b/System/Posix/User.hsc @@ -206,11 +206,13 @@ getAllGroupEntries :: IO [GroupEntry] getAllGroupEntries = withMVar lock $ \_ -> worker [] where worker accum = - do ppw <- throwErrnoIfNullAndError "getAllGroupEntries" $ c_getgrent - if ppw == nullPtr - then return (reverse accum) - else do thisentry <- unpackGroupEntry ppw - worker (thisentry : accum) + do resetErrno + ppw <- throwErrnoIfNullAndError "getAllGroupEntries" $ + c_getgrent + if ppw == nullPtr + then return (reverse accum) + else do thisentry <- unpackGroupEntry ppw + worker (thisentry : accum) foreign import ccall unsafe "getgrent" c_getgrent :: IO (Ptr CGroup) @@ -332,11 +334,13 @@ getAllUserEntries :: IO [UserEntry] getAllUserEntries = withMVar lock $ \_ -> worker [] where worker accum = - do ppw <- throwErrnoIfNullAndError "getAllUserEntries" $ c_getpwent - if ppw == nullPtr - then return (reverse accum) - else do thisentry <- unpackUserEntry ppw - worker (thisentry : accum) + do resetErrno + ppw <- throwErrnoIfNullAndError "getAllUserEntries" $ + c_getpwent + if ppw == nullPtr + then return (reverse accum) + else do thisentry <- unpackUserEntry ppw + worker (thisentry : accum) foreign import ccall unsafe "getpwent" c_getpwent :: IO (Ptr CPasswd) @@ -379,3 +383,12 @@ throwErrorIfNonZero_ loc act = do then return () else ioError (errnoToIOError loc (Errno (fromIntegral rc)) Nothing Nothing) +-- Used when a function returns NULL to indicate either an error or +-- EOF, depending on whether the global errno is nonzero. +throwErrnoIfNullAndError :: String -> IO (Ptr a) -> IO (Ptr a) +throwErrnoIfNullAndError loc act = do + rc <- act + errno <- getErrno + if rc == nullPtr && errno /= eOK + then throwErrno loc + else return rc |