コード例 #1
0
// static
VFSNode VFSNode::_platform_getExecutable() {
    const int PATH_BUFFER_SIZE = 1024;
    VString executablePath;
    executablePath.preflight(PATH_BUFFER_SIZE);
    ssize_t len = ::readlink(PROCESS_LINKPATH, executablePath.buffer(), PATH_BUFFER_SIZE - 1);
    if (len == -1) {
        throw VStackTraceException(VSystemError(), "VFSNode::_platform_getExecutable: Unable to determine executable path.");
    }

    executablePath.postflight(len);
    return VFSNode(VFSNode::normalizePath(executablePath)); // must supply normalized form to VFSNode below
}
コード例 #2
0
// static
VFSNode VFSNode::_platform_getExecutable() {
    uint32_t bufsize = 3000; // can in theory be bigger than MAXPATH=1024
    VString executablePath;
    executablePath.preflight((int) bufsize);
    char* buffer = executablePath.buffer();
    int result = _NSGetExecutablePath(buffer, &bufsize);
    if (result == -1) {
        throw VStackTraceException(VSTRING_FORMAT("VFSNode::_platform_getExecutable: Failed to get path. _NSGetExecutablePath returned %d.", result));
    }

    executablePath.postflight((int) ::strlen(buffer));

    // todo: could then convert to a "real path" in case returned path has sym links
    return VFSNode(VFSNode::normalizePath(executablePath)); // must supply normalized form to VFSNode below
}
コード例 #3
0
// static
VString VSocket::_platform_addrinfoToIPAddressString(const VString& hostName, const struct addrinfo* info) {
    void* addr;
    if (info->ai_family == AF_INET) {
        addr = (void*) &(((struct sockaddr_in*)info->ai_addr)->sin_addr);
    } else if (info->ai_family == AF_INET6) {
        addr = (void*) &(((struct sockaddr_in6*)info->ai_addr)->sin6_addr);
    } else {
        // We don't know how to access the addr for other family types. They could conceivably be added.
        throw VException(VSTRING_FORMAT("VSocket::_platform_addrinfoToIPAddressString(%s): An invalid family (%d) other than AF_INET or AF_INET6 was specified.", hostName.chars(), info->ai_family));
    }

    VString result;
    result.preflight(MAX_ADDRSTRLEN);
    const char* buf = ::inet_ntop(info->ai_family, addr, result.buffer(), MAX_ADDRSTRLEN);
    if (buf == NULL) {
        throw VException(VSystemError::getSocketError(), VSTRING_FORMAT("VSocket::_platform_addrinfoToIPAddressString(%s): inet_ntop() failed.", hostName.chars()));
    }
    result.postflight((int) ::strlen(buf));

    return result;
}