This module contains part of a Fortran API to functions detailed in ISO/IEC 9945-1:1990 Portable Operating System Interface (POSIX) - Part 1: System Application Program Interface (API) [C Language].
The functions in this module are from Section 5.1.2: Directory Operations
Error handling is described in F90_UNIX_ERRNO
.
Note that for procedures with an optional ERRNO
argument, if an error
occurs and ERRNO
is not present, the program will be terminated.
All the procedures in this module are specific and not generic.
In the description of each procedure, an argument whose KIND
is denoted
by ‘*’ can accept any kind of that type.
Other KIND
indications use the named parameters from the F90_KIND
or F90_UNIX_ERRNO
modules; these named parameters are not, however,
exported from F90_UNIX_DIRENT
.
SUBROUTINE CLOSEDIR(DIRUNIT,ERRNO) INTEGER(*),INTENT(IN) :: DIRUNIT INTEGER(error_kind),OPTIONAL,INTENT(OUT) :: ERRNOClose a directory stream that was opened by
OPENDIR
.
If DIRUNIT
does not refer to an open directory stream,
error EBADF
(see F90_UNIX_ERRNO
) is raised.
SUBROUTINE OPENDIR(DIRNAME,DIRUNIT,ERRNO) CHARACTER(*),INTENT(IN) :: DIRNAME INTEGER(*),INTENT(OUT) :: DIRUNIT INTEGER(error_kind),OPTIONAL,INTENT(OUT) :: ERRNOOpens a directory stream, returning a handle to it in
DIRUNIT
.
Possible errors include EACCES
, ENAMETOOLONG
, ENOENT
,
ENOTDIR
, EMFILE
and ENFILE
(see F90_UNIX_ERRNO
).
SUBROUTINE READDIR(DIRUNIT,NAME,LENNAME,ERRNO) INTEGER(*),INTENT(IN) :: DIRUNIT CHARACTER(*),INTENT(OUT) :: NAME INTEGER(int32 or int64),INTENT(OUT) :: LENNAME INTEGER(error_kind),OPTIONAL,INTENT(OUT) :: ERRNO
Reads the first/next directory entry.
The name of the file is placed into NAME
, blank-padded or truncated as
appropriate if the length of the file name differs from LEN(NAME)
.
The length of the file name is placed in LENNAME
.
If there are no more directory entries, NAME
is unchanged and
LENNAME
is negative.
If DIRUNIT
is not a directory stream handle produced by OPENDIR
,
or has been closed by CLOSEDIR
, error EBADF
(see
F90_UNIX_ERRNO
) is raised.
SUBROUTINE REWINDDIR(DIRUNIT,ERRNO) INTEGER(*),INTENT(IN) :: DIRUNIT INTEGER(error_kind),OPTIONAL,INTENT(OUT) :: ERRNORewinds the directory stream so that the next call to
READDIR
on that
stream will return the name of the first file in the directory.