diff options
Diffstat (limited to 'build')
-rw-r--r-- | build/buildfile | 2 | ||||
-rw-r--r-- | build/mkdir | 22 | ||||
-rw-r--r-- | build/mkdir.cxx | 21 | ||||
-rw-r--r-- | build/rule.cxx | 21 |
4 files changed, 54 insertions, 12 deletions
diff --git a/build/buildfile b/build/buildfile index 14f1063..5ae6bf9 100644 --- a/build/buildfile +++ b/build/buildfile @@ -1,3 +1,3 @@ exe{b1}: cxx{b algorithm scope parser lexer target prerequisite rule \ native context search diagnostics cxx/target cxx/rule process timestamp \ - path utility} + path utility mkdir} diff --git a/build/mkdir b/build/mkdir new file mode 100644 index 0000000..62e824b --- /dev/null +++ b/build/mkdir @@ -0,0 +1,22 @@ +// file : build/mkdir -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD_MKDIR +#define BUILD_MKDIR + +#include <sys/types.h> // mode_t + +#include <build/path> + +namespace build +{ + // Note that you should probably use the default mode 0777 and let + // the umask mechanism adjust it to the user's preferences. Errors + // are reported by throwing std::system_error. + // + void + mkdir (const path&, mode_t = 0777); +} + +#endif // BUILD_MKDIR diff --git a/build/mkdir.cxx b/build/mkdir.cxx new file mode 100644 index 0000000..1fbab03 --- /dev/null +++ b/build/mkdir.cxx @@ -0,0 +1,21 @@ +// file : build/mkdir.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include <build/mkdir> + +#include <sys/stat.h> // mkdir() + +#include <system_error> + +using namespace std; + +namespace build +{ + void + mkdir (const path& p, mode_t m) + { + if (::mkdir (p.string ().c_str (), m) != 0) + throw system_error (errno, system_category ()); + } +} diff --git a/build/rule.cxx b/build/rule.cxx index e57feca..41296f0 100644 --- a/build/rule.cxx +++ b/build/rule.cxx @@ -4,15 +4,13 @@ #include <build/rule> -#include <string.h> // strerror_r() -#include <sys/stat.h> // mkdir() -#include <sys/types.h> // mkdir() - -#include <utility> // move() +#include <utility> // move() +#include <system_error> #include <build/algorithm> #include <build/diagnostics> #include <build/timestamp> +#include <build/mkdir> using namespace std; @@ -169,13 +167,14 @@ namespace build else text << "mkdir " << t; //@@ Probably only show if [show]? - if (mkdir (d.string ().c_str (), 0777) != 0) + try + { + mkdir (d); + } + catch (const system_error& e) { - char b[512]; - const char* m (strerror_r (errno, b, sizeof (b)) == 0 - ? b - : "error message too long"); - fail << "mkdir: unable to create directory " << d.string () << ": " << m; + fail << "unable to create directory " << d.string () << ": " + << e.what (); } return target_state::updated; |