diff --git a/Foundation/src/Environment_UNIX.cpp b/Foundation/src/Environment_UNIX.cpp index 61931f68c..b7e57e431 100644 --- a/Foundation/src/Environment_UNIX.cpp +++ b/Foundation/src/Environment_UNIX.cpp @@ -37,7 +37,7 @@ FastMutex EnvironmentImpl::_mutex; std::string EnvironmentImpl::getImpl(const std::string& name) { FastMutex::ScopedLock lock(_mutex); - + const char* val = getenv(name.c_str()); if (val) return std::string(val); @@ -57,11 +57,11 @@ bool EnvironmentImpl::hasImpl(const std::string& name) void EnvironmentImpl::setImpl(const std::string& name, const std::string& value) { FastMutex::ScopedLock lock(_mutex); - + std::string var = name; var.append("="); var.append(value); - _map[name] = var; + std::swap(_map[name], var); if (putenv((char*) _map[name].c_str())) { std::string msg = "cannot set environment variable: "; @@ -156,14 +156,14 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id) int rc = getifaddrs(&ifaphead); if (rc) return; - for (struct ifaddrs* ifap = ifaphead; ifap; ifap = ifap->ifa_next) + for (struct ifaddrs* ifap = ifaphead; ifap; ifap = ifap->ifa_next) { - if (ifap->ifa_addr && ifap->ifa_addr->sa_family == AF_LINK) + if (ifap->ifa_addr && ifap->ifa_addr->sa_family == AF_LINK) { struct sockaddr_dl* sdl = reinterpret_cast(ifap->ifa_addr); caddr_t ap = LLADDR(sdl); int alen = sdl->sdl_alen; - if (ap && alen > 0) + if (ap && alen > 0) { std::memcpy(&id, ap, sizeof(id)); break; @@ -187,9 +187,9 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id) #include #ifndef __CYGWIN__ #include -#else // workaround for Cygwin, which does not have if_arp.h +#else // workaround for Cygwin, which does not have if_arp.h #define ARPHRD_ETHER 1 /* Ethernet 10Mbps */ -#endif +#endif #include #include #include @@ -221,7 +221,7 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id) if (std::sscanf(buffer, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &id[0], &id[1], &id[2], &id[3], &id[4], &id[5]) == 6) return; } - } + } // if that did not work, search active interfaces int sock = socket(PF_INET, SOCK_DGRAM, 0); @@ -258,7 +258,7 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id) } for (const char* ptr = buf; ptr < buf + ifc.ifc_len;) { - const struct ifreq* ifr = reinterpret_cast(ptr); + const struct ifreq* ifr = reinterpret_cast(ptr); int rc = ioctl(sock, SIOCGIFHWADDR, ifr); if (rc != -1) { diff --git a/Foundation/src/Environment_VX.cpp b/Foundation/src/Environment_VX.cpp index 3ee901f28..f6869bab5 100644 --- a/Foundation/src/Environment_VX.cpp +++ b/Foundation/src/Environment_VX.cpp @@ -46,7 +46,7 @@ FastMutex EnvironmentImpl::_mutex; std::string EnvironmentImpl::getImpl(const std::string& name) { FastMutex::ScopedLock lock(_mutex); - + const char* val = getenv(name.c_str()); if (val) return std::string(val); @@ -66,11 +66,11 @@ bool EnvironmentImpl::hasImpl(const std::string& name) void EnvironmentImpl::setImpl(const std::string& name, const std::string& value) { FastMutex::ScopedLock lock(_mutex); - + std::string var = name; var.append("="); var.append(value); - _map[name] = var; + std::swap(_map[name], var); if (putenv((char*) _map[name].c_str())) { std::string msg = "cannot set environment variable: "; @@ -112,7 +112,7 @@ std::string EnvironmentImpl::osArchitectureImpl() return "sh"; #else return "unknown"; -#endif +#endif } @@ -149,7 +149,7 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id) return; } } - else break; + else break; ++ifIndex; } throw SystemException("cannot get Ethernet hardware address");