1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #include <sys/types.h>
42 #include <anna/core/util/Tokenizer.hpp>
43 #include <anna/config/defines.hpp>
44 #include <anna/core/functions.hpp>
46 #include <anna/io/functions.hpp>
51 void io::functions::mkdir(const std::string& path)
52 throw(RuntimeException) {
56 tokenizer.apply(path, "/");
58 for(Tokenizer::const_iterator ii = tokenizer.begin(), maxii = tokenizer.end(); ii != maxii; ii ++) {
60 w += Tokenizer::data(ii);
62 if(io::functions::exists(w) == false) {
63 anna_signal_shield(r, ::mkdir(w.c_str(), S_IRWXU | S_IRWXG));
66 throw RuntimeException(path, errno, ANNA_FILE_LOCATION);
71 bool io::functions::exists(const char* path)
72 throw(RuntimeException) {
75 anna_signal_shield(r, stat(path, &data));
83 throw RuntimeException(path, errno, ANNA_FILE_LOCATION);
86 bool io::functions::isADirectory(const char* path)
87 throw(RuntimeException) {
90 anna_signal_shield(r, stat(path, &data));
93 throw RuntimeException(path, errno, ANNA_FILE_LOCATION);
95 return ((data.st_mode & S_IFDIR) != 0);
98 ino_t io::functions::getINode(const char* path)
99 throw(RuntimeException) {
102 anna_signal_shield(r, stat(path, &data));
105 throw RuntimeException(path, errno, ANNA_FILE_LOCATION);
111 bool io::functions::waitInput(const int fd, const Millisecond &timeout)
112 throw(RuntimeException) {
116 waiting.events = POLLIN;
117 anna_signal_shield(r, poll(&waiting, 1, timeout));
120 string msg("io::functions::waitInput: ");
121 msg += anna::functions::asString(fd);
122 throw RuntimeException(msg, errno, ANNA_FILE_LOCATION);