Clean up and documentation

This commit is contained in:
Shahram Najm 2016-06-22 15:57:01 +01:00
parent b25ac620c2
commit 228b73de10
1 changed files with 12 additions and 7 deletions

View File

@ -11,17 +11,20 @@
#include "grib_api_internal.h" #include "grib_api_internal.h"
#ifdef HAVE_MEMFS #ifdef HAVE_MEMFS
/* These two functions are implemented in the generated C file memfs.c in the build area */
/* See the memfs.py Python generator */
int codes_memfs_exists(const char* path); int codes_memfs_exists(const char* path);
FILE* codes_memfs_open(const char* path); FILE* codes_memfs_open(const char* path);
FILE* codes_fopen(const char* name, const char *mode) { FILE* codes_fopen(const char* name, const char *mode)
{
FILE *f; FILE *f;
if (strcmp(mode, "r") != 0) { if (strcmp(mode, "r") != 0) {
return fopen(name, mode); return fopen(name, mode);
} }
f = codes_memfs_open(name); f = codes_memfs_open(name); /* Load from memory */
if (f) { if (f) {
return f; return f;
} }
@ -29,12 +32,13 @@ FILE* codes_fopen(const char* name, const char *mode) {
return fopen(name, mode); return fopen(name, mode);
} }
int codes_access(const char* name, int mode) { int codes_access(const char* name, int mode)
{
if (mode != F_OK) { if (mode != F_OK) {
return access(name, mode); return access(name, mode);
} }
if (codes_memfs_exists(name)) { if (codes_memfs_exists(name)) { /* Check memory */
return 0; return 0;
} }
@ -43,13 +47,14 @@ int codes_access(const char* name, int mode) {
#else #else
FILE* codes_fopen(const char* name, const char* mode) { FILE* codes_fopen(const char* name, const char* mode)
{
return fopen(name, mode); return fopen(name, mode);
} }
int codes_access(const char* name, int mode) { int codes_access(const char* name, int mode)
{
return access(name, mode); return access(name, mode);
} }
#endif #endif