From owner-freebsd-hackers Wed Dec 3 22:29:03 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id WAA25697 for hackers-outgoing; Wed, 3 Dec 1997 22:29:03 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from wafu.netgate.net (wafu.netgate.net [204.145.147.80]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id WAA25686 for ; Wed, 3 Dec 1997 22:28:58 -0800 (PST) (envelope-from shigio@wafu.netgate.net) Received: from chiota.signet.or.jp (INS47.tama.dti.ne.jp [210.159.144.1]) by wafu.netgate.net (8.7.5/8.7.3) with ESMTP id WAA28837; Wed, 3 Dec 1997 22:30:57 GMT Message-Id: <199712032230.WAA28837@wafu.netgate.net> Received: from chiota.signet.or.jp (localhost.signet.or.jp [127.0.0.1]) by chiota.signet.or.jp (8.8.5/) with ESMTP id PAA01301; Thu, 4 Dec 1997 15:28:36 +0900 (JST) To: hackers@freebsd.org Cc: shigio@wafu.netgate.net Subject: [RFC] path converting functions. Date: Thu, 04 Dec 1997 15:28:35 +0900 From: Shigio Yamaguchi Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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(, , ); /usr/src /etc ../usr/src rel2abs - make an absolute path name from a relative path name rel2abs(, , ); ../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/