summaryrefslogtreecommitdiff
path: root/src/util/File.c
blob: 59f087077f54457b30eb394d53b4f4548abd43e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "cctk.h"

 /*@@
   @file      File.c
   @date      September 6th 1999
   @author    Gabrielle Allen
   @desc
              File Handling routines
   @enddesc
 @@*/             

#include <stdio.h>
#include <stdlib.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;   

 /*@@
   @routine   CCTK_mkdir
   @date      September 6th 1999
   @author    Gabrielle Allen
   @desc
              Create a directory, if we haven't already tried 
              to create it.
   @enddesc
 @@*/             

int CCTK_mkdir(const char *dir)
{
  int retval=-1;
  int handle;
  char *command;
  char *message;
 
  command = (char *)malloc(1024*sizeof(char));

  /* Store directory name */
  handle = Util_GetHandle(DirNames, dir, NULL);


  if (handle < 0)
  {
    /* New directory name */
    handle = Util_NewHandle(&DirNames, dir, NULL);     

  /***
    TR 13/09/99: disabled use of MKDIRFLAGS until it also works for NT
    This means either
      - we make sure to always use the bash's mkdir command (which accepts
        option '-p')
      - call the dos shell with MKDIRFLAGS set to an empty string
      - use the POSIX mkdir routine
    The disadvantage for calling mkdir without '-p' under UNIX is now
    that we can always create one subdirectory only which needs to be
    relative to an existing directory.
   ***/
#if 0
    sprintf(command, MKDIR MKDIRFLAGS " %s",dir);
#else
    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;

  } 
  else
  { 
    retval = -1;
  }

  free(command);

  return retval;

}

void FMODIFIER FORTRAN_NAME(CCTK_mkdir)(int *ierr, ONE_FORTSTRING_ARG)
{
  ONE_FORTSTRING_CREATE(arg1)
  *ierr = CCTK_mkdir(arg1);
  free(arg1); 
}