Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

CHMOD

Portability Function: Changes the access mode of a file.

Module

USE IFPORT

result = CHMOD (name,mode)

name

(Input) Character*(*). Name of the file whose access mode is to be changed. Must have a single path.

mode

(Input) Character*(*). File permission: either Read, Write, or Execute. The mode parameter can be either symbolic or absolute. An absolute mode is specified with an octal number, consisting of any combination of the following permission bits ORed together:

Permission bit

Description

Action

4000

Set user ID on execution

W*S: Ignored; never true

L*X, M*X: Settable

2000

Set group ID on execution

W*S: Ignored; never true

L*X, M*X: Settable

1000

Sticky bit

W*S: Ignored; never true

L*X, M*X: Settable

0400

Read by owner

W*S: Ignored; always true

L*X, M*X: Settable

0200

Write by owner

Settable

0100

Execute by owner

W*S: Ignored; based on file name extension

L*X, M*X: Settable

0040, 0020, 0010

Read, Write, Execute by group

W*S: Ignored; assumes owner permissions

L*X, M*X: Settable

0004, 0002, 0001

Read, Write, Execute by others

W*S: Ignored; assumes owner permissions

L*X, M*X: Settable

The following regular expression represents a symbolic mode:

[ugoa]*[+-=] [rwxXst]* 

On Windows* systems, "[ugoa]*" is ignored. On Linux* and macOS systems, a combination of the letters "ugoa" control which users' access to the file will be changed:

u

The user who owns the file

g

Other users in the group that owns the file

o

Other users not in the group that owns the file

a

All users

"[+ - =]" indicates the operation to carry out:

+

Add the permission

-

Remove the permission

=

Absolutely set the permission

"[rwxXst]*" indicates the permission to add, subtract, or set. On Windows systems, only "w" is significant and affects write permission; all other letters are ignored. On Linux and macOS systems, all letters are significant.

Results

The result type is INTEGER(4). It is zero if the mode was changed successfully; otherwise, an error code. Possible error codes are:

  • ENOENT: The specified file was not found.

  • EINVAL: The mode argument is invalid.

  • EPERM: Permission denied; the file's mode cannot be changed.

Example
USE IFPORT
integer(4) I,Istatus
I = ACCESS ("DATAFILE.TXT", "w")
if (i) then
   ISTATUS = CHMOD ("datafile.txt", "[+w]")
end if
I = ACCESS ("DATAFILE.TXT","w")
print *, i

See Also