update copyright date
[gnash.git] / libbase / GnashFileUtilities.h
blob3a0c27b590adf36ce12ace31ce1ecdab91240ff3
1 // GnashFileUtilities.h File handling for Gnash
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
5 //
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.
10 //
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.
15 //
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
21 /// This file should also be included for the following system functions:
23 /// stat()
24 /// fstat()
25 /// lstat()
26 /// dup()
27 /// readdir()
28 #ifndef GNASH_FILE_UTILITIES_H
29 #define GNASH_FILE_UTILITIES_H
31 #include "dsodefs.h"
33 #if !defined(_MSC_VER)
34 # include <unistd.h>
35 # include <sys/stat.h>
36 # include <sys/types.h>
37 # include <dirent.h>
38 # include <cerrno>
39 #else
40 #include <io.h>
41 #define dup _dup
42 #endif
44 #include <string>
46 namespace gnash {
48 /// Create a directory, granting owner rwx permissions.
50 /// On non-POSIX systems, just create the directory.
51 ///
52 /// @param dirname
53 /// Directory name, may be absolute or relative to CWD
54 ///
55 inline int mkdirUserPermissions(const std::string& dirname)
57 #if !defined(_WIN32) && !defined(_MSC_VER) && !defined(__amigaos4__)
58 return mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
59 #elif defined(__amigaos4__)
60 // on AmigaOS4 if you try to create a directory that is an assign or a drive
61 // you will receive an EINVAL or an ENOTDIR instead of EEXIST and so will force it
62 int ret = 0;
63 ret = mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
64 if (errno == EINVAL || errno == ENOTDIR)
65 errno = EEXIST;
66 return ret;
67 #else
68 return mkdir(dirname.c_str());
69 #endif
72 /// Create a directory for a given filename.
74 /// Everything after the last '/' is assumed to be the filename.
75 ///
76 /// @param filename
77 /// Full file path, may be absolute or relative to CWD
78 ///
79 DSOEXPORT bool mkdirRecursive(const std::string& filename);
81 } // namespace gnash
83 #endif