/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* AT&T Bell Laboratories
* return the real absolute pathname of the preroot dir for cmd
* if cmd==0 then current preroot path returned
*/
#include <ast.h>
#include <preroot.h>
#if FS_PREROOT
#include <ast_dir.h>
#include <ls.h>
#include <error.h>
#include <stdio.h>
#ifndef ERANGE
#endif
char*
{
register int c;
register char* p;
if (cmd)
{
sfsprintf(buf, sizeof(buf), "set x `%s= %s - </dev/null 2>&1`\nwhile :\ndo\nshift\ncase $# in\n[012]) break ;;\nesac\ncase \"$1 $2\" in\n\"+ %s\") echo $3; exit ;;\nesac\ndone\necho\n", PR_SILENT, cmd, PR_COMMAND);
*p = 0;
if (path == p) return(0);
}
else
{
char* d;
int namlen;
int euid;
int ruid;
if (stat(PR_REAL, cur) || stat("/", par) || cur->st_dev == par->st_dev && cur->st_ino == par->st_ino) ERROR(ENOTDIR);
/*
* like getcwd() but starting at the preroot
*/
d = dots;
*d++ = '/';
*p = 0;
for (;;)
{
*d++ = '.';
*d++ = '.';
*d = 0;
#if !_dir_ok || _mem_dd_fd_DIR
#else
#endif
*d++ = '/';
{
{
*--p = '/';
if (path != p)
{
d = path;
while (*d++ = *p++);
}
return(path);
}
#ifdef D_FILENO
{
goto found;
}
#endif
/*
* this fallthrough handles logical naming
*/
}
do
{
if (*p) *--p = '/';
dirp = 0;
}
}
return(0);
}
#else
#endif