1. Maxime Henrion
  2. bsd-sysctl

Commits

Maxime Henrion  committed 7f8103f

Import of the 1.0.3 release.

  • Participants
  • Parent commits 99941c0
  • Branches default
  • Tags REL_1_0_3

Comments (0)

Files changed (3)

File Setup.hs

View file
 import Distribution.Simple
+import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(withPrograms), buildDir)
+import Distribution.Simple.Program (userSpecifyArgs)
 
-main = defaultMain
+import System.Directory
+import System.FilePath
+
+-- Define __HADDOCK__ when building documentation.
+main = defaultMainWithHooks simpleUserHooks {
+  haddockHook = \pkg lbi h f -> do
+    let progs = userSpecifyArgs "hsc2hs" ["-D__HADDOCK__"] (withPrograms lbi)
+    removePreProcessedFiles (buildDir lbi)
+    haddockHook simpleUserHooks pkg lbi { withPrograms = progs } h f
+}
+
+-- Horrible hack to force re-processing of the .hsc file.  Otherwise
+-- the __HADDOCK__ macro doesn't end up being defined.
+removePreProcessedFiles :: FilePath -> IO ()
+removePreProcessedFiles dir =
+  removeFile (dir </> "System/BSD/Sysctl.hs")
+    `catch` \_ -> return ()

File System/BSD/Sysctl.hsc

View file
 -- Module      :  System.BSD.Sysctl
 -- Copyright   :  (c) Maxime Henrion 2009
 -- License     :  see LICENSE
--- 
+--
 -- Maintainer  :  mhenrion@gmail.com
 -- Stability   :  stable
 -- Portability :  portable
 -- at runtime with the 'sysctlPeekArray' function.
 --
 -- On some platforms, there are sysctl nodes that accept parameters via
--- additional components in the OID (see for instance the "kern.proc.pid" sysctl
--- described in sysctl(3) on FreeBSD).  The 'sysctlNameToOidArgs' makes it easy
--- to query such nodes as well.
+-- additional components in the OID (see for instance the \"kern.proc.pid\"
+-- sysctl described in sysctl(3) on FreeBSD).  The 'sysctlNameToOidArgs' makes
+-- it easy to query such nodes as well.
 --
 -- Nodes may be queried either by their OID as a list of integers, by their
--- binary OID for maximum speed, or by their names on platforms that support it. 
+-- binary OID for maximum speed, or by their names on platforms that support it.
 -------------------------------------------------------------------------------
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
 
-#if !defined(__linux__) && !defined(__OpenBSD__)
+#if defined(__HADDOCK__) || (!defined(__linux__) && !defined(__OpenBSD__))
 #define HAVE_SYSCTLNAMETOMIB
 #endif
 
   OID,
 
   -- * OID creation and extraction
+#ifdef HAVE_SYSCTLNAMETOMIB
   sysctlNameToOid,	-- :: String -> IO OID
   sysctlNameToOidArgs,	-- :: String -> [#{type int}] -> IO OID
+#endif
   sysctlPrepareOid,	-- :: [#{type int}] -> IO OID
   sysctlExtractOid,	-- :: OID -> IO [#{type int}]
 
 -- on (at least) Linux and OpenBSD.
 foreign import ccall unsafe "sysctlnametomib"
   c_sysctlnametomib :: CString -> Ptr CInt -> Ptr CSize -> IO CInt
-#endif
 
 -- | Get the 'OID' corresponding to a sysctl name.
 sysctlNameToOid :: String -> IO OID
-#ifdef HAVE_SYSCTLNAMETOMIB
 sysctlNameToOid name = sysctlNameToOidArgs name []
-#else
-sysctlNameToOid name = error "not available on this platform"
-#endif
 
 -- | Like 'sysctlNameToOid', but allows to provide a list of
 -- additional integers to append to the OID, for specific sysctl
 -- nodes that support parameters this way.
 sysctlNameToOidArgs :: String -> [#{type int}] -> IO OID
-#ifdef HAVE_SYSCTLNAMETOMIB
 sysctlNameToOidArgs name args =
   withCString name $ \cname -> do
     allocaArray (fromIntegral maxlen) $ \oid -> do
         return (OID fp (fromIntegral len))
   where maxlen = #{const CTL_MAXNAME}
         alen   = length args
-#else
-sysctlNameToOidArgs name args = error "not available on this platform"
-#endif
 
-#ifdef HAVE_SYSCTLNAMETOMIB
 instance SysctlKey String where
   withKey name f = sysctlNameToOid name >>= flip withKey f
 #endif

File bsd-sysctl.cabal

View file
 Name:		bsd-sysctl
-Version:	1.0.2
+Version:	1.0.3
 License-File:	LICENSE
 License:	BSD3
 Author:		Maxime Henrion