aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorCameron Cawley2019-11-03 22:48:37 +0000
committerDavid Turner2019-11-30 20:50:27 +0000
commit88761ea49ce5244dc33a0784bbfba702f82d3241 (patch)
tree72f30b7d8a231954700301807671d8e7f8d4015a /backends/platform
parent1af858466684d0e7c4f23389a5433aa8741592fa (diff)
downloadscummvm-rg350-88761ea49ce5244dc33a0784bbfba702f82d3241.tar.gz
scummvm-rg350-88761ea49ce5244dc33a0784bbfba702f82d3241.tar.bz2
scummvm-rg350-88761ea49ce5244dc33a0784bbfba702f82d3241.zip
GPH/OPENPANDORA: Replace use of strcat()/strcpy() with Common::String()
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/gph/gph-backend.cpp59
-rw-r--r--backends/platform/gph/gph.h7
-rw-r--r--backends/platform/openpandora/op-backend.cpp54
-rw-r--r--backends/platform/openpandora/op-sdl.h7
4 files changed, 52 insertions, 75 deletions
diff --git a/backends/platform/gph/gph-backend.cpp b/backends/platform/gph/gph-backend.cpp
index 3a5180149f..340b906dba 100644
--- a/backends/platform/gph/gph-backend.cpp
+++ b/backends/platform/gph/gph-backend.cpp
@@ -43,8 +43,7 @@
#include "audio/mixer_intern.h"
-#include <unistd.h>
-#include <limits.h>
+#include <unistd.h> // for getcwd()
/* Dump console info to files. */
#define DUMP_STDOUT
@@ -54,61 +53,58 @@ OSystem_GPH::OSystem_GPH()
OSystem_POSIX() {
}
+Common::String OSystem_GPH::getCurrentDirectory() {
+ char cwd[MAXPATHLEN+1];
+ return Common::String(getcwd(cwd, MAXPATHLEN));
+}
+
void OSystem_GPH::initBackend() {
assert(!_inited);
/* Setup default save path to be workingdir/saves */
- char savePath[PATH_MAX+1];
- char workDirName[PATH_MAX+1];
-
- if (getcwd(workDirName, PATH_MAX) == NULL) {
+ Common::String workDirName = getCurrentDirectory();
+ if (workDirName.empty()) {
error("Could not obtain current working directory.");
} else {
- printf("Current working directory: %s\n", workDirName);
+ printf("Current working directory: %s\n", workDirName.c_str());
}
- strcpy(savePath, workDirName);
- strcat(savePath, "/saves");
- printf("Current save directory: %s\n", savePath);
+ Common::String savePath = workDirName + "/saves";
+ printf("Current save directory: %s\n", savePath.c_str());
_savefileManager = new DefaultSaveFileManager(savePath);
#ifdef DUMP_STDOUT
// The GPH devices have a serial console on the breakout board
// but most users do not use this so we output all our STDOUT
// and STDERR to files for debug purposes.
- char STDOUT_FILE[PATH_MAX+1];
- char STDERR_FILE[PATH_MAX+1];
-
- strcpy(STDOUT_FILE, workDirName);
- strcpy(STDERR_FILE, workDirName);
- strcat(STDOUT_FILE, "/scummvm.stdout.txt");
- strcat(STDERR_FILE, "/scummvm.stderr.txt");
+ Common::String STDOUT_FILE = workDirName + "/scummvm.stdout.txt";
+ Common::String STDERR_FILE = workDirName + "/scummvm.stderr.txt";
// Flush the output in case anything is queued
fclose(stdout);
fclose(stderr);
// Redirect standard input and standard output
- FILE *newfp = freopen(STDOUT_FILE, "w", stdout);
+ FILE *newfp = freopen(STDOUT_FILE.c_str(), "w", stdout);
if (newfp == NULL) {
#if !defined(stdout)
- stdout = fopen(STDOUT_FILE, "w");
+ stdout = fopen(STDOUT_FILE.c_str(), "w");
#else
- newfp = fopen(STDOUT_FILE, "w");
+ newfp = fopen(STDOUT_FILE.c_str(), "w");
if (newfp) {
*stdout = *newfp;
}
#endif
}
- newfp = freopen(STDERR_FILE, "w", stderr);
+ newfp = freopen(STDERR_FILE.c_str(), "w", stderr);
if (newfp == NULL) {
#if !defined(stderr)
- stderr = fopen(STDERR_FILE, "w");
+ stderr = fopen(STDERR_FILE.c_str(), "w");
#else
- newfp = fopen(STDERR_FILE, "w");
+ newfp = fopen(STDERR_FILE.c_str(), "w");
if (newfp) {
*stderr = *newfp;
}
@@ -175,9 +171,8 @@ void OSystem_GPH::initSDL() {
void OSystem_GPH::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
/* Setup default extra data paths for engine data files and plugins */
- char workDirName[PATH_MAX+1];
-
- if (getcwd(workDirName, PATH_MAX) == NULL) {
+ Common::String workDirName = getCurrentDirectory();
+ if (workDirName.empty()) {
error("Error: Could not obtain current working directory.");
}
@@ -186,21 +181,13 @@ void OSystem_GPH::addSysArchivesToSearchSet(Common::SearchSet &s, int priority)
s.add("__GP2XWIZ_WORKDIR__", new Common::FSDirectory(workDirName), priority);
}
- char enginedataPath[PATH_MAX+1];
-
- strcpy(enginedataPath, workDirName);
- strcat(enginedataPath, "/engine-data");
-
+ Common::String enginedataPath = workDirName + "/engine-data";
Common::FSNode engineNode(enginedataPath);
if (engineNode.exists() && engineNode.isDirectory()) {
s.add("__GP2XWIZ_ENGDATA__", new Common::FSDirectory(enginedataPath), priority);
}
- char pluginsPath[PATH_MAX+1];
-
- strcpy(pluginsPath, workDirName);
- strcat(pluginsPath, "/plugins");
-
+ Common::String pluginsPath = workDirName + "/plugins";
Common::FSNode pluginsNode(pluginsPath);
if (pluginsNode.exists() && pluginsNode.isDirectory()) {
s.add("__GP2XWIZ_PLUGINS__", new Common::FSDirectory(pluginsPath), priority);
diff --git a/backends/platform/gph/gph.h b/backends/platform/gph/gph.h
index d7004f1582..c82f763f1d 100644
--- a/backends/platform/gph/gph.h
+++ b/backends/platform/gph/gph.h
@@ -31,10 +31,6 @@
#include "backends/events/gph/gph-events.h"
#include "backends/graphics/gph/gph-graphics.h"
-#ifndef PATH_MAX
-#define PATH_MAX 255
-#endif
-
class OSystem_GPH : public OSystem_POSIX {
public:
OSystem_GPH();
@@ -48,6 +44,9 @@ protected:
bool _inited;
bool _initedSDL;
virtual void initSDL();
+
+private:
+ Common::String getCurrentDirectory();
};
#endif
diff --git a/backends/platform/openpandora/op-backend.cpp b/backends/platform/openpandora/op-backend.cpp
index 1d620ff73b..0295643cb0 100644
--- a/backends/platform/openpandora/op-backend.cpp
+++ b/backends/platform/openpandora/op-backend.cpp
@@ -42,8 +42,7 @@
#include "audio/mixer_intern.h"
-#include <unistd.h>
-#include <limits.h>
+#include <unistd.h> // for getcwd()
/* Dump console info to files. */
#define DUMP_STDOUT
@@ -53,60 +52,57 @@ OSystem_OP::OSystem_OP()
OSystem_POSIX() {
}
+Common::String OSystem_OP::getCurrentDirectory() {
+ char cwd[MAXPATHLEN+1];
+ return Common::String(getcwd(cwd, MAXPATHLEN));
+}
+
void OSystem_OP::initBackend() {
assert(!_inited);
/* Setup default save path to be workingdir/saves */
- char savePath[PATH_MAX+1];
- char workDirName[PATH_MAX+1];
-
- if (getcwd(workDirName, PATH_MAX) == NULL) {
+ Common::String workDirName = getCurrentDirectory();
+ if (workDirName.empty()) {
error("Could not obtain current working directory.");
} else {
- printf("Current working directory: %s\n", workDirName);
+ printf("Current working directory: %s\n", workDirName.c_str());
}
- strcpy(savePath, workDirName);
- strcat(savePath, "/../saves");
- printf("Current save directory: %s\n", savePath);
+ Common::String savePath = workDirName + "/../saves");
+ printf("Current save directory: %s\n", savePath.c_str());
_savefileManager = new DefaultSaveFileManager(savePath);
#ifdef DUMP_STDOUT
// The OpenPandora has a serial console on the EXT connection but most users do not use this so we
// output all our STDOUT and STDERR to files for debug purposes.
- char STDOUT_FILE[PATH_MAX+1];
- char STDERR_FILE[PATH_MAX+1];
-
- strcpy(STDOUT_FILE, workDirName);
- strcpy(STDERR_FILE, workDirName);
- strcat(STDOUT_FILE, "/scummvm.stdout.txt");
- strcat(STDERR_FILE, "/scummvm.stderr.txt");
+ Common::String STDOUT_FILE = workDirName + "/scummvm.stdout.txt";
+ Common::String STDERR_FILE = workDirName + "/scummvm.stderr.txt";
// Flush the output in case anything is queued
fclose(stdout);
fclose(stderr);
// Redirect standard input and standard output
- FILE *newfp = freopen(STDOUT_FILE, "w", stdout);
+ FILE *newfp = freopen(STDOUT_FILE.c_str(), "w", stdout);
if (newfp == NULL) {
#if !defined(stdout)
- stdout = fopen(STDOUT_FILE, "w");
+ stdout = fopen(STDOUT_FILE.c_str(), "w");
#else
- newfp = fopen(STDOUT_FILE, "w");
+ newfp = fopen(STDOUT_FILE.c_str(), "w");
if (newfp) {
*stdout = *newfp;
}
#endif
}
- newfp = freopen(STDERR_FILE, "w", stderr);
+ newfp = freopen(STDERR_FILE.c_str(), "w", stderr);
if (newfp == NULL) {
#if !defined(stderr)
- stderr = fopen(STDERR_FILE, "w");
+ stderr = fopen(STDERR_FILE.c_str(), "w");
#else
- newfp = fopen(STDERR_FILE, "w");
+ newfp = fopen(STDERR_FILE.c_str(), "w");
if (newfp) {
*stderr = *newfp;
}
@@ -163,17 +159,13 @@ void OSystem_OP::initSDL() {
void OSystem_OP::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
/* Setup default extra data paths for engine data files and plugins */
- char workDirName[PATH_MAX+1];
-
- if (getcwd(workDirName, PATH_MAX) == NULL) {
+ Common::String workDirName = getCurrentDirectory();
+ if (workDirName.empty()) {
error("Error: Could not obtain current working directory.");
}
- char enginedataPath[PATH_MAX+1];
-
- strcpy(enginedataPath, workDirName);
- strcat(enginedataPath, "/../data");
- printf("Default engine data directory: %s\n", enginedataPath);
+ Common::String enginedataPath = workDirName + "/../data");
+ printf("Default engine data directory: %s\n", enginedataPath.c_str());
Common::FSNode engineNode(enginedataPath);
if (engineNode.exists() && engineNode.isDirectory()) {
diff --git a/backends/platform/openpandora/op-sdl.h b/backends/platform/openpandora/op-sdl.h
index dd239e58f8..815b96dd9f 100644
--- a/backends/platform/openpandora/op-sdl.h
+++ b/backends/platform/openpandora/op-sdl.h
@@ -31,10 +31,6 @@
#include "backends/events/openpandora/op-events.h"
#include "backends/graphics/openpandora/op-graphics.h"
-#ifndef PATH_MAX
-#define PATH_MAX 255
-#endif
-
class OSystem_OP : public OSystem_POSIX {
public:
OSystem_OP();
@@ -53,6 +49,9 @@ protected:
* with an OpenPandora workaround.
*/
virtual void initSDL();
+
+private:
+ Common::String getCurrentDirectory();
};
#endif
#endif //OP_SDL_H