system_closedir Subroutine

public subroutine system_closedir(dir, ierr)

NAME

    system_closedir(3f) - [M_system:QUERY_FILE] close a directory
                          stream by calling closedir(3c)
    (LICENSE:PD)

SYNOPSIS

    subroutine system_closedir(dir,ierr)

     type(c_ptr)         :: dir
     integer,intent(out) :: ierr

DESCRIPTION

    The SYSTEM_CLOSEDIR(3f) function closes the directory stream
    referred to by the argument DIR. Upon return, the value of DIR
    may no longer point to an accessible object.

OPTIONS

    dir     directory stream pointer opened by SYSTEM_OPENDIR(3f).
    ierr    Upon successful completion, SYSTEM_CLOSEDIR(3f) returns 0;
            otherwise, an error has occurred.

ERRORS

    system_closedir(3f) may fail if:

    EBADF    The dirp argument does not refer to an open directory stream.
    EINTR    The closedir() function was interrupted by a signal.

EXAMPLE

Sample program

program demo_system_closedir
use M_system, only : system_opendir,system_readdir
use M_system, only : system_closedir, system_rewinddir
use iso_c_binding, only : c_ptr
implicit none
type(c_ptr)                  :: dir
character(len=:),allocatable :: filename
integer                      :: ierr
!--- open directory stream to read from
call system_opendir('.',dir,ierr)
!--- read directory stream
do
   call system_readdir(dir,filename,ierr)
   if(filename.eq.' ')exit
   write(*,*)filename
enddo
call system_rewinddir(dir)
!--- close directory stream
call system_closedir(dir,ierr)
end program demo_system_closedir

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
type(c_ptr), value :: dir
integer, intent(out), optional :: ierr

Contents

Source Code


Source Code

subroutine system_closedir(dir,ierr)
use iso_c_binding
type(c_ptr),value            :: dir
integer,intent(out),optional :: ierr
   integer                   :: ierr_local

interface
   function c_closedir(c_dir) bind(c,name="closedir") result(c_err)
      import c_char, c_int, c_ptr
      type(c_ptr),value      :: c_dir
      integer(kind=c_int)    :: c_err
   end function c_closedir
end interface

    ierr_local = c_closedir(dir)
    if(present(ierr))then
       ierr=ierr_local
    else
       if(ierr_local /= 0) then
          print *, "*system_closedir* error", ierr_local
          stop 3
       endif
    endif

end subroutine system_closedir