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:
parent
edb5210d38
commit
75529dc402
3 changed files with 33 additions and 31 deletions
|
@ -181,10 +181,10 @@ AbstractFSNode *DSFileSystemNode::getParent() const {
|
||||||
DSFileSystemNode *p;
|
DSFileSystemNode *p;
|
||||||
|
|
||||||
if (_path != "ds:/") {
|
if (_path != "ds:/") {
|
||||||
char *path = (char *) _path.c_str();
|
const char *path = (const char *)_path.c_str();
|
||||||
int lastSlash = 4;
|
int lastSlash = 4;
|
||||||
|
|
||||||
for (int r = 4; r < (int) _path.size(); r++) {
|
for (uint r = 4; r < _path.size(); r++) {
|
||||||
if (path[r] == '\\') {
|
if (path[r] == '\\') {
|
||||||
lastSlash = r;
|
lastSlash = r;
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path) {
|
||||||
_path = path;
|
_path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDirectory) {
|
GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDir) {
|
||||||
//consolePrintf("'%s'",path.c_str());
|
//consolePrintf("'%s'",path.c_str());
|
||||||
|
|
||||||
int lastSlash = 3;
|
int lastSlash = 3;
|
||||||
|
@ -275,7 +275,7 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDire
|
||||||
_displayName = Common::String(path.c_str() + lastSlash + 1);
|
_displayName = Common::String(path.c_str() + lastSlash + 1);
|
||||||
_path = path;
|
_path = path;
|
||||||
_isValid = true;
|
_isValid = true;
|
||||||
_isDirectory = isDirectory;
|
_isDirectory = isDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -356,10 +356,10 @@ AbstractFSNode *GBAMPFileSystemNode::getParent() const {
|
||||||
GBAMPFileSystemNode *p;
|
GBAMPFileSystemNode *p;
|
||||||
|
|
||||||
if (_path != "mp:/") {
|
if (_path != "mp:/") {
|
||||||
char *path = (char *) _path.c_str();
|
const char *path = (const char *)_path.c_str();
|
||||||
int lastSlash = 4;
|
int lastSlash = 4;
|
||||||
|
|
||||||
for (int r = 4; r < (int) strlen((char *) path); r++) {
|
for (uint r = 4; r < strlen(path); r++) {
|
||||||
if (path[r] == '/') {
|
if (path[r] == '/') {
|
||||||
lastSlash = r;
|
lastSlash = r;
|
||||||
}
|
}
|
||||||
|
@ -447,7 +447,7 @@ uint32 DSFileStream::read(void *ptr, uint32 len) {
|
||||||
if (_writeBufferPos > 0) {
|
if (_writeBufferPos > 0) {
|
||||||
flush();
|
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) {
|
uint32 DSFileStream::write(const void *ptr, uint32 len) {
|
||||||
|
@ -501,15 +501,15 @@ FILE *std_fopen(const char *name, const char *mode) {
|
||||||
currentDir[0] = '\0';
|
currentDir[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
char *realName = (char *) name;
|
char realName[MAXPATHLEN];
|
||||||
|
|
||||||
// Remove file system prefix
|
// Remove file system prefix
|
||||||
if ((name[0] == 'd') && (name[1] == 's') && (name[2] == ':') && (name[3] == '/')) {
|
if ((name[0] == 'd') && (name[1] == 's') && (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);
|
||||||
if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) {
|
} else {
|
||||||
realName += 4;
|
strlcpy(realName, name, MAXPATHLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// consolePrintf("Open file:");
|
// 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
|
// Turn all back slashes into forward slashes for gba_nds_fat
|
||||||
char *p = realName;
|
char *p = realName;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (*p == '\\') *p = '/';
|
if (*p == '\\')
|
||||||
|
*p = '/';
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,7 +536,7 @@ FILE *std_fopen(const char *name, const char *mode) {
|
||||||
}
|
}
|
||||||
// MT_memoryReport();
|
// MT_memoryReport();
|
||||||
|
|
||||||
return (FILE *) result;
|
return (FILE *)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail to open file for writing. It's in ROM!
|
// Fail to open file for writing. It's in ROM!
|
||||||
|
@ -550,10 +551,10 @@ FILE *std_fopen(const char *name, const char *mode) {
|
||||||
#ifdef GBA_SRAM_SAVE
|
#ifdef GBA_SRAM_SAVE
|
||||||
if (strchr(mode, 'w')) {
|
if (strchr(mode, 'w')) {
|
||||||
// consolePrintf("Writing %s\n", realName);
|
// 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 {
|
} else {
|
||||||
// consolePrintf("Reading %s\n", realName);
|
// 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
|
#endif
|
||||||
|
|
||||||
|
@ -593,7 +594,7 @@ FILE *std_fopen(const char *name, const char *mode) {
|
||||||
zip->setAllFilesVisible(false);
|
zip->setAllFilesVisible(false);
|
||||||
|
|
||||||
// Allocate a file handle
|
// Allocate a file handle
|
||||||
int r = 0;
|
r = 0;
|
||||||
while (s_handle[r].used)
|
while (s_handle[r].used)
|
||||||
r++;
|
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);
|
// consolePrintf("fread %d,%d %d ", size, numItems, ptr);
|
||||||
|
|
||||||
if (DS::isGBAMPAvailable()) {
|
if (DS::isGBAMPAvailable()) {
|
||||||
readPastEndOfFile = false;
|
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)) {
|
if (!FAT_feof((FAT_FILE *) handle)) {
|
||||||
return numItems;
|
return numItems;
|
||||||
} else {
|
} 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);
|
// 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;
|
handle->pos += size * numItems;
|
||||||
|
|
||||||
return numItems;
|
return numItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t std_fwrite(const 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) {
|
||||||
if ((handle == stdin)) return 0;
|
if ((handle == stdin))
|
||||||
|
return 0;
|
||||||
|
|
||||||
if ((handle == stderr) || (handle == stdout)) {
|
if ((handle == stderr) || (handle == stdout)) {
|
||||||
// consolePrintf((char *) ptr);
|
// 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);
|
//consolePrintf("fwrite size=%d\n", size * numItems);
|
||||||
|
|
||||||
if (DS::isGBAMPAvailable()) {
|
if (DS::isGBAMPAvailable()) {
|
||||||
FAT_fwrite(((char *) (ptr)), size, numItems, (FAT_FILE *) handle);
|
FAT_fwrite(ptr, size, numItems, (FAT_FILE *) handle);
|
||||||
return numItems;
|
return numItems;
|
||||||
|
|
||||||
int length = size * numItems;
|
int length = size * numItems;
|
||||||
|
|
|
@ -209,16 +209,16 @@ public:
|
||||||
#undef stdout
|
#undef stdout
|
||||||
#undef stdin
|
#undef stdin
|
||||||
|
|
||||||
#define stdout ((DS::fileHandle*) -1)
|
#define stdout ((DS::fileHandle *) -1)
|
||||||
#define stderr ((DS::fileHandle*) -2)
|
#define stderr ((DS::fileHandle *) -2)
|
||||||
#define stdin ((DS::fileHandle*) -3)
|
#define stdin ((DS::fileHandle *) -3)
|
||||||
|
|
||||||
#define FILE DS::fileHandle
|
#define FILE DS::fileHandle
|
||||||
|
|
||||||
// Please do not remove any of these prototypes that appear not to be required.
|
// Please do not remove any of these prototypes that appear not to be required.
|
||||||
FILE* std_fopen(const char *name, const char *mode);
|
FILE* std_fopen(const char *name, const char *mode);
|
||||||
void std_fclose(FILE *handle);
|
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);
|
size_t std_fwrite(const void *ptr, size_t size, size_t numItems, FILE *handle);
|
||||||
bool std_feof(FILE *handle);
|
bool std_feof(FILE *handle);
|
||||||
long int std_ftell(FILE *handle);
|
long int std_ftell(FILE *handle);
|
||||||
|
|
|
@ -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());
|
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
|
// Skip chunks until we reach the data chunk
|
||||||
chunkHeader 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'))) {
|
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_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);
|
dataChunkStart = DS::std_ftell(file);
|
||||||
|
@ -266,7 +266,7 @@ void decompressBlock() {
|
||||||
|
|
||||||
|
|
||||||
do {
|
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);
|
DS::std_fread(&block[0], waveHeader.fmtBlockAlign - sizeof(blockHeader), 1, file);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue