aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2004-06-30 14:13:50 +0000
committertradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a>2004-06-30 14:13:50 +0000
commit40214def7760f358107f9a05b658b6aeb48ef7ee (patch)
tree46d507df680dad488541040776446c6f3e44bef0
parent900dc4a77378fff0144d44740427b419d9975c12 (diff)
Added new routine IOUtil_AssembleFilename() to generate a checkpoint/filereader
filename and returns the pointer to that (allocated) string. This routine is meant to replace IOUtil_PrepareFilename() which is now marked as deprecated. This closes PR IO/1791: "IOUtil_PrepareFilename does not check buffer length". git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@212 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
-rw-r--r--src/CheckpointRecovery.c138
-rw-r--r--src/ioutil_CheckpointRecovery.h8
2 files changed, 146 insertions, 0 deletions
diff --git a/src/CheckpointRecovery.c b/src/CheckpointRecovery.c
index 0831a25..2040959 100644
--- a/src/CheckpointRecovery.c
+++ b/src/CheckpointRecovery.c
@@ -17,6 +17,7 @@
#include "ioGH.h"
#include "ioutil_CheckpointRecovery.h"
+#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
@@ -121,6 +122,139 @@ int IOUtil_RegisterRecover (const char *name, recover_fn_t recover_fn)
/*@@
+ @routine IOUtil_AssembleFilename
+ @date 30 June 2004
+ @author Thomas Radke
+ @desc
+ This routine assembles the full basename for checkpoint/recovery
+ and filereader files, paying attention to the different types:
+
+ * it returns the full filename (directory+filename)
+ * for cp files it prepends the iteration number as "it_%d"
+ * for chunked files it prepends the file number as "file_%d"
+
+ This routine replaces the old routine IOUtil_PrepareFilename()
+ which should not be used anymore.
+ @enddesc
+
+ @var GH
+ @vdesc pointer to CCTK grid hierarchy
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var basefilename
+ @vdesc basename of the file
+ @vtype const char *
+ @vio in
+ @endvar
+ @var postfix
+ @vdesc optional postfix to append to the basename
+ (eg. ".tmp" for temporary files, or "" for no postfix)
+ @vtype const char *
+ @vio in
+ @var extension
+ @vdesc file extension to append to the basefilename
+ (should be given with the dot, eg. as ".h5")
+ @vtype const char *
+ @vio in
+ @endvar
+ @var called_from
+ @vdesc indicates the caller function:
+ * either Filereader (FILEREADER_DATA)
+ * or IOUtil_RecoverGH() (CP_RECOVER_DATA)
+ @vtype int
+ @vio in
+ @endvar
+ @var file_ioproc
+ @vdesc the IO processor number (for chunked files)
+ @vtype int
+ @vio in
+ @endvar
+ @var file_unchunked
+ @vdesc flag to indicate whether file mode is unchunked or not
+ @vtype int
+ @vio in
+ @endvar
+
+ @returntype char *
+ @returndesc
+ the filename (must be freed after use)
+ @endreturndesc
+@@*/
+char *IOUtil_AssembleFilename (const cGH *GH,
+ const char *basefilename,
+ const char *postfix,
+ const char *extension,
+ int called_from,
+ int file_ioproc,
+ int file_unchunked)
+{
+ DECLARE_CCTK_PARAMETERS
+ size_t filenamelen;
+ char *filename;
+ const char *dir, *basename;
+ char iteration_postfix[32], filenumber_postfix[32];
+
+
+ /* get the right parameters */
+ dir = basename = NULL;
+ switch (called_from)
+ {
+ case CP_INITIAL_DATA:
+ dir = checkpoint_dir;
+ basename = checkpoint_ID_file;
+ break;
+
+ case CP_EVOLUTION_DATA:
+ dir = checkpoint_dir;
+ basename = checkpoint_file;
+ break;
+
+ case CP_RECOVER_DATA:
+ case CP_RECOVER_PARAMETERS:
+ case FILEREADER_DATA:
+ dir = recover_dir;
+ basename = basefilename ? basefilename : recover_file;
+ break;
+
+ default:
+ CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOUtil_AssembleFilename: unknown calling mode %d",
+ called_from);
+ break;
+ }
+
+ /* if checkpoint filename, merge in the iteration number
+ and for chunked files also the file number */
+ iteration_postfix[0] = 0;
+ if (called_from == CP_INITIAL_DATA || called_from == CP_EVOLUTION_DATA)
+ {
+ snprintf (iteration_postfix, sizeof (iteration_postfix), ".it_%d",
+ (int) GH->cctk_iteration);
+ }
+
+ /* If not one unchunked file give a file number */
+ filenumber_postfix[0] = 0;
+ if (! file_unchunked)
+ {
+ snprintf (filenumber_postfix, sizeof (filenumber_postfix), ".file_%d",
+ file_ioproc);
+ }
+
+ assert (dir && basename && postfix && extension);
+ filenamelen = strlen (dir) + strlen (basename) + strlen (postfix) +
+ strlen (iteration_postfix) + strlen (filenumber_postfix) +
+ strlen (extension) + 2;
+ filename = malloc (filenamelen);
+ assert (filename);
+ snprintf (filename, filenamelen, "%s/%s%s%s%s%s", dir, basename, postfix,
+ iteration_postfix, filenumber_postfix, extension);
+
+ return (filename);
+}
+
+
+ /*@@
@routine IOUtil_PrepareFilename
@date Fri Aug 21 14:54:38 1998
@author Gerd Lanfermann
@@ -191,6 +325,10 @@ void IOUtil_PrepareFilename (const cGH *GH,
DECLARE_CCTK_PARAMETERS
+ CCTK_WARN (1, "IOUtil_PrepareFilename(): this routine is deprecated in "
+ "beta15 and should not be used anymore. Please use "
+ "IOUtil_AssembleFilename() instead.");
+
/* get the right parameters */
switch (called_from)
{
diff --git a/src/ioutil_CheckpointRecovery.h b/src/ioutil_CheckpointRecovery.h
index c0bf445..d5c27bf 100644
--- a/src/ioutil_CheckpointRecovery.h
+++ b/src/ioutil_CheckpointRecovery.h
@@ -31,6 +31,14 @@ enum {CP_INITIAL_DATA, CP_EVOLUTION_DATA, CP_RECOVER_PARAMETERS,
************************************************************************/
/* create a checkpoint filename */
+char *IOUtil_AssembleFilename (const cGH *GH,
+ const char *basefilename,
+ const char *postfix,
+ const char *extension,
+ int called_from,
+ int file_ioproc,
+ int file_unchunked);
+/* IOUtil_PrepareFilename() is deprecated - don't use it anymore */
void IOUtil_PrepareFilename (const cGH *GH,
const char *basefilename,
char *fname,