head	1.4;
access;
symbols
	version39-45:1.3
	version39-41:1.2;
locks;
comment	@ *  @;


1.4
date	94.06.19.15.09.10;	author rluebbert;	state Exp;
branches;
next	1.3;

1.3
date	92.08.09.20.43.22;	author amiga;	state Exp;
branches;
next	1.2;

1.2
date	92.05.22.01.45.51;	author mwild;	state Exp;
branches;
next	1.1;

1.1
date	92.05.14.19.55.40;	author mwild;	state Exp;
branches;
next	;


desc
@change CD to specified path
@


1.4
log
@*** empty log message ***
@
text
@/*
 *  This file is part of ixemul.library for the Amiga.
 *  Copyright (C) 1991, 1992  Markus M. Wild
 *  Portions Copyright (C) 1994 Rafael W. Luebbert
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Id: chdir.c,v 1.2 1992/05/22 01:45:51 mwild Exp $
 *
 *  $Log: chdir.c,v $
 *  Revision 1.2  1992/05/22  01:45:51  mwild
 *  remove ix_panic call, seems to happen more than I thought
 *
 * Revision 1.1  1992/05/14  19:55:40  mwild
 * Initial revision
 *
 */

#define KERNEL
#include "ixemul.h"

#ifdef DEBUG
#define DP(a) KPrintF a
#else
#define DP(a)
#endif


/* if we change our directory, we have to remember the original cd, when
 * the process was started, because we're not allowed to unlock this
 * lock, since we didn't obtain it. */
/* BPTR __startup_cd = -1; */
#define __startup_cd (u.u_startup_cd)

int
chdir (char *path)
{
  BPTR oldlock, newlock;
  int error;
  int omask;
  char *buf = (char *) kmalloc (MAXPATHLEN);
  /* Sigh... CurrentDir() is a DOS-library function, it would probably be
   * ok to just use pr_CurrentDir, but alas, this way we're conformant to
   * programming style guidelines, but we pay the overhead of locking dosbase
   */
  omask = syscall (SYS_sigsetmask, ~0);

  newlock = __lock (path, ACCESS_READ);

  if (newlock)
    {
      oldlock = CurrentDir (newlock);
      if (__startup_cd == (BPTR)-1) __startup_cd = oldlock;
      else __unlock (oldlock);

      /* this one is for Mike B. Smith ;-) */
	  /* kmalloc is lots cheaper than malloc */
	  if (buf)
	    {
	      /* NOTE: This shortcuts any symlinks. But then, Unix does the
	       *       same, and a shell that wants to be smart about symlinks,
	       *       has to track chdir()s itself as well */
	      if (NameFromLock (newlock, buf, MAXPATHLEN))
	        SetCurrentDirName (buf);
	      kfree (buf);
	    }
	  /* but no matter what happened above, I consider the chdir() to have
	   * succeeded, whether the stored name is correct or not. */
      syscall (SYS_sigsetmask, omask);
      return 0;
    }
  error = __ioerr_to_errno (IoErr ());

  syscall (SYS_sigsetmask, omask);
  errno = error;
  return -1;
}
@


1.3
log
@change to use 2.x header files by default
@
text
@d4 1
d35 1
a35 1
#define DP(a) kprintf a
a39 1
extern int _dos20;
d53 1
a53 1
  
a68 2
      if (_dos20)
	{
a69 1
	  char *buf = (char *) kmalloc (MAXPATHLEN);
d72 2
a73 2
	      /* NOTE: this shortcuts any symlinks. But then, Unix does the
	       *       same, and a shell that wants to smart about symlinks,
d76 1
a76 7
	        if (!SetCurrentDirName (buf))
#if 0
		  /* annoyed people... */
	          ix_panic ("chdir: couldn't set current directory name!");
#else
		  ;
#endif
a80 1
	}
@


1.2
log
@remove ix_panic call, seems to happen more than I thought
@
text
@d19 1
a19 1
 *  $Id: chdir.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
d22 3
a37 41

#define BASE_EXT_DECL
#define BASE_PAR_DECL	
#define BASE_PAR_DECL0	
#define BASE_NAME	ix.ix_dos_base
__inline static LONG NameFromLock(BASE_PAR_DECL BPTR lock, UBYTE* buffer, long int len)
{
	BASE_EXT_DECL
	register LONG res __asm("d0");
	register void *a6 __asm ("a6");
	register BPTR d1 __asm("d1");
	register UBYTE* d2 __asm("d2");
	register long int d3 __asm("d3");

	a6 = BASE_NAME;
	d1 = lock;
	d2 = buffer;
	d3 = len;
	__asm volatile ("
	jsr a6@@(-0x192)"
	: "=r" (res)
	: "r" (a6), "r" (d1), "r" (d2), "r" (d3)
	: "d0", "d1", "a0", "a1", "d2", "d3");
	return res;
}
__inline static BOOL SetCurrentDirName(BASE_PAR_DECL UBYTE* name)
{
	BASE_EXT_DECL
	register BOOL res __asm("d0");
	register void *a6 __asm ("a6");
	register UBYTE* d1 __asm("d1");

	a6 = BASE_NAME;
	d1 = name;
	__asm volatile ("
	jsr a6@@(-0x22e)"
	: "=r" (res)
	: "r" (a6), "r" (d1)
	: "d0", "d1", "a0", "a1");
	return res;
}
@


1.1
log
@Initial revision
@
text
@d19 1
a19 1
 *  $Id$
d21 4
a24 1
 *  $Log$
d118 2
d121 3
@
