bindings/examples/fortran/files.f90¶
Complete Fortran example. Build with python bindings/fortran/build.py; run the resulting ELF on GaspardOS x64.
Source files · Download files.f90
! Read-only directory listing. No file is created or removed.
program files
use gaspardos_gui
implicit none
character(kind=c_char, len=11), target :: path = '/AHCIDISK0' // c_null_char
type(GO64_FSInfo), target :: info
integer(c_int64_t) :: fd, r, pause
integer :: entries, idle
fd = gof_fs_open(c_loc(path(1:1)), GO64_RDONLY)
if (fd < 0) stop 1
entries = 0
idle = 0
do while (entries < 100 .and. idle < 1000)
r = GO64_fs_readdir(fd, c_loc(info))
if (r == -11) then
idle = idle + 1
pause = GO64_yield()
cycle
end if
if (r <= 0) exit
entries = entries + 1
! name is UTF-16, not a Fortran CHARACTER string.
print *, 'id=', info%id, 'bytes=', info%bytes, 'directory=', info%is_directory
end do
do idle = 1, 1000
r = GO64_fs_close(fd)
if (r /= -11) exit
pause = GO64_yield()
end do
if (r < 0) stop 2
end program files