NAME
M_system(3fm) - [M_system::INTRO] Fortran interface to C system interface (LICENSE:PD)
SYNOPSIS
Public objects:
! ENVIRONMENT use m_system, only : set_environment_variable, system_unsetenv, & system_putenv, system_getenv
use m_system, only : system_intenv, system_readenv, system_clearenv ! FILE SYSTEM use M_system, only : system_getcwd, system_link, & system_mkfifo, system_remove, system_rename, & system_umask, system_unlink, fileglob, & system_rmdir, system_chdir, system_mkdir, & system_stat, system_isdir, system_islnk, system_isreg, & system_isblk, system_ischr, system_isfifo, & system_realpath, & system_access, & system_utime, & system_issock, system_perm, & system_memcpy
!!use M_system, only : system_getc, system_putc ! ERROR PROCESSING use M_system, only : system_errno, system_perror ! INFO use M_system, only : system_getegid, system_geteuid, system_getgid, & system_gethostname, system_getpid, system_getppid, system_setsid, & system_getsid, system_getuid, system_uname ! SIGNALS use M_system, only : system_kill ! RANDOM NUMBERS use M_system, only : system_rand, system_srand ! PROCESS INFORMATION use M_system, only : system_cpu_time
DESCRIPTION
M_system(3fm) is a collection of Fortran procedures that call C or a C wrapper using the ISO_C_BINDING interface to access system calls. System calls are a special set of functions used by programs to communicate directly with an operating system.Generally, system calls are slower than normal function calls because when you make a call control is relinquished to the operating system to perform the system call. In addition, depending on the nature of the system call, your program may be blocked by the OS until the system call has finished, thus making the execution time of your program even longer.
One rule-of-thumb that should always be followed when calling a system call -- Always check the return value.
ENVIRONMENT ACCESS
o system_putenv(3f): call putenv(3c) o system_getenv(3f): function call to get_environment_variable(3f) o system_unsetenv(3f): call unsetenv(3c) to remove variable from environment o set_environment_variable(3f): set environment variable by calling setenv(3c) o system_initenv(3f): initialize environment table for reading o system_readenv(3f): read next entry from environment table o system_clearenv(3f): emulate clearenv(3c) to clear environment
FILE SYSTEM
o system_chdir(3f): call chdir(3c) to change current directory of a process o system_getcwd(3f): call getcwd(3c) to get pathname of current working directory o system_stat(3f): determine system information of file by name o system_perm(3f): create string representing file permission and type o system_access(3f): determine filename access or existence o system_isdir(3f): determine if filename is a directory o system_islnk(3f): determine if filename is a link o system_isreg(3f): determine if filename is a regular file o system_isblk(3f): determine if filename is a block device o system_ischr(3f): determine if filename is a character device o system_isfifo(3f): determine if filename is a fifo - named pipe o system_issock(3f): determine if filename is a socket o system_realpath(3f): resolve a pathname o system_chmod(3f): call chmod(3c) to set file permission mode o system_chown(3f): call chown(3c) to set file owner o system_getumask(3f): call umask(3c) to get process permission mask o system_setumask(3f): call umask(3c) to set process permission mask o system_mkdir(3f): call mkdir(3c) to create empty directory o system_mkfifo(3f): call mkfifo(3c) to create a special FIFO file o system_link(3f): call link(3c) to create a filename link o system_rename(3f): call rename(3c) to change filename o system_remove(3f): call remove(3c) to remove file o system_rmdir(3f): call rmdir(3c) to remove empty directory o system_unlink(3f): call unlink(3c) to remove a link to a file o system_utime(3f): call utime(3c) to set file access and modification times o fileglob(3f): Returns list of files using a file globbing pattern
STREAM IO
o system_getc(3f): get a character from stdin o system_putc(3f): put a character on stdout
RANDOM NUMBERS
o system_srand(3f): call srand(3c) o system_rand(3f): call rand(3c)
C ERROR INFORMATION
o system_errno(3f): return errno(3c) o system_perror(3f): call perror(3c) to display last C error message
QUERIES
o system_geteuid(3f): call geteuid(3c) o system_getuid(3f): call getuid(3c) o system_getegid(3f): call getegid(3c) o system_getgid(3f): call getgid(3c) o system_getpid(3f): call getpid(3c) o system_getppid(3f): call getppid(3c) o system_gethostname(3f): get name of current host o system_uname(3f): call my_uname(3c) which calls uname(3c) o system_getlogin(3f): get login name o system_getpwuid(3f): get login name associated with given UID o system_getgrgid(3f): get group name associated with given GID o system_cpu_time(3f) : get processor time in seconds using times(3c)
FUTURE DIRECTIONS
A good idea of what system routines are commonly required is to refer to the POSIX binding standards. (Note: IEEE 1003.9-1992 was withdrawn 6 February 2003.) The IEEE standard covering Fortran 77 POSIX bindings is available online, though currently (unfortunately) only from locations with appropriate subscriptions to the IEEE server (e.g., many university networks). For those who do have such access, the link is: POSIX Fortran 77 Language Interfaces (IEEE Std 1003.9-1992) (pdf)
SEE ALSO
Some vendors provide their own way to access POSIX functions and make those available as modules; for instance ...
o the IFPORT module of Intel o or the f90_* modules of NAG. o There are also other compiler-independent efforts to make the POSIX procedures accessible from Fortran...
o Posix90 (doc), o flib.a platform/files and directories, o fortranposix.
NAME
system_access(3f) - [M_system] checks accessibility or existence of a pathname (LICENSE:PD)
SYNOPSIS
logical function system_access(pathname,amode)
character(len=*),intent(in) :: pathname integer,intent(in) :: amode
DESCRIPTION
The system_access(3f) function checks pathname existence and access permissions. The function checks the pathname for accessibility according to the bit pattern contained in amode, using the real user ID in place of the effective user ID and the real group ID in place of the effective group ID.
The value of amode is either the bitwise-inclusive OR of the access permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
OPTIONS
pathname a character string representing a directory pathname. Trailing spaces are ignored. amode bitwise-inclusive OR of the values R_OK, W_OK, X_OK, or F_OK.
RETURN VALUE
If not true an error occurred or the requested access is not granted
EXAMPLE
check if filename is accessibleSample program:
program demo_system_access Use M_system, only : system_access, F_OK, R_OK, W_OK, X_OK implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/usr/bin/bash ', & '/tmp/NOTTHERE ', & '/usr/local ', & '. ', & 'PROBABLY_NOT '] do i=1,size(names) write(*,*)' does ',trim(names(i)),' exist? ', system_access(names(i),F_OK) write(*,*)' is ',trim(names(i)),' readable? ', system_access(names(i),R_OK) write(*,*)' is ',trim(names(i)),' writeable? ', system_access(names(i),W_OK) write(*,*)' is ',trim(names(i)),' executable? ', system_access(names(i),X_OK) enddo end program demo_system_access
NAME
system_chdir(3f) - [M_system] call chdir(3c) from Fortran to change working directory (LICENSE:PD)
SYNOPSIS
subroutine system_chdir(path, err)
character(len=*) :: path integer, optional, intent(out) :: err
DESCRIPTION
system_chdir(3f) changes the current working directory of the calling process to the directory specified in path. The current working directory is the starting point for interpreting relative pathnames (those not starting with '/').
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
Depending on the file system, other errors can be returned. The more general errors for chdir() are listed below, by their C definitions:Errors
EACCES Search permission is denied for one of the components of path. (See also path_resolution(7).) EFAULT path points outside your accessible address space. EIO An I/O error occurred. ELOOP Too many symbolic links were encountered in resolving path. ENAMETOOLONG path is too long. ENOENT The file does not exist. ENOMEM Insufficient kernel memory was available. ENOTDIR A component of path is not a directory.
SEE ALSO
chroot(2), getcwd(3), path_resolution(7)
EXAMPLE
Change working directory from FortranRESULTS: Sample run output:program demo_system_chdir use M_system, only : system_chdir implicit none integer :: ierr
call execute_command_line('pwd') call system_chdir('/tmp',ierr) call execute_command_line('pwd') write(*,*)'*CHDIR TEST* IERR=',ierr
end program demo_system_chdir
/home/urbanjs/V600 /tmp *CHDIR TEST* IERR= 0
NAME
system_chmod(3f) - [M_system] call chmod(3c) to change permission mode of a file relative to directory file descriptor (LICENSE:PD)
SYNOPSIS
function system_chmod(filename,mode) result(ierr)
character(len=*),intent(in) :: filename integer,value,intent(in) :: mode integer :: ierr
DESCRIPTION
The system_chmod(3f) function shall change UID, _ISGID, S_ISVTX, and the file permission bits of the file named by the pathname pointed to by the path argument to the corresponding bits in the mode argument. The application shall ensure that the effective user ID of the process matches the owner of the file or the process has appropriate privileges in order to do this.S_ISUID, S_ISGID, S_ISVTX, and the file permission bits are described in <sys/stat.h>.
If the calling process does not have appropriate privileges, and if the group ID of the file does not match the effective group ID or one of the supplementary group IDs and if the file is a regular file, bit S_ISGID (set-group-ID on execution) in the file's mode shall be cleared upon successful return from chmod().
Additional implementation-defined restrictions may cause the S_ISUID and S_ISGID bits in mode to be ignored.
Upon successful completion, system_chmod() marks for update the last file status change timestamp of the file.
Values for flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in <fcntl.h>:
AT_SYMLINK_NOFOLLOW
If path names a symbolic link, then the mode of the symbolic link is changed.
RETURN VALUE
Upon successful completion, system_chmod(3f) returns 0. Otherwise, it returns -1 and sets errno to indicate the error. If -1 is returned, no change to the file mode occurs.
EXAMPLES
Sample program:program demo_system_chmod use M_system, only : system_chmod use M_system, only : system_stat use M_system, only : R_GRP,R_OTH,R_USR,RWX_G,RWX_O use M_system, only : RWX_U,W_GRP,W_OTH,W_USR,X_GRP,X_OTH,X_USR use M_system, only : DEFFILEMODE, ACCESSPERMS use,intrinsic :: iso_fortran_env, only : int64 implicit none integer :: ierr integer :: status integer(kind=int64) :: buffer(13) !Setting Read Permissions for User, Group, and Others ! The following example sets read permissions for the owner, group, and others. open(file='_test1',unit=10) write(10,*)'TEST FILE 1' close(unit=10) ierr=system_chmod('_test1', IANY([R_USR,R_GRP,R_OTH])) !Setting Read, Write, and Execute Permissions for the Owner Only ! The following example sets read, write, and execute permissions for the owner, ! and no permissions for group and others. open(file='_test2',unit=10) write(10,*)'TEST FILE 2' close(unit=10) ierr=system_chmod('_test2', RWX_U) !Setting Different Permissions for Owner, Group, and Other ! The following example sets owner permissions for CHANGEFILE to ! read, write, and execute, group permissions to read and ! execute, and other permissions to read. open(file='_test3',unit=10) write(10,*)'TEST FILE 3' close(unit=10) ierr=system_chmod('_test3', IANY([RWX_U,R_GRP,X_GRP,R_OTH])); !Setting and Checking File Permissions ! The following example sets the file permission bits for ! a file named /home/cnd/mod1, then calls the stat() function to ! verify the permissions. ierr=system_chmod("home/cnd/mod1", IANY([RWX_U,RWX_G,R_OTH,W_OTH])) call system_stat("home/cnd/mod1", buffer,status) ! In order to ensure that the S_ISUID and S_ISGID bits are set, ! an application requiring this should use stat() after a ! successful chmod() to verify this. ! Any files currently open could possibly become invalid if the mode ! of the file is changed to a value which would deny access to ! that process. end program demo_system_chmod
NAME
system_chown(3f) - [M_system] change file owner and group (LICENSE:PD)
SYNOPSIS
logical function system_chown(path,owner,group)
character(len=*),intent(in) :: path integer,intent(in) :: owner integer,intent(in) :: group
DESCRIPTION
The chown(3f) function changes owner and group of a fileThe path argument points to a pathname naming a file. The user ID and group ID of the named file shall be set to the numeric values contained in owner and group, respectively.
Only processes with an effective user ID equal to the user ID of the file or with appropriate privileges may change the ownership of a file.
OPTIONS
path a character string representing a file pathname. Trailing spaces are ignored. owner UID of owner that ownership is to be changed to group GID of group that ownership is to be changed to
RETURN VALUE
The system_chown() function should return zero (0) if successful. Otherwise, these functions shall return 1 and set errno to indicate the error. If 1 is returned, no changes are made in the user ID and group ID of the file.
EXAMPLE
Sample program:
program demo_system_chown Use M_system, only : system_chown Use M_system, only : system_getuid Use M_system, only : system_getgid use M_system, only : system_perror implicit none integer :: i character(len=80),parameter :: names(*)=[character(len=80) :: 'myfile1','/usr/local'] do i=1,size(names) if(.not. system_chown(& & trim(names(i)), & & system_getuid(), & & system_getgid()) & )then call system_perror('*demo_system_chown* '//trim(names(i))) endif enddo end program demo_system_chown
NAME
system_clearenv(3f) - [M_system:ENVIRONMENT] clear environment by calling clearenv(3c) (LICENSE:PD)
SYNOPSIS
subroutine system_clearenv(ierr)
integer,intent(out),optional :: ierr
DESCRIPTION
The clearenv() procedure clears the environment of all name-value
pairs. Typically used in security-conscious applications or ones where configuration control requires ensuring specific variables are set.
RETURN VALUES
ierr returns zero on success, and a nonzero value on failure. Optional. If not present and an error occurs the program stops.
EXAMPLE
Sample program:
program demo_system_clearenv use M_system, only : system_clearenv implicit none ! environment before clearing call execute_command_line('env|wc') ! environment after clearing (not necessarily blank!!) call system_clearenv() call execute_command_line('env') end program demo_system_clearenvTypical output:
89 153 7427 PWD=/home/urbanjs/V600 SHLVL=1
NAME
system_closedir(3f) - [M_system] close a directory stream by calling closedir(3c) (LICENSE:PD)
SYNOPSIS
subroutine system_closedir(dir,ierr)
type(c_ptr) :: dir integer,intent(out) :: ierr
DESCRIPTION
The SYSTEM_CLOSEDIR(3f) function closes the directory stream referred to by the argument DIR. Upon return, the value of DIR may no longer point to an accessible object.
OPTIONS
dir directory stream pointer opened by SYSTEM_OPENDIR(3f). ierr Upon successful completion, SYSTEM_CLOSEDIR(3f) returns 0; otherwise, an error has occurred.
ERRORS
system_closedir(3f) may fail if:
EBADF The dirp argument does not refer to an open directory stream. EINTR The closedir() function was interrupted by a signal.
EXAMPLE
Sample programprogram demo_system_closedir use M_system, only : system_opendir,system_readdir use M_system, only : system_closedir, system_rewinddir use iso_c_binding, only : c_ptr implicit none type(c_ptr) :: dir character(len=:),allocatable :: filename integer :: ierr !--- open directory stream to read from call system_opendir('.',dir,ierr) !--- read directory stream do call system_readdir(dir,filename,ierr) if(filename.eq.' ')exit write(*,*)filename enddo call system_rewinddir(dir) !--- close directory stream call system_closedir(dir,ierr) end program demo_system_closedir
NAME
system_cpu_time(3f) - [M_system] get processor time by calling times(3c) (LICENSE:PD)
SYNOPSIS
subroutine system_cpu_time(c_user, c_system, c_total)
real,intent(out) :: c_total real,intent(out) :: c_user real,intent(out) :: c_system
DESCRIPTION
OUTPUT
c_total total processor time ( c_user + c_system ) c_user processor user time c_system processor system time
ERRORS
No errors are defined.
EXAMPLES
Sample program:
program demo_system_cpu_time use M_system, only : system_cpu_time use ISO_C_BINDING, only : c_float implicit none real :: user_start, system_start, total_start real :: user_finish, system_finish, total_finish integer :: i integer :: itimes=1000000 real :: value call system_cpu_time(total_start,user_start,system_start) value=0.0 do i=1,itimes value=sqrt(real(i)+value) enddo write(10,*)value flush(10) write(*,*)'average sqrt value=',value/itimes call system_cpu_time(total_finish,user_finish,system_finish) write(*,*)'USER ......',user_finish-user_start write(*,*)'SYSTEM ....',system_finish-system_start write(*,*)'TOTAL .....',total_finish-total_start end program demo_system_cpu_timeTypical Results:
NAME
system_errno(3f) - [M_system] C error return value (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_errno()
DESCRIPTION
Many C routines return an error code which can be queried by errno. The M_system(3fm) is primarily composed of Fortran routines that call C routines. In the cases where an error code is returned vi system_errno(3f) these routines will indicate it.
EXAMPLE
Sample program:program demo_system_errno use M_system, only : system_errno, system_unlink, system_perror implicit none integer :: stat stat=system_unlink('not there/OR/anywhere') if(stat.ne.0)then write(*,*)'err=',system_errno() call system_perror('*demo_system_errno*') endif end program demo_system_errnoTypical Results:
err= 2 *demo_system_errno*: No such file or directory
NAME
system_getcwd(3f) - [M_system] call getcwd(3c) to get the pathname of the current working directory (LICENSE:PD)
SYNOPSIS
subroutine system_getcwd(output,ierr)
character(len=:),allocatable,intent(out) :: output integer,intent(out) :: ierr
DESCRIPTION
system_getcwd(3f) calls the C routine getcwd(3c) to obtain the absolute pathname of the current working directory.
RETURN VALUE
OUTPUT The absolute pathname of the current working directory The pathname shall contain no components that are dot or dot-dot, or are symbolic links. IERR is not zero if an error occurs.
EXAMPLE
Sample program:program demo_system_getcwd use M_system, only : system_getcwd implicit none character(len=:),allocatable :: dirname integer :: ierr call system_getcwd(dirname,ierr) if(ierr.eq.0)then write(*,*)'CURRENT DIRECTORY ',trim(dirname) else write(*,*)'ERROR OBTAINING CURRENT DIRECTORY NAME' endif end program demo_system_getcwd
NAME
system_getegid(3f) - [M_system:QUERY] get the effective group ID (GID) of current process from Fortran by calling getegid(3c) (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_getegid()
DESCRIPTION
The getegid() function returns the effective group ID of the calling process.
RETURN VALUE
The getegid() should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
getegid(), system_geteuid(), getuid(), setegid(), seteuid(), setgid(), setregid(), setreuid(), setuid()
EXAMPLE
Get group ID from Fortranprogram demo_system_getegid use M_system, only : system_getegid implicit none write(*,*)'GID=',system_getegid() end program demo_system_getegid
NAME
system_getenv(3f) - [M_system:ENVIRONMENT] get environment variable from Fortran by calling get_environment_variable(3f) (LICENSE:PD)
SYNOPSIS
function system_getenv(name)
character(len=:),allocatable :: system_getenv character(len=*),intent(in) :: name
DESCRIPTION
The system_getenv() function gets the value of an environment variable.
OPTIONS
name Return the value of the specified environment variable or blank if the variable is not defined.
EXAMPLE
Sample setting an environment variable from Fortran:program demo_system_getenv use M_system, only : system_getenv implicit none integer :: ierr
write(*,'("USER : ",a)')system_getenv('USER') write(*,'("LOGNAME : ",a)')system_getenv('LOGNAME') write(*,'("USERNAME : ",a)')system_getenv('USERNAME')
end program demo_system_getenv
NAME
system_geteuid(3f) - [M_system:QUERY] get effective UID of current process from Fortran by calling geteuid(3c) (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_geteuid()
DESCRIPTION
The system_geteuid(3f) function shall return the effective user ID of the calling process. The geteuid() function shall always be successful and no return value is reserved to indicate the error.
EXAMPLE
Get group ID from Fortran:program demo_system_geteuid use M_system, only : system_geteuid implicit none write(*,*)'EFFECTIVE UID=',system_geteuid() end program demo_system_geteuid
NAME
system_getgid(3f) - [M_system:QUERY] get the real group ID (GID) of current process from Fortran by calling getgid(3c) (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_getgid()
DESCRIPTION
The getgid() function returns the real group ID of the calling process.
RETURN VALUE
The getgid() should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
getegid(), system_geteuid(), getuid(), setegid(), seteuid(), setgid(), setregid(), setreuid(), setuid()
EXAMPLE
Get group ID from Fortranprogram demo_system_getgid use M_system, only : system_getgid implicit none write(*,*)'GID=',system_getgid() end program demo_system_getgid
NAME
system_getgrgid(3f) - [M_system:QUERY] get groupd name associated with a GID (LICENSE:PD)
SYNOPSIS
function system_getgrgid(gid) result (gname)
class(*),intent(in) :: gid ! any INTEGER type character(len=:),allocatable :: gname
DESCRIPTION
The system_getlogin() function returns a string containing the group name associated with the given GID. If no match is found it returns a null string and sets errno to indicate the error.
OPTION
gid GID to try to look up associated group for. Can be of any INTEGER type.
RETURN VALUE
gname returns the group name. Blank if an error occurs
EXAMPLE
Sample program:program demo_system_getgrgid use M_system, only : system_getgrgid use M_system, only : system_getgid implicit none character(len=:),allocatable :: name name=system_getgrgid( system_getgid() ) write(*,'("group[",a,"] for ",i0)')name,system_getgid() end program demo_system_getgrgidResults:
group[default] for 197121
NAME
system_gethostname(3f) - [M_system:QUERY] get name of current host (LICENSE:PD)
SYNOPSIS
subroutine system_gethostname(string,ierr)
character(len=:),allocatable,intent(out) :: NAME integer,intent(out) :: IERR
DESCRIPTION
The system_gethostname(3f) procedure returns the standard host name for the current machine.
OPTIONS
string returns the hostname. Must be an allocatable CHARACTER variable. ierr Upon successful completion, 0 shall be returned; otherwise, -1 shall be returned.
EXAMPLE
Sample program:program demo_system_gethostname
use M_system, only : system_gethostname implicit none character(len=:),allocatable :: name integer :: ierr
call system_gethostname(name,ierr) if(ierr.eq.0)then write(*,'("hostname[",a,"]")')name else write(*,'(a)')'ERROR: could not get hostname' endif
end program demo_system_gethostname
NAME
system_getlogin(3f) - [M_system:QUERY] get login name (LICENSE:PD)
SYNOPSIS
function system_getlogin() result (fname)
character(len=:),allocatable :: FNAME
DESCRIPTION
The system_getlogin() function returns a string containing the user name associated by the login activity with the controlling terminal of the current process. Otherwise, it returns a null string and sets errno to indicate the error.
Three names associated with the current process can be determined:
o system_getpwuid(system_getuid()) returns the name associated with the real user ID of the process. o system_getpwuid(system_geteuid()) returns the name associated with the effective user ID of the process o system_getlogin() returns the name associated with the current login activity
RETURN VALUE
fname returns the login name.
EXAMPLE
Sample program:program demo_system_getlogin use M_system, only : system_getlogin implicit none character(len=:),allocatable :: name name=system_getlogin() write(*,'("login[",a,"]")')name end program demo_system_getloginResults:
login[JSU]
NAME
system_getpid(3f) - [M_system:QUERY] get PID (process ID) of current process from Fortran by calling getpid(3c) (LICENSE:PD)
SYNOPSIS
integer function system_getpid()
DESCRIPTION
The system_getpid() function returns the process ID of the calling process.
RETURN VALUE
The value returned is the integer process ID. The system_getpid() function shall always be successful and no return value is reserved to indicate an error.
EXAMPLE
Get process PID from Fortranprogram demo_system_getpid use M_system, only : system_getpid implicit none write(*,*)'PID=',system_getpid() end program demo_system_getpid
NAME
system_getppid(3f) - [M_system:QUERY] get parent process ID (PPID) of current process from Fortran by calling getppid(3c) (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_getppid()
DESCRIPTION
The system_getppid() function returns the parent process ID of the calling process.
RETURN VALUE
The system_getppid() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
exec, fork(), getpgid(), getpgrp(), getpid(), kill(), setpgid(), setsid()
EXAMPLE
Get parent process PID (PPID) from Fortranprogram demo_system_getppid use M_system, only : system_getppid implicit none
write(*,*)'PPID=',system_getppid()
end program demo_system_getppid
NAME
system_getpwuid(3f) - [M_system:QUERY] get login name associated with a UID (LICENSE:PD)
SYNOPSIS
function system_getpwuid(uid) result (uname)
class(*),intent(in) :: uid ! any INTEGER type character(len=:),allocatable :: uname
DESCRIPTION
The system_getpwuid() function returns a string containing the user name associated with the given UID. If no match is found it returns a null string and sets errno to indicate the error.
OPTION
uid UID to try to look up associated username for. Can be of any INTEGER type.
RETURN VALUE
uname returns the login name.
EXAMPLE
Sample program:program demo_system_getpwuid use M_system, only : system_getpwuid use M_system, only : system_getuid use,intrinsic :: iso_fortran_env, only : int64 implicit none character(len=:),allocatable :: name integer(kind=int64) :: uid uid=system_getuid() name=system_getpwuid(uid) write(*,'("login[",a,"] has UID ",i0)')name,uid end program demo_system_getpwuid
NAME
system_getsid(3f) - [M_system:QUERY] get the process group ID of a session leader (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_getsid(pid) integer(kind=c_int) :: pid
DESCRIPTION
The system_getsid() function obtains the process group ID of the process that is the session leader of the process specified by pid. If pid is 0, it specifies the calling process.
RETURN VALUE
Upon successful completion, system_getsid() shall return the process group ID of the session leader of the specified process. Otherwise, it shall return -1 and set errno to indicate the error.
EXAMPLE
Get SID from Fortranprogram demo_system_getsid use M_system, only : system_getsid use ISO_C_BINDING, only : c_int implicit none write(*,*)'SID=',system_getsid(0_c_int) end program demo_system_getsid
NAME
system_getuid(3f) - [M_system:QUERY] get real UID of current process from Fortran by calling getuid(3c) (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_getuid()
DESCRIPTION
The system_getuid(3f) function shall return the real user ID of the calling process. The getuid() function shall always be successful and no return value is reserved to indicate the error.
EXAMPLE
Get group ID from Fortran:program demo_system_getuid use M_system, only : system_getuid implicit none write(*,*)'UID=',system_getuid() end program demo_system_getuidResults:
UID= 197609
NAME
system_getumask(3f) - [M_system] get current umask (LICENSE:PD)
SYNOPSIS
integer function system_getumask() result (umask_value)
DESCRIPTION
The return value from getumask(3f) is the value of the file creation mask, obtained by using umask(3c).
EXAMPLE
Sample programprogram demo_getumask use M_system, only : system_getumask, system_setumask integer :: i write(*,101)(system_getumask(),i=1,4) 101 format(1x,i0,1x,"O'",o4.4,"'",1x,'Z"',z0,"'",1x,"B'",b12.12,"'") end program demo_getumaskExpected output
18 O'022' Z"12' B'000010010"
NAME
system_initenv(3f) - [M_system:ENVIRONMENT] initialize environment table pointer and size so table can be read by readenv(3f) (LICENSE:PD)
SYNOPSIS
subroutine system_initenv()
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) 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.
EXAMPLE
Sample program:program demo_system_initenv 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_initenvSample results:
USERDOMAIN_ROAMINGPROFILE=buzz HOMEPATH=\Users\JSU APPDATA=C:\Users\JSU\AppData\Roaming MANPATH=/home/urbanjs/V600/LIBRARY/libGPF/download/tmp/man:/home/urbanjs/V600/doc/man::: DISPLAYNUM=0 ProgramW6432=C:\Program Files HOSTNAME=buzz XKEYSYMDB=/usr/share/X11/XKeysymDB PUBLISH_CMD= OnlineServices=Online Services : : :
NAME
system_isblk(3f) - [M_system] checks if argument is a block device (LICENSE:PD)
SYNOPSIS
logical function system_isblk(pathname)
character(len=*),intent(in) :: pathname logical :: system_isblk
DESCRIPTION
The isblk(3f) function checks if path is a path to a block device.
OPTIONS
path a character string representing a block device pathname. Trailing spaces are ignored.
RETURN VALUE
The system_isblk() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
system_isreg(3f), system_stat(3f), system_isdir(3f), system_perm(3f)
EXAMPLE
check if filename is a block deviceprogram demo_system_isblk Use M_system, only : system_isblk implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/tmp ', & '/tmp/NOTTHERE ', & '/usr/local ', & '. ', & 'block_device.tst', & 'PROBABLY_NOT '] do i=1,size(names) write(*,*)' is ',trim(names(i)),' a block device? ', system_isblk(names(i)) enddo end program demo_system_isblkResults:
NAME
system_ischr(3f) - [M_system] checks if argument is a character device (LICENSE:PD)
SYNOPSIS
logical function system_ischr(pathname)
character(len=*),intent(in) :: pathname logical :: system_ischr
DESCRIPTION
The ischr(3f) function checks if path is a path to a character device.
OPTIONS
path a character string representing a character device pathname. Trailing spaces are ignored.
RETURN VALUE
The system_ischr() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
system_isreg(3f), system_stat(3f), system_isdir(3f), system_perm(3f)
EXAMPLE
check if filename is a character fileprogram demo_system_ischr Use M_system, only : system_ischr implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/tmp ', & '/tmp/NOTTHERE ', & '/usr/local ', & '. ', & 'char_dev.test ', & 'PROBABLY_NOT '] do i=1,size(names) write(*,*)' is ',trim(names(i)),' a character device? ', system_ischr(names(i)) enddo end program demo_system_ischrResults:
NAME
system_isdir(3f) - [M_system] checks if argument is a directory path (LICENSE:PD)
SYNOPSIS
logical function system_isdir(pathname)
character(len=*),intent(in) :: pathname logical :: system_isdir
DESCRIPTION
The system_isdir(3f) function checks if path is a directory.
OPTIONS
path a character string representing a directory pathname. Trailing spaces are ignored.
RETURN VALUE
The system_isdir() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
system_islnk(3f), system_stat(3f), isreg(3f), system_perm(3f)
EXAMPLE
check if filename is a directoryprogram demo_system_isdir Use M_system, only : system_isdir implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/tmp ', & '/tmp/NOTTHERE ', & '/usr/local ', & '. ', & 'PROBABLY_NOT '] do i=1,size(names) write(*,*)' is ',trim(names(i)),' a directory? ', system_isdir(names(i)) enddo end program demo_system_isdirResults:
is /tmp a directory? T is /tmp/NOTTHERE a directory? F is /usr/local a directory? T is . a directory? T is PROBABLY_NOT a directory? F
NAME
system_isfifo(3f) - [M_system] checks if argument is a fifo - named pipe (LICENSE:PD)
SYNOPSIS
logical function system_isfifo(pathname)
character(len=*),intent(in) :: pathname logical :: system_isfifo
DESCRIPTION
The isfifo(3f) function checks if path is a path to a fifo - named pipe.
OPTIONS
path a character string representing a fifo - named pipe pathname. Trailing spaces are ignored.
RETURN VALUE
The system_isfifo() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
system_isreg(3f), system_stat(3f), system_isdir(3f), system_perm(3f)
EXAMPLE
check if filename is a FIFO fileprogram demo_system_isfifo Use M_system, only : system_isfifo implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/tmp ', & '/tmp/NOTTHERE ', & '/usr/local ', & '. ', & 'fifo.test ', & 'PROBABLY_NOT '] do i=1,size(names) write(*,*)' is ',trim(names(i)),' a fifo(named pipe)? ', system_isfifo(names(i)) enddo end program demo_system_isfifo
NAME
system_islnk(3f) - [M_system] checks if argument is a link (LICENSE:PD)
SYNOPSIS
logical function system_islnk(pathname)
character(len=*),intent(in) :: pathname
logical :: system_islnk
DESCRIPTION
The islnk(3f) function checks if path is a path to a link.
OPTIONS
path a character string representing a link pathname. Trailing spaces are ignored.
RETURN VALUE
The system_islnk() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
system_isreg(3f), system_stat(3f), system_isdir(3f), system_perm(3f)
EXAMPLE
Sample program:
program demo_system_islnk Use M_system, only : system_islnk implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/tmp ', & '/tmp/NOTTHERE ', & '/usr/local ', & '. ', & 'link.test ', & 'PROBABLY_NOT '] do i=1,size(names) write(*,*)' is ',trim(names(i)),' a link? ', system_islnk(names(i)) enddo end program demo_system_islnkResults:
NAME
system_isreg(3f) - [M_system] checks if argument is a regular file (LICENSE:PD)
SYNOPSIS
logical function system_isreg(pathname)
character(len=*),intent(in) :: pathname logical :: system_isreg
DESCRIPTION
The isreg(3f) function checks if path is a regular file
OPTIONS
path a character string representing a pathname. Trailing spaces are ignored.
RETURN VALUE
The system_isreg() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
system_islnk(3f), system_stat(3f), system_isdir(3f), system_perm(3f)
EXAMPLE
check if filename is a regular fileprogram demo_system_isreg Use M_system, only : system_isreg implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/tmp ', & 'test.txt ', & '. '] do i=1,size(names) write(*,*)' is ',trim(names(i)),' a regular file? ', system_isreg(names(i)) enddo end program demo_system_isreg
NAME
system_issock(3f) - [M_system] checks if argument is a socket (LICENSE:PD)
SYNOPSIS
logical function system_issock(pathname)
character(len=*),intent(in) :: pathname logical :: system_issock
DESCRIPTION
The issock(3f) function checks if path is a path to a socket
OPTIONS
path a character string representing a socket pathname. Trailing spaces are ignored.
RETURN VALUE
The system_issock() function should always be successful and no return value is reserved to indicate an error.
ERRORS
No errors are defined.
SEE ALSO
system_isreg(3f), system_stat(3f), system_isdir(3f), system_perm(3f)
EXAMPLE
check if filename is a socketprogram demo_system_issock Use M_system, only : system_issock implicit none integer :: i character(len=80),parameter :: names(*)=[ & '/tmp ', & '/tmp/NOTTHERE ', & '/usr/local ', & '. ', & 'sock.test ', & 'PROBABLY_NOT '] do i=1,size(names) write(*,*)' is ',trim(names(i)),' a socket? ', system_issock(names(i)) enddo end program demo_system_issock
NAME
system_kill(3f) - [M_system] send a signal to a process or a group of processes (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_kill(pid,sig)
integer,intent(in) :: pid integer,intent(in) :: sig
DESCRIPTION
The kill() function shall send a signal to a process or a group of processes specified by pid. The signal to be sent is specified by sig and is either one from the list given in <signal.h> or 0. If sig is 0 (the null signal), error checking is performed but no signal is actually sent. The null signal can be used to check the validity of pid.
For a process to have permission to send a signal to a process designated by pid, unless the sending process has appropriate privileges, the real or effective user ID of the sending process shall match the real or saved set-user-ID of the receiving process.
If pid is greater than 0, sig shall be sent to the process whose process ID is equal to pid.
If pid is 0, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the process group ID of the sender, and for which the process has permission to send a signal.
If pid is -1, sig shall be sent to all processes (excluding an unspecified set of system processes) for which the process has permission to send that signal.
If pid is negative, but not -1, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the absolute value of pid, and for which the process has permission to send a signal.
If the value of pid causes sig to be generated for the sending process, and if sig is not blocked for the calling thread and if no other thread has sig unblocked or is waiting in a sigwait() function for sig, either sig or at least one pending unblocked signal shall be delivered to the sending thread before kill() returns.
The user ID tests described above shall not be applied when sending SIGCONT to a process that is a member of the same session as the sending process.
An implementation that provides extended security controls may impose further implementation-defined restrictions on the sending of signals, including the null signal. In particular, the system may deny the existence of some or all of the processes specified by pid.
The kill() function is successful if the process has permission to send sig to any of the processes specified by pid. If kill() fails, no signal shall be sent.
RETURN VALUE
Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.
ERRORS
The kill() function shall fail if:
EINVAL The value of the sig argument is an invalid or unsupported signal number. EPERM The process does not have permission to send the signal to any receiving process. ESRCH No process or process group can be found corresponding to that specified by pid. The following sections are informative.
EXAMPLE
Sample program:program demo_system_kill use M_system, only : system_kill use M_system, only : system_perror implicit none integer :: i,pid,ios,ierr,signal=9 character(len=80) :: argumentend program demo_system_kill
do i=1,command_argument_count() ! get arguments from command line call get_command_argument(i, argument) ! convert arguments to integers assuming they are PID numbers read(argument,'(i80)',iostat=ios) pid if(ios.ne.0)then write(*,*)'bad PID=',trim(argument) else write(*,*)'kill SIGNAL=',signal,' PID=',pid ! send signal SIGNAL to pid PID ierr=system_kill(pid,signal) ! write message if an error was detected if(ierr.ne.0)then call system_perror('*demo_system_kill*') endif endif enddo
SEE ALSO
getpid(), raise(), setsid(), sigaction(), sigqueue(),
NAME
system_link(3f) - [M_system] link one file to another file relative to two directory file descriptors (LICENSE:PD)
SYNOPSIS
integer function link(oldpath,newpath);
character(len=*),intent(in) :: oldpath character(len=*),intent(in) :: newpath
DESCRIPTION
The link() function shall create a new link (directory entry) for the existing file, path1.The path1 argument points to a pathname naming an existing file. The path2 argument points to a pathname naming the new directory entry to be created. The link() function shall atomically create a new link for the existing file and the link count of the file shall be incremented by one.
If path1 names a directory, link() shall fail unless the process has appropriate privileges and the implementation supports using link() on directories.
If path1 names a symbolic link, it is implementation-defined whether link() follows the symbolic link, or creates a new link to the symbolic link itself.
Upon successful completion, link() shall mark for update the last file status change timestamp of the file. Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.
If link() fails, no link shall be created and the link count of the file shall remain unchanged.
The implementation may require that the calling process has permission to access the existing file.
The linkat() function shall be equivalent to the link() function except that symbolic links shall be handled as specified by the value of flag (see below) and except in the case where either path1 or path2 or both are relative paths. In this case a relative path path1 is interpreted relative to the directory associated with the file descriptor fd1 instead of the current working directory and similarly for path2 and the file descriptor fd2. If the file descriptor was opened without O_SEARCH, the function shall check whether directory searches are permitted using the current permissions of the directory underlying the file descriptor. If the file descriptor was opened with O_SEARCH, the function shall not perform the check.
Values for flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in <fcntl.h>:
AT_SYMLINK_FOLLOW
If path1 names a symbolic link, a new link for the target of the symbolic link is created.
If linkat() is passed the special value AT_FDCWD in the fd1 or fd2 parameter, the current working directory shall be used for the respective path argument. If both fd1 and fd2 have value AT_FDCWD, the behavior shall be identical to a call to link(), except that symbolic links shall be handled as specified by the value of flag.
Some implementations do allow links between file systems.
If path1 refers to a symbolic link, application developers should use linkat() with appropriate flags to select whether or not the symbolic link should be resolved.
If the AT_SYMLINK_FOLLOW flag is clear in the flag argument and the path1 argument names a symbolic link, a new link is created for the symbolic link path1 and not its target.
RETURN VALUE
Upon successful completion, these functions shall return 0. Otherwise, these functions shall return -1 and set errno to indicate the error.
EXAMPLES
Creating a Link to a Fileprogram demo_system_link use M_system, only : system_link, system_perror integer :: ierr ierr = system_link('myfile1','myfile2') if(ierr.ne.0)then call system_perror('*demo_system_link*') endif end program demo_system_link
NAME
system_mkdir(3f) - [M_system] call mkdir(3c) to create a new directory (LICENSE:PD)
SYNOPSIS
DESCRIPTION
Predefined variables are typically used to set permission modes. You can bytewise-OR together these variables to to create the most common permissions mode:
User: R_USR (read), W_USR (write), X_USR(execute) Group: R_GRP (read), W_GRP (write), X_GRP(execute) Others: R_OTH (read), W_OTH (write), X_OTH(execute)Additionally, some shortcuts are provided (basically a bitwise-OR combination of the above):
Read + Write + Execute: RWX_U (User), RWX_G (Group), RWX_O (Others) DEFFILEMODE: Equivalent of 0666 =rw-rw-rw- ACCESSPERMS: Equivalent of 0777 = rwxrwxrwxTherefore, to give only the user rwx (read+write+execute) rights whereas group members and others may not do anything, you can use any of the following mkdir() calls equivalently:
ierr= mkdir("mydir", IANY([R_USR, W_USR, X_USR])); ierr= mkdir("mydir", RWX_U);In order to give anyone any rights (mode 0777 = rwxrwxrwx), you can use any of the following calls equivalently:
ierr= mkdir("mydir",IANY([R_USR,W_USR,X_USR,R_GRP,W_GRP,X_GRP,R_OTH,W_OTH,X_OTH])); ierr= mkdir("mydir",IANY([RWX_U,RWX_G,RWX_O])); ierr= mkdir("mydir",ACCESSPERMS);
EXAMPLE
Sample program:program demo_system_mkdir use M_system, only : system_perror use M_system, only : system_mkdir use M_system, only : R_GRP,R_OTH,R_USR,RWX_G,RWX_O use M_system, only : RWX_U,W_GRP,W_OTH,W_USR,X_GRP,X_OTH,X_USR use M_system, only : DEFFILEMODE, ACCESSPERMS implicit none integer :: ierr ierr=system_mkdir('_scratch',IANY([R_USR,W_USR,X_USR])) end program demo_system_mkdir
NAME
system_mkfifo(3f) - [M_system] make a FIFO special file relative to directory file descriptor (LICENSE:PD)
SYNOPSIS
function system_mkfifo(pathname,mode) result(ierr)
character(len=*),intent(in) :: pathname integer,intent(in) :: mode integer :: ierr
DESCRIPTION
A regular pipe can only connect two related processes. It is created by a process and will vanish when the last process closes it.A named pipe, also called a FIFO for its behavior, can be used to connect two unrelated processes and exists independently of the processes; meaning it can exist even if no one is using it. A FIFO is created using the mkfifo() library function.
The mkfifo() function creates a new FIFO special file named by the pathname.
The file permission bits of the new FIFO are initialized from mode.
The file permission bits of the mode argument are modified by the process' file creation mask.
When bits in mode other than the file permission bits are set, the effect is implementation-defined.
If path names a symbolic link, mkfifo() shall fail and set errno to [EEXIST].
The FIFO's user ID will be set to the process' effective user ID.
The FIFO's group ID shall be set to the group ID of the parent directory or to the effective group ID of the process.
Implementations shall provide a way to initialize the FIFO's group ID to the group ID of the parent directory.
Implementations may, but need not, provide an implementation-defined way to initialize the FIFO's group ID to the effective group ID of the calling process.
Upon successful completion, mkfifo() shall mark for update the last data access, last data modification, and last file status change timestamps of the file.
Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.
Predefined variables are typically used to set permission modes.
You can bytewise-OR together these variables to to create the most common permissions mode:
User: R_USR (read), W_USR (write), X_USR(execute) Group: R_GRP (read), W_GRP (write), X_GRP(execute) Others: R_OTH (read), W_OTH (write), X_OTH(execute)Additionally, some shortcuts are provided (basically a bitwise-OR combination of the above):
Read + Write + Execute: RWX_U (User), RWX_G (Group), RWX_O (Others) DEFFILEMODE: Equivalent of 0666 =rw-rw-rw- ACCESSPERMS: Equivalent of 0777 = rwxrwxrwxTherefore, to give only the user rwx (read+write+execute) rights whereas group members and others may not do anything, you can use any of the following mkfifo() calls equivalently:
ierr= mkfifo("myfile", IANY([R_USR, W_USR, X_USR])); ierr= mkfifo("myfile", RWX_U);In order to give anyone any rights (mode 0777 = rwxrwxrwx), you can use any of the following calls equivalently:
ierr= mkfifo("myfile",IANY([R_USR,W_USR,X_USR,R_GRP,W_GRP,X_GRP,R_OTH,W_OTH,X_OTH])); ierr= mkfifo("myfile",IANY([RWX_U,RWX_G,RWX_O])); ierr= mkfifo("myfile",ACCESSPERMS);
RETURN VALUE
Upon successful completion, return 0. Otherwise, return -1 and set errno to indicate the error. If -1 is returned, no FIFO is created.
EXAMPLES
The following example shows how to create a FIFO file named /home/cnd/mod_done, with read/write permissions for owner, and with read permissions for group and others.program demo_system_mkfifo use M_system, only : system_mkfifo, system_perror use M_system, only : R_GRP,R_OTH,R_USR,RWX_G,RWX_O use M_system, only : RWX_U,W_GRP,W_OTH,W_USR,X_GRP,X_OTH,X_USR use M_system, only : DEFFILEMODE, ACCESSPERMS implicit none integer :: status status = system_mkfifo("/tmp/buffer", IANY([W_USR, R_USR, R_GRP, R_OTH])) if(status.ne.0)then call system_perror('*mkfifo* error:') endif end program demo_system_mkfifoNow some other process (or this one) can read from /tmp/buffer while this program is running or after, consuming the data as it is read.
NAME
system_opendir(3f) - [M_system] open directory stream by calling opendir(3c) (LICENSE:PD)
SYNOPSIS
subroutine system_opendir(dirname,dir,ierr)
character(len=*), intent(in) :: dirname type(c_ptr) :: dir integer,intent(out) :: ierr
DESCRIPTION
The system_opendir(3f) procedure opens a directory stream corresponding to the directory named by the dirname argument. The directory stream is positioned at the first entry.
RETURN VALUE
Upon successful completion, a pointer to a C dir type is returned. Otherwise, these functions shall return a null pointer and set IERR to indicate the error.
ERRORS
An error corresponds to a condition described in opendir(3c):
EACCES Search permission is denied for the component of the path prefix of dirname or read permission is denied for dirname. ELOOP A loop exists in symbolic links encountered during resolution of the dirname argument. ENAMETOOLONG The length of a component of a pathname is longer than {NAME_MAX}. ENOENT A component of dirname does not name an existing directory or dirname is an empty string. ENOTDIR A component of dirname names an existing file that is neither a directory nor a symbolic link to a directory. ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the dirname argument. EMFILE All file descriptors available to the process are currently open. ENAMETOOLONG The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}. ENFILE Too many files are currently open in the system.
APPLICATION USAGE
The opendir() function should be used in conjunction with readdir(), closedir(), and rewinddir() to examine the contents of the directory (see the EXAMPLES section in readdir()). This method is recommended for portability.
OPTIONS
dirname name of directory to open a directory stream for
RETURNS
dir pointer to directory stream. If an error occurred, it will not be associated. ierr 0 indicates no error occurred
EXAMPLE
Sample program:program demo_system_opendir use M_system, only : system_opendir,system_readdir use M_system, only : system_closedir use iso_c_binding implicit none type(c_ptr) :: dir character(len=:),allocatable :: filename integer :: ierr !--- open directory stream to read from call system_opendir('.',dir,ierr) if(ierr.eq.0)then !--- read directory stream do call system_readdir(dir,filename,ierr) if(filename.eq.' ')exit write(*,*)filename enddo endif !--- close directory stream call system_closedir(dir,ierr) end program demo_system_opendir
NAME
system_perm(3f) - [M_system] get file type and permission as a string (LICENSE:PD)
SYNOPSIS
function system_perm(mode) result (perms)
integer(kind=int64),intent(in) :: MODE character(len=:),allocatable :: PERMS
DESCRIPTION
The system_perm(3f) function returns a string containing the type and permission of a file implied by the value of the mode value.
RETURN VALUE
PERMS returns the permission string in a format similar to that used by Unix commands such as ls(1).
EXAMPLE
Sample program:program demo_system_perm use M_system, only : system_perm, system_stat use,intrinsic :: iso_fortran_env, only : int64 implicit none character(len=4096) :: string integer(kind=int64) :: values(13) integer :: ierr character(len=:),allocatable :: perms values=0 call get_command_argument(1, string) ! get pathname from command line call system_stat(string,values,ierr) ! get pathname information if(ierr.eq.0)then perms=system_perm(values(3)) ! convert permit mode to a string ! print permits as a string, decimal value, and octal value write(*,'("for ",a," permits[",a,"]",1x,i0,1x,o0)') & trim(string),perms,values(3),values(3) endif end program demo_system_permResults:
demo_system_perm /tmp
for /tmp permits[drwxrwxrwx --S] 17407 41777
NAME
perror(3f) - [M_system] print error message for last C error on stderr (LICENSE:PD)
SYNOPSIS
subroutine system_perror(prefix)
character(len=*),intent(in) :: prefix
DESCRIPTION
Use system_perror(3f) to print an error message on stderr corresponding to the current value of the C global variable errno. Unless you use NULL as the argument prefix, the error message will begin with the prefix string, followed by a colon and a space (:). The remainder of the error message produced is one of the strings described for strerror(3c).
EXAMPLE
Sample program:program demo_system_perror use M_system, only : system_perror,system_rmdir implicit none character(len=:),allocatable :: DIRNAME DIRNAME='/NOT/THERE/OR/ANYWHERE' ! generate an error with a routine that supports errno and perror(3c) if(system_rmdir(DIRNAME).ne.0)then call system_perror('*demo_system_perror*:'//DIRNAME) endif write(*,'(a)')"That's all Folks!" end program demo_system_perrorExpected results:
*demo_system_perror*:/NOT/THERE/OR/ANYWHERE: No such file or directory That's all Folks!
NAME
system_putenv(3f) - [M_system:ENVIRONMENT] set environment variable from Fortran by calling putenv(3c) (LICENSE:PD)
SYNOPSIS
subroutine system_putenv(string, err)
character(len=*),intent(in) :: string integer, optional, intent(out) :: err
DESCRIPTION
The system_putenv() function adds or changes the value of environment variables.
OPTIONS
string string of format "NAME=value". If name does not already exist in the environment, then string is added to the environment. If name does exist, then the value of name in the environment is changed to value. The string passed to putenv(3c) becomes part of the environment, so this routine creates a string each time it is called that increases the amount of memory the program uses. err The system_putenv() function returns zero on success, or nonzero if an error occurs. A non-zero error usually indicates sufficient memory does not exist to store the variable.
EXAMPLE
Sample setting an environment variable from Fortran:program demo_system_putenv use M_system, only : system_putenv use iso_c_binding implicit none integer :: ierr ! write(*,'(a)')'no environment variables containing "GRU":' call execute_command_line('env|grep GRU') ! call system_putenv('GRU=this is the value',ierr) write(*,'(a,i0)')'now "GRU" should be defined: ',ierr call execute_command_line('env|grep GRU') ! call system_putenv('GRU2=this is the second value',ierr) write(*,'(a,i0)')'now "GRU" and "GRU2" should be defined: ',ierr call execute_command_line('env|grep GRU') ! call system_putenv('GRU2',ierr) call system_putenv('GRU',ierr) write(*,'(a,i0)')'should be gone, varies with different putenv(3c): ',ierr call execute_command_line('env|grep GRU') write(*,'(a)')'system_unsetenv(3f) is a better way to remove variables' ! end program demo_system_putenvResults:
no environment variables containing "GRU": now "GRU" should be defined: 0 GRU=this is the value now "GRU" and "GRU2" should be defined: 0 GRU2=this is the second value GRU=this is the value should be gone, varies with different putenv(3c): 0 system_unsetenv(3f) is a better way to remove variables
NAME
system_readdir(3f) - [M_system] read a directory using readdir(3c) (LICENSE:PD)
SYNOPSIS
subroutine system_readdir(dir,filename,ierr)
type(c_ptr),value :: dir character(len=:),intent(out),allocatable :: filename integer,intent(out) :: ierr
DESCRIPTION
system_readdir(3f) returns the name of the directory entry at the current position in the directory stream specified by the argument DIR, and positions the directory stream at the next entry. It returns a null name upon reaching the end of the directory stream.
OPTIONS
DIR A pointer to the directory opened by system_opendir(3f).
RETURNS
FILENAME the name of the directory entry at the current position in the directory stream specified by the argument DIR, and positions the directory stream at the next entry. The readdir() function does not return directory entries containing empty names. If entries for dot or dot-dot exist, one entry is returned for dot and one entry is returned for dot-dot.
The entry is marked for update of the last data access timestamp each time it is read.
reaching the end of the directory stream, the name is a blank name.
IERR If IERR is set to non-zero on return, an error occurred.
EXAMPLE
Sample program:program demo_system_readdir use M_system, only : system_opendir,system_readdir use M_system, only : system_rewinddir,system_closedir use iso_c_binding implicit none
type(c_ptr) :: dir character(len=:),allocatable :: filename integer :: i, ierr !--- open directory stream to read from call system_opendir('.',dir,ierr) if(ierr.eq.0)then !--- read directory stream twice do i=1,2 write(*,'(a,i0)')'PASS ',i do call system_readdir(dir,filename,ierr) if(filename.eq.' ')exit write(*,*)filename enddo call system_rewinddir(dir) enddo endif !--- close directory stream call system_closedir(dir,ierr)
end program demo_system_readdir
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_readenvSample results:
USERDOMAIN_ROAMINGPROFILE=buzz HOMEPATH=\Users\JSU APPDATA=C:\Users\JSU\AppData\Roaming MANPATH=/home/urbanjs/V600/LIBRARY/libGPF/download/tmp/man:/home/urbanjs/V600/doc/man::: DISPLAYNUM=0 ProgramW6432=C:\Program Files HOSTNAME=buzz XKEYSYMDB=/usr/share/X11/XKeysymDB PUBLISH_CMD= OnlineServices=Online Services : : :
NAME
system_realpath(3f) - [M_system] call realpath(3c) to resolve a pathname (LICENSE:PD)
SYNOPSIS
function system_realpath(input) result(output)
character(len=*),intent(in) :: input character(len=:),allocatable :: output
DESCRIPTION
system_realpath(3f) calls the C routine realpath(3c) to obtain the absolute pathname of given path
OPTIONS
INPUT pathname to resolve
RETURN VALUE
OUTPUT The absolute pathname of the given input pathname. The pathname shall contain no components that are dot or dot-dot, or are symbolic links. It is equal to the NULL character if an error occurred.
EXAMPLE
Sample program:Example usage:program demo_system_realpath use M_system, only : system_realpath, system_perror implicit none ! resolve each pathname given on command line character(len=:),allocatable :: pathi,patho integer :: i integer :: filename_length do i = 1, command_argument_count() ! get pathname from command line arguments call get_command_argument (i , length=filename_length) allocate(character(len=filename_length) :: pathi) call get_command_argument (i , value=pathi) ! ! resolve each pathname patho=system_realpath(pathi) if(patho.ne.char(0))then write(*,*)trim(pathi),'=>',trim(patho) else call system_perror('*system_realpath* error for pathname '//trim(pathi)//':') write(*,*)trim(pathi),'=>',trim(patho) endif deallocate(pathi) enddo ! if there were no pathnames give resolve the pathname "." if(i.eq.1)then patho=system_realpath('.') write(*,*)'.=>',trim(patho) endif end program demo_system_realpath
demo_system_realpath .=>/home/urbanjs/V600
cd /usr/share/man demo_system_realpath . .. NotThere .=>/usr/share/man ..=>/usr/share *system_realpath* error for pathname NotThere:: No such file or directory NotThere=>NotThere
NAME
system_remove(3f) - [M_system] call remove(3c) to remove file (LICENSE:PD)
SYNOPSIS
function system_remove(path) result(err)
character(*),intent(in) :: path integer(c_int) :: err
DESCRIPTION
Fortran supports scratch files via the OPEN(3c) command; but does not otherwise allow for removing files. The system_remove(3f) command allows for removing files by name that the user has the authority to remove by calling the C remove(3c) function.
EXAMPLE
Sample program:program demo_system_remove use M_system, only : system_remove character(len=*),parameter :: FILE='MyJunkFile.txt' integer :: ierr write(*,*)'BEFORE CREATED '//FILE call execute_command_line('ls -l '//FILE) write(*,*)Expected Results:
! note intentionally causes error if file exists open(unit=10,file=FILE,status='NEW') write(*,*)'AFTER OPENED '//FILE call execute_command_line('ls -l '//FILE) write(*,*)
write(10,'(a)') 'This is a file I want to delete' close(unit=10) write(*,*)'AFTER CLOSED ' call execute_command_line('ls -l '//FILE) write(*,*)
ierr=system_remove(FILE) write(*,*)'AFTER REMOVED',IERR call execute_command_line('ls -l '//FILE) write(*,*)
end program demo_system_remove
> BEFORE CREATED MyJunkFile.txt > ls: cannot access 'MyJunkFile.txt': No such file or directory > > AFTER OPENED MyJunkFile.txt > -rw-r--r-- 1 JSU None 0 Nov 19 19:32 MyJunkFile.txt > > AFTER CLOSED > -rw-r--r-- 1 JSU None 32 Nov 19 19:32 MyJunkFile.txt > > AFTER REMOVED 0 > ls: cannot access 'MyJunkFile.txt': No such file or directory
NAME
system_rename(3f) - [M_system] call rename(3c) to rename a system file (LICENSE:PD)
SYNOPSIS
function system_rename(input,output) result(ierr)
character(*),intent(in) :: input,output integer :: ierr
DESCRIPTION
Rename a file by calling rename(3c). It is not recommended that the rename occur while either filename is being used on a file currently OPEN(3f) by the program.Both the old and new names must be on the same device.
OPTIONS
INPUT system filename of an existing file to rename OUTPUT system filename to be created or overwritten by INPUT file. Must be on the same device as the INPUT file.
RETURNS
IERR zero (0) if no error occurs. If not zero a call to system_errno(3f) or system_perror(3f) is supported to diagnose error
EXAMPLE
Sample program:Expected output:program demo_system_rename use M_system, only : system_rename use M_system, only : system_remove use M_system, only : system_perror implicit none character(len=256) :: string integer :: ios, ierr
! try to remove junk files just in case ierr=system_remove('_scratch_file_') write(*,'(a,i0)') 'should not be zero ',ierr call system_perror('*demo_system_rename*') ierr=system_remove('_renamed_scratch_file_') write(*,'(a,i0)') 'should not be zero ',ierr call system_perror('*demo_system_rename*')
! create scratch file to rename open(unit=10,file='_scratch_file_',status='new') write(10,'(a)') 'Test by renaming "_scratch_file_" to "_renamed_scratch_file_"' write(10,'(a)') 'IF YOU SEE THIS ON OUTPUT THE RENAME WORKED' close(10) ! rename scratch file ierr=system_rename('_scratch_file_','_renamed_scratch_file_') if(ierr.ne.0)then write(*,*)'ERROR RENAMING FILE ',ierr endif ! read renamed file open(unit=11,file='_renamed_scratch_file_',status='old') INFINITE: do read(11,'(a)',iostat=ios)string if(ios.ne.0)exit INFINITE write(*,'(a)')trim(string) enddo INFINITE close(unit=11)
! clean up ierr=system_remove('_scratch_file_') write(*,'(a,i0)') 'should not be zero ',ierr ierr=system_remove('_renamed_scratch_file_') write(*,'(a,i0)') 'should be zero ',ierr
end program demo_system_rename
> should not be zero -1 > *demo_system_rename*: No such file or directory > should not be zero -1 > *demo_system_rename*: No such file or directory > Test by renaming "_scratch_file_" to "_renamed_scratch_file_" > IF YOU SEE THIS ON OUTPUT THE RENAME WORKED > should not be zero -1 > should be zero 0
NAME
system_rewinddir(3f) - [M_system] call rewinddir(3c) to rewind directory stream (LICENSE:PD)
SYNOPSIS
subroutine system_rewinddir(dir)
type(c_ptr),value :: dir
DESCRIPTION
Return to pointer to the beginning of the list for a currently open directory list.
OPTIONS
DIR A C_pointer assumed to have been allocated by a call to SYSTEM_OPENDIR(3f).
EXAMPLE
Sample program:program demo_system_rewinddir use M_system, only : system_opendir,system_readdir use M_system, only : system_rewinddir,system_closedir use iso_c_binding implicit none
type(c_ptr) :: dir character(len=:),allocatable :: filename integer :: i, ierr !>>> open directory stream to read from call system_opendir('.',dir,ierr) !>>> read directory stream twice do i=1,2 write(*,'(a,i0)')'PASS ',i do call system_readdir(dir,filename,ierr) if(filename.eq.' ')exit write(*,*)filename enddo !>>> rewind directory stream call system_rewinddir(dir) enddo !>>> close directory stream call system_closedir(dir,ierr)
end program demo_system_rewinddir
NAME
system_rmdir(3f) - [M_system] call rmdir(3c) to remove empty directories (LICENSE:PD)
SYNOPSIS
function system_rmdir(dirname) result(err)
character(*),intent(in) :: dirname integer(c_int) :: err
DESCRIPTION
DIRECTORY The name of a directory to remove if it is empty err zero (0) if no error occurred
EXAMPLE
Sample program:program demo_system_rmdir use M_system, only : system_perror use M_system, only : system_rmdir, system_mkdir use M_system, only : RWX_U implicit none integer :: ierr write(*,*)'BEFORE TRY TO CREATE _scratch/' call execute_command_line('ls -ld _scratch')Expected output:
write(*,*)'TRY TO CREATE _scratch/' ierr=system_mkdir('_scratch',RWX_U) write(*,*)'IERR=',ierr call execute_command_line('ls -ld _scratch')
write(*,*)'TRY TO REMOVE _scratch/' ierr=system_rmdir('_scratch') write(*,*)'IERR=',ierr call execute_command_line('ls -ld _scratch')
write(*,*)'TRY TO REMOVE _scratch when it should be gone/' ierr=system_rmdir('_scratch') call system_perror('*test of system_rmdir*') write(*,*)'IERR=',ierr call execute_command_line('ls -ld _scratch')
end program demo_system_rmdir
NAME
system_setsid(3f) - [M_system:QUERY] create session and set the process group ID of a session leader (LICENSE:PD)
SYNOPSIS
integer(kind=c_int) function system_setsid(pid) integer(kind=c_int) :: pid
DESCRIPTION
The setsid() function creates a new session, if the calling process is not a process group leader. Upon return the calling process shall be the session leader of this new session, shall be the process group leader of a new process group, and shall have no controlling terminal. The process group ID of the calling process shall be set equal to the process ID of the calling process. The calling process shall be the only process in the new process group and the only process in the new session.
RETURN VALUE
Upon successful completion, setsid() shall return the value of the new process group ID of the calling process. Other†wise, it shall return âˆ'1 and set errno to indicate the error.
ERRORS
The setsid() function shall fail if:
o The calling process is already a process group leader o the process group ID of a process other than the calling process matches the process ID of the calling process.
EXAMPLE
Set SID from Fortranprogram demo_system_setsid use M_system, only : system_setsid implicit none write(*,*)'SID=',system_setsid() end program demo_system_setsid
NAME
system_setumask(3f) - [M_system] set the file mode creation umask (LICENSE:PD)
SYNOPSIS
integer function system_setumask(new_umask) result (old_umask)
integer,intent(in) :: new_umask integer(kind=c_int) :: umask_c
DESCRIPTION
The system_umask(3f) function sets the file mode creation mask of the process to cmask and return the previous value of the mask. Only the file permission bits of cmask (see <sys/stat.h>) are used; the meaning of the other bits is implementation-defined.The file mode creation mask of the process is used to turn off permission bits in the mode argument supplied during calls to the following functions:
* open(), openat(), creat(), mkdir(), mkdirat(), mkfifo(), and mkfifoat() * mknod(), mknodat() * mq_open() * sem_open() Bit positions that are set in cmask are cleared in the mode of the created file.
RETURN VALUE
The file permission bits in the value returned by umask() shall be the previous value of the file mode creation mask. The state of any other bits in that value is unspecified, except that a subsequent call to umask() with the returned value as cmask shall leave the state of the mask the same as its state before the first call, including any unspecified use of those bits.
ERRORS
No errors are defined.
EXAMPLE
Sample programprogram demo_setumask use M_system, only : system_getumask, system_setumask integer :: newmask integer :: i integer :: old_umask write(*,101)(system_getumask(),i=1,4) 101 format(1x,i0,1x,"O'",o4.4,"'",1x,'Z"',z0,"'",1x,"B'",b12.12,"'") newmask=63 old_umask=system_setumask(newmask) write(*,*)'NEW' write(*,101)(system_getumask(),i=1,4) end program demo_setumaskExpected output
18 O'022' Z"12' B'000010010"
NEW
63 O'077' Z"3F' B'000111111"
NAME
SYSTEM_STAT - [M_system] Get file status information (LICENSE:PD)
SYNTAX
CALL SYSTEM_STAT(NAME, VALUES [, STATUS],[DEBUG])character(len=*),intent(in) :: NAME integer(kind=int64),intent(out) :: values(13) integer,optional,intent(out) :: status integer,intent(in) :: debug
DESCRIPTION
This function returns information about a file. No permissions are required on the file itself, but execute (search) permission is required on all of the directories in path that lead to the file. The elements that are obtained and stored in the array VALUES:
VALUES(1) Device ID VALUES(2) Inode number VALUES(3) File mode VALUES(4) Number of links VALUES(5) Owner's uid VALUES(6) Owner's gid VALUES(7) ID of device containing directory entry for file (0 if not available) VALUES(8) File size (bytes) VALUES(9) Last access time as a Unix Epoch time rounded to seconds VALUES(10) Last modification time as a Unix Epoch time rounded to seconds VALUES(11) Last file status change time as a Unix Epoch time rounded to seconds VALUES(12) Preferred I/O block size (-1 if not available) VALUES(13) Number of blocks allocated (-1 if not available)Not all these elements are relevant on all systems. If an element is not relevant, it is returned as 0.
OPTIONS
NAME The type shall be CHARACTER, of the default kind and a valid path within the file system. VALUES The type shall be INTEGER(8), DIMENSION(13). STATUS (Optional) status flag of type INTEGER(4). Returns 0 on success and a system specific error code otherwise. DEBUG (Optional) print values being returned from C routine being called if value of 0 is used
EXAMPLE
program demo_system_statuse M_system, only : system_stat, system_getpwuid, system_getgrgid use M_time, only : fmtdate, u2d use, intrinsic :: iso_fortran_env, only : int32, int64 implicit noneResults:
integer(kind=int64) :: buff(13) integer(kind=int32) :: status character(len=*),parameter :: fmt_date='year-month-day hour:minute:second'
integer(kind=int64) :: & Device_ID, Inode_number, File_mode, Number_of_links, Owner_uid, & Owner_gid, Directory_device, File_size, Last_access, Last_modification, & Last_status_change, Preferred_block_size, Number_of_blocks_allocated equivalence & ( buff(1) , Device_ID ) , & ( buff(2) , Inode_number ) , & ( buff(3) , File_mode ) , & ( buff(4) , Number_of_links ) , & ( buff(5) , Owner_uid ) , & ( buff(6) , Owner_gid ) , & ( buff(7) , Directory_device ) , & ( buff(8) , File_size ) , & ( buff(9) , Last_access ) , & ( buff(10) , Last_modification ) , & ( buff(11) , Last_status_change ) , & ( buff(12) , Preferred_block_size ) , & ( buff(13) , Number_of_blocks_allocated )
CALL SYSTEM_STAT("/etc/hosts", buff, status)
if (status == 0) then write (*, FMT="('Device ID(hex/decimal):', & & T30, Z0,'h/',I0,'d')") buff(1),buff(1) write (*, FMT="('Inode number:', & & T30, I0)") buff(2) write (*, FMT="('File mode (octal):', & & T30, O19)") buff(3) write (*, FMT="('Number of links:', & & T30, I0)") buff(4) write (*, FMT="('Owner''s uid/username:', & & T30, I0,1x, A)") buff(5), system_getpwuid(buff(5)) write (*, FMT="('Owner''s gid/group:', & & T30, I0,1x, A)") buff(6), system_getgrgid(buff(6)) write (*, FMT="('Device where located:', & & T30, I0)") buff(7) write (*, FMT="('File size(bytes):', & & T30, I0)") buff(8) write (*, FMT="('Last access time:', & & T30, I0,1x, A)") buff(9), fmtdate(u2d(int(buff(9))),fmt_date) write (*, FMT="('Last modification time:', & & T30, I0,1x, A)") buff(10),fmtdate(u2d(int(buff(10))),fmt_date) write (*, FMT="('Last status change time:', & & T30, I0,1x, A)") buff(11),fmtdate(u2d(int(buff(11))),fmt_date) write (*, FMT="('Preferred block size(bytes):', & & T30, I0)") buff(12) write (*, FMT="('No. of blocks allocated:', & & T30, I0)") buff(13) endif
end program demo_system_stat
Device ID(hex/decimal): 3E6BE045h/1047257157d Inode number: 1407374886070599 File mode (octal): 100750 Number of links: 1 Owner's uid/username: 18 SYSTEM Owner's gid/group: 18 SYSTEM Device where located: 0 File size(bytes): 824 Last access time: 1557983191 2019-05-16 01:06:31 Last modification time: 1557983191 2019-05-16 01:06:31 Last status change time: 1557983532 2019-05-16 01:12:12 Preferred block size(bytes): 65536 No. of blocks allocated: 4
NAME
system_uname(3f) - [M_system] call a C wrapper that calls uname(3c) to get current system information from Fortran (LICENSE:PD)
SYNOPSIS
subroutine system_uname(WHICH,NAMEOUT)
character(KIND=C_CHAR),intent(in) :: WHICH character(len=*),intent(out) :: NAMEOUT
DESCRIPTION
Given a letter, return a corresponding description of the current operating system. The NAMEOUT variable is assumed sufficiently large enough to hold the value.
s return the kernel name r return the kernel release v return the kernel version n return the network node hostname m return the machine hardware name T test mode -- print all information, in the following order - srvnm
EXAMPLE
Call uname(3c) from Fortranprogram demo_system_uname use M_system, only : system_uname implicit none integer,parameter :: is=100 integer :: i character(len=*),parameter :: letters='srvnmxT' character(len=is) :: string=' '
do i=1,len(letters) write(*,'(80("="))') call system_uname(letters(i:i),string) write(*,*)'=====> TESTING system_uname('//letters(i:i)//')--->'//trim(string) enddo
end program demo_system_uname
NAME
system_unlink(3f) - [M_system] remove a directory entry relative to directory file descriptor (LICENSE:PD)
SYNOPSIS
integer function unlink(path);
character(len=*) :: path
DESCRIPTION
The unlink() function shall remove a link to a file. If path names a symbolic link, unlink() shall remove the symbolic link named by path and shall not affect any file or directory named by the contents of the symbolic link. Otherwise, unlink() shall remove the link named by the pathname pointed to by path and shall decrement the link count of the file referenced by the link.When the file's link count becomes 0 and no process has the file open, the space occupied by the file shall be freed and the file shall no longer be accessible. If one or more processes have the file open when the last link is removed, the link shall be removed before unlink() returns, but the removal of the file contents shall be postponed until all references to the file are closed.
The path argument shall not name a directory unless the process has appropriate privileges and the implementation supports using unlink() on directories.
Upon successful completion, unlink() shall mark for update the last data modification and last file status change timestamps of the parent directory. Also, if the file's link count is not 0, the last file status change timestamp of the file shall be marked for update.
Values for flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in <fcntl.h>:
AT_REMOVEDIR
Remove the directory entry specified by fd and path as a directory, not a normal file.
RETURN VALUE
Upon successful completion, these functions shall return 0. Otherwise, these functions shall return -1 and set errno to indicate the error. If -1 is returned, the named file shall not be changed.
EXAMPLES
Removing a link to a fileprogram demo_system_unlink use M_system, only : system_unlink, system_perror integer :: ierr ierr = system_unlink('myfile1') if(ierr.ne.0)then call system_perror('*demo_system_unlink*') endif end program demo_system_unlink
NAME
system_unsetenv(3f) - [M_system:ENVIRONMENT] delete an environment variable by calling unsetenv(3c) (LICENSE:PD)
SYNOPSIS
subroutine system_unsetenv(name,ierr)
character(len=*),intent(in) :: name integer,intent(out),optional :: ierr
DESCRIPTION
The system_unsetenv(3f) function deletes the variable name from the environment.
OPTIONS
name name of variable to delete. If name does not exist in the environment, then the function succeeds, and the environment is unchanged. ierr The system_unsetenv(3f) function returns zero on success, or -1 on error. name is NULL, points to a string of length 0, or contains an '=' character. Insufficient memory to add a new variable to the environment.
EXAMPLE
Sample program:program demo_system_unsetenv use M_system, only : system_unsetenv, system_putenv implicit none call system_putenv('GRU=this is the value') write(*,'(a)')'The variable GRU should be set' call execute_command_line('env|grep GRU') call system_unsetenv('GRU') write(*,'(a)')'The variable GRU should not be set' call execute_command_line('env|grep GRU') end program demo_system_unsetenv
NAME
system_utime(3f) - [M_system] set file access and modification times (LICENSE:PD)
SYNOPSIS
function utime(pathname,times)
character(len=*),intent(in) :: pathname integer,intent(in),optional :: times(2) logical :: utime
DESCRIPTION
The system_utime(3f) function sets the access and modification times of the file named by the path argument by calling utime(3c).If times() is not present the access and modification times of the file shall be set to the current time.
To use system_utime(3f) the effective user ID of the process must match the owner of the file, or the process has to have write permission to the file or has appropriate privileges,
OPTIONS
times If present, the values will be interpreted as the access and modification times as Unix Epoch values. That is, they are times measured in seconds since the Unix Epoch. pathname name of the file whose access and modification times are to be updated.
RETURN VALUE
Upon successful completion .TRUE. is returned. Otherwise, and the file times remain unaffected.
ERRORS
The underlying utime(3c) function fails if:
EACCES Search permission is denied by a component of the path prefix; or the times argument is a null pointer and the effective user ID of the process does not match the owner of the file, the process does not have write permission for the file, and the process does not have appropriate privileges. ELOOP A loop exists in symbolic links encountered during resolution of the path argument. ENAMETOOLONG The length of a component of a pathname is longer than {NAME_MAX}. ENOENT A component of path does not name an existing file or path is an empty string. ENOTDIR A component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory, or the path argument contains at least one non-<slash> character and ends with one or more trailing <slash> characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory. EPERM The times argument is not a null pointer and the effective user ID of the calling process does not match the owner of the file and the calling process does not have appropriate privileges. EROFS The file system containing the file is read-only.
The utime() function may fail if:
ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument.
ENAMETOOLONG The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}.
EXAMPLES
Sample programprogram demo_system_utime use M_system, only : system_utime, system_perror use M_time, only : d2u implicit none character(len=4096) :: pathname integer :: times(2) integer :: i do i=1,command_argument_count() call get_command_argument(i, pathname) if(.not.system_utime(pathname,times))then call system_perror('*demo_system_utime*') endif enddo end program demo_system_utime