summaryrefslogtreecommitdiff
path: root/rld-path.cpp
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-09-07 10:47:00 +1000
committerChris Johns <chrisj@rtems.org>2014-09-07 10:47:00 +1000
commit5c75d3435ae8e049a3049a6eec1295f1de2694cf (patch)
treef16740b1b5ce05adff8e9451cd58b347091ec0d4 /rld-path.cpp
parent7eb74f8b5318e14508eba980dc97c2813624963e (diff)
rtems-tld: Add --wrapper option to aid testing.
The --wrapper option lets a user control the wrapper file name and location to aid testing. Add keep support to tempfiles so specific tempfile can be set to be kept. Add unlink to the rld::path namespace.
Diffstat (limited to 'rld-path.cpp')
-rw-r--r--rld-path.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/rld-path.cpp b/rld-path.cpp
index 8e24d3a..2163706 100644
--- a/rld-path.cpp
+++ b/rld-path.cpp
@@ -19,6 +19,7 @@
#endif
#include <sys/stat.h>
+#include <unistd.h>
#include <rld.h>
@@ -83,7 +84,8 @@ namespace rld
joined = base + part;
}
- void path_join (const std::string& base, const paths& parts, std::string& joined)
+ void
+ path_join (const std::string& base, const paths& parts, std::string& joined)
{
joined = base;
for (paths::const_iterator pi = parts.begin ();
@@ -128,5 +130,29 @@ namespace rld
path.clear ();
}
+ void
+ unlink (const std::string& path, bool not_present_error)
+ {
+ struct stat sb;
+ if (::stat (path.c_str (), &sb) >= 0)
+ {
+ if (!S_ISREG (sb.st_mode))
+ throw rld::error ("Not a regular file", "unlinking: " + path);
+
+ int r;
+#if _WIN32
+ r = ::remove(path.c_str ());
+#else
+ r = ::unlink (path.c_str ());
+#endif
+ if (r < 0)
+ throw rld::error (::strerror (errno), "unlinking: " + path);
+ }
+ else
+ {
+ if (not_present_error)
+ throw rld::error ("Not found", "unlinking: " + path);
+ }
+ }
}
}