Portability Function: Changes the access mode of a file.
Module: USE IFPORT
Syntax
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*32, W*64: Ignored; never true L*X, M*X: Settable |
2000 | Set group ID on execution | W*32, W*64: Ignored; never true L*X, M*X: Settable |
1000 | Sticky bit | W*32, W*64: Ignored; never true L*X, M*X: Settable |
0400 | Read by owner | W*32, W*64: Ignored; always true L*X, M*X: Settable |
0200 | Write by owner | Settable |
0100 | Execute by owner | W*32, W*64: Ignored; based on file name extension L*X, M*X: Settable |
0040, 0020, 0010 | Read, Write, Execute by group | W*32, W*64: Ignored; assumes owner permissions L*X, M*X: Settable |
0004, 0002, 0001 | Read, Write, Execute by others | W*32, W*64: Ignored; assumes owner permissions L*X, M*X: Settable |
The following regular expression represents a symbolic mode:
[ugoa]*[+-=] [rwxXst]*
"[ugoa]*" is ignored on Windows* systems. On Linux* and Mac OS* 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 Mac OS 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:
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also
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