diff --git a/supportApp/hdf5Src/H5system.c b/supportApp/hdf5Src/H5system.c index e6ca5d4..1172b31 100644 --- a/supportApp/hdf5Src/H5system.c +++ b/supportApp/hdf5Src/H5system.c @@ -801,6 +801,31 @@ Wgettimeofday(struct timeval *tv, struct timezone *tz) * *------------------------------------------------------------------------- */ +/* mingw does not have getenv_s or _putenv_s to work around */ +#ifdef __MINGW32__ + +int +Wsetenv(const char *name, const char *value, int overwrite) +{ + char buffer[256]; + char *envName; + + /* If we're not overwriting, check if the environment variable exists. + * If it does (i.e.: the required buffer size to store the variable's + * value is non-zero), then return an error code. + */ + if(!overwrite) { + envName = getenv(name); + if (envName) + return -1; + } /* end if */ + + snprintf(buffer, sizeof(buffer)-1, "%s=%s", name, value); + return putenv(buffer); +} /* end Wsetenv() */ + +#else + int Wsetenv(const char *name, const char *value, int overwrite) { @@ -820,6 +845,8 @@ Wsetenv(const char *name, const char *value, int overwrite) return (int)_putenv_s(name, value); } /* end Wsetenv() */ +#endif /* __MINGW32__ */ + #ifdef H5_HAVE_WINSOCK2_H #pragma comment(lib, "advapi32.lib") #endif @@ -852,6 +879,13 @@ int c99_snprintf(char* str, size_t size, const char* format, ...) return count; } +#ifdef __MINGW32__ +/* mingw does not have _vsnprintf_s or vcsprintf */ +int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) +{ + return vsnprintf(str, size, format, ap); +} +#else int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) { int count = -1; @@ -863,6 +897,7 @@ int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) return count; } +#endif /* __MING32__ */ /*-------------------------------------------------------------------------