const char *RAND_file_name(char *buf, size_t size)
{
    char *s = NULL;
#ifdef __OpenBSD__
    struct stat sb;
#endif

    if (OPENSSL_issetugid() == 0)
        s = getenv("RANDFILE");
    if (s != NULL && *s && strlen(s) + 1 < size) {
        if (OPENSSL_strlcpy(buf, s, size) >= size)
            return NULL;
    } else {
        if (OPENSSL_issetugid() == 0)
            s = getenv("HOME");
#ifdef DEFAULT_HOME
        if (s == NULL) {
            s = DEFAULT_HOME;
        }
#endif
        if (s && *s && strlen(s) + strlen(RFILE) + 2 < size) {
            OPENSSL_strlcpy(buf, s, size);
#ifndef OPENSSL_SYS_VMS
            OPENSSL_strlcat(buf, "/", size);
#endif
            OPENSSL_strlcat(buf, RFILE, size);
        } else
            buf[0] = '\0';      /* no file name */
    }

#ifdef __OpenBSD__
    /*
     * given that all random loads just fail if the file can't be seen on a
     * stat, we stat the file we're returning, if it fails, use /dev/arandom
     * instead. this allows the user to use their own source for good random
     * data, but defaults to something hopefully decent if that isn't
     * available.
     */

    if (!buf[0])
        if (OPENSSL_strlcpy(buf, "/dev/arandom", size) >= size) {
            return (NULL);
        }
    if (stat(buf, &sb) == -1)
        if (OPENSSL_strlcpy(buf, "/dev/arandom", size) >= size) {
            return (NULL);
        }
#endif
    return (buf);
}