paths: add system path queries
This commit is contained in:
parent
3d085c4de7
commit
74700363ab
@ -494,6 +494,7 @@ list (
|
|||||||
parse/value.hpp
|
parse/value.hpp
|
||||||
parse/si.cpp
|
parse/si.cpp
|
||||||
parse/si.hpp
|
parse/si.hpp
|
||||||
|
paths.cpp
|
||||||
paths.hpp
|
paths.hpp
|
||||||
platform.hpp
|
platform.hpp
|
||||||
point.cpp
|
point.cpp
|
||||||
@ -752,6 +753,7 @@ if (TESTS)
|
|||||||
parse/value
|
parse/value
|
||||||
parse/time
|
parse/time
|
||||||
parse/si
|
parse/si
|
||||||
|
paths
|
||||||
point
|
point
|
||||||
polynomial
|
polynomial
|
||||||
pool
|
pool
|
||||||
|
11
paths.hpp
11
paths.hpp
@ -3,15 +3,24 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*
|
*
|
||||||
* Copyright 2020, Danny Robson <danny@nerdcruft.net>
|
* Copyright 2022, Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
namespace cruft::paths {
|
namespace cruft::paths {
|
||||||
|
/// Return the path to the system's temporary directory.
|
||||||
|
std::filesystem::path temp (void);
|
||||||
|
|
||||||
|
|
||||||
|
/// Expand paths that contain platform specific variables
|
||||||
|
///
|
||||||
|
/// eg, "$TMPDIR/foo" and "%HOMEPATH%/foo"
|
||||||
std::filesystem::path
|
std::filesystem::path
|
||||||
expand (std::filesystem::path const&);
|
expand (std::filesystem::path const&);
|
||||||
}
|
}
|
@ -16,6 +16,17 @@
|
|||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::filesystem::path
|
||||||
|
cruft::paths::temp (void)
|
||||||
|
{
|
||||||
|
if (char const *tmpdir = getenv ("TMPDIR"); tmpdir)
|
||||||
|
return tmpdir;
|
||||||
|
|
||||||
|
return "/tmp";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
std::filesystem::path
|
std::filesystem::path
|
||||||
cruft::paths::expand (std::filesystem::path const &val)
|
cruft::paths::expand (std::filesystem::path const &val)
|
||||||
@ -29,4 +40,4 @@ cruft::paths::expand (std::filesystem::path const &val)
|
|||||||
|
|
||||||
CHECK_EQ (words.we_offs, 0u);
|
CHECK_EQ (words.we_offs, 0u);
|
||||||
return words.we_wordv[0];
|
return words.we_wordv[0];
|
||||||
}
|
}
|
15
test/paths.cpp
Normal file
15
test/paths.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <cruft/util/tap.hpp>
|
||||||
|
|
||||||
|
#include <cruft/util/paths.hpp>
|
||||||
|
#include <cruft/util/fs/scoped.hpp>
|
||||||
|
#include <cruft/util/fs/tmp.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
int main (int, char**)
|
||||||
|
{
|
||||||
|
cruft::TAP::logger tap;
|
||||||
|
|
||||||
|
tap.expect (!cruft::paths::temp ().empty (), "temp directory is not empty");
|
||||||
|
|
||||||
|
return tap.status ();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user