158f0484fSRodney W. Grimes.\" Copyright (c) 1989, 1991, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 658f0484fSRodney W. Grimes.\" are met: 758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 858f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1058f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1158f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 12fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 1358f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1458f0484fSRodney W. Grimes.\" without specific prior written permission. 1558f0484fSRodney W. Grimes.\" 1658f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1758f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1858f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1958f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2058f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2158f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2258f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2358f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2458f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2558f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2658f0484fSRodney W. Grimes.\" SUCH DAMAGE. 2758f0484fSRodney W. Grimes.\" 28*ab9ef34eSBrooks Davis.Dd July 18, 2019 2958f0484fSRodney W. Grimes.Dt SETMODE 3 3058f0484fSRodney W. Grimes.Os 3158f0484fSRodney W. Grimes.Sh NAME 3258f0484fSRodney W. Grimes.Nm getmode , 3358f0484fSRodney W. Grimes.Nm setmode 3458f0484fSRodney W. Grimes.Nd modify mode bits 3525bb73e0SAlexey Zelkin.Sh LIBRARY 3625bb73e0SAlexey Zelkin.Lb libc 3758f0484fSRodney W. Grimes.Sh SYNOPSIS 3832eef9aeSRuslan Ermilov.In unistd.h 3958f0484fSRodney W. Grimes.Ft mode_t 4058f0484fSRodney W. Grimes.Fn getmode "const void *set" "mode_t mode" 41d1084925SJoerg Wunsch.Ft void * 4258f0484fSRodney W. Grimes.Fn setmode "const char *mode_str" 4358f0484fSRodney W. Grimes.Sh DESCRIPTION 4458f0484fSRodney W. GrimesThe 4558f0484fSRodney W. Grimes.Fn getmode 4658f0484fSRodney W. Grimesfunction 4758f0484fSRodney W. Grimesreturns a copy of the file permission bits 4858f0484fSRodney W. Grimes.Fa mode 4958f0484fSRodney W. Grimesas altered by the values pointed to by 5058f0484fSRodney W. Grimes.Fa set . 5158f0484fSRodney W. GrimesWhile only the mode bits are altered, other parts of the file mode 5258f0484fSRodney W. Grimesmay be examined. 5358f0484fSRodney W. Grimes.Pp 5458f0484fSRodney W. GrimesThe 5558f0484fSRodney W. Grimes.Fn setmode 5658f0484fSRodney W. Grimesfunction 5758f0484fSRodney W. Grimestakes an absolute (octal) or symbolic value, as described in 5858f0484fSRodney W. Grimes.Xr chmod 1 , 5958f0484fSRodney W. Grimesas an argument 6058f0484fSRodney W. Grimesand returns a pointer to mode values to be supplied to 6158f0484fSRodney W. Grimes.Fn getmode . 6258f0484fSRodney W. GrimesBecause some of the symbolic values are relative to the file 6358f0484fSRodney W. Grimescreation mask, 6458f0484fSRodney W. Grimes.Fn setmode 6558f0484fSRodney W. Grimesmay call 6658f0484fSRodney W. Grimes.Xr umask 2 . 6758f0484fSRodney W. GrimesIf this occurs, the file creation mask will be restored before 6858f0484fSRodney W. Grimes.Fn setmode 6958f0484fSRodney W. Grimesreturns. 7058f0484fSRodney W. GrimesIf the calling program changes the value of its file creation mask 7158f0484fSRodney W. Grimesafter calling 7258f0484fSRodney W. Grimes.Fn setmode , 7358f0484fSRodney W. Grimes.Fn setmode 7458f0484fSRodney W. Grimesmust be called again if 7558f0484fSRodney W. Grimes.Fn getmode 7658f0484fSRodney W. Grimesis to modify future file modes correctly. 7758f0484fSRodney W. Grimes.Pp 7858f0484fSRodney W. GrimesIf the mode passed to 7958f0484fSRodney W. Grimes.Fn setmode 8081e4e6a2SWarner Loshis invalid or if memory cannot be allocated for the return value, 8158f0484fSRodney W. Grimes.Fn setmode 8258f0484fSRodney W. Grimesreturns 8358f0484fSRodney W. Grimes.Dv NULL . 8481e4e6a2SWarner Losh.Pp 8581e4e6a2SWarner LoshThe value returned from 8681e4e6a2SWarner Losh.Fn setmode 8781e4e6a2SWarner Loshis obtained from 8881e4e6a2SWarner Losh.Fn malloc 8981e4e6a2SWarner Loshand should be returned to the system with 9081e4e6a2SWarner Losh.Fn free 9181e4e6a2SWarner Loshwhen the program is done with it, generally after a call to 9281e4e6a2SWarner Losh.Fn getmode . 9358f0484fSRodney W. Grimes.Sh ERRORS 9458f0484fSRodney W. GrimesThe 9558f0484fSRodney W. Grimes.Fn setmode 9658f0484fSRodney W. Grimesfunction 9758f0484fSRodney W. Grimesmay fail and set errno for any of the errors specified for the library 9858f0484fSRodney W. Grimesroutine 99e382e86bSPedro F. Giffuni.Xr malloc 3 100e382e86bSPedro F. Giffunior 101e382e86bSPedro F. Giffuni.Xr strtol 3 . 102e382e86bSPedro F. GiffuniIn addition, 103e382e86bSPedro F. Giffuni.Fn setmode 104e382e86bSPedro F. Giffuniwill fail and set 105e382e86bSPedro F. Giffuni.Va errno 106e382e86bSPedro F. Giffunito: 107e382e86bSPedro F. Giffuni.Bl -tag -width Er 108e382e86bSPedro F. Giffuni.It Bq Er EINVAL 109e382e86bSPedro F. GiffuniThe 110e382e86bSPedro F. Giffuni.Fa mode 111e382e86bSPedro F. Giffuniargument does not represent a valid mode. 112e382e86bSPedro F. Giffuni.El 11358f0484fSRodney W. Grimes.Sh SEE ALSO 11458f0484fSRodney W. Grimes.Xr chmod 1 , 11558f0484fSRodney W. Grimes.Xr stat 2 , 11658f0484fSRodney W. Grimes.Xr umask 2 , 11758f0484fSRodney W. Grimes.Xr malloc 3 11858f0484fSRodney W. Grimes.Sh HISTORY 11958f0484fSRodney W. GrimesThe 12058f0484fSRodney W. Grimes.Fn getmode 12158f0484fSRodney W. Grimesand 12258f0484fSRodney W. Grimes.Fn setmode 1237bdf80e5SMike Pritchardfunctions first appeared in 1247bdf80e5SMike Pritchard.Bx 4.4 . 125*ab9ef34eSBrooks Davis.Sh BUGS 126*ab9ef34eSBrooks DavisThe 127*ab9ef34eSBrooks Davis.Fn setmode 128*ab9ef34eSBrooks Davisfunction is not thread safe. 129*ab9ef34eSBrooks DavisFiles created in other threads while 130*ab9ef34eSBrooks Davis.Fn setmode 131*ab9ef34eSBrooks Davisis being called may be created with a umask of 0. 132