From eec463764dbc2e83325695583a1b73bebc492a9e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 1 Jun 2012 13:50:41 -0500 Subject: Add xrealpath() at suggestion of Ashish Briggers. --- lib/lib.c | 8 ++++++++ lib/lib.h | 1 + 2 files changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/lib.c b/lib/lib.c index 1b5488ef..612c29e1 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -345,6 +345,14 @@ char *xabspath(char *path) return path; } +// Resolve all symlinks, returning malloc() memory. +char *xrealpath(char *path) +{ + char *new = realpath(path, NULL); + if (!new) perror_exit("realpath '%s'", path); + return new; +} + void xchdir(char *path) { if (chdir(path)) error_exit("chdir '%s'", path); diff --git a/lib/lib.h b/lib/lib.h index b5292b85..5a184ccf 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -116,6 +116,7 @@ char *xreadfile(char *name); char *xgetcwd(void); void xstat(char *path, struct stat *st); char *xabspath(char *path); +char *xrealpath(char *path); void xchdir(char *path); void xmkpath(char *path, int mode); void xsetuid(uid_t uid); -- cgit v1.2.3