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

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @remove file
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50.  
  51. #if __GNUC__ != 2
  52. #define alloca __builtin_alloca
  53. #endif
  54.  
  55. static int
  56. __delete_func (struct StandardPacket *sp, struct MsgPort *handler,
  57.                BPTR parent_lock,
  58.            BSTR name,
  59.            void *dummy, int *no_error)
  60. {
  61.   sp->sp_Pkt.dp_Type = ACTION_DELETE_OBJECT;
  62.   sp->sp_Pkt.dp_Arg1 = parent_lock;
  63.   sp->sp_Pkt.dp_Arg2 = name;
  64.  
  65.   PutPacket (handler, sp);
  66.   __wait_sync_packet (sp);
  67.  
  68.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  69.  
  70.   /* stop if we failed because of symlink - reference */
  71.   return 0;
  72. }
  73.  
  74. int
  75. unlink (char *name)
  76. {
  77.   int err, i;
  78.   struct file **fp;
  79.   int result;
  80.  
  81.   result = 0;
  82.  
  83.   /* first try to normally delete the file, if we get an
  84.    * 'object in use' error, we'll try another way out.. */
  85.   if (__plock (name, __delete_func, 0)) goto ret;
  86.  
  87.   /* so there was an error.. */
  88.   err = IoErr();
  89.   if (err == ERROR_OBJECT_IN_USE)
  90.     {
  91.       /* check whether the name is an absolute filename, if yes, we
  92.        * can walk thru our filetab to see, whether WE have this file
  93.        * open, and set its unlink-flag, if not, return the error */
  94.  
  95.       /* if we fully and consistent allow Unix-pathnames, we can test
  96.        * for a leading '/' too. */
  97.       if (index(name, ':') || (ix.ix_translate_slash && name[1] && name[0] == '/'))
  98.     {
  99.       for (fp = u.u_ofile, i=0; i < NOFILE; i++, fp++)
  100.         if (*fp && (*fp)->f_name && !strcmp((*fp)->f_name, name))
  101.           {
  102.         (*fp)->f_flags |= FUNLINK;
  103.         goto ret;
  104.           }
  105.     }
  106.     }
  107.   errno = __ioerr_to_errno(err);
  108.   result = -1;
  109.  
  110. ret:
  111.   return result;
  112. }
  113. @
  114.