home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / chmod.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  3.2 KB  |  148 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.2;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.2
  10. date    92.05.18.12.19.34;    author mwild;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.05.14.19.55.40;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @change protection bits of file, achmod() is a SetProtection() replacement
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @now completely ignore FIBF_DELETE, correctly set errno in case of failure
  28. @
  29. text
  30. @/*
  31.  *  This file is part of ixemul.library for the Amiga.
  32.  *  Copyright (C) 1991, 1992  Markus M. Wild
  33.  *
  34.  *  This library is free software; you can redistribute it and/or
  35.  *  modify it under the terms of the GNU Library General Public
  36.  *  License as published by the Free Software Foundation; either
  37.  *  version 2 of the License, or (at your option) any later version.
  38.  *
  39.  *  This library is distributed in the hope that it will be useful,
  40.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  41.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  42.  *  Library General Public License for more details.
  43.  *
  44.  *  You should have received a copy of the GNU Library General Public
  45.  *  License along with this library; if not, write to the Free
  46.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47.  *
  48.  *  $Id: chmod.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  49.  *
  50.  *  $Log: chmod.c,v $
  51.  * Revision 1.1  1992/05/14  19:55:40  mwild
  52.  * Initial revision
  53.  *
  54.  */
  55.  
  56. #define KERNEL
  57. #include "ixemul.h"
  58.  
  59. #if __GNUC__ != 2
  60. #define alloca __builtin_alloca
  61. #endif
  62.  
  63. static int
  64. __chmod_func (struct StandardPacket *sp, struct MsgPort *handler,
  65.               BPTR parent_lock,
  66.           BSTR name,
  67.           int mask, int *no_error)
  68. {
  69.   sp->sp_Pkt.dp_Type = ACTION_SET_PROTECT;
  70.   sp->sp_Pkt.dp_Arg1 = 0;
  71.   sp->sp_Pkt.dp_Arg2 = parent_lock;
  72.   sp->sp_Pkt.dp_Arg3 = name;
  73.   sp->sp_Pkt.dp_Arg4 = mask;
  74.   
  75.   PutPacket (handler, sp);
  76.   __wait_sync_packet (sp);
  77.   
  78.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  79.   return 1;
  80. }
  81.  
  82.  
  83. int
  84. chmod(char *name, int mode)
  85. {
  86.   long amiga_mode = FIBF_READ|FIBF_WRITE|FIBF_EXECUTE;
  87.   /* RWED-permissions are "lo-active", if cleared they allow the operation */
  88.   int result;
  89.  
  90.   if (mode & S_IXUSR) amiga_mode &= ~FIBF_EXECUTE;
  91.   if (mode & S_IWUSR) amiga_mode &= ~FIBF_WRITE;
  92.   if (mode & S_IRUSR) amiga_mode &= ~FIBF_READ;
  93.  
  94.   result = __plock (name, __chmod_func, amiga_mode);
  95.   if (result == 0)
  96.     errno = __ioerr_to_errno (IoErr ());
  97.  
  98.   return result == -1 ? 0 : -1;
  99. }
  100.  
  101.  
  102. /* a signal proof SetProtection(), nothing more ;-) */
  103. int
  104. achmod (char *name, int mode)
  105. {
  106.   int result;
  107.  
  108.   result = __plock (name, __chmod_func, mode) == -1 ? 0 : -1;
  109.   if (result == 0)
  110.     errno = __ioerr_to_errno (IoErr ());
  111.  
  112.   return result;
  113. }
  114. @
  115.  
  116.  
  117. 1.1
  118. log
  119. @Initial revision
  120. @
  121. text
  122. @d19 1
  123. a19 1
  124.  *  $Id$
  125. d21 4
  126. a24 1
  127.  *  $Log$
  128. d57 1
  129. a57 1
  130.   long amiga_mode = FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE;
  131. d62 1
  132. a62 1
  133.   if (mode & S_IWUSR) amiga_mode &= ~(FIBF_WRITE|FIBF_DELETE);
  134. a63 8
  135. #if 0
  136.   /* sigh.. this causes unfixable problems, if a unix program reads
  137.      stat(), and then keeps the bits it gets, you can't remove a
  138.      delete protection once set when omitting write permission.. */
  139.  
  140.   /* let a set sticky-bit mean that delete-permission is not granted */
  141.   if (mode & S_ISVTX) amiga_mode |= FIBF_DELETE;
  142. #endif
  143. d66 2
  144. d77 7
  145. a83 1
  146.   return __plock (name, __chmod_func, mode) == -1 ? 0 : -1;
  147. @
  148.