From cd9a4ea692ba87aa03a80489bf03736e713722c7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Feb 2015 08:54:03 +0200 Subject: Sort out diagnostics for mkdir --- build/buildfile | 2 +- build/mkdir | 22 ++++++++++++++++++++++ build/mkdir.cxx | 21 +++++++++++++++++++++ build/rule.cxx | 21 ++++++++++----------- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 build/mkdir create mode 100644 build/mkdir.cxx 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 // mode_t + +#include + +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 + +#include // mkdir() + +#include + +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 -#include // strerror_r() -#include // mkdir() -#include // mkdir() - -#include // move() +#include // move() +#include #include #include #include +#include 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; -- cgit v1.1