mirror of https://github.com/ecmwf/eccodes.git
SUP-2586: Contribution for Windows (memfs part)
This commit is contained in:
parent
820b48e643
commit
0ec1a0bf80
53
memfs.py
53
memfs.py
|
@ -8,7 +8,7 @@ import binascii
|
|||
assert len(sys.argv) > 2
|
||||
|
||||
# For now exclude GRIB3 as it is still experimental
|
||||
EXCLUDED = 'grib3'
|
||||
EXCLUDED = ['grib3']
|
||||
|
||||
dirs = [os.path.realpath(x) for x in sys.argv[1:-1]]
|
||||
print(dirs)
|
||||
|
@ -35,17 +35,19 @@ for directory in dirs:
|
|||
NAMES.append(dname)
|
||||
|
||||
for dirpath, dirnames, files in os.walk(directory, followlinks=True):
|
||||
if EXCLUDED in dirnames:
|
||||
print('Note: %s/%s will not be included.' % (dirpath,EXCLUDED))
|
||||
for ex in EXCLUDED:
|
||||
if ex in dirnames:
|
||||
print('Note: %s/%s will not be included.' % (dirpath,ex))
|
||||
|
||||
# Prune the walk by modifying the dirnames in-place
|
||||
dirnames[:] = [dirname for dirname in dirnames if dirname != EXCLUDED]
|
||||
dirnames[:] = [dirname for dirname in dirnames if dirname not in EXCLUDED]
|
||||
for name in files:
|
||||
full = '%s/%s' % (dirpath, name)
|
||||
_, ext = os.path.splitext(full)
|
||||
if ext not in ['.def', '.table', '.tmpl']:
|
||||
continue
|
||||
|
||||
full = full.replace("\\","/")
|
||||
fname = full[full.find("/%s/" % (dname,)):]
|
||||
#print("MEMFS add", fname)
|
||||
name = re.sub(r'\W', '_', fname)
|
||||
|
@ -171,6 +173,49 @@ static FILE* fmemopen(const char* buffer, size_t size, const char* mode){
|
|||
return funopen(f, &read_mem, &write_mem, &seek_mem, &close_mem);
|
||||
}
|
||||
|
||||
#elif defined(ECCODES_ON_WINDOWS)
|
||||
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <windows.h>
|
||||
|
||||
static FILE *fmemopen(void* buffer, size_t size, const char* mode) {
|
||||
char path[MAX_PATH - 13];
|
||||
if (!GetTempPath(sizeof(path), path))
|
||||
return NULL;
|
||||
|
||||
char filename[MAX_PATH + 1];
|
||||
if (!GetTempFileName(path, "eccodes", 0, filename))
|
||||
return NULL;
|
||||
|
||||
HANDLE h = CreateFile(filename,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
|
||||
NULL);
|
||||
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return NULL;
|
||||
|
||||
int fd = _open_osfhandle((intptr_t)h, _O_RDWR);
|
||||
if (fd < 0) {
|
||||
CloseHandle(h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FILE* f = _fdopen(fd, "w+");
|
||||
if (!f) {
|
||||
_close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fwrite(buffer, size, 1, f);
|
||||
rewind(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static size_t entries_count = sizeof(entries)/sizeof(entries[0]);
|
||||
|
|
Loading…
Reference in New Issue