diff options
author | David Bremner <david@tethera.net> | 2014-01-27 10:12:12 -0400 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2014-04-08 07:27:14 -0300 |
commit | af5c3afa91cc29268c6754ea70f15cae30f22403 (patch) | |
tree | cc1fe830310c9debb7de0a19f707c06858479697 /compat/canonicalize_file_name.c | |
parent | 134dbadaf517c6962c2588f36f1f8782277e2f95 (diff) |
compat: add canonicalize_file_name
the POSIX 2008 behaviour of realpath is not available everywhere so we
provide a simple wrapper function. We use (and provide) the gnu
extension canonicalize_file_name to make it cleaner to test for the
feature we need; otherwise we have to rely on realpath segfaulting if
the second argument is null.
Diffstat (limited to 'compat/canonicalize_file_name.c')
-rw-r--r-- | compat/canonicalize_file_name.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compat/canonicalize_file_name.c b/compat/canonicalize_file_name.c new file mode 100644 index 00000000..e92c0f62 --- /dev/null +++ b/compat/canonicalize_file_name.c @@ -0,0 +1,18 @@ +#include "compat.h" +#include <limits.h> +#undef _GNU_SOURCE +#include <stdlib.h> + +char * +canonicalize_file_name (const char * path) +{ +#ifdef PATH_MAX + char *resolved_path = malloc (PATH_MAX+1); + if (resolved_path == NULL) + return NULL; + + return realpath (path, resolved_path); +#else +#error undefined PATH_MAX _and_ missing canonicalize_file_name not supported +#endif +} |