Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

PXFREADDIR error codes

Chris_Payne
Beginner
705 Views
Anyone know where these error codes are documented? I get either 2 or 128 based on an unknown difference. Which one is an error and which one (if either) means I reached the end of the directory?

Thanks
0 Kudos
1 Solution
John4
Valued Contributor I
705 Views

POSIX error codes are system-dependent ---although the first thirty-something ones tend to be the same from one system to another.

The errno.h header (which, in my system, is located in /usr/include/asm-generic) can help you determine the exact error... Or you could just call the strerror function and get the actual error string, e.g.:

[fortran]use iso_c_binding

implicit none

interface
   function mystrerror(errnum) bind(C, NAME = 'strerror')
        import
        type(C_PTR) :: mystrerror
        integer(C_INT), value :: errnum
    end function
end interface

integer :: i
type(C_PTR) :: ptr
character(KIND=C_CHAR), pointer :: cstr(:)
character(255) :: fstr

ptr = mystrerror(128_C_INT)
call C_F_POINTER(ptr, cstr, [255])

fstr = ''
 do i = 1, SIZE(cstr)
    if (cstr(i) == C_NULL_CHAR) exit
   fstr(i:i) = cstr(i)
enddo

print '("the string for error #", I0, " is: ", A)', 128, TRIM(fstr)
end [/fortran]

View solution in original post

0 Kudos
2 Replies
Ron_Green
Moderator
705 Views
the PXF calls are wrappers to Posix calls. So

man 3 readdir

will give you the info you need, along with /usr/include/dirent.h

ron
0 Kudos
John4
Valued Contributor I
706 Views

POSIX error codes are system-dependent ---although the first thirty-something ones tend to be the same from one system to another.

The errno.h header (which, in my system, is located in /usr/include/asm-generic) can help you determine the exact error... Or you could just call the strerror function and get the actual error string, e.g.:

[fortran]use iso_c_binding

implicit none

interface
   function mystrerror(errnum) bind(C, NAME = 'strerror')
        import
        type(C_PTR) :: mystrerror
        integer(C_INT), value :: errnum
    end function
end interface

integer :: i
type(C_PTR) :: ptr
character(KIND=C_CHAR), pointer :: cstr(:)
character(255) :: fstr

ptr = mystrerror(128_C_INT)
call C_F_POINTER(ptr, cstr, [255])

fstr = ''
 do i = 1, SIZE(cstr)
    if (cstr(i) == C_NULL_CHAR) exit
   fstr(i:i) = cstr(i)
enddo

print '("the string for error #", I0, " is: ", A)', 128, TRIM(fstr)
end [/fortran]

0 Kudos
Reply