OSDN Git Service

Add xrealpath() at suggestion of Ashish Briggers.
authorRob Landley <rob@landley.net>
Fri, 1 Jun 2012 18:50:41 +0000 (13:50 -0500)
committerRob Landley <rob@landley.net>
Fri, 1 Jun 2012 18:50:41 +0000 (13:50 -0500)
lib/lib.c
lib/lib.h

index 1b5488e..612c29e 100644 (file)
--- 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);
index b5292b8..5a184cc 100644 (file)
--- 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);