1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
{- Functions that operate on OsPath, but treat the contents of files as
- Strings.
-
- These functions all set the close-on-exec flag to True, unlike
- the Prelude versions.
-
- Copyright 2025 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
{-# OPTIONS_GHC -fno-warn-tabs #-}
{-# LANGUAGE CPP #-}
module Utility.FileIO.String
(
#ifdef WITH_OSPATH
readFileString,
writeFileString,
appendFileString,
#endif
) where
#ifdef WITH_OSPATH
import qualified Utility.FileIO.CloseOnExec as I
import Utility.OsPath (OsPath)
import Prelude (String, IO, (>>=))
import System.IO (IOMode(..), hGetContents, hPutStr)
readFileString :: OsPath -> IO String
readFileString f = I.openFile f ReadMode >>= hGetContents
writeFileString :: OsPath -> String -> IO ()
writeFileString f txt = I.withFile f WriteMode (\hdl -> hPutStr hdl txt)
appendFileString :: OsPath -> String -> IO ()
appendFileString f txt = I.withFile f AppendMode (\hdl -> hPutStr hdl txt)
#endif
|