head	1.2;
access;
symbols
	version39-41:1.2;
locks;
comment	@ *  @;


1.2
date	92.05.18.12.19.34;	author mwild;	state Exp;
branches;
next	1.1;

1.1
date	92.05.14.19.55.40;	author mwild;	state Exp;
branches;
next	;


desc
@change protection bits of file, achmod() is a SetProtection() replacement
@


1.2
log
@now completely ignore FIBF_DELETE, correctly set errno in case of failure
@
text
@/*
 *  This file is part of ixemul.library for the Amiga.
 *  Copyright (C) 1991, 1992  Markus M. Wild
 *
 *  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.
 *
 *  $Id: chmod.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
 *
 *  $Log: chmod.c,v $
 * Revision 1.1  1992/05/14  19:55:40  mwild
 * Initial revision
 *
 */

#define KERNEL
#include "ixemul.h"

#if __GNUC__ != 2
#define alloca __builtin_alloca
#endif

static int
__chmod_func (struct StandardPacket *sp, struct MsgPort *handler,
              BPTR parent_lock,
	      BSTR name,
	      int mask, int *no_error)
{
  sp->sp_Pkt.dp_Type = ACTION_SET_PROTECT;
  sp->sp_Pkt.dp_Arg1 = 0;
  sp->sp_Pkt.dp_Arg2 = parent_lock;
  sp->sp_Pkt.dp_Arg3 = name;
  sp->sp_Pkt.dp_Arg4 = mask;
  
  PutPacket (handler, sp);
  __wait_sync_packet (sp);
  
  *no_error = sp->sp_Pkt.dp_Res1 == -1;
  return 1;
}


int
chmod(char *name, int mode)
{
  long amiga_mode = FIBF_READ|FIBF_WRITE|FIBF_EXECUTE;
  /* RWED-permissions are "lo-active", if cleared they allow the operation */
  int result;

  if (mode & S_IXUSR) amiga_mode &= ~FIBF_EXECUTE;
  if (mode & S_IWUSR) amiga_mode &= ~FIBF_WRITE;
  if (mode & S_IRUSR) amiga_mode &= ~FIBF_READ;

  result = __plock (name, __chmod_func, amiga_mode);
  if (result == 0)
    errno = __ioerr_to_errno (IoErr ());

  return result == -1 ? 0 : -1;
}


/* a signal proof SetProtection(), nothing more ;-) */
int
achmod (char *name, int mode)
{
  int result;

  result = __plock (name, __chmod_func, mode) == -1 ? 0 : -1;
  if (result == 0)
    errno = __ioerr_to_errno (IoErr ());

  return result;
}
@


1.1
log
@Initial revision
@
text
@d19 1
a19 1
 *  $Id$
d21 4
a24 1
 *  $Log$
d57 1
a57 1
  long amiga_mode = FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE;
d62 1
a62 1
  if (mode & S_IWUSR) amiga_mode &= ~(FIBF_WRITE|FIBF_DELETE);
a63 8
#if 0
  /* sigh.. this causes unfixable problems, if a unix program reads
     stat(), and then keeps the bits it gets, you can't remove a
     delete protection once set when omitting write permission.. */

  /* let a set sticky-bit mean that delete-permission is not granted */
  if (mode & S_ISVTX) amiga_mode |= FIBF_DELETE;
#endif
d66 2
d77 7
a83 1
  return __plock (name, __chmod_func, mode) == -1 ? 0 : -1;
@
