Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/l/lchown.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/l/lchown.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/l/lchown.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/l/lchown.html on line 8
Change the user ID and group ID of a file or symbolic link
#include <sys/types.h>
#include <unistd.h>
int lchown( const char * path,
uid_t owner,
gid_t group );
- path
- The name of the file whose ownership you want to change.
- owner
- The user ID of the new owner.
- group
- The group ID of the new owner.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The lchown() function changes the user ID and group ID of the
file specified by path to be the numeric values contained in
owner and group, respectively.
It's similar to
chown(),
except in the case where
the named file is a symbolic link.
In this case, lchown() changes the ownership of the symbolic link file itself,
while chown() changes the ownership of the file or directory
to which the symbolic link refers.
Only processes with an effective user ID equal to the user ID of the
file or with appropriate privileges (for example, the superuser) may change
the ownership of a file.
In QNX Neutrino, the _POSIX_CHOWN_RESTRICTED flag is enforced.
This means that only the superuser may change the ownership of a file.
The group of a file may be changed by the superuser, or
also by a process with the effective user ID equal to the user ID of
the file, if (and only if) owner is equal to the user ID of
the file and group is equal to the effective group ID of the calling process.
If the path argument refers to a regular file, the
set-user-ID (S_ISUID) and set-group-ID
(S_ISGID)
bits of the file mode are cleared, if the function is successful.
If lchown() succeeds, the st_ctime field of the file is marked for update.
- 0
- Success.
- -1
- An error occurred (errno is set).
- EACCES
- Search permission is denied on a component of the path prefix.
- ELOOP
- Too many levels of symbolic links or prefixes.
- ENAMETOOLONG
- The length of the path string exceeds
PATH_MAX, or a pathname component is longer than
NAME_MAX.
- ENOENT
- A component of the path prefix doesn't exist,
or the path arguments points to an empty string.
- ENOSYS
- The lchown() function isn't implemented for the filesystem specified in path.
- ENOTDIR
- A component of the path prefix isn't a directory.
- EPERM
- The effective user ID does not match the owner of the file, or the
calling process does not have appropriate privileges.
- EROFS
- The named file resides on a read-only filesystem.
/*
* Change the ownership of a list of files
* to the current user/group
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main( int argc, char **argv )
{
int i;
int ecode = 0;
for( i = 1; i < argc; i++ ) {
if( lchown( argv[i], getuid(), getgid() ) == -1 ) {
perror( argv[i] );
ecode++;
}
}
return( ecode );
}
POSIX 1003.1 XSI
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
chmod(),
chown(),
errno,
fchown(),
fstat(),
open(),
stat()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/l/lchown.html on line 247
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/l/lchown.html on line 247