diff options
author | Sven Hesse | 2009-04-30 15:57:10 +0000 |
---|---|---|
committer | Sven Hesse | 2009-04-30 15:57:10 +0000 |
commit | ae46e8e1cabbee8662bd81e647d15fe5991549e2 (patch) | |
tree | c164c90c24cb250f1c5b9cec8d7309ba8b832196 /engines | |
parent | df9932669a5d8b046f9b78fc7004982adc4b119b (diff) | |
download | scummvm-rg350-ae46e8e1cabbee8662bd81e647d15fe5991549e2.tar.gz scummvm-rg350-ae46e8e1cabbee8662bd81e647d15fe5991549e2.tar.bz2 scummvm-rg350-ae46e8e1cabbee8662bd81e647d15fe5991549e2.zip |
Adding a strdup-like inline function
svn-id: r40216
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gob/demos/demoplayer.cpp | 12 | ||||
-rw-r--r-- | engines/gob/detection.cpp | 22 | ||||
-rw-r--r-- | engines/gob/gob.h | 13 | ||||
-rw-r--r-- | engines/gob/videoplayer.cpp | 3 |
4 files changed, 25 insertions, 25 deletions
diff --git a/engines/gob/demos/demoplayer.cpp b/engines/gob/demos/demoplayer.cpp index c19a955981..e130f875b4 100644 --- a/engines/gob/demos/demoplayer.cpp +++ b/engines/gob/demos/demoplayer.cpp @@ -67,8 +67,7 @@ void DemoPlayer::playVideo(const char *fileName) { uint32 waitTime = 0; char *file, *filePtr; - file = filePtr = new char[strlen(fileName) + 1]; - strcpy(file, fileName); + file = filePtr = strdupcpy(fileName); // Trimming spaces front while (*file == ' ') @@ -121,13 +120,8 @@ void DemoPlayer::playVideoNormal() { } void DemoPlayer::playVideoDoubled() { - const char *fileNameOpened; - char *fileName; - - fileNameOpened = _vm->_vidPlayer->getFileName(); - - fileName = new char[strlen(fileNameOpened) + 1]; - strcpy(fileName, fileNameOpened); + const char *fileNameOpened = _vm->_vidPlayer->getFileName(); + char *fileName = strdupcpy(fileNameOpened); _vm->_vidPlayer->primaryClose(); diff --git a/engines/gob/detection.cpp b/engines/gob/detection.cpp index 31ab8cae03..a0e934eb41 100644 --- a/engines/gob/detection.cpp +++ b/engines/gob/detection.cpp @@ -3147,21 +3147,15 @@ bool GobMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameD namespace Gob { void GobEngine::initGame(const GOBGameDescription *gd) { - if (gd->startTotBase == 0) { - _startTot = new char[10]; - strcpy(_startTot, "intro.tot"); - } else { - _startTot = new char[strlen(gd->startTotBase) + 1]; - strcpy(_startTot, gd->startTotBase); - } + if (gd->startTotBase == 0) + _startTot = strdupcpy("intro.tot"); + else + _startTot = strdupcpy(gd->startTotBase); - if (gd->startStkBase == 0) { - _startStk = new char[10]; - strcpy(_startStk, "intro.stk"); - } else { - _startStk = new char[strlen(gd->startStkBase) + 1]; - strcpy(_startStk, gd->startStkBase); - } + if (gd->startStkBase == 0) + _startStk = strdupcpy("intro.stk"); + else + _startStk = strdupcpy(gd->startStkBase); _gameType = gd->gameType; _features = gd->features; diff --git a/engines/gob/gob.h b/engines/gob/gob.h index d5ef25b7d2..3e7c0bfc0a 100644 --- a/engines/gob/gob.h +++ b/engines/gob/gob.h @@ -135,6 +135,19 @@ inline char *strncpy0(char *dest, const char *src, size_t n) { return dest; } +inline char *strdupcpy(const char *str) { + if (!str) + return 0; + + size_t len = strlen(str) + 1; + + char *nstr = new char[len]; + + memcpy(nstr, str, len); + + return nstr; +} + // A "smart" reference counting templated class template<typename T> class ReferenceCounter { diff --git a/engines/gob/videoplayer.cpp b/engines/gob/videoplayer.cpp index 76b574f44f..9b3724428a 100644 --- a/engines/gob/videoplayer.cpp +++ b/engines/gob/videoplayer.cpp @@ -77,8 +77,7 @@ bool VideoPlayer::Video::open(const char *fileName, Type which) { return false; } - _fileName = new char[strlen(fileName) + 1]; - strcpy(_fileName, fileName); + _fileName = strdupcpy(fileName); _defaultX = _video->getX(); _defaultY = _video->getY(); |