Windows support: merge branch dtip-windows from Github

This commit is contained in:
Shahram Najm 2019-01-11 12:49:31 +00:00
parent ef43a281d1
commit 0e431eea67
7 changed files with 42 additions and 57 deletions

View File

@ -283,9 +283,18 @@ if( IEEE_LE )
set( IEEE_BE 0 )
endif()
# Symbols need to be explicitly exported on Windows so we can link to dlls.
if( EC_OS_NAME MATCHES "windows" )
# Symbols need to be explicitly exported on Windows so we can link to dlls.
set( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE )
# Suppress compliler warnings - see ECC-850
# Suppress warnings about using 'insecure' functions. Fixing this would require changes all over
# the codebase which would damage portability.
ecbuild_add_c_flags("/D_CRT_SECURE_NO_WARNINGS")
# Suppress warnings about using well-known C functions.
ecbuild_add_c_flags("/D_CRT_NONSTDC_NO_DEPRECATE")
# Suppress C4267: warns about possible loss of data when converting 'size_t' to 'int'.
ecbuild_add_c_flags("/wd4267")
endif()
###############################################################################

View File

@ -14,7 +14,9 @@
/* Microsoft Windows Visual Studio support */
#if defined(_WIN32) && defined(_MSC_VER)
#define ECCODES_ON_WINDOWS
#ifndef YY_NO_UNISTD_H
#define YY_NO_UNISTD_H
#endif
#endif
#endif

View File

@ -215,7 +215,7 @@ static void grib_md5_flush(grib_md5_state* s)
void grib_md5_init(grib_md5_state* s)
{
Assert( sizeof(UnsignedInt64) == 8 );
Assert( sizeof(uint64_t) == 8 );
memset(s,0,sizeof(grib_md5_state));
s->h0 = 0x67452301;
s->h1 = 0xefcdab89;
@ -243,8 +243,8 @@ void grib_md5_add(grib_md5_state* s,const void* data,size_t len)
void grib_md5_end(grib_md5_state* s, char *digest)
{
UnsignedInt64 h = 8;
UnsignedInt64 bits, leng = s->size * h;
uint64_t h = 8;
uint64_t bits, leng = s->size * h;
unsigned char c = 0x80;
int i;

View File

@ -12,17 +12,10 @@
*/
#include <stdlib.h>
#include "eccodes_windef.h"
#ifdef ECCODES_ON_WINDOWS
typedef unsigned __int64 UnsignedInt64;
#else
#include <stdint.h>
typedef uint64_t UnsignedInt64;
#endif
typedef struct grib_md5_state {
UnsignedInt64 size;
uint64_t size;
unsigned long words[64];
unsigned long word_count;

View File

@ -9,12 +9,6 @@
*/
#include "config.h"
/* #include <sys/types.h> */
/* #include <inttypes.h> */
/* #include <stdio.h> */
/* #include <stdlib.h> */
/* #include <errno.h> */
/* #include <string.h> */
#include "grib_api_internal.h"
#ifndef ECCODES_ON_WINDOWS

View File

@ -51,29 +51,22 @@ void scan(const char* name)
}
}
#else
// based on similar code in grib_tools.c
static int isWinDir(const struct _finddata_t *fileinfo)
{
if((fileinfo->attrib & 16) == 16)
return 1;
return 0;
}
void scan(const char* name)
{
struct _finddata_t fileinfo;
intptr_t handle;
if((handle = _findfirst(name, &fileinfo)) != -1)
{
char tmp[1024];
do {
if(isWinDir(&fileinfo))
sprintf(tmp, "%s/*", name);
if((handle = _findfirst(tmp, &fileinfo)) != -1)
{
do {
if(fileinfo.name[0] != '.') {
sprintf(tmp, "%s/%s", name, fileinfo.name);
scan(tmp);
}
}
} while(!_findnext(handle, &fileinfo));
_findclose(handle);
}
else
validate(name);

View File

@ -532,38 +532,32 @@ static int scan(grib_context* c,grib_runtime_options* options,const char* dir)
process(c,options,buf);
}
}
closedir(d);
return 0;
}
#else
static int isWinDir(const struct _finddata_t *fileinfo)
{
if((fileinfo->attrib & 16) == 16)
return 1;
return 0;
}
static void doProcessing(grib_context* c,grib_runtime_options* options,const char* dir, const struct _finddata_t *fileinfo)
{
if(isWinDir(fileinfo))
{
if(strcmp(fileinfo->name, ".") != 0 && strcmp(fileinfo->name,"..") != 0) {
char buf[1024];
sprintf(buf,"%s/%s",dir,fileinfo->name);
process(c,options,buf);
}
}
}
static int scan(grib_context* c,grib_runtime_options* options,const char* dir) {
struct _finddata_t fileinfo;
intptr_t handle;
if((handle = _findfirst(dir, &fileinfo)) != -1)
doProcessing(c, options, dir, &fileinfo);
char buffer[1024];
sprintf(buffer, "%s/*", dir);
if((handle = _findfirst(buffer, &fileinfo)) != -1)
{
do {
if(strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name,"..") != 0) {
char buf[1024];
sprintf(buf, "%s/%s", dir, fileinfo.name);
process(c,options,buf);
}
} while(!_findnext(handle, &fileinfo));
_findclose(handle);
}
else
{
grib_context_log(c,(GRIB_LOG_ERROR) | (GRIB_LOG_PERROR) , "opendir %s",dir);
return GRIB_IO_PROBLEM;
}
while(!_findnext(handle, &fileinfo))
doProcessing(c, options, dir, &fileinfo);
return 0;
}
#endif