-- | Calls @getloadavg (3)@ to get system load average. 
--   Provides error checking, and the result may be Nothing in case of error.
--   If there is not enough data the samples will be copied from more recent samples.
getLoadAvgSafe :: IO (Maybe LoadAvg)
getLoadAvgSafe = allocaArray 3 $ \arr ->
    do
      res <- getloadavg_C arr 3
      case res of
        -- Kind of hacky, I know
        3 -> do
          [a,b,c] <- peekArray 3 arr
          return . Just $ LoadAvg a b c
        2 -> do
          [a,b] <- peekArray 2 arr
          return . Just $ LoadAvg a b b
        1 -> do
          [a] <- peekArray 1 arr
          return . Just $ LoadAvg a a a
        -- Instead of matching with _ perhaps whe should check that we got '-1' here
        _ -> return Nothing

-- | Tries to read @\/proc\/loadavg@ and parse it's output with 'parseLoadAvg'. Either may fail with IO exception. 
getLoadAvgSafe :: IO (Maybe LoadAvg)
getLoadAvgSafe = allocaArray 3 $ \arr ->
    do
      res <- getloadavg_C arr 3
      case res of
        -- Kind of hacky, I know
        3 -> do
          [a,b,c] <- peekArray 3 arr
          return . Just $ LoadAvg a b c
        2 -> do
          [a,b] <- peekArray 2 arr
          return . Just $ LoadAvg a b b
        1 -> do
          [a] <- peekArray 1 arr
          return . Just $ LoadAvg a a a
        -- Instead of matching with _ perhaps whe should check that we got '-1' here
        _ -> return Nothing

-- | Tries to read @\/proc\/loadavg@ and parse it's output with 'parseLoadAvg'. Either may fail with IO exception. 
getLoadAvgSafe = allocaArray 3 $ \arr ->
    do
      res <- getloadavg_C arr 3
      case res of
        -- Kind of hacky, I know
        3 -> do
          [a,b,c] <- peekArray 3 arr
          return . Just $ LoadAvg a b c
        2 -> do
          [a,b] <- peekArray 2 arr
          return . Just $ LoadAvg a b b
        1 -> do
          [a] <- peekArray 1 arr
          return . Just $ LoadAvg a a a
        -- Instead of matching with _ perhaps whe should check that we got '-1' here
        _ -> return Nothing

-- | Tries to read @\/proc\/loadavg@ and parse it's output with 'parseLoadAvg'. Either may fail with IO exception. 