diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-11-21 13:27:23 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2022-11-21 13:27:23 -0500 |
commit | 3a56337be36496ae4c11eb9afff092ebc0283256 (patch) | |
tree | a8b461b6f7ac334a3d7a4e391265c22bdee8aaae /compiler/GHC/Utils | |
parent | 451aeac3b07f171f148995717d0d9a1eefe08f0e (diff) | |
download | haskell-wip/drop-touch.tar.gz |
Drop dependence on `touch`wip/drop-touch
This drops GHC's dependence on the `touch` program, instead implementing
it within GHC. This eliminates an external dependency and means that we
have one fewer program to keep track of in the `configure` script
Diffstat (limited to 'compiler/GHC/Utils')
-rw-r--r-- | compiler/GHC/Utils/Touch.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/compiler/GHC/Utils/Touch.hs b/compiler/GHC/Utils/Touch.hs new file mode 100644 index 0000000000..b6181584f0 --- /dev/null +++ b/compiler/GHC/Utils/Touch.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE CPP #-} + +module GHC.Utils.Touch (touch) where + +import GHC.Prelude + +#if defined(mingw32_HOST_OS) +import System.Win32.File +import System.Win32.Time +#else +import System.Posix.Files +import System.Posix.IO +#endif + +-- | Set the mtime of the given file to the current time. +touch :: FilePath -> IO () +touch file = do +#if defined(mingw32_HOST_OS) + hdl <- createFile file gENERIC_WRITE fILE_SHARE_NONE Nothing oPEN_ALWAYS fILE_ATTRIBUTE_NORMAL Nothing + t <- getSystemTimeAsFileTime + setFileTime hdl Nothing Nothing (Just t) + closeHandle hdl +#else + let oflags = defaultFileFlags { noctty = True } + fd <- openFd file WriteOnly (Just 0o666) oflags + touchFd fd + closeFd fd +#endif + |