24 #include "ns3/core-config.h" 30 #if defined (HAVE_DIRENT_H) && defined (HAVE_SYS_TYPES_H) 33 #include <sys/types.h> 36 #if defined (HAVE_SYS_STAT_H) && defined (HAVE_SYS_TYPES_H) 39 #include <sys/types.h> 44 #include <mach-o/dyld.h> 48 #include <sys/types.h> 49 #include <sys/sysctl.h> 60 #if defined (__win32__) 61 #define SYSTEM_PATH_SEP "\\" 63 #define SYSTEM_PATH_SEP "/" 76 namespace SystemPath {
91 std::list<std::string> elements =
Split (path);
92 std::list<std::string>::const_iterator last = elements.end();
94 return Join (elements.begin (), last);
109 std::string filename;
110 #if defined(__linux__) 113 char *buffer = (
char*)malloc (size);
114 memset (buffer, 0, size);
118 status = readlink(
"/proc/self/exe", buffer, size);
119 if (status != 1 || (status == -1 && errno != ENAMETOOLONG))
125 buffer = (
char*)malloc (size);
126 memset (buffer, 0, size);
135 #elif defined (__win32__) 141 LPTSTR lpFilename = (LPTSTR) malloc (
sizeof(TCHAR) * size);
142 DWORD status = GetModuleFilename (0, lpFilename, size);
143 while (status == size)
147 lpFilename = (LPTSTR) malloc (
sizeof(TCHAR) * size);
148 status = GetModuleFilename (0, lpFilename, size);
151 filename = lpFilename;
154 #elif defined (__APPLE__) 156 uint32_t bufsize = 1024;
157 char *buffer = (
char *) malloc (bufsize);
159 int status = _NSGetExecutablePath (buffer, &bufsize);
163 buffer = (
char *) malloc (bufsize);
164 status = _NSGetExecutablePath (buffer, &bufsize);
170 #elif defined (__FreeBSD__) 173 std::size_t bufSize = 1024;
174 char *buf = (
char *) malloc(bufSize);
178 mib[2] = KERN_PROC_PATHNAME;
181 sysctl(mib, 4, buf, &bufSize, NULL, 0);
188 std::string
Append (std::string left, std::string right)
195 if (lastSep != left.size () - 1)
199 left = left.substr (0, left.size () - 1);
205 std::list<std::string>
Split (std::string path)
208 std::list<std::string> retval;
209 std::string::size_type current = 0, next = 0;
211 while (next != std::string::npos)
213 std::string item = path.substr (current, next - current);
214 retval.push_back (item);
218 std::string item = path.substr (current, next - current);
219 retval.push_back (item);
223 std::string
Join (std::list<std::string>::const_iterator begin,
224 std::list<std::string>::const_iterator end)
227 std::string retval =
"";
228 for (std::list<std::string>::const_iterator i = begin; i != end; i++)
245 std::list<std::string> files;
246 #if defined HAVE_OPENDIR 247 DIR *dp = opendir (path.c_str ());
252 struct dirent *de = readdir (dp);
255 files.push_back (de->d_name);
259 #elif defined (HAVE_FIND_FIRST_FILE) 262 WIN32_FIND_DATA fileData;
264 hFind = FindFirstFile (path.c_str (), &FindFileData);
265 if (hFind == INVALID_HANDLE_VALUE)
271 files.push_back (fileData.cFileName);
272 }
while (FindNextFile (hFind, &fileData));
275 #error "No support for reading a directory on this platform" 286 path = getenv (
"TMP");
289 path = getenv (
"TEMP");
292 path =
const_cast<char *
> (
"/tmp");
300 time_t now = time (NULL);
301 struct tm *tm_now = localtime (&now);
307 long int n = rand ();
320 std::ostringstream oss;
322 << tm_now->tm_min <<
"." << tm_now->tm_sec <<
"." <<
n;
333 std::list<std::string> elements =
Split (path);
334 auto i = elements.begin ();
335 while (i != elements.end ())
345 std::string tmp =
Join (elements.begin (), i);
346 bool makeDirErr =
false;
348 #if defined(HAVE_MKDIR_H) 349 makeDirErr = mkdir (tmp.c_str (), S_IRWXU);
NS_FATAL_x macro definitions.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
std::list< std::string > Split(std::string path)
Split a file system path into directories according to the local path separator.
ns3::SystemPath declarations.
std::string Join(std::list< std::string >::const_iterator begin, std::list< std::string >::const_iterator end)
Join a list of file system path directories into a single file system path.
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
std::string MakeTemporaryDirectoryName(void)
Get the name of a temporary directory.
std::list< std::string > ReadFiles(std::string path)
Get the list of files located in a file system directory.
std::string Dirname(std::string path)
Get the directory path for a file.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
void MakeDirectories(std::string path)
Create all the directories leading to path.
std::string FindSelfDirectory(void)
Get the file system path to the current executable.
std::string Append(std::string left, std::string right)
Join two file system path elements.
#define SYSTEM_PATH_SEP
System-specific path separator used between directory names.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.