Manpages - setmode.3bsd

(See

for include usage.)

The

function accepts a string representation of a file mode change, compiles it to binary form, and returns an abstract representation that may be passed to

The string may be an numeric (octal) or symbolic string of the form accepted by

and may represent either an exact mode to set or a change to make to the existing mode.

The

function adjusts the file permission bits given by

according to the compiled change representation

and returns the adjusted mode. While only the permission bits are altered, other parts of the file mode, particularly the type, may be examined.

Because some of the possible symbolic values are defined relative to the file creation mask,

may call

temporarily changing the mask. If this occurs, the file creation mask will be restored before

returns. If the calling program changes the value of its file creation mask after calling

must be called again to recompile the mode string if

is to modify future file modes correctly.

If the mode passed to

is invalid,

returns

The value returned from

is obtained from

and should be returned to the system with

when the program is done with it, generally after a call to

The effects of the shell command

can be duplicated as follows:

const char *file = “myscript.sh”; struct stat st; mode_t newmode;

stat(file, st); newmode = getmode(setmode(“a+x”), st.st_mode); chmod(file, newmode);

The

function may fail and set

for any of the errors specified for the library routines

or

In addition,

will fail and set

to:

The

argument does not represent a valid mode.

The

and

functions first appeared in

The type of

should really be some opaque struct type used only by these functions rather than

Author: dt

Created: 2022-02-20 Sun 20:00