home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / chmod.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  3KB  |  94 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #define _KERNEL
  21. #include "ixemul.h"
  22. #include "kprintf.h"
  23. #include "multiuser.h"
  24.  
  25. /* not static because also used in nodspecial.c */
  26. int
  27. __chmod_func (struct StandardPacket *sp, struct MsgPort *handler,
  28.               BPTR parent_lock,
  29.           BSTR name,
  30.           int mask, int *no_error)
  31. {
  32.   sp->sp_Pkt.dp_Type = ACTION_SET_PROTECT;
  33.   sp->sp_Pkt.dp_Arg1 = 0;
  34.   sp->sp_Pkt.dp_Arg2 = parent_lock;
  35.   sp->sp_Pkt.dp_Arg3 = name;
  36.   sp->sp_Pkt.dp_Arg4 = mask;
  37.   
  38.   PutPacket (handler, sp);
  39.   __wait_sync_packet (sp);
  40.   
  41.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  42.   return 1;
  43. }
  44.  
  45.  
  46. int
  47. chmod(const char *name, mode_t mode)
  48. {
  49.   long amiga_mode = FIBF_READ|FIBF_WRITE|FIBF_DELETE|FIBF_EXECUTE;
  50.   /* RWED-permissions are "lo-active", if cleared they allow the operation */
  51.   int result;
  52.  
  53.   if (mode & S_IXUSR) amiga_mode &= ~FIBF_EXECUTE;
  54.   if (mode & S_IWUSR) amiga_mode &= ~(FIBF_WRITE|FIBF_DELETE);
  55.   if (mode & S_IRUSR) amiga_mode &= ~FIBF_READ;
  56. #ifdef FIBF_GRP_EXECUTE
  57.   if (mode & S_IXGRP) amiga_mode |= FIBF_GRP_EXECUTE;
  58.   if (mode & S_IWGRP) amiga_mode |= FIBF_GRP_WRITE|FIBF_GRP_DELETE;
  59.   if (mode & S_IRGRP) amiga_mode |= FIBF_GRP_READ;
  60.   if (mode & S_IXOTH) amiga_mode |= FIBF_OTR_EXECUTE;
  61.   if (mode & S_IWOTH) amiga_mode |= FIBF_OTR_WRITE|FIBF_OTR_DELETE;
  62.   if (mode & S_IROTH) amiga_mode |= FIBF_OTR_READ;
  63. #endif
  64.   if (mode & S_ISTXT) amiga_mode |= FIBF_HOLD;
  65.   if (mode & S_ISUID) amiga_mode |= muFIBF_SET_UID;
  66.   if (mode & S_ISGID) amiga_mode |= muFIBF_SET_GID;
  67.  
  68.   result = __plock (name, __chmod_func, (void *)amiga_mode);
  69.   if (result == 0)
  70.     {
  71.       errno = __ioerr_to_errno (IoErr ());
  72.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  73.     }
  74.  
  75.   return result == -1 ? 0 : -1;
  76. }
  77.  
  78.  
  79. /* a signal proof SetProtection(), nothing more ;-) */
  80. int
  81. achmod (char *name, int mode)
  82. {
  83.   int result;
  84.  
  85.   result = __plock (name, __chmod_func, (void *)mode) == -1 ? 0 : -1;
  86.   if (result == 0)
  87.     {
  88.       errno = __ioerr_to_errno (IoErr ());
  89.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  90.     }
  91.  
  92.   return result;
  93. }
  94.