home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
MISC
/
chown.c
< prev
next >
Wrap
C/C++ Source or Header
|
2009-11-06
|
2KB
|
78 lines
/*
* c h o w n . c
*
* Creation Date: 03-July-1991 by trn@warper.jhuapl.edu <Tony Nardo>
* Last Modified:
*
* Change file ownership #. Somewhat dissimilar to UNIX in that it
* forces group *and* file ownership to change, but I wanted to keep
* this simple.
*
* This software has been tested on an MVME147 OSK (Microware) system
* implementing OS-9 level 2.
*
* No warranty expressed or implied. :-)
*/
#include <strings.h>
#define HELP "usage: chown group#.user# file [file2...]\n"
main( argc, argv )
register int argc;
register char **argv;
{
unsigned long owner;
unsigned short gid, uid;
register int i, error;
register char *dot;
/*
* Must be sufficiently privileged to use chown.
*/
owner = getuid();
if( owner & 0xffff0000 ) {
printf( "No permission to use chown\n" );
exit( 0 );
}
/*
* Too few arguments will force a HELP message.
*/
if( argc < 3 ) {
printf( HELP );
exit( 0 );
}
/*
* Lack of a "." in the "GID.UID" field will also force HELP.
*/
dot = index( argv[1], '.' );
if( ! dot ) {
printf( HELP );
exit( 0 );
}
/*
* Extract the GID and UID. Don't bother with sanity checks.
*/
*dot = 0; /* erase period to terminate GID */
dot++; /* and look beyond it for UID */
uid = atoi( dot ); /* get UID, GID */
gid = atoi( argv[1] );
owner = ( gid << 16 ) | uid; /* OS9 format owner # format */
/*
* All seems OK, go ahead and try to change ownerships!
*/
i = 2;
do {
error = chown( argv[ i ], owner );
if( error ) {
printf( "chown: %s: No such file or directory\n",
argv[ i ] );
}
} while( ++i < argc );
}