# flibs/m_vstrplatform(n) 1.0 "flibs"

## NAME

flibs/m_vstrplatform - Platform-dependent routines and features

## TABLE OF CONTENTS

TABLE OF CONTENTS
SYNOPSIS
DESCRIPTION
OVERVIEW
Dynamic or static buffer
Pre-processing
ROUTINES
COPYRIGHT

## SYNOPSIS

vstrplatform_system (command ?, status?)
vstrplatform_osstring() result ( currentos )
vstrplatform_platformstring() result ( currentplatform )
vstrplatform_getenvvar(envvar) result ( value )
vstrplatform_getenvvar(envvar) result ( value )
vstrplatform_cd ( dirname ?, status?)
vstrplatform_cd ( dirname ?, status?)
platform_stat ( filename , statarray ?, status?)
platform_stat ( filename , statarray ?, status?)

## DESCRIPTION

The m_vstrplatform module provides several routines, which take dynamic strings arguments, to interact with the operating system.

## OVERVIEW

The goal of this module is to provide system access with commands which take dynamic strings as arguments. It is based on m_platform, which takes character-based arguments. In the following example, extracted from the m_vfile module included in flibs, one sets the current working directory by using vstrplatform_cd on a dynamic string variable.

        type ( t_vstring ) :: dirname
        integer :: status
        call vstrplatform_cd ( dirname , status )

This is a sketch of available routines :

- vstrplatform_system Executes an external command on the system
- vstrplatform_get_environment_variable Get to one environment variable
- vstrplatform_cd Change the system current directory
- vstrplatform_stat Get status of a file

### Dynamic or static buffer

The internal algorithms provided by m_vstrplatform are based on basic fortran character strings. In several situations, the dynamic vstring has to be converted into a basic fortran character buffer string, which size has to be given explicitely in the source code, with the len = <something> statement (in the character ( len = <something>)).

- If the _VSTRPLATFORM_STATIC_BUFFER macro is defined, then character strings of constant size VSTRPLATFORM_MAXIMUM_ENVVAR_LENGTH are used as buffers.
- If the _VSTRPLATFORM_STATIC_BUFFER macro is not defined (which is the default), then character strings of dynamic size are used as buffers with the fortran 90 "len = vstring_length(this)" statement.

The second solution is more efficient, because the strings are not oversized or undersized, depending on the real number of characters in the dynamic string. But the feature may not be provided by the compiler at hand. For example, problems with the dynamic length character string have been experienced with Intel Fortran 8.

### Pre-processing

The following preprocessing macro may be defined :

- _VSTRPLATFORM_STATIC_BUFFER : see the section "Dynamic or static buffer"

## ROUTINES

The module contains the following routines.

vstrplatform_system (command ?, status?)
  type ( t_vstring ) :: command
  integer, intent (out), optional :: status
  Run an external command, optionally retrieving the status of that command. Under Windows the "call system" may generate the display of a console. If status is supplied, it contains 0 on success or nonzero error code upon return.
vstrplatform_osstring() result ( currentos )
  type ( t_vstring ) :: currentos
  Returns a string containing the current operating system running on the current machine, one of "Windows 95", "Windows NT", "MacOS", "SunOS", "Linux" or "Unix".
vstrplatform_platformstring() result ( currentplatform )
  type ( t_vstring ) :: currentplatform
  Returns a string containing the current platform running on the current machine, one of "Windows", "Mac", "Unix".
vstrplatform_getenvvar(envvar) result ( value )
  type ( t_vstring ), intent(in) :: envvar
  type ( t_vstring ) :: value
  Returns the value of the environment variable envvar.
vstrplatform_getenvvar(envvar) result ( value )
  character(len=*), intent(in) :: envvar
  type ( t_vstring ) :: value
  Same as previous with character(len=*) dirname.
vstrplatform_cd ( dirname ?, status?)
  type(t_vstring), intent(in) :: dirname
  integer, intent(out) , optional :: status
  Change working directory to dirname. If status is supplied, it contains 0 on success or nonzero error code upon return
vstrplatform_cd ( dirname ?, status?)
  character(len=*), intent(in) :: dirname
  integer, intent(out) , optional :: status
  Same as previous with character(len=*) dirname.
platform_stat ( filename , statarray ?, status?)
  type(t_vstring), intent(in) :: filename
  integer, dimension (1:13) , intent(out) :: filename
  integer, intent(out) , optional :: status
  Get status of the file filename and fills the array statarray with the following content.
  - statarray(1) Device ID
  - statarray(2) Inode number
  - statarray(3) File mode
  - statarray(4) Number of links
  - statarray(5) Owner's uid
  - statarray(6) Owner's gid
  - statarray(7) ID of device containing directory entry for file (0 if not available)
  - statarray(8) File size (bytes)
  - statarray(9) Last access time
  - statarray(10) Last modification time
  - statarray(11) Last file status change time
  - statarray(12) Preferred I/O block size (-1 if not available)
  - statarray(13) Number of blocks allocated (-1 if not available)
  If status is supplied, it contains 0 on success or nonzero error code upon return
platform_stat ( filename , statarray ?, status?)
  character(len=*), intent(in) :: filename
  integer, dimension (1:13) , intent(out) :: filename
  integer, intent(out) , optional :: status
  Same as previous with character(len=*) dirname.

## COPYRIGHT

Copyright © 2008 Arjen Markus <arjenmarkus@sourceforge.net>
Copyright © 2008 Michael Baudin <michael.baudin@gmail.com>