Copyright | (c) The University of Glasgow 2022 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | libraries@haskell.org |
Stability | provisional |
Portability | non-portable (requires POSIX) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
POSIX directory support (internal module, no PVP guarantees)
Synopsis
- newtype DirStream = DirStream (Ptr CDir)
- data CDir
- data CDirent
- newtype DirStreamOffset = DirStreamOffset COff
- newtype DirStreamWithPath a = DirStreamWithPath (a, Ptr CDir)
- fromDirStreamWithPath :: DirStreamWithPath a -> DirStream
- toDirStreamWithPath :: a -> DirStream -> DirStreamWithPath a
- newtype DirEnt = DirEnt (Ptr CDirent)
- dirEntName :: DirEnt -> IO CString
- dirEntType :: DirEnt -> IO DirType
- newtype DirType where
- DirType CChar
- pattern UnknownType :: DirType
- pattern NamedPipeType :: DirType
- pattern CharacterDeviceType :: DirType
- pattern DirectoryType :: DirType
- pattern BlockDeviceType :: DirType
- pattern RegularFileType :: DirType
- pattern SymbolicLinkType :: DirType
- pattern SocketType :: DirType
- pattern WhiteoutType :: DirType
- isUnknownType :: DirType -> Bool
- isNamedPipeType :: DirType -> Bool
- isCharacterDeviceType :: DirType -> Bool
- isDirectoryType :: DirType -> Bool
- isBlockDeviceType :: DirType -> Bool
- isRegularFileType :: DirType -> Bool
- isSymbolicLinkType :: DirType -> Bool
- isSocketType :: DirType -> Bool
- isWhiteoutType :: DirType -> Bool
- getRealDirType :: IO FileStatus -> DirType -> IO DirType
- readDirStreamWith :: (DirEnt -> IO a) -> DirStream -> IO (Maybe a)
- readDirStreamWithPtr :: Ptr DirEnt -> (DirEnt -> IO a) -> DirStream -> IO (Maybe a)
Documentation
newtype DirStreamOffset Source #
DirStreamOffset COff |
fromDirStreamWithPath :: DirStreamWithPath a -> DirStream Source #
Convert a DirStreamWithPath
to a DirStream
.
Note that the underlying pointer is shared by both values, hence any
modification to the resulting DirStream
will also modify the original
DirStreamWithPath
.
Since: unix-2.8.6.0
toDirStreamWithPath :: a -> DirStream -> DirStreamWithPath a Source #
Construct a DirStreamWithPath
from a DirStream
.
Note that the underlying pointer is shared by both values, hence any
modification to the pointer of the resulting DirStreamWithPath
will also
modify the original DirStream
.
Since: unix-2.8.6.0
Since: unix-2.8.6.0
The value of the d_type
field of a dirent
struct.
Note that the possible values of that type depend on the filesystem that is
queried. From readdir(3)
:
Currently, only some filesystems (among them: Btrfs, ext2, ext3, and ext4) have full support for returning the file type in d_type. All applications must properly handle a return of DT_UNKNOWN.
For example, JFS is a filesystem that does not support d_type
;
See https://github.com/haskell/ghcup-hs/issues/766
Furthermore, dirent
or the constants represented by the associated pattern
synonyms of this type may not be provided by the underlying platform. In that
case none of those patterns will match and the application must handle that
case accordingly.
Since: unix-2.8.6.0
pattern UnknownType :: DirType | The |
pattern NamedPipeType :: DirType | The |
pattern CharacterDeviceType :: DirType | The |
pattern DirectoryType :: DirType | The |
pattern BlockDeviceType :: DirType | The |
pattern RegularFileType :: DirType | The |
pattern SymbolicLinkType :: DirType | The |
pattern SocketType :: DirType | The |
pattern WhiteoutType :: DirType | The |
isUnknownType :: DirType -> Bool Source #
Checks if this DirType
refers to an entry of unknown type.
Since: unix-2.8.6.0
isNamedPipeType :: DirType -> Bool Source #
Checks if this DirType
refers to a named pipe entry.
Since: unix-2.8.6.0
isCharacterDeviceType :: DirType -> Bool Source #
Checks if this DirType
refers to a character device entry.
Since: unix-2.8.6.0
isDirectoryType :: DirType -> Bool Source #
Checks if this DirType
refers to a directory entry.
Since: unix-2.8.6.0
isBlockDeviceType :: DirType -> Bool Source #
Checks if this DirType
refers to a block device entry.
Since: unix-2.8.6.0
isRegularFileType :: DirType -> Bool Source #
Checks if this DirType
refers to a regular file entry.
Since: unix-2.8.6.0
isSymbolicLinkType :: DirType -> Bool Source #
Checks if this DirType
refers to a symbolic link entry.
Since: unix-2.8.6.0
isSocketType :: DirType -> Bool Source #
Checks if this DirType
refers to a socket entry.
Since: unix-2.8.6.0
isWhiteoutType :: DirType -> Bool Source #
Checks if this DirType
refers to a whiteout entry.
Since: unix-2.8.6.0
getRealDirType :: IO FileStatus -> DirType -> IO DirType Source #
Since: unix-2.8.6.0
readDirStreamWith :: (DirEnt -> IO a) -> DirStream -> IO (Maybe a) Source #
readDirStreamWith f dp
calls readdir
to obtain the next directory entry
(struct dirent
) for the open directory stream dp
. If an entry is read,
it passes the pointer to that structure to the provided function f
for
processing. It returns the result of that function call wrapped in a Just
if an entry was read and Nothing
if the end of the directory stream was
reached.
NOTE: The lifetime of the pointer wrapped in the DirEnt
is limited to
invocation of the callback and it will be freed automatically after. Do not
pass it to the outside world!
Since: unix-2.8.6.0
readDirStreamWithPtr :: Ptr DirEnt -> (DirEnt -> IO a) -> DirStream -> IO (Maybe a) Source #
A version of readDirStreamWith
that takes a pre-allocated pointer in
addition to the other arguments. This pointer is used to store the pointer
to the next directory entry, if there is any. This function is intended for
use cases where you need to read a lot of directory entries and want to
reuse the pointer for each of them. Using for example readDirStream
or
readDirStreamWith
in this scenario would allocate a new pointer for each
call of these functions.
NOTE: You are responsible for releasing the pointer after you are done.
Since: unix-2.8.6.0