1{-# LANGUAGE CPP #-} 2{-# LANGUAGE Safe #-} 3{- 4Copyright (c) 2005-2011 John Goerzen <jgoerzen@complete.org> 5 6All rights reserved. 7 8For license and copyright information, see the file LICENSE 9-} 10 11{- | 12 Module : System.IO.StatCompat 13 Copyright : Copyright (C) 2005-2011 John Goerzen 14 SPDX-License-Identifier: BSD-3-Clause 15 16 Stability : provisional 17 Portability: portable 18 19Provide a stat-like structure for use in MissingH. Especially 20useful with HVFS and on Windows. See also "System.IO.WindowsCompat". 21 22-} 23 24module System.IO.StatCompat 25where 26import System.Posix.Consts 27import System.Posix.Types 28#if !(defined(mingw32_HOST_OS) || defined(mingw32_TARGET_OS) || defined(__MINGW32__)) 29import System.Posix.Files (intersectFileModes) 30#endif 31import Data.Bits ((.&.)) 32 33#if (defined(mingw32_HOST_OS) || defined(mingw32_TARGET_OS) || defined(__MINGW32__)) 34type LinkCount = Int 35type UserID = Int 36type GroupID = Int 37#endif 38 39data FileStatusCompat = 40 FileStatusCompat {deviceID :: DeviceID, 41 fileID :: FileID, 42 fileMode :: FileMode, 43 linkCount :: LinkCount, 44 fileOwner :: UserID, 45 fileGroup :: GroupID, 46 specialDeviceID :: DeviceID, 47 fileSize :: FileOffset, 48 accessTime :: EpochTime, 49 modificationTime :: EpochTime, 50 statusChangeTime :: EpochTime 51 } 52 53sc_helper :: FileMode -> FileStatusCompat -> Bool 54sc_helper comp stat = 55 (fileMode stat `intersectFileModes` fileTypeModes) == comp 56 57isBlockDevice,isCharacterDevice,isNamedPipe,isRegularFile,isDirectory,isSymbolicLink,isSocket :: FileStatusCompat -> Bool 58isBlockDevice = sc_helper blockSpecialMode 59isCharacterDevice = sc_helper characterSpecialMode 60isNamedPipe = sc_helper namedPipeMode 61isRegularFile = sc_helper regularFileMode 62isDirectory = sc_helper directoryMode 63isSymbolicLink = sc_helper symbolicLinkMode 64isSocket = sc_helper socketMode 65 66#if (defined(mingw32_HOST_OS) || defined(mingw32_TARGET_OS) || defined(__MINGW32__)) 67intersectFileModes :: FileMode -> FileMode -> FileMode 68intersectFileModes m1 m2 = m1 .&. m2 69#endif 70