summaryrefslogtreecommitdiffstats
path: root/test/h5test.c
diff options
context:
space:
mode:
authorBill Wendling <wendling@ncsa.uiuc.edu>2001-05-25 21:00:00 (GMT)
committerBill Wendling <wendling@ncsa.uiuc.edu>2001-05-25 21:00:00 (GMT)
commit4101a3561f9925bdc432d280dfc7b0c682a3472f (patch)
treecc0d66910999a961b1a68f8e9e8025b07cedbbad /test/h5test.c
parent44c5d2ff509a6aada50a6bd7c3effc5e5fd059ac (diff)
downloadhdf5-4101a3561f9925bdc432d280dfc7b0c682a3472f.zip
hdf5-4101a3561f9925bdc432d280dfc7b0c682a3472f.tar.gz
hdf5-4101a3561f9925bdc432d280dfc7b0c682a3472f.tar.bz2
[svn-r3943] Purpose:
Backport Description: Backport of patch to HDF5 1.5 branch which puts temp files in /tmp/${USER,LOGIN} if defined for parallel tests. Platforms tested: Linux
Diffstat (limited to 'test/h5test.c')
-rw-r--r--test/h5test.c143
1 files changed, 111 insertions, 32 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 2486acb..25b1ec1 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -1,6 +1,6 @@
/*
- * Copyright © 1998 NCSA
- * All rights reserved.
+ * Copyright © 1998-2001 National Center for Supercomputing Applications
+ * All rights reserved.
*
* Programmer: Robb Matzke <matzke@llnl.gov>
* Thursday, November 19, 1998
@@ -15,7 +15,7 @@
#ifdef WIN32
#include <process.h>
-#endif
+#endif /* WIN32 */
/*
* Define these environment variables or constants to influence functions in
@@ -264,38 +264,46 @@ h5_reset(void)
char *
h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size)
{
- const char *prefix=NULL;
- const char *suffix=".h5"; /* suffix has default */
+ const char *prefix = NULL;
+ const char *suffix = ".h5"; /* suffix has default */
+ char *ptr, last = '\0';
+ size_t i, j;
#ifdef H5_WANT_H5_V1_2_COMPAT
- H5F_driver_t driver;
-#else /* H5_WANT_H5_V1_2_COMPAT */
- hid_t driver;
+ H5F_driver_t driver;
+#else
+ hid_t driver;
#endif /* H5_WANT_H5_V1_2_COMPAT */
- if (!base_name || !fullname || size<1) return NULL;
+ if (!base_name || !fullname || size < 1)
+ return NULL;
+
+ memset(fullname, 0, size);
#ifdef H5_WANT_H5_V1_2_COMPAT
/* figure out the suffix */
- if (H5P_DEFAULT!=fapl){
- if ((driver=H5Pget_driver(fapl))<0)
+ if (H5P_DEFAULT != fapl){
+ if ((driver = H5Pget_driver(fapl)) < 0)
return NULL;
- if (H5F_LOW_FAMILY==driver) {
+
+ if (H5F_LOW_FAMILY == driver) {
suffix = "%05d.h5";
- } else if (H5F_LOW_CORE==driver) {
+ } else if (H5F_LOW_CORE == driver) {
suffix = NULL;
}
}
/* Use different ones depending on parallel or serial driver used. */
- if (H5P_DEFAULT!=fapl && H5F_LOW_MPIO==driver){
+ if (H5P_DEFAULT != fapl && H5F_LOW_MPIO == driver){
/* For parallel:
* First use command line option, then the environment variable,
* then try the constant
*/
prefix = (paraprefix ? paraprefix : getenv("HDF5_PARAPREFIX"));
+
#ifdef HDF5_PARAPREFIX
- if (!prefix) prefix = HDF5_PARAPREFIX;
-#endif
+ if (!prefix)
+ prefix = HDF5_PARAPREFIX;
+#endif /* HDF5_PARAPREFIX */
}else{
/* For serial:
* First use the environment variable, then try the constant
@@ -307,43 +315,101 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size)
}
#else /* H5_WANT_H5_V1_2_COMPAT */
/* figure out the suffix */
- if (H5P_DEFAULT!=fapl){
- if ((driver=H5Pget_driver(fapl))<0) return NULL;
- if (H5FD_FAMILY==driver) {
+ if (H5P_DEFAULT != fapl){
+ if ((driver = H5Pget_driver(fapl)) < 0)
+ return NULL;
+
+ if (H5FD_FAMILY == driver) {
suffix = "%05d.h5";
- } else if (H5FD_CORE==driver || H5FD_MULTI==driver) {
+ } else if (H5FD_CORE == driver || H5FD_MULTI == driver) {
suffix = NULL;
}
}
/* Use different ones depending on parallel or serial driver used. */
- if (H5P_DEFAULT!=fapl && H5FD_MPIO==driver){
+ if (H5P_DEFAULT != fapl && H5FD_MPIO == driver){
/* For parallel:
* First use command line option, then the environment variable,
* then try the constant
*/
prefix = (paraprefix ? paraprefix : getenv("HDF5_PARAPREFIX"));
+
#ifdef HDF5_PARAPREFIX
- if (!prefix) prefix = HDF5_PARAPREFIX;
-#endif
+ if (!prefix)
+ prefix = HDF5_PARAPREFIX;
+#endif /* HDF5_PARAPREFIX */
}else{
/* For serial:
* First use the environment variable, then try the constant
*/
prefix = getenv("HDF5_PREFIX");
+
#ifdef HDF5_PREFIX
- if (!prefix) prefix = HDF5_PREFIX;
-#endif
+ if (!prefix)
+ prefix = HDF5_PREFIX;
+#endif /* HDF5_PREFIX */
}
#endif /* H5_WANT_H5_V1_2_COMPAT */
-
/* Prepend the prefix value to the base name */
if (prefix && *prefix) {
- if (HDsnprintf(fullname, size, "%s/%s", prefix, base_name)==(int)size) {
- return NULL; /*buffer is too small*/
- }
- } else if (strlen(base_name)>=size) {
+#ifdef H5_WANT_H5_V1_2_COMPAT
+ if (H5P_DEFAULT != fapl && H5F_LOW_MPIO == driver) {
+#else
+ if (H5P_DEFAULT != fapl && H5FD_MPIO == driver) {
+#endif /* H5_WANT_H5_V1_2_COMPAT */
+ /* This is a parallel system */
+ char *subdir;
+
+ if (!strcmp(prefix, HDF5_PARAPREFIX)) {
+ /* If the prefix specifies the HDF5_PARAPREFIX directory, then
+ * default to using the "/tmp/$USER" or "/tmp/$LOGIN"
+ * directory instead. */
+ char *user, *login;
+
+ user = getenv("USER");
+ login = getenv("LOGIN");
+ subdir = (user ? user : login);
+
+ if (subdir) {
+ for (i = 0; i < size && prefix[i]; i++)
+ fullname[i] = prefix[i];
+
+ fullname[i++] = '/';
+
+ for (j = 0; i < size && subdir[j]; i++, j++)
+ fullname[i] = subdir[j];
+ }
+ }
+
+ if (!fullname[0])
+ /* We didn't append the prefix yet */
+ strncpy(fullname, prefix, MIN(strlen(prefix), size));
+
+ if (strlen(fullname) + strlen(base_name) + 1 < size) {
+ /* Append the base_name with a slash first. Multiple slashes are
+ * handled below. */
+ struct stat buf;
+
+ if (stat(fullname, &buf) < 0)
+ /* The directory doesn't exist just yet */
+ if (mkdir(fullname, 0755) < 0 && errno != EEXIST)
+ /* We couldn't make the "/tmp/${USER,LOGIN}" subdirectory.
+ * Default to PREFIX's original prefix value. */
+ strcpy(fullname, prefix);
+
+ strcat(fullname, "/");
+ strcat(fullname, base_name);
+ } else {
+ /* Buffer is too small */
+ return NULL;
+ }
+ } else {
+ if (HDsnprintf(fullname, size, "%s/%s", prefix, base_name) == (int)size)
+ /* Buffer is too small */
+ return NULL;
+ }
+ } else if (strlen(base_name) >= size) {
return NULL; /*buffer is too small*/
} else {
strcpy(fullname, base_name);
@@ -351,7 +417,9 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size)
#ifdef H5_WANT_H5_V1_2_COMPAT
/* Append a suffix */
- if ((driver=H5Pget_driver(fapl))<0) return NULL;
+ if ((driver = H5Pget_driver(fapl)) < 0)
+ return NULL;
+
switch (driver) {
case H5F_LOW_SPLIT:
case H5F_LOW_CORE:
@@ -365,12 +433,23 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size)
break;
}
#endif /* H5_WANT_H5_V1_2_COMPAT */
+
/* Append a suffix */
if (suffix) {
- if (strlen(fullname)+strlen(suffix)>=size) return NULL;
+ if (strlen(fullname) + strlen(suffix) >= size)
+ return NULL;
+
strcat(fullname, suffix);
}
+ /* Remove any double slashes in the filename */
+ for (ptr = fullname, i = j = 0; ptr && i < size; i++, ptr++) {
+ if (*ptr != '/' || last != '/')
+ fullname[j++] = *ptr;
+
+ last = *ptr;
+ }
+
return fullname;
}