[Top] [Contents] [Index] [ ? ]

Fortran 95 Posix bindings


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Overview of Posix90


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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!


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Portability

At present, Posix90 is limited to gfortran and GNU/Linux. This might change if volunteers are found which port.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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:

Note that there is a space after -I, but no space after -L.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Using the library


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Posix90 modules available


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Module f90_unix_dir


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1.1 Parameters and Types

 
integer, parameter :: mode_kind

Integer kind used for file permissions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Module f90_unix_dirent


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 Module f90_unix_env


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 Module f90_unix_errno


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 Module f90_unix_file


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6 Module f90_unix_io


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.7 Module f90_unix_proc


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.8 Module f90_unix_regexp


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9 Module f90_unix_signal


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Concept Index

Jump to:   C   D   E   F   G   L   M   N   O   P   R   S   T   U  
Index Entry Section

C
chdir4.1.2 Subroutines and Functions
clk_tck4.3.2 Subroutines and Functions
CLOCK_KIND4.3.1 Parameters and Types
closedir4.2.2 Subroutines and Functions
ctermid4.3.2 Subroutines and Functions

D
DIR4.2.1 Parameters and Types

E
E2BIG4.4.1 Parameters and Types
EACCES4.4.1 Parameters and Types
EAGAIN4.4.1 Parameters and Types
EBADF4.4.1 Parameters and Types
EBUSY4.4.1 Parameters and Types
ECHILD4.4.1 Parameters and Types
EDEADLK4.4.1 Parameters and Types
EDOM4.4.1 Parameters and Types
EEXIST4.4.1 Parameters and Types
EFAULT4.4.1 Parameters and Types
EFBIG4.4.1 Parameters and Types
EINTR4.4.1 Parameters and Types
EINVAL4.4.1 Parameters and Types
EIO4.4.1 Parameters and Types
EISDIR4.4.1 Parameters and Types
EMFILE4.4.1 Parameters and Types
EMLINK4.4.1 Parameters and Types
ENAMETOOLONG4.4.1 Parameters and Types
ENFILE4.4.1 Parameters and Types
ENODEV4.4.1 Parameters and Types
ENOENT4.4.1 Parameters and Types
ENOEXEC4.4.1 Parameters and Types
ENOLCK4.4.1 Parameters and Types
ENOMEM4.4.1 Parameters and Types
ENOSPC4.4.1 Parameters and Types
ENOSYS4.4.1 Parameters and Types
ENOTDIR4.4.1 Parameters and Types
ENOTEMPTY4.4.1 Parameters and Types
ENOTTY4.4.1 Parameters and Types
ENXIO4.4.1 Parameters and Types
EPERM4.4.1 Parameters and Types
EPIPE4.4.1 Parameters and Types
ERANGE4.4.1 Parameters and Types
EROFS4.4.1 Parameters and Types
ESPIPE4.4.1 Parameters and Types
ESRCH4.4.1 Parameters and Types
EXDEV4.4.1 Parameters and Types

F
f90_unix_dir4.1 Module f90_unix_dir
f90_unix_dirent4.2 Module f90_unix_dirent
f90_unix_env4.3 Module f90_unix_env
f90_unix_errno4.4 Module f90_unix_errno
f90_unix_file4.5 Module f90_unix_file
f90_unix_io4.6 Module f90_unix_io
f90_unix_proc4.7 Module f90_unix_proc
f90_unix_regexp4.8 Module f90_unix_regexp
f90_unix_signal4.9 Module f90_unix_signal

G
get_errno4.4.2 Subroutines and Functions
getarg24.3.2 Subroutines and Functions
getcwd4.1.2 Subroutines and Functions
getegid4.3.2 Subroutines and Functions
getenv24.3.2 Subroutines and Functions
geteuid4.3.2 Subroutines and Functions
getgid4.3.2 Subroutines and Functions
getgroups4.3.2 Subroutines and Functions
gethostname4.3.2 Subroutines and Functions
getlogin4.3.2 Subroutines and Functions
getpgrp4.3.2 Subroutines and Functions
getppid4.3.2 Subroutines and Functions
getuid4.3.2 Subroutines and Functions
GID_KIND4.3.1 Parameters and Types

L
L_CTERMID4.3.1 Parameters and Types
link4.1.2 Subroutines and Functions
LONG_KIND4.3.1 Parameters and Types

M
mkfifo4.1.2 Subroutines and Functions
mode_kind4.1.1 Parameters and Types

N
NULL4.3.1 Parameters and Types

O
opendir4.2.2 Subroutines and Functions

P
perror4.4.2 Subroutines and Functions
PID_KIND4.3.1 Parameters and Types

R
readdir4.2.2 Subroutines and Functions
regcomp4.8.2 Subroutines and Functions
regerror4.8.2 Subroutines and Functions
regexec4.8.2 Subroutines and Functions
regfree4.8.2 Subroutines and Functions
rewinddir4.2.2 Subroutines and Functions
rmdir4.1.2 Subroutines and Functions

S
SC_ARG_MAX4.3.1 Parameters and Types
SC_CHILD_MAX4.3.1 Parameters and Types
SC_CLK_TCK4.3.1 Parameters and Types
SC_HOST_NAME_MAX4.3.1 Parameters and Types
SC_LOGIN_NAME_MAX4.3.1 Parameters and Types
SC_OPEN_MAX4.3.1 Parameters and Types
SC_PAGESIZE4.3.1 Parameters and Types
SC_RE_DUP_MAX4.3.1 Parameters and Types
SC_STREAM_MAX4.3.1 Parameters and Types
SC_SYMLOOP_MAX4.3.1 Parameters and Types
SC_TTY_NAME_MAX4.3.1 Parameters and Types
SC_TZNAME_MAX4.3.1 Parameters and Types
SC_VERSION4.3.1 Parameters and Types
set_errno4.4.2 Subroutines and Functions
setgid4.3.2 Subroutines and Functions
setpgid4.3.2 Subroutines and Functions
setsid4.3.2 Subroutines and Functions
setuid4.3.2 Subroutines and Functions
SIZET_KIND4.3.1 Parameters and Types
strerror4.4.2 Subroutines and Functions
subroutine mkdir4.1.2 Subroutines and Functions
sysconf4.3.2 Subroutines and Functions

T
time4.3.2 Subroutines and Functions
TIME_KIND4.3.1 Parameters and Types
times4.3.2 Subroutines and Functions

U
UID_KIND4.3.1 Parameters and Types
uname4.3.2 Subroutines and Functions
unlink4.1.2 Subroutines and Functions

Jump to:   C   D   E   F   G   L   M   N   O   P   R   S   T   U  

[Top] [Contents] [Index] [ ? ]

Footnotes

(1)

.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

(2)

Be carefull with trailing spaces, use trim() or string(1:len) a lot


[Top] [Contents] [Index] [ ? ]

Table of Contents


[Top] [Contents] [Index] [ ? ]

Short Table of Contents


[Top] [Contents] [Index] [ ? ]

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:


This document was generated by Klaus Ramstöck on May, 31 2006 using texi2html 1.76.