Mercurial > hg > orthanc-webviewer
diff Orthanc/Core/Toolbox.cpp @ 145:d850500b8ca6
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Nov 2016 10:15:05 +0100 |
parents | 9362080e5e3d |
children | 4217644ac904 |
line wrap: on
line diff
--- a/Orthanc/Core/Toolbox.cpp Fri Sep 16 09:19:10 2016 +0200 +++ b/Orthanc/Core/Toolbox.cpp Tue Nov 08 10:15:05 2016 +0100 @@ -111,6 +111,18 @@ namespace Orthanc { + void Toolbox::USleep(uint64_t microSeconds) + { +#if defined(_WIN32) + ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000))); +#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__native_client__) + usleep(microSeconds); +#else +#error Support your platform here +#endif + } + + #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 static bool finish_; static ServerBarrierEvent barrierEvent_; @@ -135,18 +147,6 @@ #endif - void Toolbox::USleep(uint64_t microSeconds) - { -#if defined(_WIN32) - ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000))); -#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) - usleep(microSeconds); -#else -#error Support your platform here -#endif - } - - static ServerBarrierEvent ServerBarrierInternal(const bool* stopFlag) { #if defined(_WIN32) @@ -312,7 +312,7 @@ const std::string& path) { boost::filesystem::ofstream f; - f.open(path, std::ofstream::binary); + f.open(path, std::ofstream::out | std::ofstream::binary); if (!f.good()) { throw OrthancException(ErrorCode_CannotWriteFile); @@ -321,6 +321,12 @@ if (size != 0) { f.write(reinterpret_cast<const char*>(content), size); + + if (!f.good()) + { + f.close(); + throw OrthancException(ErrorCode_FileStorageCannotWrite); + } } f.close(); @@ -838,6 +844,23 @@ } + bool Toolbox::IsAsciiString(const void* data, + size_t size) + { + const uint8_t* p = reinterpret_cast<const uint8_t*>(data); + + for (size_t i = 0; i < size; i++, p++) + { + if (*p > 127 || (*p != 0 && iscntrl(*p))) + { + return false; + } + } + + return true; + } + + std::string Toolbox::ConvertToAscii(const std::string& source) { std::string result;