home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / __lock.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  3.7 KB  |  176 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. @Lock() replacement
  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. struct lock_vec {
  56.   int    mode;
  57.   int    resolve_last;
  58. #ifdef LOCK2
  59.   BPTR  *dup_parent;
  60.   char **base_name;
  61. #endif
  62. };
  63.  
  64. static int
  65. __lock_func (struct StandardPacket *sp, struct MsgPort *handler,
  66.              BPTR parent_lock,
  67.          BSTR name,
  68.          struct lock_vec *lv, int *no_error)
  69. {
  70.   sp->sp_Pkt.dp_Type = ACTION_LOCATE_OBJECT;
  71.   sp->sp_Pkt.dp_Arg1 = parent_lock;
  72.   sp->sp_Pkt.dp_Arg2 = name;
  73.   sp->sp_Pkt.dp_Arg3 = lv->mode;
  74.  
  75.   PutPacket (handler, sp);
  76.   __wait_sync_packet (sp);
  77.   
  78.   *no_error = sp->sp_Pkt.dp_Res1 > 0;
  79.   
  80. #ifdef LOCK2
  81.   if (*no_error && lv->dup_parent)
  82.     *lv->dup_parent = DupLock (parent_lock);
  83.   if (*no_error && lv->base_name)
  84.     {
  85.       u_char *tmp = BTOCPTR (name);
  86.     
  87.       *(lv->base_name) = syscall (SYS_malloc, tmp[0] + 1);
  88.       bcopy (tmp+1, *lv->base_name, tmp[0]);
  89.       (*(lv->base_name))[tmp[0]] = 0;
  90.     }
  91. #endif
  92.  
  93.   /* continue if we failed because of symlink - reference ? */
  94.   return lv->resolve_last;
  95. }
  96.  
  97. BPTR
  98. __lock (char *name, int mode)
  99. {
  100.   struct lock_vec lv;
  101.  
  102.   lv.mode = mode;
  103.   lv.resolve_last = 1;
  104. #ifdef LOCK2
  105.   lv.dup_parent = 0;
  106.   lv.base_name = 0;
  107. #endif
  108.   
  109.   return __plock (name, __lock_func, &lv);
  110. }
  111.  
  112. BPTR
  113. __llock (char *name, int mode)
  114. {
  115.   struct lock_vec lv;
  116.  
  117.   lv.mode = mode;
  118.   lv.resolve_last = 0;
  119. #ifdef LOCK2
  120.   lv.dup_parent = 0;
  121.   lv.base_name = 0;
  122. #endif
  123.  
  124.   return __plock (name, __lock_func, &lv);
  125. }
  126.  
  127. #ifdef LOCK2
  128. BPTR
  129. __lock2 (char *name, int mode, BPTR *parent_lock, char **base_name)
  130. {
  131.   struct lock_vec lv;
  132.   BPTR res;
  133.  
  134.   lv.mode = mode;
  135.   lv.resolve_last = 1;
  136.   lv.dup_parent = parent_lock;
  137.   lv.base_name  = base_name;
  138.   
  139.   res = __plock (name, __lock_func, &lv);
  140.   
  141. #if 0
  142.   /* disabled currently, because the only client was __load_seg(), and I
  143.    * did a cleaner solution by CurrentDir()'ing to the file itself. */
  144.  
  145.   if (res >= 0)
  146.     {
  147.       /* If you __lock2("device:file"), then you always get a parent lock
  148.        * of zero, which just means in this case, that the file is in the
  149.        * root directory of the file system. However, functions that use 
  150.        * __lock2() want to be able to CurrentDir to this lock, so 0 won't work.
  151.        * So if parent_lock is 0, and the specified file really is such a 
  152.        * one-level file, then we __lock() the device explicitly */
  153.  
  154.       if (parent_lock && !*parent_lock)
  155.     {
  156.       char *cp, c;
  157.       
  158.       cp = index (name, ':');
  159.       if (cp && !index (cp, '/'))    /* is it a first-level file ? */
  160.         {
  161.           cp++;
  162.           c = *cp;
  163.           *cp = 0;    /* temporarily terminate the string after the colon */
  164.           *parent_lock = __lock (name, ACCESS_READ);
  165.           *cp = c;
  166.         }
  167.     }
  168.     }
  169.  
  170. #endif
  171.  
  172.   return res;
  173. }
  174. #endif /* LOCK2 */
  175. @
  176.