From e2470a89c3cd542b9c2a1e63ed0d78e0f39bed68 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 7 May 2020 01:01:30 -0400 Subject: Add realpath.c (Darwin is so great) --- scripts/CMakeLists.txt | 16 ++++++++++++++++ scripts/realpath.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 scripts/realpath.c (limited to 'scripts') diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index a9dc74a..bfa6eb2 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -1,3 +1,19 @@ +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/spmbuild + ${CMAKE_CURRENT_BINARY_DIR} + COPYONLY +) + +if (APPLE) + add_executable(spm_realpath + realpath.c + ) + install( + PROGRAMS spm_realpath + DESTINATION bin + ) +endif () + install( PROGRAMS spmbuild DESTINATION bin diff --git a/scripts/realpath.c b/scripts/realpath.c new file mode 100644 index 0000000..15504a0 --- /dev/null +++ b/scripts/realpath.c @@ -0,0 +1,28 @@ +#include +#include +#include + +/** + * Apple loves being different. There's no `realpath` program on MacOS + * @param argc + * @param argv + * @return + */ +int main(int argc, char *argv[]) { + char *path; + + if (argc < 2) { + fprintf(stderr, "usage: %s filename\n", argv[0]); + return 1; + } + + path = realpath(argv[1], NULL); + if (path) { + puts(path); + free(path); + } else { + perror(argv[1]); + } + + return errno; +} \ No newline at end of file -- cgit