mirror of https://github.com/lammps/lammps.git
add support for utils::guesspath() on macos
This commit is contained in:
parent
22f295ffd8
commit
cfa94dfbaf
|
@ -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
|
||||
|
|
|
@ -408,7 +408,7 @@ namespace utils {
|
|||
|
||||
/*! Try to detect pathname from FILE pointer.
|
||||
*
|
||||
* Currently only supported on Linux, otherwise will report "(unknown)".
|
||||
* Currently only supported on Linux and macOS, otherwise will report "(unknown)".
|
||||
*
|
||||
* \param buf storage buffer for pathname. output will be truncated if not large enough
|
||||
* \param len size of storage buffer. output will be truncated to this length - 1
|
||||
|
|
|
@ -722,7 +722,7 @@ TEST(Utils, guesspath)
|
|||
{
|
||||
char buf[256];
|
||||
FILE *fp = fopen("test_guesspath.txt", "w");
|
||||
#if defined(__linux__)
|
||||
#if defined(__linux__) || (__APPLE__)
|
||||
const char *path = utils::guesspath(buf, sizeof(buf), fp);
|
||||
ASSERT_THAT(path, EndsWith("test_guesspath.txt"));
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue