home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 18
/
aminetcdnumber181997.iso
/
Aminet
/
dev
/
gcc
/
ixemulsrc.lha
/
ixemul
/
library
/
chown.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-11
|
2KB
|
73 lines
/*
* This file is part of ixemul.library for the Amiga.
* Copyright (C) 1991, 1992 Markus M. Wild
* Portions Copyright (C) 1994 Rafael W. Luebbert
* Portions Copyright (C) 1996 Jeff Shepherd
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define _KERNEL
#include "ixemul.h"
#include "kprintf.h"
#include <stdlib.h>
int
__chown_func (struct StandardPacket *sp, struct MsgPort *handler,
BPTR parent_lock,
BSTR name,
int ugid, int *no_error)
{
sp->sp_Pkt.dp_Type = ACTION_SET_OWNER;
sp->sp_Pkt.dp_Arg1 = 0;
sp->sp_Pkt.dp_Arg2 = parent_lock;
sp->sp_Pkt.dp_Arg3 = name;
sp->sp_Pkt.dp_Arg4 = ugid;
PutPacket (handler, sp);
__wait_sync_packet (sp);
*no_error = sp->sp_Pkt.dp_Res1 == -1;
return 1;
}
int
chown(const char *name, uid_t uid, gid_t gid)
{
int user;
int result;
struct stat stb;
if (syscall (SYS_lstat, name, &stb) == -1) return -1;
if (stb.st_mode & 0600)
{
if (syscall (SYS_chmod, name, stb.st_mode & ~0176000) == -1) return -1;
}
if (uid == (uid_t)(-1)) uid = stb.st_uid;
if (gid == (gid_t)(-1)) gid = stb.st_gid;
user = (__unix2amigaid(uid) << 16) | __unix2amigaid(gid);
result = __plock(name,__chown_func, (void *)user);
if (result == 0)
{
errno = __ioerr_to_errno (IoErr ());
KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
}
return result == -1 ? 0 : -1;
}