system_readenv Function

public function system_readenv() result(string)

NAME

system_readenv(3f) - [M_system:ENVIRONMENT] step thru and read
                     environment table
(LICENSE:PD)

SYNOPSIS

   function system_readenv() result(string)

    character(len=:),allocatable  :: string

DESCRIPTION

A simple interface allows reading the environment variable table of the
process. Call system_initenv(3f) to initialize reading the environment
table, then call system_readenv(3f) can be called until a blank line
is returned. If more than one thread reads the environment or the
environment is changed while being read the results are undefined.

OPTIONS

string  the string returned from the environment of the form "NAME=VALUE"

EXAMPLE

Sample program:

program demo_system_readenv
use M_system, only : system_initenv, system_readenv
character(len=:),allocatable :: string
   call system_initenv()
   do
      string=system_readenv()
      if(string.eq.'')then
         exit
      else
         write(*,'(a)')string
      endif
   enddo
end program demo_system_readenv

Sample results:

USERDOMAIN_ROAMINGPROFILE=buzz
HOMEPATH=\Users\JSU
APPDATA=C:\Users\JSU\AppData\Roaming
MANPATH=/home/u/LIBRARY/libGPF/download/tmp/man:/home/u/doc/man:::
DISPLAYNUM=0
ProgramW6432=C:\Program Files
HOSTNAME=buzz
XKEYSYMDB=/usr/share/X11/XKeysymDB
PUBLISH_CMD=
OnlineServices=Online Services
     :
     :
     :

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

None

Return Value character(len=:), allocatable


Contents

Source Code


Source Code

function system_readenv() result(string)

! ident_26="@(#) M_system system_readenv(3f) read next entry from environment table"

character(len=:),allocatable  :: string
character(kind=c_char)        :: c_buff(longest_env_variable+1)

interface
   subroutine c_readenv(c_string) bind (C,NAME='my_readenv')
      import c_char, c_int, c_ptr, c_size_t
      character(kind=c_char),intent(out)  :: c_string(*)
   end subroutine c_readenv
end interface

  c_buff=' '
  c_buff(longest_env_variable+1:longest_env_variable+1)=c_null_char
  call c_readenv(c_buff)
  string=trim(arr2str(c_buff))

end function system_readenv