From 0c26f0c94ea2631476edec587439ca436ce0c5a9 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 14 Sep 2015 01:31:31 +0100 Subject: [PATCH] simple api to change dir --- ostd/filesystem.hh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ostd/filesystem.hh b/ostd/filesystem.hh index 31196ca..667802f 100644 --- a/ostd/filesystem.hh +++ b/ostd/filesystem.hh @@ -537,6 +537,19 @@ inline FileInfo path_join(const A &...args) { return FileInfo(path); } +inline bool directory_change(ConstCharRange path) { + char buf[1024]; + if (path.size() >= 1024) + return false; + memcpy(buf, path.data(), path.size()); + buf[path.size()] = '\0'; +#ifndef OSTD_PLATFORM_WIN32 + return !chdir(buf); +#else + return !_chdir(buf); +#endif +} + } /* namespace ostd */ #endif \ No newline at end of file