A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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.
 
std::string ns3::SystemPath::CreateValidSystemPath (const std::string path)
 Replace incompatible characters in a path, to get a path compatible with different file systems.
 
std::string ns3::SystemPath::Dirname (std::string path)
 Get the directory path for a file.
 
bool ns3::SystemPath::Exists (const std::string path)
 Check if a path exists.
 
std::string ns3::SystemPath::FindSelfDirectory ()
 Get the file system path to the current executable.
 
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.
 
void ns3::SystemPath::MakeDirectories (std::string path)
 Create all the directories leading to path.
 
std::string ns3::SystemPath::MakeTemporaryDirectoryName ()
 Get the name of a temporary directory.
 
std::list< std::string > ns3::SystemPath::ReadFiles (std::string path)
 Get the list of files located in a file system directory.
 
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.
 
std::list< std::string > ns3::SystemPath::Split (std::string path)
 Split a file system path into directories according to the local path separator.
 

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 220 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:

◆ CreateValidSystemPath()

std::string ns3::SystemPath::CreateValidSystemPath ( const std::string  path)

Replace incompatible characters in a path, to get a path compatible with different file systems.

Parameters
[in]pathThe path to check.
Returns
A compatible path.

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

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

+ 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 120 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 347 of file system-path.cc.

References ns3::SystemPath::Dirname(), NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::SystemPath::ReadFiles(), and ns3::SystemPath::Split().

+ Here is the call graph for this function:

◆ FindSelfDirectory()

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

Get the file system path to the current executable.

This path is only equivalent to the current working directory when the executable is executed in its parent directory.

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 130 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 247 of file system-path.cc.

References NS_LOG_FUNCTION, and SYSTEM_PATH_SEP.

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

+ 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 330 of file system-path.cc.

References NS_FATAL_ERROR, and NS_LOG_FUNCTION.

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

+ Here is the caller graph for this function:

◆ MakeTemporaryDirectoryName()

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

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-coded 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 numbers 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 285 of file system-path.cc.

References ns3::EnvironmentVariable::Get(), NS_LOG_FUNCTION_NOARGS, and SYSTEM_PATH_SEP.

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

+ Here is the call graph for this function:
+ 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 271 of file system-path.cc.

References NS_FATAL_ERROR, and NS_LOG_FUNCTION.

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

+ 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 86 of file system-path.cc.

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

Referenced by ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow().

+ Here is the call graph for this function:
+ 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 238 of file system-path.cc.

References NS_LOG_FUNCTION, ns3::SplitString(), and SYSTEM_PATH_SEP.

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

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