summaryrefslogtreecommitdiff
path: root/libc/stdlib/canonicalize.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2010-09-16 12:22:34 +0200
committerCarmelo Amoroso <carmelo.amoroso@st.com>2010-09-16 12:22:34 +0200
commit26606098c2eb57d288b2e0edca471c71d0d7fa51 (patch)
tree8a1ba1d68fd10cbba7a12c70ca9618ac50a33854 /libc/stdlib/canonicalize.c
parenta9e2521be8c96d2b22339253a0a335e0063b66e5 (diff)
libc: Add canonicalize_file_name function
Add canonicalize_file_name function and its related tests. Required by elfutils and coreutils (readlink). Signed-off-by: Salvatore Cro <salvatore.cro@st.com> Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/stdlib/canonicalize.c')
-rw-r--r--libc/stdlib/canonicalize.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/libc/stdlib/canonicalize.c b/libc/stdlib/canonicalize.c
new file mode 100644
index 000000000..06e710ab7
--- /dev/null
+++ b/libc/stdlib/canonicalize.c
@@ -0,0 +1,38 @@
+/*
+ * canonicalize.c -- Return a malloc'd string containing the canonical
+ * absolute name of the named file. The last file name component need
+ * not exist, and may be a symlink to a nonexistent file.
+ * Copyright (C) 2009 STMicroelectronics
+ * Author: Salvatore Cro <salvatore.cro@st.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <stdlib.h>
+#include <limits.h>
+
+#ifdef __USE_GNU
+
+#ifndef PATH_MAX
+# ifdef _POSIX_VERSION
+# define PATH_MAX _POSIX_PATH_MAX
+# else
+# ifdef MAXPATHLEN
+# define PATH_MAX MAXPATHLEN
+# else
+# define PATH_MAX 1024
+# endif
+# endif
+#endif
+
+char * canonicalize_file_name (const char *name)
+{
+ char *buf = (char *) malloc(PATH_MAX);
+
+ if(unlikely(buf == NULL))
+ return NULL;
+
+ *buf='\0';
+ return realpath (name, buf);
+}
+#endif