/*
Linux specific routine:

char *executable_path (char buffer [MAXPATHLEN]);

Returns the full path of the running executable. Works on Linux 2.2
and above with a mounted /proc file system. Returns NULL if it is
not able to get the path.

Copyright (C) 2000 Frank Heckenbach <frank@pascal.gnu.de>

This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without
modifications, as long as this notice is preserved.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY, to the extent permitted by law; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
*/

#include <sys/param.h>
#include <unistd.h>
#include <sys/utsname.h>

#define executable_path(buffer) \
( \
  { \
    struct utsname uts; \
    (uname (&uts) >= 0 && !strcmp (uts.sysname, "Linux") \
      && strcmp (uts.release, "2.2") >= 0) \
    ? realpath ("/proc/self/exe", (buffer)) : NULL; \
  } \
)
