libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]



#include <sys/stat.h>

int fchmod(int fd, mode_t mode);


This function changes the mode (writable or write-only) of the file opened under the file descriptor fd. The value of mode can be a combination of one or more of the S_I* constants described in the description of the chmod function (see section chmod).

Some S_I* constants are ignored for regular files:

fchmod will always succeed for character devices, but the mode will be ignored.

fchmod may not be able to change the mode of files that have been opened using low-level methods. High-level methods for opening files include the fopen (see section fopen) and open (see section open) functions. Low-level methods include the _open (see section _open) and _dos_open (see section _dos_open) functions. In particular, redirected handles cannot have their mode changed with fchmod.

fchmod may also not work as expected under DOS. For instance, if a file is opened as read-write, then changed to read-only with fchmod, but then written to, then the mode will not be changed.

This function can be hooked by File System Extensions (see section File System Extensions).

Return Value

Zero if the file exists and the mode was changed, else -1.


POSIX 1003.2-1992; 1003.1-2001


int fd;

fd = open("/tmp/dj.dat", O_RDWR);
fchmod(fd, S_IWUSR|S_IRUSR);

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004