X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmUtil.cxx;h=05ab21a5d5c91b9944dc927ef16f0f7b944f50a1;hb=57514b6da5b0ee3a9a1c37a15ccde6f5e1ae1688;hp=509b6984604b3d26b73b63d7bc0c7eb9bf99af8a;hpb=c03bc9b5e7d49126a10d49f78682410a5500c412;p=gdcm.git diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 509b6984..05ab21a5 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2004/11/16 10:25:53 $ - Version: $Revision: 1.65 $ + Date: $Date: 2004/12/13 15:12:33 $ + Version: $Revision: 1.70 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,12 +27,18 @@ #include //only included in implementation file #include //only included in implementation file -#include // for gethostname -#include // for gethostbyname +#if defined(_MSC_VER) + #include // for gethostname & gethostbyname + #undef GetCurrentTime +#else +#ifndef __BORLANDC__ + #include // for gethostname + #include // for gethostbyname +#endif +#endif namespace gdcm { - /** * \ingroup Globals * \brief Provide a better 'c++' approach for sprintf @@ -88,7 +94,7 @@ int Util::CountSubstring (const std::string& str, const std::string& subStr) { int count = 0; // counts how many times it appears - unsigned int x = 0; // The index position in the string + std::string::size_type x = 0; // The index position in the string do { @@ -114,21 +120,21 @@ std::string Util::CreateCleanString(std::string const & s) { std::string str = s; - for(unsigned int i=0;i0) + if(str.size() > 0) { - if(!isprint(s[str.size()-1])) + if(!isprint((unsigned char)s[str.size()-1])) { - if(s[str.size()-1]==0) + if(s[str.size()-1] == 0) { - str[str.size()-1]=' '; + str[str.size()-1] = ' '; } } } @@ -298,6 +304,19 @@ std::string Util::GetIPAddress() # define HOST_NAME_MAX 255 // In this case we should maybe check the string was not truncated. // But I don't known how to check that... +#if defined(_MSC_VER) || defined(__BORLANDC__) + // with WinSock DLL we need to initialise the WinSock before using gethostname + WORD wVersionRequested = MAKEWORD(1,0); + WSADATA WSAData; + int err = WSAStartup(wVersionRequested,&WSAData); + if (err != 0) { + /* Tell the user that we could not find a usable */ + /* WinSock DLL. */ + WSACleanup(); + return "127.0.0.1"; + } +#endif + #endif //HOST_NAME_MAX std::string str; @@ -319,6 +338,11 @@ std::string Util::GetIPAddress() (unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]); } // str now contains one local IP address + +#if defined(_MSC_VER) || defined(__BORLANDC__) + WSACleanup(); +#endif + } } // If an error occur r == -1