Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 04 Dec 1997 15:28:35 +0900
From:      Shigio Yamaguchi <shigio@wafu.netgate.net>
To:        hackers@freebsd.org
Cc:        shigio@wafu.netgate.net
Subject:   [RFC] path converting functions.
Message-ID:  <199712032230.WAA28837@wafu.netgate.net>

next in thread | raw e-mail | index | archive | help
Hello, hackers.

I've written a set of simple functions to perform conversions between
an absolute path name and a relative path name.

Thoughts about this?

	o Are there any other functions that will do this?
	o Is this useful?
	o Is this the correct way to do it?

------------------------------------------------------------------------

abs2rel - make a relative path name from an absolute path name

	abs2rel(<original path name>, <base directory>, <result>);

	<original path name>	<base directory>	<result>
	/usr/src		/etc			../usr/src


rel2abs - make an absolute path name from a relative path name

	rel2abs(<original path name>, <base directory>, <result>);

	<original path name>	<base directory>	<result>
	../usr/src		/etc			/usr/src

EXAMPLE:

	char	result[MAXPATHLEN];
	char	result2[MAXPATHLEN];
	char	*base = "/usr/local/src";
	
	if (abs2rel("/usr/src/sys/kern/init_main.c", base, result))
		printf("%s\n", result);
	else
		fprintf(stderr, "abs2rel failed. (errno = %d)\n", errno);
	if (rel2abs(result, base, result2))
		printf("%s\n", result2);
	else
		fprintf(stderr, "rel2abs failed. (errno = %d)\n", errno);

    yields:

	../../src/sys/kern/init_main.c
	/usr/src/sys/kern/init_main.c

------------------------------------------------------------------------

abs2rel and rel2abs (source code and online manual) are available on

	http://wafu.netgate.net/tama/indexe.html#pathconvertc

Thank you in advance.
--
Shigio Yamaguchi (Freelance programmer)
	Mail: shigio@wafu.netgate.net, WWW: http://wafu.netgate.net/tama/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199712032230.WAA28837>