diff options
author | Johannes Schickel | 2010-11-29 18:30:23 +0000 |
---|---|---|
committer | Johannes Schickel | 2010-11-29 18:30:23 +0000 |
commit | 39aad6ece718acb39ad38ba5858f2aeeb5c29474 (patch) | |
tree | 1e962555638267bf675dc4ec4d26791441c5c9f5 /backends/platform/sdl/posix | |
parent | 91a6b7f5372bfb93a1a7816ea1b7f3a5c65164fd (diff) | |
download | scummvm-rg350-39aad6ece718acb39ad38ba5858f2aeeb5c29474.tar.gz scummvm-rg350-39aad6ece718acb39ad38ba5858f2aeeb5c29474.tar.bz2 scummvm-rg350-39aad6ece718acb39ad38ba5858f2aeeb5c29474.zip |
SDL: Move createLogFile implementions to the OSystem_SDL subclasses.
svn-id: r54581
Diffstat (limited to 'backends/platform/sdl/posix')
-rw-r--r-- | backends/platform/sdl/posix/posix.cpp | 51 | ||||
-rw-r--r-- | backends/platform/sdl/posix/posix.h | 2 |
2 files changed, 53 insertions, 0 deletions
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 6f91188184..65a3f52f6f 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -31,6 +31,9 @@ #include "backends/saves/posix/posix-saves.h" #include "backends/fs/posix/posix-fs-factory.h" +#include <errno.h> +#include <sys/stat.h> + OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName) : _baseConfigName(baseConfigName) { @@ -67,4 +70,52 @@ Common::String OSystem_POSIX::getDefaultConfigFileName() { return configFile; } +Common::WriteStream *OSystem_POSIX::createLogFile() { + const char *home = getenv("HOME"); + if (home == NULL) + return 0; + + Common::String logFile(home); + logFile += "/.scummvm"; + + 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 + return 0; + } + + logFile += "/logs"; + + // 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 + return 0; + } + + logFile += "/scummvm.log"; + + Common::FSNode file(logFile); + return file.createWriteStream(); +} + #endif diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index 13f9304f1e..a0a0b89c40 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -43,6 +43,8 @@ protected: Common::String _baseConfigName; virtual Common::String getDefaultConfigFileName(); + + virtual Common::WriteStream *createLogFile(); }; #endif |