#include <unistd.h>
#include <limits.h>

char *os_find_self(void)
{
    // Using PATH_MAX is generally bad, but that's what readlink() says it uses.
    size_t size = PATH_MAX;
    char *path = malloc(size);
    if (readlink("/proc/self/exe", path, size) == 0) {
        return path;
    } else {
        free(path);
        return NULL;
    }
}


#include <unistd.h>
#include <stdlib.h>

char *os_find_self(void)
{
    // PATH_MAX (used by readlink(2)) is not necessarily available
    size_t size = 4096;
    char *path = malloc(size);
    size_t used = readlink("/proc/self/exe", path, size);
    // need strictly less than size, or else we probably truncated
    if (used < size) {
        return path;
    } else {
        free(path);
        return NULL;
    }
}


Mend improper use of readlink(2)
Mend improper use of readlink(2)

The return-code checking for readlink(2) would never succeed before this
change.

Also avoid referencing a PATH_MAX that may be missing.
