darcs patch: Added support for getpwent/getgrent (and 1 more)

Wed Aug 30 08:25:50 CDT 2006 John Goerzen

applied, thanks. Simon John Goerzen wrote:
Wed Aug 30 08:25:50 CDT 2006 John Goerzen
* Added support for getpwent/getgrent Wed Aug 30 08:45:17 CDT 2006 John Goerzen
* Fix compilation issues with new getgrent/getpwent code ------------------------------------------------------------------------
New patches:
[Added support for getpwent/getgrent John Goerzen
**20060830132550] { hunk ./System/Posix/User.hsc 31 + getAllGroupEntries, hunk ./System/Posix/User.hsc 37 + getAllUserEntries, hunk ./System/Posix/User.hsc 52 -#if !defined(HAVE_GETPWNAM_R) || !defined(HAVE_GETPWUID_R) +#if !defined(HAVE_GETPWNAM_R) || !defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT) hunk ./System/Posix/User.hsc 202 +-- | @getAllGroupEntries@ returns all group entries on the system by +-- repeatedly calling @getgrent@ +getAllGroupEntries :: IO [GroupEntry] +#ifdef HAVE_GETGRENT +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) + +foreign import ccall unsafe "getgrent" + c_getgrent :: IO (Ptr CGroup) +#else +getAllGroupEntries = error "System.Posix.User.getAllGroupEntries: not supported" +#endif + hunk ./System/Posix/User.hsc 259 -#if !defined(HAVE_GETPWNAM_R) || !defined(HAVE_GETPWUID_R) +-- Also, getpwent/setpwent require a global lock since they maintain +-- an internal file position pointer. +#if !defined(HAVE_GETPWNAM_R) || !defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT) hunk ./System/Posix/User.hsc 327 + +-- | @getAllUserEntries@ returns all user entries on the system by +-- repeatedly calling @getpwent@ +getAllUserEntries :: IO [UserEntry] +#ifdef HAVE_GETPWENT +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) + +foreign import ccall unsafe "getpwent" + c_getpwent :: IO (Ptr CPasswd) +#else +getAllUserEntries = error "System.Posix.User.getAllUserEntries: not supported" +#endif hunk ./configure.ac 20 +AC_CHECK_FUNCS([getpwent getgrent]) } [Fix compilation issues with new getgrent/getpwent code John Goerzen
**20060830134517] { hunk ./System/Posix/User.hsc 209 - 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) hunk ./System/Posix/User.hsc 337 - 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) hunk ./System/Posix/User.hsc 386 +-- 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 } Context:
[includes -> install-includes Ross Paterson
**20060829123744] [Added some Haddock docs for UserEntry and GroupEntry John Goerzen **20060829185932] [Add missing field gr_passwd to GroupEntry John Goerzen **20060829185536] [Whitespace changes for better alignment in unpackUserEntry John Goerzen **20060829185300] [Added pw_passwd and pw_gecos fields to UserEntry structure John Goerzen **20060829185051 System.Posix.User was missing pw_gecos and pw_passwd in UserEntry. I have added them, so now the full struct passwd is represented. ] [exclude Setup.hs from build Ross Paterson
**20060824183535] [add boilerplate Setup.hs Ross Paterson **20060824115019] [Added more documentation to System.Posix.Files Johan Tibell **20060813102350] [fix markup (#854) Ross Paterson **20060820002322] [change test for buildability Ross Paterson **20060819144834 Checking for dlfcn.h instead of creat() should make the Cabal build fail more gracefully under MinGW. ] [document args to executeFile Simon Marlow
**20060809104559] [fix bogosity in getEnvironmentPrim Simon Marlow **20060531144640] [Track the GHC source tree reoganisation Simon Marlow **20060407041758] [TAG Initial conversion from CVS complete John Goerzen **20060112154138] Patch bundle hash: 63c2eb2b05cb291e8e47b65cbe87bf177738c4fe ------------------------------------------------------------------------
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
participants (2)
-
John Goerzen
-
Simon Marlow