示例#1
0
/*
 * vislib::net::Socket::BindToDevice
 */
void vislib::net::Socket::BindToDevice(const StringA& name) {
#ifndef _WIN32
    struct ifreq interface;

    ::strncpy(interface.ifr_ifrn.ifrn_name, name.PeekBuffer(), 
        name.Length() + 1);

    if (::setsockopt(this->handle, SOL_SOCKET, SO_BINDTODEVICE, &interface,
            sizeof(interface)) == -1) {
        throw SocketException(__FILE__, __LINE__);
    }
#endif /* !_WIN32 */
}
示例#2
0
/*
 * vislib::sys::Path::Resolve
 */
vislib::StringA vislib::sys::Path::Resolve(StringA path, StringA basepath) {
    // TODO: Windows shell API resolve does not work in the expected
    // way, so we use the same manual approach for Windows and Linux.

#ifdef _WIN32
    /* Replace unchefmäßige path separators. */
    basepath.Replace('/', SEPARATOR_A);
    path.Replace('/', SEPARATOR_A);
#endif /* _WIN32 */

    if (Path::IsRelative(basepath)) {
        basepath = Resolve(basepath);
    }

    if (path.IsEmpty()) {
        /* Path is empty, i. e. return current working directory. */
        return Path::Canonicalise(basepath);
    
    } else if (Path::IsAbsolute(path)) {
        /* Path is absolute, just return it. */
        return Path::Canonicalise(path);

    } else if ((path[0] == MYDOCUMENTS_MARKER_A) 
            && ((path.Length() == 1) || path[1] == SEPARATOR_A)) {
        /*
         * replace leading ~ with users home directory
         */
        path.Replace(MYDOCUMENTS_MARKER_A, Path::GetUserHomeDirectoryA(), 1);
        return Path::Canonicalise(path);

    } else if ((path[0] == SEPARATOR_A) && (path[1] != SEPARATOR_A)) {
        /*
         * Concatenate current drive and relative path, and canonicalise
         * the result.
         */
        return Path::Concatenate(basepath.Substring(0, 2), path, true);

    } else {
        /*
         * Concatenate current directory and relative path, and canonicalise
         * the result.
         */
        return Path::Concatenate(basepath, path, true);
    }
}