DS: Fix various warnings and errors in the DS FS code

* Do not modify the strings passed to std_fopen anymore
* Correct signature of std_fread
* Do not cast away constness, nor perform unnecessary casts

svn-id: r50693
This commit is contained in:
Max Horn 2010-07-05 16:12:31 +00:00
parent edb5210d38
commit 75529dc402
3 changed files with 33 additions and 31 deletions

View file

@ -181,10 +181,10 @@ AbstractFSNode *DSFileSystemNode::getParent() const {
DSFileSystemNode *p;
if (_path != "ds:/") {
char *path = (char *) _path.c_str();
const char *path = (const char *)_path.c_str();
int lastSlash = 4;
for (int r = 4; r < (int) _path.size(); r++) {
for (uint r = 4; r < _path.size(); r++) {
if (path[r] == '\\') {
lastSlash = r;
}
@ -262,7 +262,7 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path) {
_path = path;
}
GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDirectory) {
GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDir) {
//consolePrintf("'%s'",path.c_str());
int lastSlash = 3;
@ -275,7 +275,7 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDire
_displayName = Common::String(path.c_str() + lastSlash + 1);
_path = path;
_isValid = true;
_isDirectory = isDirectory;
_isDirectory = isDir;
}
@ -356,10 +356,10 @@ AbstractFSNode *GBAMPFileSystemNode::getParent() const {
GBAMPFileSystemNode *p;
if (_path != "mp:/") {
char *path = (char *) _path.c_str();
const char *path = (const char *)_path.c_str();
int lastSlash = 4;
for (int r = 4; r < (int) strlen((char *) path); r++) {
for (uint r = 4; r < strlen(path); r++) {
if (path[r] == '/') {
lastSlash = r;
}
@ -447,7 +447,7 @@ uint32 DSFileStream::read(void *ptr, uint32 len) {
if (_writeBufferPos > 0) {
flush();
}
return std_fread((byte *)ptr, 1, len, (FILE *)_handle);
return std_fread(ptr, 1, len, (FILE *)_handle);
}
uint32 DSFileStream::write(const void *ptr, uint32 len) {
@ -501,15 +501,15 @@ FILE *std_fopen(const char *name, const char *mode) {
currentDir[0] = '\0';
}
char *realName = (char *) name;
char realName[MAXPATHLEN];
// Remove file system prefix
if ((name[0] == 'd') && (name[1] == 's') && (name[2] == ':') && (name[3] == '/')) {
realName += 4;
}
if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) {
realName += 4;
strlcpy(realName, name + 4, MAXPATHLEN);
} else if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) {
strlcpy(realName, name + 4, MAXPATHLEN);
} else {
strlcpy(realName, name, MAXPATHLEN);
}
// consolePrintf("Open file:");
@ -521,7 +521,8 @@ FILE *std_fopen(const char *name, const char *mode) {
// Turn all back slashes into forward slashes for gba_nds_fat
char *p = realName;
while (*p) {
if (*p == '\\') *p = '/';
if (*p == '\\')
*p = '/';
p++;
}
@ -550,10 +551,10 @@ FILE *std_fopen(const char *name, const char *mode) {
#ifdef GBA_SRAM_SAVE
if (strchr(mode, 'w')) {
// consolePrintf("Writing %s\n", realName);
s_handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, true);
s_handle[r].sramFile = DSSaveFileManager::instance()->openSavefile(realName, true);
} else {
// consolePrintf("Reading %s\n", realName);
s_handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, false);
s_handle[r].sramFile = DSSaveFileManager::instance()->openSavefile(realName, false);
}
#endif
@ -593,7 +594,7 @@ FILE *std_fopen(const char *name, const char *mode) {
zip->setAllFilesVisible(false);
// Allocate a file handle
int r = 0;
r = 0;
while (s_handle[r].used)
r++;
@ -626,13 +627,13 @@ void std_fclose(FILE *handle) {
}
}
size_t std_fread(const void *ptr, size_t size, size_t numItems, FILE *handle) {
size_t std_fread(void *ptr, size_t size, size_t numItems, FILE *handle) {
// consolePrintf("fread %d,%d %d ", size, numItems, ptr);
if (DS::isGBAMPAvailable()) {
readPastEndOfFile = false;
int bytes = FAT_fread((void *) ptr, size, numItems, (FAT_FILE *) handle);
int bytes = FAT_fread(ptr, size, numItems, (FAT_FILE *) handle);
if (!FAT_feof((FAT_FILE *) handle)) {
return numItems;
} else {
@ -665,14 +666,15 @@ size_t std_fread(const void *ptr, size_t size, size_t numItems, FILE *handle) {
// consolePrintf("read %d ", size * numItems);
memcpy((void *) ptr, handle->data + handle->pos, size * numItems);
memcpy(ptr, handle->data + handle->pos, size * numItems);
handle->pos += size * numItems;
return numItems;
}
size_t std_fwrite(const void *ptr, size_t size, size_t numItems, FILE *handle) {
if ((handle == stdin)) return 0;
if ((handle == stdin))
return 0;
if ((handle == stderr) || (handle == stdout)) {
// consolePrintf((char *) ptr);
@ -682,7 +684,7 @@ size_t std_fwrite(const void *ptr, size_t size, size_t numItems, FILE *handle) {
//consolePrintf("fwrite size=%d\n", size * numItems);
if (DS::isGBAMPAvailable()) {
FAT_fwrite(((char *) (ptr)), size, numItems, (FAT_FILE *) handle);
FAT_fwrite(ptr, size, numItems, (FAT_FILE *) handle);
return numItems;
int length = size * numItems;

View file

@ -218,7 +218,7 @@ public:
// Please do not remove any of these prototypes that appear not to be required.
FILE* std_fopen(const char *name, const char *mode);
void std_fclose(FILE *handle);
size_t std_fread(const void *ptr, size_t size, size_t numItems, FILE *handle);
size_t std_fread(void *ptr, size_t size, size_t numItems, FILE *handle);
size_t std_fwrite(const void *ptr, size_t size, size_t numItems, FILE *handle);
bool std_feof(FILE *handle);
long int std_ftell(FILE *handle);

View file

@ -162,7 +162,7 @@ void playTrack(int track, int numLoops, int startFrame, int duration) {
}
DS::std_fread((const void *) &waveHeader, sizeof(waveHeader), 1, file);
DS::std_fread(&waveHeader, sizeof(waveHeader), 1, file);
consolePrintf("File: %s\n", fname.c_str());
@ -186,11 +186,11 @@ void playTrack(int track, int numLoops, int startFrame, int duration) {
// Skip chunks until we reach the data chunk
chunkHeader chunk;
DS::std_fread((const void *) &chunk, sizeof(chunkHeader), 1, file);
DS::std_fread(&chunk, sizeof(chunkHeader), 1, file);
while (!((chunk.name[0] == 'd') && (chunk.name[1] == 'a') && (chunk.name[2] == 't') && (chunk.name[3] == 'a'))) {
DS::std_fseek(file, chunk.size, SEEK_CUR);
DS::std_fread((const void *) &chunk, sizeof(chunkHeader), 1, file);
DS::std_fread(&chunk, sizeof(chunkHeader), 1, file);
}
dataChunkStart = DS::std_ftell(file);
@ -266,7 +266,7 @@ void decompressBlock() {
do {
DS::std_fread((const void *) &blockHeader, sizeof(blockHeader), 1, file);
DS::std_fread(&blockHeader, sizeof(blockHeader), 1, file);
DS::std_fread(&block[0], waveHeader.fmtBlockAlign - sizeof(blockHeader), 1, file);