GRIB-798: Visual Studio support: replace use of rint() for VS 2013

This commit is contained in:
Shahram Najm 2015-07-17 13:51:36 +01:00
parent 93fa444e11
commit bea65a9159
2 changed files with 22 additions and 24 deletions

View File

@ -71,8 +71,10 @@ extern "C" {
#include <direct.h>
#include <io.h>
/* Replace Unix rint() for Windows */
double rint(double x);
/* Replace C99/Unix rint() for Windows Visual C++ (only before VC++ 2013 versions) */
#if defined _MSC_VER && _MSC_VER < 1800
double rint(double x);
#endif
#ifndef S_ISREG
#define S_ISREG(mode) (mode & S_IFREG)
@ -1428,7 +1430,6 @@ typedef struct j2k_encode_helper {
} j2k_encode_helper;
#include "grib_api_prototypes.h"

View File

@ -8,32 +8,29 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/***************************************************************************
* Enrico Fucile
* *
***************************************************************************/
#include "grib_api_internal.h"
#ifdef ECCODES_ON_WINDOWS
/* Microsoft Windows Visual Studio support. Implementation of Unix rint() */
double rint(double x)
{
char * buf = 0;
int decimal=0, sign=0, err = 0;
double result = 0;
buf = (char*) malloc(_CVTBUFSIZE);
err = _fcvt_s(buf, _CVTBUFSIZE, x, 0, &decimal, &sign);
Assert(err == 0);
result = atof(buf);
if(sign == 1) {
result = result * -1;
}
free(buf);
return result;
}
/* Replace C99/Unix rint() for Windows Visual C++ (only before VC++ 2013 versions) */
#if defined _MSC_VER && _MSC_VER < 1800
double rint(double x)
{
char * buf = 0;
int decimal=0, sign=0, err = 0;
double result = 0;
buf = (char*) malloc(_CVTBUFSIZE);
err = _fcvt_s(buf, _CVTBUFSIZE, x, 0, &decimal, &sign);
Assert(err == 0);
result = atof(buf);
if(sign == 1) {
result = result * -1;
}
free(buf);
return result;
}
#endif
#endif
static void set_total_length(unsigned char* buffer,long *section_length,long *section_offset,int edition,size_t totalLength) {
long off;
switch (edition) {