Rework the text to make it clearer; it was really pretty confusing before.
Add an example; note some bugs/shortcomings. Bump date.
This commit is contained in:
parent
8f5f9030b6
commit
6557571403
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: setmode.3,v 1.18 2005/10/01 20:08:01 christos Exp $
|
||||
.\" $NetBSD: setmode.3,v 1.19 2009/01/04 07:54:15 dholland Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1989, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -29,7 +29,7 @@
|
||||
.\"
|
||||
.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95
|
||||
.\"
|
||||
.Dd October 1, 2005
|
||||
.Dd January 4, 2009
|
||||
.Dt SETMODE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -40,34 +40,40 @@
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In unistd.h
|
||||
.Ft mode_t
|
||||
.Fn getmode "const void *set" "mode_t mode"
|
||||
.Ft void *
|
||||
.Fn setmode "const char *mode_str"
|
||||
.Ft mode_t
|
||||
.Fn getmode "const void *set" "mode_t mode"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn setmode
|
||||
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
|
||||
.Fn getmode .
|
||||
The string may be an numeric (octal) or symbolic string of the form
|
||||
accepted by
|
||||
.Xr chmod 1 ,
|
||||
and may represent either an exact mode to set or a change to make to
|
||||
the existing mode.
|
||||
.Pp
|
||||
The
|
||||
.Fn getmode
|
||||
function
|
||||
returns a copy of the file permission bits
|
||||
adjusts the file permission bits given by
|
||||
.Fa mode
|
||||
as altered by the values pointed to by
|
||||
.Fa set .
|
||||
While only the mode bits are altered, other parts of the file mode
|
||||
may be examined.
|
||||
according to the compiled change representation
|
||||
.Fa set ,
|
||||
and returns the adjusted mode.
|
||||
While only the permission bits are altered, other parts of the file
|
||||
mode, particularly the type, may be examined.
|
||||
.Pp
|
||||
The
|
||||
.Fn setmode
|
||||
function
|
||||
takes an absolute (octal) or symbolic value, as described in
|
||||
.Xr chmod 1 ,
|
||||
as an argument
|
||||
and returns a pointer to mode values to be supplied to
|
||||
.Fn getmode .
|
||||
Because some of the symbolic values are relative to the file
|
||||
creation mask,
|
||||
Because some of the possible symbolic values are defined relative to
|
||||
the file creation mask,
|
||||
.Fn setmode
|
||||
may call
|
||||
.Xr umask 2 .
|
||||
.Xr umask 2 ,
|
||||
temporarily changing the mask.
|
||||
If this occurs, the file creation mask will be restored before
|
||||
.Fn setmode
|
||||
returns.
|
||||
@ -75,7 +81,7 @@ If the calling program changes the value of its file creation mask
|
||||
after calling
|
||||
.Fn setmode ,
|
||||
.Fn setmode
|
||||
must be called again if
|
||||
must be called again to recompile the mode string if
|
||||
.Fn getmode
|
||||
is to modify future file modes correctly.
|
||||
.Pp
|
||||
@ -85,6 +91,19 @@ is invalid,
|
||||
.Fn setmode
|
||||
returns
|
||||
.Dv NULL .
|
||||
.Sh EXAMPLES
|
||||
The effects of the shell command
|
||||
.Ql "chmod a+x myscript.sh"
|
||||
can be duplicated as follows:
|
||||
.Bd -literal -offset indent
|
||||
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);
|
||||
.Ed
|
||||
.Sh ERRORS
|
||||
The
|
||||
.Fn setmode
|
||||
@ -118,3 +137,14 @@ and
|
||||
.Fn setmode
|
||||
functions first appeared in
|
||||
.Bx 4.4 .
|
||||
.Sh BUGS
|
||||
Each call to
|
||||
.Nm setmode
|
||||
allocates a small amount of memory that there is no correct way to
|
||||
free.
|
||||
.Pp
|
||||
The type of
|
||||
.Fa set
|
||||
should really be some opaque struct type used only by these functions
|
||||
rather than
|
||||
.Ft void * .
|
||||
|
Loading…
Reference in New Issue
Block a user