From 974942db43ff2d1fa7ba71ad60f9bb9eae2d8631 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Sat, 6 Feb 2016 13:03:36 -0500 Subject: CBT Version 1.0-BETA --- realpath/realpath.c | 35 +++++++++++++++++++++++++++++++++++ realpath/realpath.sh | 18 ++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 realpath/realpath.c create mode 100755 realpath/realpath.sh (limited to 'realpath') diff --git a/realpath/realpath.c b/realpath/realpath.c new file mode 100644 index 0000000..055dbcf --- /dev/null +++ b/realpath/realpath.c @@ -0,0 +1,35 @@ +// http://stackoverflow.com/questions/284662/how-do-you-normalize-a-file-path-in-bash +// realpath.c: display the absolute path to a file or directory. +// Adam Liss, August, 2007 +// This program is provided "as-is" to the public domain, without express or +// implied warranty, for any non-profit use, provided this notice is maintained. + +#include +#include +#include +#include +#include + +static char *s_pMyName; +void usage(void); + +int main(int argc, char *argv[]) +{ + char + sPath[PATH_MAX]; + + + s_pMyName = strdup(basename(argv[0])); + + if (argc < 2) + usage(); + + printf("%s\n", realpath(argv[1], sPath)); + return 0; +} + +void usage(void) +{ + fprintf(stderr, "usage: %s PATH\n", s_pMyName); + exit(1); +} \ No newline at end of file diff --git a/realpath/realpath.sh b/realpath/realpath.sh new file mode 100755 index 0000000..de4d964 --- /dev/null +++ b/realpath/realpath.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# is there a realiable cross-platform was to do this without relying on compiling C code? + +DIR=$(dirname $(readlink "$0") 2>/dev/null || dirname "$0" 2>/dev/null ) +which realpath 2>&1 > /dev/null +REALPATH_INSTALLED=$? + +if [ ! $REALPATH_INSTALLED -eq 0 ]; then + if [ ! -f $DIR/realpath ]; then + >&2 echo "Compiling realpath" + gcc $DIR/realpath.c -o $DIR/realpath + chmod u+x $DIR/realpath + fi + $DIR/realpath $1 +else + realpath $1 +fi -- cgit v1.2.3