2121module System.Posix.Directory.Common (
2222 DirStream (.. ),
2323 CDir ,
24+ CDirent ,
25+ DirStreamOffset (.. ),
26+
2427 DirStreamWithPath (.. ),
2528 fromDirStreamWithPath ,
2629 toDirStreamWithPath ,
27-
2830 DirEnt (.. ),
29- CDirent ,
3031 dirEntName ,
3132 dirEntType ,
3233 DirType ( DirType
@@ -40,15 +41,20 @@ module System.Posix.Directory.Common (
4041 , SocketType
4142 , WhiteoutType
4243 ),
43- isUnknownType , isBlockDeviceType , isCharacterDeviceType , isNamedPipeType ,
44- isRegularFileType , isDirectoryType , isSymbolicLinkType , isSocketType ,
44+ isUnknownType ,
45+ isNamedPipeType ,
46+ isCharacterDeviceType ,
47+ isDirectoryType ,
48+ isBlockDeviceType ,
49+ isRegularFileType ,
50+ isSymbolicLinkType ,
51+ isSocketType ,
4552 isWhiteoutType ,
4653 getRealDirType ,
4754 unsafeOpenDirStreamFd ,
4855 readDirStreamWith ,
4956 readDirStreamWithPtr ,
5057
51- DirStreamOffset (.. ),
5258 rewindDirStream ,
5359 closeDirStream ,
5460#ifdef HAVE_SEEKDIR
@@ -75,22 +81,28 @@ import System.Posix.Files.Common
7581
7682newtype DirStream = DirStream (Ptr CDir )
7783
84+ -- | @since 2.8.6.0
7885newtype DirStreamWithPath a = DirStreamWithPath (a , Ptr CDir )
7986
8087-- | Convert a 'DirStreamWithPath' to a 'DirStream'.
8188-- Note that the underlying pointer is shared by both values, hence any
8289-- modification to the resulting 'DirStream' will also modify the original
8390-- 'DirStreamWithPath'.
91+ --
92+ -- @since 2.8.6.0
8493fromDirStreamWithPath :: DirStreamWithPath a -> DirStream
8594fromDirStreamWithPath (DirStreamWithPath (_, ptr)) = DirStream ptr
8695
8796-- | Construct a 'DirStreamWithPath' from a 'DirStream'.
8897-- Note that the underlying pointer is shared by both values, hence any
8998-- modification to the pointer of the resulting 'DirStreamWithPath' will also
9099-- modify the original 'DirStream'.
100+ --
101+ -- @since 2.8.6.0
91102toDirStreamWithPath :: a -> DirStream -> DirStreamWithPath a
92103toDirStreamWithPath path (DirStream ptr) = DirStreamWithPath (path, ptr)
93104
105+ -- | @since 2.8.6.0
94106newtype DirEnt = DirEnt (Ptr CDirent )
95107
96108-- We provide a hand-written instance here since GeneralizedNewtypeDeriving and
@@ -126,6 +138,8 @@ data {-# CTYPE "struct dirent" #-} CDirent
126138-- synonyms of this type may not be provided by the underlying platform. In that
127139-- case none of those patterns will match and the application must handle that
128140-- case accordingly.
141+ --
142+ -- @since 2.8.6.0
129143newtype DirType = DirType CChar
130144 deriving (Eq , Ord , Show )
131145
@@ -166,22 +180,40 @@ pattern WhiteoutType :: DirType
166180pattern WhiteoutType = DirType (CONST_DT_WHT )
167181
168182-- | Checks if this 'DirType' refers to an entry of unknown type.
183+ --
184+ -- @since 2.8.6.0
169185isUnknownType :: DirType -> Bool
170186-- | Checks if this 'DirType' refers to a block device entry.
187+ --
188+ -- @since 2.8.6.0
171189isBlockDeviceType :: DirType -> Bool
172190-- | Checks if this 'DirType' refers to a character device entry.
191+ --
192+ -- @since 2.8.6.0
173193isCharacterDeviceType :: DirType -> Bool
174194-- | Checks if this 'DirType' refers to a named pipe entry.
195+ --
196+ -- @since 2.8.6.0
175197isNamedPipeType :: DirType -> Bool
176198-- | Checks if this 'DirType' refers to a regular file entry.
199+ --
200+ -- @since 2.8.6.0
177201isRegularFileType :: DirType -> Bool
178202-- | Checks if this 'DirType' refers to a directory entry.
203+ --
204+ -- @since 2.8.6.0
179205isDirectoryType :: DirType -> Bool
180206-- | Checks if this 'DirType' refers to a symbolic link entry.
207+ --
208+ -- @since 2.8.6.0
181209isSymbolicLinkType :: DirType -> Bool
182210-- | Checks if this 'DirType' refers to a socket entry.
211+ --
212+ -- @since 2.8.6.0
183213isSocketType :: DirType -> Bool
184214-- | Checks if this 'DirType' refers to a whiteout entry.
215+ --
216+ -- @since 2.8.6.0
185217isWhiteoutType :: DirType -> Bool
186218
187219isUnknownType dtype = dtype == UnknownType
@@ -194,6 +226,7 @@ isSymbolicLinkType dtype = dtype == SymbolicLinkType
194226isSocketType dtype = dtype == SocketType
195227isWhiteoutType dtype = dtype == WhiteoutType
196228
229+ -- | @since 2.8.6.0
197230getRealDirType :: IO FileStatus -> DirType -> IO DirType
198231getRealDirType _ BlockDeviceType = return BlockDeviceType
199232getRealDirType _ CharacterDeviceType = return CharacterDeviceType
@@ -225,6 +258,8 @@ getRealDirType getFileStatus _ = do
225258--
226259-- The input file descriptor must not have been used with @threadWaitRead@ or
227260-- @threadWaitWrite@.
261+ --
262+ -- @since 2.8.6.0
228263unsafeOpenDirStreamFd :: Fd -> IO DirStream
229264unsafeOpenDirStreamFd (Fd fd) = mask_ $ do
230265 ptr <- c_fdopendir fd
@@ -257,6 +292,8 @@ foreign import capi unsafe "dirent.h fdopendir"
257292-- __NOTE:__ The lifetime of the pointer wrapped in the `DirEnt` is limited to
258293-- invocation of the callback and it will be freed automatically after. Do not
259294-- pass it to the outside world!
295+ --
296+ -- @since 2.8.6.0
260297readDirStreamWith :: (DirEnt -> IO a ) -> DirStream -> IO (Maybe a )
261298readDirStreamWith f dstream = alloca
262299 (\ ptr_dEnt -> readDirStreamWithPtr ptr_dEnt f dstream)
@@ -270,6 +307,8 @@ readDirStreamWith f dstream = alloca
270307-- call of these functions.
271308--
272309-- __NOTE__: You are responsible for releasing the pointer after you are done.
310+ --
311+ -- @since 2.8.6.0
273312readDirStreamWithPtr :: Ptr DirEnt -> (DirEnt -> IO a ) -> DirStream -> IO (Maybe a )
274313readDirStreamWithPtr ptr_dEnt f dstream@ (DirStream dirp) = do
275314 resetErrno
@@ -291,12 +330,14 @@ readDirStreamWithPtr ptr_dEnt f dstream@(DirStream dirp) = do
291330 then return Nothing
292331 else throwErrno " readDirStream"
293332
333+ -- | @since 2.8.6.0
294334dirEntName :: DirEnt -> IO CString
295335dirEntName (DirEnt dEntPtr) = d_name dEntPtr
296336
297337foreign import ccall unsafe " __hscore_d_name"
298338 d_name :: Ptr CDirent -> IO CString
299339
340+ -- | @since 2.8.6.0
300341dirEntType :: DirEnt -> IO DirType
301342dirEntType (DirEnt dEntPtr) = DirType <$> d_type dEntPtr
302343
0 commit comments