File:  [Research Unix] / researchv10no / cmd / asd / fullname.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

/*
 *	fullname -- return the full pathname corresponding to the
 *	abbreviated pathname given as argument.  Returned value
 *	is in a buffer that will stay around no longer than its
 *	argument or the next call to fullname, whichever is earlier.
 */

#include "asd.h"

char *
fullname (s)
	register char *s;
{
	register char *t;
	static char *r;
	static int size;
	register unsigned n;

	/* if first char is slash, absolute path */
	if (s[0] == '/')
		return s;
	
	/* strip leading './' */
	while (s[0] == '.' && s[1] == '/')
		s += 2;
	
	t = pwd();

	/* null string or "." means current directory */
	if (s[0] == '\0' || strcmp (s, ".") == 0)
		return t;
	
	n = strlen (s) + strlen (t) + 2;
	if (n > size) {
		r = ralloc (r, n);
		size = n;
	}

	strcpy (r, t);
	strcat (r, "/");
	strcat (r, s);

	return r;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.