Updated: April 19, 2023 |
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 );
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.
/* * 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 ); }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |