add support for utils::guesspath() on macos

This commit is contained in:
Axel Kohlmeyer
2021-09-08 12:09:14 -04:00
parent 22f295ffd8
commit cfa94dfbaf
3 changed files with 14 additions and 2 deletions

View File

@ -32,6 +32,11 @@
#include <unistd.h> // for readlink
#endif
#if defined(__APPLE__)
#include <sys/syslimits.h>
#include <fcntl.h> // for fcntl
#endif
/*! \file utils.cpp */
/*
@ -162,6 +167,13 @@ const char *utils::guesspath(char *buf, int len, FILE *fp)
// get pathname from /proc or copy (unknown)
if (readlink(fmt::format("/proc/self/fd/{}", fd).c_str(), buf, len - 1) <= 0)
strncpy(buf, "(unknown)", len - 1);
#elif defined(__APPLE__)
int fd = fileno(fp);
char filepath[PATH_MAX];
if (fcntl(fd,F_GETPATH,filepath) != -1)
strncpy(buf, filepath, len - 1);
else
strncpy(buf, "(unknown)", len - 1);
#else
strncpy(buf, "(unknown)", len - 1);
#endif