Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TRAIL_UnixUtils.H File Reference
#include <ostream>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
Include dependency graph for TRAIL_UnixUtils.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Directory
 

Functions

std::string TRAIL_CWD (void)
 
void TRAIL_SafeRemove (const std::string &fname, const std::string &ext)
 
int TRAIL_CD (const std::string &path, std::ostream *=NULL)
 
bool TRAIL_FILEEXISTS (const std::string &fname)
 
bool TRAIL_ISDIR (const std::string &fname)
 
bool TRAIL_ISLINK (const std::string &fname)
 
int TRAIL_CreateDirectory (const std::string &fname)
 
std::string TRAIL_ResolveLink (const std::string &path)
 
std::string ResolveLink (const std::string &path)
 

Function Documentation

std::string ResolveLink ( const std::string &  path)

Definition at line 103 of file TRAIL_UnixUtils.C.

References s, and x.

Referenced by TRAIL_RemeshShuffle().

104 {
105  std::string retVal;
106  char buf[1024];
107  size_t s = readlink(path.c_str(),buf,1024);
108  if(!(s <= 0)){
109  buf[s] = '\0';
110  retVal.assign(buf);
111  }
112  std::string::size_type x = retVal.find_last_of("/");
113  if(x != std::string::npos)
114  retVal.erase(x);
115  return (retVal);
116 }
double s
Definition: blastest.C:80
void int int REAL * x
Definition: read.cpp:74

Here is the caller graph for this function:

int TRAIL_CD ( const std::string &  path,
std::ostream *  = NULL 
)

Definition at line 181 of file TRAIL_UnixUtils.C.

References TRAIL_CWD().

Referenced by TRAIL_AutoSurfer(), TRAIL_MergeRocinFiles(), TRAIL_RemeshWrite(), TRAIL_TransferSurfDataFILE(), and TRAIL_WriteWindow().

182 {
183  if(ouf)
184  *ouf << "TRAIL_CD: Switching directory from "
185  << TRAIL_CWD() << " to " << path << std::endl;
186  int result = chdir(path.c_str());
187  if(ouf)
188  *ouf << "TRAIL_CD: CWD(" << TRAIL_CWD() << ")" << std::endl;
189  return(result);
190 
191 }
std::string TRAIL_CWD(void)

Here is the call graph for this function:

Here is the caller graph for this function:

int TRAIL_CreateDirectory ( const std::string &  fname)

Definition at line 81 of file TRAIL_UnixUtils.C.

Referenced by TRAIL_Debug(), TRAIL_RemeshAutoSurfer(), and TRAIL_RemeshWrite().

82 {
83  return(mkdir(fname.c_str(),S_IRGRP | S_IXGRP | S_IRWXU));
84 }

Here is the caller graph for this function:

std::string TRAIL_CWD ( void  )

Definition at line 174 of file TRAIL_UnixUtils.C.

Referenced by TRAIL_AutoSurfer(), TRAIL_CD(), TRAIL_MergeRocinFiles(), TRAIL_RemeshAutoSurfer(), TRAIL_RemeshRunDirSetup(), TRAIL_RemeshWrite(), TRAIL_TransferSurfDataFILE(), TRAIL_WriteWindow(), and GEM_Partition::WriteRocstar().

175 {
176  char buf[1024];
177  return(std::string(getcwd(buf,1024)));
178 }

Here is the caller graph for this function:

bool TRAIL_FILEEXISTS ( const std::string &  fname)

Definition at line 50 of file TRAIL_UnixUtils.C.

Referenced by TRAIL_RemeshWrite(), and TRAIL_SafeRemove().

51 {
52  struct stat fstat;
53  if(lstat(fname.c_str(),&fstat))
54  return false;
55  return true;
56 }

Here is the caller graph for this function:

bool TRAIL_ISDIR ( const std::string &  fname)

Definition at line 59 of file TRAIL_UnixUtils.C.

Referenced by TRAIL_RemeshWrite().

60 {
61  struct stat fstat;
62  if(stat(fname.c_str(),&fstat))
63  return false;
64  if(S_ISDIR(fstat.st_mode))
65  return true;
66  return false;
67 }

Here is the caller graph for this function:

bool TRAIL_ISLINK ( const std::string &  fname)

Definition at line 70 of file TRAIL_UnixUtils.C.

Referenced by TRAIL_RemeshWrite(), and TRAIL_SafeRemove().

71 {
72  struct stat fstat;
73  if(lstat(fname.c_str(),&fstat))
74  return false;
75  if(S_ISLNK(fstat.st_mode))
76  return true;
77  return(false);
78 }

Here is the caller graph for this function:

std::string TRAIL_ResolveLink ( const std::string &  path)

Definition at line 87 of file TRAIL_UnixUtils.C.

References s, and x.

88 {
89  std::string retVal;
90  char buf[1024];
91  size_t s = readlink(path.c_str(),buf,1024);
92  if(!(s <= 0)){
93  buf[s] = '\0';
94  retVal.assign(buf);
95  }
96  std::string::size_type x = retVal.find_last_of("/");
97  if(x != std::string::npos)
98  retVal.erase(x);
99  return (retVal);
100 }
double s
Definition: blastest.C:80
void int int REAL * x
Definition: read.cpp:74
void TRAIL_SafeRemove ( const std::string &  fname,
const std::string &  ext 
)

Definition at line 32 of file TRAIL_UnixUtils.C.

References n, TRAIL_FILEEXISTS(), and TRAIL_ISLINK().

Referenced by TRAIL_RemeshWrite().

33 {
34  if(!TRAIL_FILEEXISTS(fname))
35  return;
36  if(TRAIL_ISLINK(fname))
37  unlink(fname.c_str());
38  std::string savename_base(fname+"."+ext);
39  std::string savename(savename_base);
40  unsigned int n = 1;
41  while(TRAIL_FILEEXISTS(savename)){
42  std::ostringstream Ostr;
43  Ostr << savename_base << n++;
44  savename.assign(Ostr.str());
45  }
46  rename(fname.c_str(),savename.c_str());
47 }
bool TRAIL_FILEEXISTS(const std::string &fname)
const NT & n
bool TRAIL_ISLINK(const std::string &fname)

Here is the call graph for this function:

Here is the caller graph for this function: