Adding a strdup-like inline function

svn-id: r40216
This commit is contained in:
Sven Hesse 2009-04-30 15:57:10 +00:00
parent df9932669a
commit ae46e8e1ca
4 changed files with 25 additions and 25 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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 {

View File

@ -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();