A Discrete-Event Network Simulator
API
Host Filesystem

Encapsulate OS-specific functions to manipulate file and directory paths. More...

+ Collaboration diagram for Host Filesystem:

Files

file  system-path-examples.cc
 Example program illustrating use of ns3::SystemPath.
 
file  system-path.cc
 ns3::SystemPath implementation.
 
file  system-path.h
 ns3::SystemPath declarations.
 

Namespaces

namespace  ns3::SystemPath
 Namespace for various file and directory path functions.
 

Functions

std::string ns3::SystemPath::Append (std::string left, std::string right)
 Join two file system path elements. More...
 
std::string ns3::SystemPath::Dirname (std::string path)
 Get the directory path for a file. More...
 
bool ns3::SystemPath::Exists (const std::string path)
 Check if a path exists. More...
 
std::string ns3::SystemPath::FindSelfDirectory (void)
 Get the file system path to the current executable. More...
 
std::string ns3::SystemPath::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. More...
 
void ns3::SystemPath::MakeDirectories (std::string path)
 Create all the directories leading to path. More...
 
std::string ns3::SystemPath::MakeTemporaryDirectoryName (void)
 Get the name of a temporary directory. More...
 
std::list< std::string > ns3::SystemPath::ReadFiles (std::string path)
 Get the list of files located in a file system directory. More...
 
std::tuple< std::list< std::string >, bool > ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow (std::string path)
 Get the list of files located in a file system directory with error. More...
 
std::list< std::string > ns3::SystemPath::Split (std::string path)
 Split a file system path into directories according to the local path separator. More...
 

Detailed Description

Encapsulate OS-specific functions to manipulate file and directory paths.

The functions provided here are used mostly to implement the ns-3 test framework.

Function Documentation

◆ Append()

std::string ns3::SystemPath::Append ( std::string  left,
std::string  right 
)

Join two file system path elements.

Parameters
[in]leftA path element
[in]rightA path element
Returns
A concatenation of the two input paths

Definition at line 241 of file system-path.cc.

References NS_LOG_FUNCTION, and SYSTEM_PATH_SEP.

Referenced by ns3::TestCase::CreateDataDirFilename(), ns3::TestCase::CreateTempDirFilename(), ns3::DesMetrics::Initialize(), and ns3::CommandLine::PrintDoxygenUsage().

+ Here is the caller graph for this function:

◆ Dirname()

std::string ns3::SystemPath::Dirname ( std::string  path)

Get the directory path for a file.

This is an internal function (by virtue of not being declared in a .h file); the public API is FindSelfDirectory().

Parameters
[in]pathThe full path to a file.
Returns
The full path to the containing directory.

Definition at line 141 of file system-path.cc.

References ns3::SystemPath::Join(), NS_LOG_FUNCTION, and ns3::SystemPath::Split().

Referenced by ns3::SystemPath::Exists(), and ns3::SystemPath::FindSelfDirectory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Exists()

bool ns3::SystemPath::Exists ( const std::string  path)

Check if a path exists.

Path can be a file or directory.

Parameters
[in]pathThe path to check.
Returns
true if the path exists.

Definition at line 393 of file system-path.cc.

References ns3::SystemPath::Dirname(), create-module::file, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::SystemPath::ReadFiles(), ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow(), and ns3::SystemPath::Split().

+ Here is the call graph for this function:

◆ FindSelfDirectory()

std::string ns3::SystemPath::FindSelfDirectory ( void  )

Get the file system path to the current executable.

Returns
The directory in which the currently-executing binary is located

This function returns the path to the running $PREFIX. Mac OS X: _NSGetExecutablePath() (man 3 dyld) Linux: readlink /proc/self/exe Solaris: getexecname() FreeBSD: sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1 BSD with procfs: readlink /proc/curproc/file Windows: GetModuleFileName() with hModule = NULL

Definition at line 150 of file system-path.cc.

References ns3::SystemPath::Dirname(), NS_ASSERT, NS_FATAL_ERROR, and NS_LOG_FUNCTION_NOARGS.

Referenced by ns3::TestRunnerImpl::GetTopLevelSourceDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Join()

std::string ns3::SystemPath::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.

This is the inverse of Split.

Parameters
[in]beginIterator to first element to join
[in]endIterator to one past the last element to join
Returns
A path that is a concatenation of all the input elements.

Definition at line 276 of file system-path.cc.

References NS_LOG_FUNCTION, and SYSTEM_PATH_SEP.

Referenced by ns3::TestCase::CreateTempDirFilename(), ns3::SystemPath::Dirname(), ns3::TestRunnerImpl::GetTopLevelSourceDir(), and ns3::SystemPath::MakeDirectories().

+ Here is the caller graph for this function:

◆ MakeDirectories()

void ns3::SystemPath::MakeDirectories ( std::string  path)

Create all the directories leading to path.

Parameters
[in]pathA path to a directory

Definition at line 361 of file system-path.cc.

References ns3::SystemPath::Join(), NS_LOG_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::SystemPath::Split().

Referenced by ns3::TestCase::CreateTempDirFilename().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeTemporaryDirectoryName()

std::string ns3::SystemPath::MakeTemporaryDirectoryName ( void  )

Get the name of a temporary directory.

The returned path identifies a directory which does not exist yet. Call ns3::SystemPath::MakeDirectories to create it. Yes, there is a well-known security race in this API but we don't care in ns-3.

The final path to the directory is going to look something like

/tmp/ns3.14.30.29.32767

The first part, "/tmp/" is the absolute path found by inspecting the environment variables TMPand TEMP, in order. If neither exists the hard-codes root path /tmp/ is used.

The directory name itself starts with the "ns3" identifier telling folks who is making all of the temp directories.

The next three number give the hour, minute and second, separated by periods.

The final number is randomly generated, to avoid name collisions.

Returns
A path which identifies a temporary directory.

Definition at line 314 of file system-path.cc.

References sample-rng-plot::n, NS_LOG_FUNCTION_NOARGS, and SYSTEM_PATH_SEP.

Referenced by ns3::TestRunnerImpl::Run().

+ Here is the caller graph for this function:

◆ ReadFiles()

std::list< std::string > ns3::SystemPath::ReadFiles ( std::string  path)

Get the list of files located in a file system directory.

Parameters
[in]pathA path which identifies a directory
Returns
A list of the filenames which are located in the input directory

Definition at line 300 of file system-path.cc.

References NS_FATAL_ERROR, NS_LOG_FUNCTION, and ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow().

Referenced by ns3::SystemPath::Exists(), and ns3::TestRunnerImpl::IsTopLevelSourceDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadFilesNoThrow()

std::tuple< std::list< std::string >, bool > ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow ( std::string  path)

Get the list of files located in a file system directory with error.

Parameters
[in]pathA path which identifies a directory
Returns
Tuple with a list of the filenames which are located in the input directory or error flag true if directory doesn't exist.

Definition at line 87 of file system-path.cc.

References NS_LOG_FUNCTION.

Referenced by ns3::SystemPath::Exists(), and ns3::SystemPath::ReadFiles().

+ Here is the caller graph for this function:

◆ Split()

std::list< std::string > ns3::SystemPath::Split ( std::string  path)

Split a file system path into directories according to the local path separator.

This is the inverse of Join.

Parameters
[in]pathA path
Returns
A list of path elements that can be joined together again with the Join function.
See also
ns3::SystemPath::Join

Definition at line 258 of file system-path.cc.

References NS_LOG_FUNCTION, and SYSTEM_PATH_SEP.

Referenced by ns3::CommandLine::CommandLine(), ns3::SystemPath::Dirname(), ns3::SystemPath::Exists(), ns3::TestRunnerImpl::GetTopLevelSourceDir(), ns3::DesMetrics::Initialize(), and ns3::SystemPath::MakeDirectories().

+ Here is the caller graph for this function: