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

  1. head    1.3;
  2. access;
  3. symbols
  4.     version39-41:1.2;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.3
  10. date    92.08.09.20.43.22;    author amiga;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    92.05.22.01.45.51;    author mwild;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    92.05.14.19.55.40;    author mwild;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @change CD to specified path
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @change to use 2.x header files by default
  33. @
  34. text
  35. @/*
  36.  *  This file is part of ixemul.library for the Amiga.
  37.  *  Copyright (C) 1991, 1992  Markus M. Wild
  38.  *
  39.  *  This library is free software; you can redistribute it and/or
  40.  *  modify it under the terms of the GNU Library General Public
  41.  *  License as published by the Free Software Foundation; either
  42.  *  version 2 of the License, or (at your option) any later version.
  43.  *
  44.  *  This library is distributed in the hope that it will be useful,
  45.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  46.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  47.  *  Library General Public License for more details.
  48.  *
  49.  *  You should have received a copy of the GNU Library General Public
  50.  *  License along with this library; if not, write to the Free
  51.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  52.  *
  53.  *  $Id: chdir.c,v 1.2 1992/05/22 01:45:51 mwild Exp $
  54.  *
  55.  *  $Log: chdir.c,v $
  56.  *  Revision 1.2  1992/05/22  01:45:51  mwild
  57.  *  remove ix_panic call, seems to happen more than I thought
  58.  *
  59.  * Revision 1.1  1992/05/14  19:55:40  mwild
  60.  * Initial revision
  61.  *
  62.  */
  63.  
  64. #define KERNEL
  65. #include "ixemul.h"
  66.  
  67. #ifdef DEBUG
  68. #define DP(a) kprintf a
  69. #else
  70. #define DP(a)
  71. #endif
  72.  
  73. extern int _dos20;
  74.  
  75. /* if we change our directory, we have to remember the original cd, when
  76.  * the process was started, because we're not allowed to unlock this
  77.  * lock, since we didn't obtain it. */
  78. /* BPTR __startup_cd = -1; */
  79. #define __startup_cd (u.u_startup_cd)
  80.  
  81. int
  82. chdir (char *path)
  83. {
  84.   BPTR oldlock, newlock;
  85.   int error;
  86.   int omask;
  87.   
  88.   /* Sigh... CurrentDir() is a DOS-library function, it would probably be
  89.    * ok to just use pr_CurrentDir, but alas, this way we're conformant to
  90.    * programming style guidelines, but we pay the overhead of locking dosbase
  91.    */
  92.   omask = syscall (SYS_sigsetmask, ~0);
  93.  
  94.   newlock = __lock (path, ACCESS_READ);
  95.  
  96.   if (newlock)
  97.     {
  98.       oldlock = CurrentDir (newlock);
  99.       if (__startup_cd == (BPTR)-1) __startup_cd = oldlock;
  100.       else __unlock (oldlock);
  101.  
  102.       /* this one is for Mike B. Smith ;-) */
  103.       if (_dos20)
  104.     {
  105.       /* kmalloc is lots cheaper than malloc */
  106.       char *buf = (char *) kmalloc (MAXPATHLEN);
  107.       if (buf)
  108.         {
  109.           /* NOTE: this shortcuts any symlinks. But then, Unix does the
  110.            *       same, and a shell that wants to smart about symlinks,
  111.            *       has to track chdir()s itself as well */
  112.           if (NameFromLock (newlock, buf, MAXPATHLEN))
  113.             if (!SetCurrentDirName (buf))
  114. #if 0
  115.           /* annoyed people... */
  116.               ix_panic ("chdir: couldn't set current directory name!");
  117. #else
  118.           ;
  119. #endif
  120.           kfree (buf);
  121.         }
  122.       /* but no matter what happened above, I consider the chdir() to have
  123.        * succeeded, whether the stored name is correct or not. */
  124.     }
  125.       syscall (SYS_sigsetmask, omask);
  126.       return 0;
  127.     }
  128.   error = __ioerr_to_errno (IoErr ());
  129.  
  130.   syscall (SYS_sigsetmask, omask);
  131.   errno = error;
  132.   return -1;
  133. }
  134. @
  135.  
  136.  
  137. 1.2
  138. log
  139. @remove ix_panic call, seems to happen more than I thought
  140. @
  141. text
  142. @d19 1
  143. a19 1
  144.  *  $Id: chdir.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  145. d22 3
  146. a37 41
  147.  
  148. #define BASE_EXT_DECL
  149. #define BASE_PAR_DECL    
  150. #define BASE_PAR_DECL0    
  151. #define BASE_NAME    ix.ix_dos_base
  152. __inline static LONG NameFromLock(BASE_PAR_DECL BPTR lock, UBYTE* buffer, long int len)
  153. {
  154.     BASE_EXT_DECL
  155.     register LONG res __asm("d0");
  156.     register void *a6 __asm ("a6");
  157.     register BPTR d1 __asm("d1");
  158.     register UBYTE* d2 __asm("d2");
  159.     register long int d3 __asm("d3");
  160.  
  161.     a6 = BASE_NAME;
  162.     d1 = lock;
  163.     d2 = buffer;
  164.     d3 = len;
  165.     __asm volatile ("
  166.     jsr a6@@(-0x192)"
  167.     : "=r" (res)
  168.     : "r" (a6), "r" (d1), "r" (d2), "r" (d3)
  169.     : "d0", "d1", "a0", "a1", "d2", "d3");
  170.     return res;
  171. }
  172. __inline static BOOL SetCurrentDirName(BASE_PAR_DECL UBYTE* name)
  173. {
  174.     BASE_EXT_DECL
  175.     register BOOL res __asm("d0");
  176.     register void *a6 __asm ("a6");
  177.     register UBYTE* d1 __asm("d1");
  178.  
  179.     a6 = BASE_NAME;
  180.     d1 = name;
  181.     __asm volatile ("
  182.     jsr a6@@(-0x22e)"
  183.     : "=r" (res)
  184.     : "r" (a6), "r" (d1)
  185.     : "d0", "d1", "a0", "a1");
  186.     return res;
  187. }
  188. @
  189.  
  190.  
  191. 1.1
  192. log
  193. @Initial revision
  194. @
  195. text
  196. @d19 1
  197. a19 1
  198.  *  $Id$
  199. d21 4
  200. a24 1
  201.  *  $Log$
  202. d118 2
  203. d121 3
  204. @
  205.