From 714fa064dcc57b7c7e3cdeb1f62c9f36cfea6e51 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 29 Mar 2010 11:27:13 +0000 Subject: make getAllGroupEntries work when called again; fixes #3816 --- System/Posix/User.hsc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/System/Posix/User.hsc b/System/Posix/User.hsc index 2427de0..e1c0f95 100644 --- a/System/Posix/User.hsc +++ b/System/Posix/User.hsc @@ -222,7 +222,7 @@ getGroupEntryForName = error "System.Posix.User.getGroupEntryForName: not suppor getAllGroupEntries :: IO [GroupEntry] #ifdef HAVE_GETGRENT getAllGroupEntries = - withMVar lock $ \_ -> worker [] + withMVar lock $ \_ -> bracket_ c_setgrent c_endgrent $ worker [] where worker accum = do resetErrno ppw <- throwErrnoIfNullAndError "getAllGroupEntries" $ @@ -234,6 +234,10 @@ getAllGroupEntries = foreign import ccall unsafe "getgrent" c_getgrent :: IO (Ptr CGroup) +foreign import ccall unsafe "setgrent" + c_setgrent :: IO () +foreign import ccall unsafe "endgrent" + c_endgrent :: IO () #else getAllGroupEntries = error "System.Posix.User.getAllGroupEntries: not supported" #endif -- cgit v1.2.3