ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
fs.h
1 // --- Hongce Zhang
7 
8 #ifndef ILANG_UTIL_FS_H__
9 #define ILANG_UTIL_FS_H__
10 
11 #include <string>
12 #include <vector>
13 
14 namespace ilang {
15 
17 bool os_portable_exist(const std::string& path);
18 
20 bool os_portable_mkdir(const std::string& dir);
21 
23 bool os_portable_copy_dir(const std::string& src, const std::string& dst);
24 
26 bool os_portable_copy_file_to_dir(const std::string& src,
27  const std::string& dst);
28 
30 bool os_portable_move_file_to_dir(const std::string& src,
31  const std::string& dst);
32 
34 bool os_portable_remove_file(const std::string& file);
35 
37 bool os_portable_remove_directory(const std::string& dir);
38 
40 std::string os_portable_append_dir(const std::string& dir1,
41  const std::string& dir2);
42 
44 std::string os_portable_append_dir(const std::string& dir1,
45  const std::vector<std::string>& dirs);
46 
48 std::string os_portable_join_dir(const std::vector<std::string>& dirs);
49 
51 std::string os_portable_remove_file_name_extension(const std::string& fname);
52 
56  bool timeout;
58  enum _failure { PREIO = 0, FORK = 1, ALARM, ARG, EXEC, WAIT, NONE } failure;
60  unsigned ret;
64  double seconds;
65 };
66 
68 enum redirect_t { NONE = 0, STDOUT = 1, STDERR = 2, BOTH = 3 };
71 execute_result
72 os_portable_execute_shell(const std::vector<std::string>& cmdargs,
73  const std::string& redirect_output_file = "",
74  redirect_t rdt = redirect_t::BOTH,
75  unsigned timeout = 0,
76  const std::string& pid_file_name = "");
77 
81 std::string os_portable_file_name_from_path(const std::string& path);
82 
87 std::string os_portable_path_from_path(const std::string& path);
88 
90 std::string os_portable_read_last_line(const std::string& filename);
91 
93 bool os_portable_chdir(const std::string& dirname);
94 
96 std::string os_portable_getcwd();
97 
98 #if (defined(__unix__) || defined(unix) || defined(__APPLE__) || \
99  defined(__MACH__) || defined(__FreeBSD__)) && \
100  !defined(__linux__)
101 
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105 
127 FILE* fmemopen_osx(void* buf, size_t size, const char* mode);
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif // fmemopen_osx guard
134 
135 }; // namespace ilang
136 
137 #endif // ILANG_UTIL_FS_H__
bool os_portable_remove_file(const std::string &file)
Remove one file.
std::string os_portable_path_from_path(const std::string &path)
double seconds
the execution time
Definition: fs.h:64
bool os_portable_remove_directory(const std::string &dir)
Remove one directory.
std::string os_portable_append_dir(const std::string &dir1, const std::string &dir2)
Append two paths.
bool os_portable_copy_dir(const std::string &src, const std::string &dst)
Copy all file from a source dir to the destination dir.
bool os_portable_move_file_to_dir(const std::string &src, const std::string &dst)
Move one file to the destination dir.
bool os_portable_mkdir(const std::string &dir)
Create a dir, true -&gt; suceeded , ow false.
std::string os_portable_remove_file_name_extension(const std::string &fname)
C:\a.txt -&gt; C:\a or /a/b/c.txt -&gt; a/b/c.
bool subexit_normal
true if it exits with _exit() call
Definition: fs.h:62
bool os_portable_exist(const std::string &path)
Check if path exist.
bool timeout
has timeout
Definition: fs.h:56
the result from executing
Definition: fs.h:54
redirect_t
the type of redirect
Definition: fs.h:68
std::string os_portable_getcwd()
Get the current directory.
bool os_portable_copy_file_to_dir(const std::string &src, const std::string &dst)
Copy one file to the destination dir.
execute_result os_portable_execute_shell(const std::vector< std::string > &cmdargs, const std::string &redirect_output_file="", redirect_t rdt=redirect_t::BOTH, unsigned timeout=0, const std::string &pid_file_name="")
bool os_portable_chdir(const std::string &dirname)
Change current directory: true if success.
std::string os_portable_read_last_line(const std::string &filename)
read the last meaningful line from a file
std::string os_portable_file_name_from_path(const std::string &path)
unsigned ret
return value
Definition: fs.h:60
_failure
failed execution
Definition: fs.h:58
std::string os_portable_join_dir(const std::vector< std::string > &dirs)
Join paths.