diff options
-rw-r--r-- | src/util/File.c | 65 |
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); } - |