From d2fa7372e4359f1e1f06c68adb33daddca873342 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 4 Oct 2010 08:20:48 +0000 Subject: [PATCH] Let libCGAL_ImageIO set temporarily the LC_NUMERIC locale to "C", during the read/write operation of Inrimage headers. Otherwise the I/O operations can fail when the decimal point is not a dot. --- CGALimageIO/src/CGALimageIO/inr.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CGALimageIO/src/CGALimageIO/inr.cpp b/CGALimageIO/src/CGALimageIO/inr.cpp index 13c49772c7a..11175d5c7bf 100644 --- a/CGALimageIO/src/CGALimageIO/inr.cpp +++ b/CGALimageIO/src/CGALimageIO/inr.cpp @@ -43,7 +43,19 @@ typedef struct { } stringListHead; /* string list descriptor */ +#include +class Set_numeric_locale { + const char * old_locale; +public: + Set_numeric_locale(const char* locale) + : old_locale(std::setlocale(LC_NUMERIC, locale)) + { + } + ~Set_numeric_locale() { + std::setlocale(LC_NUMERIC, old_locale); + } +}; static void addStringElement(stringListHead *strhead, const char *str); @@ -59,6 +71,8 @@ int _writeInrimageHeader(const _image *im, ENDIANNESS end) { unsigned int pos, i; char type[30], endianness[5], buf[257], scale[20]; + Set_numeric_locale num_locale("C"); + if(im->openMode != OM_CLOSE) { /* fix word kind */ switch(im->wordKind) { @@ -209,6 +223,8 @@ int readInrimageHeader(const char *,_image *im) { stringListHead strl = { NULL, NULL }; stringListElement *oel, *el; + Set_numeric_locale num_locale("C"); + if(im->openMode != OM_CLOSE) { /* read image magic number */ if(!fgetns(str, 257, im )) return -1;