aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl
diff options
context:
space:
mode:
authorJohannes Schickel2016-01-29 18:09:05 +0100
committerJohannes Schickel2016-02-02 08:45:58 +0100
commitd8394d3f7777d4e6125a4b539c9c17f484dd97e1 (patch)
tree40a1818c190d9d2e4d78042b9537a5bc6668cf5e /backends/platform/sdl
parentbe2af0613143c2a3426be426dec1274e5d79e0a0 (diff)
downloadscummvm-rg350-d8394d3f7777d4e6125a4b539c9c17f484dd97e1.tar.gz
scummvm-rg350-d8394d3f7777d4e6125a4b539c9c17f484dd97e1.tar.bz2
scummvm-rg350-d8394d3f7777d4e6125a4b539c9c17f484dd97e1.zip
POSIX: Factor directory creation code into its own function.
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r--backends/platform/sdl/posix/posix.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index a711c3a96b..07e8ad8448 100644
--- a/backends/platform/sdl/posix/posix.cpp
+++ b/backends/platform/sdl/posix/posix.cpp
@@ -40,6 +40,36 @@
#include <sys/wait.h>
#include <unistd.h>
+namespace {
+/**
+ * Assure that a directory path exists.
+ *
+ * @param path The path which is required to exist.
+ * @return true in case the directoy exists (or was created), false otherwise.
+ */
+bool assureDirectoryExists(const Common::String &path) {
+ struct stat sb;
+
+ // Check whether the dir exists
+ if (stat(path.c_str(), &sb) == -1) {
+ // The dir does not exist, or stat failed for some other reason.
+ if (errno != ENOENT) {
+ return false;
+ }
+
+ // If the problem was that the path pointed to nothing, try
+ // to create the dir.
+ if (mkdir(path.c_str(), 0755) != 0) {
+ return false;
+ }
+ } else if (!S_ISDIR(sb.st_mode)) {
+ // Path is no directory. Oops
+ return false;
+ }
+
+ return true;
+}
+} // End of anonymous namespace
OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName)
:
@@ -113,20 +143,7 @@ Common::WriteStream *OSystem_POSIX::createLogFile() {
logFile = "/mtd_ram";
#endif
- struct stat sb;
-
- // Check whether the dir exists
- if (stat(logFile.c_str(), &sb) == -1) {
- // The dir does not exist, or stat failed for some other reason.
- if (errno != ENOENT)
- return 0;
-
- // If the problem was that the path pointed to nothing, try
- // to create the dir.
- if (mkdir(logFile.c_str(), 0755) != 0)
- return 0;
- } else if (!S_ISDIR(sb.st_mode)) {
- // Path is no directory. Oops
+ if (!assureDirectoryExists(logFile)) {
return 0;
}
@@ -136,18 +153,7 @@ Common::WriteStream *OSystem_POSIX::createLogFile() {
logFile += "/logs";
#endif
- // Check whether the dir exists
- if (stat(logFile.c_str(), &sb) == -1) {
- // The dir does not exist, or stat failed for some other reason.
- if (errno != ENOENT)
- return 0;
-
- // If the problem was that the path pointed to nothing, try
- // to create the dir.
- if (mkdir(logFile.c_str(), 0755) != 0)
- return 0;
- } else if (!S_ISDIR(sb.st_mode)) {
- // Path is no directory. Oops
+ if (!assureDirectoryExists(logFile)) {
return 0;
}