summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-04-28 14:56:41 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-04-28 14:56:41 +0000
commit95ddf6ca8d39a2c205c809256cabd4f9960b1e13 (patch)
treedf2b9b9061adc9e09ea5c128b764b6d42775098d /src/util
parent7010d2f26eb69fd2bed2cb1d51d0aa29916cc2fe (diff)
Check with stat(2) if the directory to be created already exists.
This should work for NT as well. Changed return values of CCTK_mkdir(): 0 dir was successfully created positive dir already exists negative failed to create dir for some reason Currently it still uses system(3) to create the dir where you cannot really check for an error code. This should be replaced by mkdir(2) in the future. git-svn-id: http://svn.cactuscode.org/flesh/trunk@1620 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util')
-rw-r--r--src/util/File.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/util/File.c b/src/util/File.c
index 59f08707..67aaa2fa 100644
--- a/src/util/File.c
+++ b/src/util/File.c
@@ -11,16 +11,21 @@
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "cctk_WarnLevel.h"
#include "cctk_FortranString.h"
-#include "StoreHandledData.h"
static char *rcsid = "$Header$";
CCTK_FILEVERSION(util_File_c)
-static cHandledData *DirNames = NULL;
+/* some systems (eg. Windows NT) don't define this macro */
+#ifndef S_ISDIR
+#define S_ISDIR(mode) ((mode) & S_IFMT) == S_IFDIR)
+#endif
+
/*@@
@routine CCTK_mkdir
@@ -30,25 +35,30 @@ static cHandledData *DirNames = NULL;
Create a directory, if we haven't already tried
to create it.
@enddesc
+ @var dir
+ @vdesc directory name to create
+ @vtype const char *
+ @vio in
+ @endvar
+
+ @returntype int
+ @returndesc negative: failed to create dir for some reason
+ 0 dir was successfully created
+ positive directory already exists
+ @endreturndesc
+
@@*/
int CCTK_mkdir(const char *dir)
{
- int retval=-1;
- int handle;
+ int retval;
+ struct stat statbuf;
char *command;
- char *message;
- command = (char *)malloc(1024*sizeof(char));
-
- /* Store directory name */
- handle = Util_GetHandle(DirNames, dir, NULL);
+ if(stat(dir, &statbuf) == 0)
+ return(S_ISDIR(statbuf.st_mode) ? +1 : -1);
-
- if (handle < 0)
- {
- /* New directory name */
- handle = Util_NewHandle(&DirNames, dir, NULL);
+ command = (char *) malloc(strlen(MKDIR MKDIRFLAGS) + strlen(dir) + 2);
/***
TR 13/09/99: disabled use of MKDIRFLAGS until it also works for NT
@@ -62,30 +72,22 @@ int CCTK_mkdir(const char *dir)
relative to an existing directory.
***/
#if 0
- sprintf(command, MKDIR MKDIRFLAGS " %s",dir);
+ sprintf(command, MKDIR MKDIRFLAGS " %s",dir);
#else
- sprintf(command, MKDIR " %s",dir);
+ sprintf(command, MKDIR " %s",dir);
#endif
- message = (char *)malloc(1024*sizeof(char));
- sprintf(message,"Creating directory: \"%s\"",command);
- CCTK_Info("Cactus",message);
- free(message);
-
- /*** FIXME: not sure what a successfull system call look like
- across all architecures - ignore for now
- and set zero for Cactus success ***/
- retval = system(command);
- retval = 0;
+ CCTK_VInfo("Cactus","Creating directory: \"%s\"",command);
- }
- else
- {
- retval = -1;
- }
+ /*** FIXME: not sure what a successful system call looks like
+ across all architecures - ignore for now
+ and set zero for Cactus success ***/
+ retval = system(command);
free(command);
+ retval = 0;
+
return retval;
}
@@ -96,4 +98,3 @@ void FMODIFIER FORTRAN_NAME(CCTK_mkdir)(int *ierr, ONE_FORTSTRING_ARG)
*ierr = CCTK_mkdir(arg1);
free(arg1);
}
-