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

ID 767251
Date 3/22/2024
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

Windows: Ignored; never true

Linux: Settable

2000

Set group ID on execution

Windows: Ignored; never true

Linux: Settable

1000

Sticky bit

Windows: Ignored; never true

Linux: Settable

0400

Read by owner

Windows: Ignored; always true

Linux: Settable

0200

Write by owner

Settable

0100

Execute by owner

Windows: Ignored; based on file name extension

Linux: Settable

0040, 0020, 0010

Read, Write, Execute by group

Windows: Ignored; assumes owner permissions

Linux: Settable

0004, 0002, 0001

Read, Write, Execute by others

Windows: Ignored; assumes owner permissions

Linux: Settable

The following regular expression represents a symbolic mode:

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

On Windows* systems, "[ugoa]*" is ignored. On Linux* 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 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