NOINLINE std::string dbg_logfile_path()

in src/dxapi/native/platform/platform.cpp [259:308]


NOINLINE std::string dbg_logfile_path(const char * name, const char * ext)
{
    std::string out;
    static dx_thread::critical_section section;

    if (NULL == log_file_base) {
        dx_thread::yield_lock lock(section);
        char filename[0x800];
        const char *root;
        unsigned pid = dbg_get_pid();

        root = getenv("DXAPI_LOG_PATH");
#if DX_PLATFORM_WINDOWS
        if (NULL == root) {
            root = getenv("TEMP");
        }
#else
        if (NULL == root) {
            root = ".";
        }
#endif
        if (NULL != root && strlen_ni(root) < sizeof(filename) - 0x20) {
            auto t = localtime_from_us(timestamp_us());
            if (NULL != t) {
                snprintf(filename, sizeof(filename), "%s/" LOG_FILE_NAME_PREFIX "%02d%02d_%02d%02d%02d_%05u_", root,
                t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,
                pid);
            }
            else {
                snprintf(filename, sizeof(filename), "%s/" LOG_FILE_NAME_PREFIX "%05u_", root, pid);
            }

            log_file_base = _strdup(filename);
        }

        if (NULL == log_file_base) {
            dbg_log_enabled = false;
        }
    }

    // Do not remove this comparison
    if (NULL != log_file_base) {
        out.append(log_file_base);
        out.append(name);
        out.append(".");
        out.append(ext);
    }

    return out;
}