cd_pwd.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Knowledge Ventures *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* cd [-LP] [dirname]
* cd [-LP] [old] [new]
* pwd [-LP]
*
* David Korn
* AT&T Labs
* research!dgk
*
*/
#include "defs.h"
#include <stak.h>
#include <error.h>
#include "variables.h"
#include "path.h"
#include "name.h"
#include "builtins.h"
#include <ls.h>
#include <ctype.h>
#ifdef PATH_BFPATH
/*
* Invalidate path name bindings to relative paths
*/
{
}
#endif
{
#ifdef PATH_BFPATH
register char *dir;
Pathcomp_t *cdpath = 0;
#else
#endif
register const char *dp;
int saverrno=0;
char *oldpwd;
if(sh_isoption(SH_RESTRICTED))
{
case 'L':
flag = 0;
break;
case 'P':
flag = 1;
break;
case ':':
break;
case '?':
break;
}
if(argc==2)
#if _WINIX
#else
if(*dir != '/')
#endif /* _WINIX */
{
#ifdef PATH_BFPATH
{
{
}
}
#else
#endif
if(!oldpwd)
}
#ifndef PATH_BFPATH
if(!cdpath)
cdpath = "";
#endif
if(*dir=='.')
{
/* test for pathname . ./ .. or ../ */
dp++;
#ifdef PATH_BFPATH
cdpath = 0;
#else
cdpath = "";
#endif
}
rval = -1;
do
{
#ifdef PATH_BFPATH
#else
#endif
#if _WINIX
{
}
#endif /* _WINIX */
{
/* don't add '/' of oldpwd is / itself */
stakputc('/');
stakputc(0);
}
if(!flag)
{
register char *cp;
#if SHOPT_FS_3D
continue;
/* eliminate trailing '/' */
*cp = 0;
#else
continue;
#endif /* SHOPT_FS_3D */
}
goto success;
}
while(cdpath);
/* use absolute chdir() if relative chdir() fails */
if(rval<0)
{
if(saverrno)
}
if(flag)
{
{
}
}
#ifdef PATH_BFPATH
#else
#endif
if(*dir != '/')
return(0);
if(oldpwd)
/* delete trailing '/' */
#ifdef PATH_BFPATH
#endif
return(0);
}
{
register int n, flag = 0;
register char *cp;
{
case 'L':
flag = 0;
break;
case 'P':
flag = 1;
break;
case ':':
break;
case '?':
break;
}
if(error_info.errors)
if(flag)
{
#if SHOPT_FS_3D
{
}
else
#endif /* SHOPT_FS_3D */
}
return(0);
}