tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg-config difference when run in pkgsrc vs normal run?



On Sun, Jul 07, 2024 at 02:19:14AM +0300, Andrew Randrianasulu wrote:
> Another part of our unportability related to way we use /proc for getting
> our own executable name/path. Is there more portable way to do so?
That is indeed very tricky to do and AFAIK no portable way exists.
A good example how to do it on NetBSD w/o /proc requirement is in
src/lib/libexecinfo/backtrace.c:
---8<---
#ifdef __linux__
#define SELF "/proc/self/exe"
#else
#include <sys/sysctl.h>
#define SELF "/proc/curproc/file"
#endif
static int
open_self(int flags)
{
 const char *pathname = SELF;
#ifdef KERN_PROC_PATHNAME
 static const int name[] = {
 CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
 };
 char path[MAXPATHLEN];
 size_t len;
 len = sizeof(path);
 if (sysctl(name, __arraycount(name), path, &len, NULL, 0) != -1)
 pathname = path;
#endif
 return open(pathname, flags);
}
--->8---
Martin


Home | Main Index | Thread Index | Old Index

AltStyle によって変換されたページ (->オリジナル) /