Fortran 95 Posix bindings
1. Overview of Posix90
1.1 About Posix90
Why Posix90? After all, you who read this document know most likely
enough about mixed-language programming sou you could write your own
stubs. But such things tend to be quick hacks, and I wanted a clean
solution: Here it is!
1.2 Portability
At present, Posix90
is limited to gfortran and GNU/Linux. This
might change if volunteers are found which port.
2. Linking against the Posix90
library
It is assumed here that you build the library from source. This is
necessary, as the .mod files(1) which gfortran emits are still in a state of flux. It is
too much work to provide them for all formats, compiling yourself is
by far the best solution.
Place all .mod files in one directory, say /usr/local/include/f90 and
place libposix90.a in another- say /usr/local/lib. You then need three
compiler switches:
-
-I /usr/local/include/f90 , to tell the compiler where to search for
.mod files
-
-lposix90, to tell the compiler to bind against libposix90.a
-
-L/usr/local/lib , to tell the compiler where to find libposix90.a
Note that there is a space after -I, but no space after -L.
3. Using the library
3.1 Calling and naming conventions
Wherever possible, the names of the original posix routines are
used. char * arguments are mapped to character(len=*)(2). If
the string is intent(out), an optional len argument is given to allow
for trailing blanks. Int simply maps to integer. Small typedef'ed
types like pid_t map to integer(pid_kind). More complex types like
FILE map to type(FILE). Note that you should never pass derived types
directly to C, as they are build alike their C pendants, but lack
padding, makeing them assignment incompatible! Another issue here is
the -fpackderived compiler switch.
All routines which possibly fail have an optional errno argument. If
present, an error condition ( 0 == no error) is returned. If not
present, an error message is printed if appropriate and execution
stopped. All routines reset errno on entry. This behaviour is
different from C, but makes it much easier to attribute an error to
the offending routine.
4. Posix90
modules available
4.1 Module f90_unix_dir
4.1.1 Parameters and Types
| integer, parameter :: mode_kind
|
Integer kind used for file permissions.
4.1.2 Subroutines and Functions
| subroutine chdir(path, errno)
character(len=*), intent(in) :: path
integer, intent(out), optional :: errno
|
See man 2 chdir
| subroutine getcwd(path, lenpath, errno)
character(len=*), intent(out) :: path
integer, intent(out), optional :: lenpath, errno
|
See man 2 getcwd
| subroutine link(existing, new, errno)
character(len=*), intent(in) :: existing, new
integer, intent(out), optional :: errno
|
See man 2 link
| subroutine mkdir(path, mode, errno)
character(len=*), intent(in) :: path
integer(mode_kind), intent(in) :: mode
integer, intent(out), optional :: errno
|
See man 2 mkdir
| subroutine mkfifo(path, mode, errno)
character(len=*), intent(in) :: path
integer(mode_kind), intent(in) :: mode
integer, intent(out), optional :: errno
|
See man 2 mkfifo
| subroutine rmdir(path, errno)
character(len=*), intent(in) :: path
integer, intent(out), optional :: errno
|
See man 2 rmdir
| subroutine unlink(path, errno)
character(len=*), intent(in) :: path
integer, intent(out), optional :: errno
|
See man 2 unlink
4.2 Module f90_unix_dirent
4.2.1 Parameters and Types
| integer, parameter :: dir_kind
|
| type DIR
integer(dir_kind):: dir
end type DIR
|
Complex type handled by the routines in this section. You should not
need to access its components directly.
4.2.2 Subroutines and Functions
| subroutine closedir(dirp, errno)
type(dir), intent(inout) :: dirp
integer, intent(out), optional :: errno
|
See man 3 closedir.
| subroutine opendir(dirname, dirp, errno)
character(len=*), intent(in) :: dirname
type(dir), intent(inout) :: dirp
integer, intent(out), optional :: errno
|
See man 3 opendir.
| subroutine readdir(dirp, name, lenname, errno)
type(dir), intent(inout) :: dirp
character(len=*), intent(out) :: name
integer, intent(out) :: lenname
integer, intent(out), optional :: errno
|
See man 3 readdir. The lenname argument is needed in case of trailing
blanks in name
.
| subroutine rewinddir(dirp, errno)
type(dir), intent(inout) :: dirp
integer, intent(out), optional :: errno
|
See man 3 rewinddir.
4.3 Module f90_unix_env
4.3.1 Parameters and Types
| integer, parameter :: CLOCK_KIND
integer, parameter :: TIME_KIND
integer, parameter :: LONG_KIND
integer, parameter :: GID_KIND
integer, parameter :: UID_KIND
integer, parameter :: PID_KIND
integer, parameter :: SIZET_KIND
|
Integer kind parameters for various data types.
| integer, parameter :: NULL
|
| integer, parameter :: L_CTERMID
|
Max. length of the result of ctermid()
.
| integer, parameter :: SC_ARG_MAX
integer, parameter :: SC_CHILD_MAX
integer, parameter :: SC_HOST_NAME_MAX
integer, parameter :: SC_LOGIN_NAME_MAX
integer, parameter :: SC_CLK_TCK
integer, parameter :: SC_OPEN_MAX
integer, parameter :: SC_PAGESIZE
integer, parameter :: SC_RE_DUP_MAX
integer, parameter :: SC_STREAM_MAX
integer, parameter :: SC_SYMLOOP_MAX
integer, parameter :: SC_TTY_NAME_MAX
integer, parameter :: SC_TZNAME_MAX
integer, parameter :: SC_VERSION
|
Possible values for the name argument to sysconf()
.
| type tms
sequence
integer(clock_kind):: utime, stime,cutime,cstime
end type tms
|
Structure used in times()
. See man 2 times.
| type utsname
sequence
character(len=80):: sysname, nodename, release, version, machine
end type utsname
|
Structure used in uname(). See man 2 uname.
4.3.2 Subroutines and Functions
| integer(kind=clock_kind) function clk_tck()
|
Returns the clock ticks per second.
| character(len=L_CTERMID) function ctermid(len)
integer, intent(out), optional :: len
|
| subroutine getarg2(k, arg, lenarg, errno)
integer, intent(in) :: K
character(len=*), intent(out), optional :: arg
integer, intent(out), optional :: lenarg, errno
|
This routine is called getarg2
to avoid a name clash with the build-in
getarg
. Note that lenarg
is at present always
len_trim(arg)
.
| integer(GID_KIND) function getegid()
|
| subroutine getenv2(name, value, lenvalue, errno)
character(len=*), intent(in) :: name
character(len=*), intent(out), optional :: value
integer, intent(out), optional :: lenvalue, errno
|
This routine is called getenv2
to avoid a name clash with the build-in
getenv
. Note that lenvalue
is at present always
len_trim(value)
.
| integer(uid_kind) function geteuid()
integer(uid_kind),external::c_geteuid
geteuid = c_geteuid()
|
| integer(gid_kind) function getgid()
|
| subroutine getgroups(grouplist, ngroups, errno)
integer(gid_kind), optional :: grouplist(:)
integer, optional, intent(out) :: ngroups, errno
|
| subroutine gethostname(name, lenname, errno)
character(len=*), optional, intent(out) :: name
integer, optional, intent(out) :: lenname, errno
|
| subroutine getlogin(name, lenname, errno)
character(len=*), optional, intent(out) :: name
integer, optional, intent(out) :: lenname, errno
|
| integer(PID_KIND) function getpgrp()
|
| integer(PID_KIND) function getppid()
|
| integer(UID_KIND) function getuid()
|
| subroutine setgid(gid, errno)
integer(GID_KIND), intent(in) :: gid
integer, intent(out), optional :: errno
|
| subroutine setpgid(gid, pgid, errno)
integer(GID_KIND), intent(in) :: gid, pgid
integer, intent(out), optional :: errno
|
| subroutine setsid(errno)
integer, intent(out), optional :: errno
|
| subroutine setuid(gid, errno)
integer(UID_KIND), intent(in) :: gid
integer, intent(out), optional :: errno
|
| subroutine sysconf(name, val,errno)
integer, intent(in) :: name
integer(long_kind), intent(out) :: val
integer, intent(out), optional :: errno
|
| integer(TIME_KIND) function time(errno)
integer, optional, intent(out) :: errno
integer(TIME_KIND), external :: c_time
|
| integer(CLOCK_KIND) function times(buffer, errno)
type(tms) :: buffer
integer, optional, intent(out) :: errno
|
| subroutine uname(name, errno)
type(utsname), intent(out) :: name
integer, optional, intent(out) :: errno
|
4.4 Module f90_unix_errno
4.4.1 Parameters and Types
| integer, parameter :: E2BIG
integer, parameter :: EACCES
integer, parameter :: EAGAIN
integer, parameter :: EBADF
integer, parameter :: EBUSY
integer, parameter :: ECHILD
integer, parameter :: EDEADLK
integer, parameter :: EDOM
integer, parameter :: EEXIST
integer, parameter :: EFAULT
integer, parameter :: EFBIG
integer, parameter :: EINTR
integer, parameter :: EINVAL
integer, parameter :: EIO
integer, parameter :: EISDIR
integer, parameter :: EMFILE
integer, parameter :: EMLINK
integer, parameter :: ENAMETOOLONG
integer, parameter :: ENFILE
integer, parameter :: ENODEV
integer, parameter :: ENOENT
integer, parameter :: ENOEXEC
integer, parameter :: ENOLCK
integer, parameter :: ENOMEM
integer, parameter :: ENOSPC
integer, parameter :: ENOSYS
integer, parameter :: ENOTDIR
integer, parameter :: ENOTEMPTY
integer, parameter :: ENOTTY
integer, parameter :: ENXIO
integer, parameter :: EPERM
integer, parameter :: EPIPE
integer, parameter :: ERANGE
integer, parameter :: EROFS
integer, parameter :: ESPIPE
integer, parameter :: ESRCH
integer, parameter :: EXDEV
|
Error codes known to the module. Their names match the C equivalents.
4.4.2 Subroutines and Functions
| character(len=80) function strerror(err, errno)
integer, intent(in) :: err
integer, intent(out), optional :: errno
|
See man 3 strerror.
| subroutine perror(str, errc)
character(len=*), intent(in) :: str
integer, intent(in), optional :: errc
|
See man 3 perror.
| integer function get_errno()
|
Get the value of errno.
| subroutine set_errno(errc)
integer, intent(in), optional :: errc
|
Set the value of errno to errc
or 0, if errc
is missing.
4.5 Module f90_unix_file
4.6 Module f90_unix_io
4.7 Module f90_unix_proc
4.8 Module f90_unix_regexp
4.8.1 Parameters and Types
| integer, parameter :: REG_EXTENDED
integer, parameter :: REG_ICASE
integer, parameter :: REG_NOSUB
integer, parameter :: REG_NEWLINE
integer, parameter :: REG_NOTBOL
integer, parameter :: REG_NOTEOL
|
Flags for regcomp and regexec. See man 3 regcomp
| integer, parameter :: REGEX_KIND
integer, parameter :: REGMATCH_KIND
integer, parameter :: REGOFF_KIND
|
Kinds used in the module. You should not need to use these direcly.
| type regex_t
integer(regex_kind) :: rp
end type regex_t
|
Type used to hold compiled regular expressions. You should not need to
access its components directly.
| type regmatch_t
integer(regoff_kind) :: rm_so, rm_eo
end type regmatch_t
|
Type used to hold indices of matches. Note that these indices are
adjusted to fortran numbering.
4.8.2 Subroutines and Functions
| subroutine regcomp(preg, regex, cflags, errc)
type(regex_t) :: preg
character(len=*), intent(in) :: regex
integer, intent(in) :: cflags
integer, intent(out), optional :: errc
|
See man 3 regcomp. Missing errc argument aborts on error.
| subroutine regexec(preg, string, pmatch, eflags, errc)
type(regex_t), intent(in) :: preg
character(len=*), intent(in) :: string
type(regmatch_t) :: pmatch(:)
integer, intent(in) :: eflags
integer, intent(out), optional :: errc
|
See man 3 regexec. Note that the offsets in pmatch are adjusted to fortran
conventions, aka the first char has index 1, not 0. Missing errc
argument aborts on error. No match is considered an error.
| subroutine regerror(e, preg, msg)
integer, intent(in) :: e
type(regex_t), intent(in) :: preg
character(len=*), intent(out) :: msg
|
See man 3 regerror.
| subroutine regfree(preg)
type(regex_t), intent(in) :: preg
|
See man 3 regfree.
4.9 Module f90_unix_signal
Concept Index
Footnotes
.mod files hold the information
which data and which routines constitute a module. They are created as
a module is compiled and are needed when this module is used
elsewhere
Be
carefull with trailing spaces, use trim() or string(1:len) a lot
Table of Contents
Short Table of Contents
About This Document
This document was generated by Klaus Ramstöck on May, 31 2006 using texi2html 1.76.
The buttons in the navigation panels have the following meaning:
Button |
Name |
Go to |
From 1.2.3 go to |
[ < ] |
Back |
previous section in reading order |
1.2.2 |
[ > ] |
Forward |
next section in reading order |
1.2.4 |
[ << ] |
FastBack |
beginning of this chapter or previous chapter |
1 |
[ Up ] |
Up |
up section |
1.2 |
[ >> ] |
FastForward |
next chapter |
2 |
[Top] |
Top |
cover (top) of document |
|
[Contents] |
Contents |
table of contents |
|
[Index] |
Index |
index |
|
[ ? ] |
About |
about (help) |
|
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
- 1. Section One
- 1.1 Subsection One-One
- 1.2 Subsection One-Two
- 1.2.1 Subsubsection One-Two-One
- 1.2.2 Subsubsection One-Two-Two
- 1.2.3 Subsubsection One-Two-Three
<== Current Position
- 1.2.4 Subsubsection One-Two-Four
- 1.3 Subsection One-Three
- 1.4 Subsection One-Four
This document was generated by Klaus Ramstöck on May, 31 2006 using texi2html 1.76.