1 // GnashFileUtilities.cpp File handling for Gnash
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef GNASH_FILE_HEADERS_H
21 #define GNASH_FILE_HEADERS_H
23 #include "GnashFileUtilities.h"
26 #include <boost/tokenizer.hpp>
31 /// Create a directory for a given filename.
33 /// Everything after the last '/' is assumed to be the filename.
35 mkdirRecursive(const std::string
& filename
)
37 // Not a directory, nothing to do.
38 std::string::size_type pos
= filename
.rfind("/");
39 if (pos
== std::string::npos
) {
42 const std::string
& target
= filename
.substr(0, pos
);
44 typedef boost::tokenizer
<boost::char_separator
<char> > Tok
;
45 boost::char_separator
<char> sep("/");
48 // Start from the root if the given filename was given
49 // with an absolute path
50 if ( filename
[0] == '/' ) newdir
+= "/";
52 for (Tok::iterator tit
= t
.begin(); tit
!= t
.end(); ++tit
) {
56 if (newdir
.find("..") != std::string::npos
) {
60 int ret
= mkdirUserPermissions(newdir
);
62 if ((errno
!= EEXIST
) && (ret
!= 0)) {
65 newdir
.push_back('/');