mirror of https://github.com/OpenTTD/OpenTTD
(svn r12960) -Codechange: handle return values of (some) file system related functions.
parent
1050f07ed1
commit
56e1178dca
|
@ -271,8 +271,12 @@ static void IConsoleWriteToLogFile(const char *string)
|
||||||
{
|
{
|
||||||
if (_iconsole_output_file != NULL) {
|
if (_iconsole_output_file != NULL) {
|
||||||
/* if there is an console output file ... also print it there */
|
/* if there is an console output file ... also print it there */
|
||||||
fwrite(string, strlen(string), 1, _iconsole_output_file);
|
if (fwrite(string, strlen(string), 1, _iconsole_output_file) != 1 ||
|
||||||
fwrite("\n", 1, 1, _iconsole_output_file);
|
fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
|
||||||
|
fclose(_iconsole_output_file);
|
||||||
|
_iconsole_output_file = NULL;
|
||||||
|
IConsolePrintF(_icolour_def, "cannot write to log file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,8 +91,8 @@ void FioSeekToFile(uint8 slot, uint32 pos)
|
||||||
byte FioReadByte()
|
byte FioReadByte()
|
||||||
{
|
{
|
||||||
if (_fio.buffer == _fio.buffer_end) {
|
if (_fio.buffer == _fio.buffer_end) {
|
||||||
_fio.pos += FIO_BUFFER_SIZE;
|
_fio.buffer = _fio.buffer_start;
|
||||||
fread(_fio.buffer = _fio.buffer_start, 1, FIO_BUFFER_SIZE, _fio.cur_fh);
|
_fio.pos += fread(_fio.buffer, 1, FIO_BUFFER_SIZE, _fio.cur_fh);
|
||||||
}
|
}
|
||||||
return *_fio.buffer++;
|
return *_fio.buffer++;
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,7 @@ uint32 FioReadDword()
|
||||||
void FioReadBlock(void *ptr, uint size)
|
void FioReadBlock(void *ptr, uint size)
|
||||||
{
|
{
|
||||||
FioSeekTo(FioGetPos(), SEEK_SET);
|
FioSeekTo(FioGetPos(), SEEK_SET);
|
||||||
_fio.pos += size;
|
_fio.pos += fread(ptr, 1, size, _fio.cur_fh);
|
||||||
fread(ptr, 1, size, _fio.cur_fh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void FioCloseFile(int slot)
|
static inline void FioCloseFile(int slot)
|
||||||
|
@ -430,7 +429,7 @@ char *BuildWithFullPath(const char *dir)
|
||||||
|
|
||||||
/* Add absolute path */
|
/* Add absolute path */
|
||||||
if (s == NULL || dest != s) {
|
if (s == NULL || dest != s) {
|
||||||
getcwd(dest, MAX_PATH);
|
if (getcwd(dest, MAX_PATH) == NULL) *dest = '\0';
|
||||||
AppendPathSeparator(dest, MAX_PATH);
|
AppendPathSeparator(dest, MAX_PATH);
|
||||||
ttd_strlcat(dest, dir, MAX_PATH);
|
ttd_strlcat(dest, dir, MAX_PATH);
|
||||||
}
|
}
|
||||||
|
@ -484,8 +483,7 @@ static bool TarListAddFile(const char *filename)
|
||||||
memset(&empty[0], 0, sizeof(empty));
|
memset(&empty[0], 0, sizeof(empty));
|
||||||
|
|
||||||
while (!feof(f)) {
|
while (!feof(f)) {
|
||||||
fread(&th, 1, 512, f);
|
pos += fread(&th, 1, 512, f);
|
||||||
pos += 512;
|
|
||||||
|
|
||||||
/* Check if we have the new tar-format (ustar) or the old one (a lot of zeros after 'link' field) */
|
/* Check if we have the new tar-format (ustar) or the old one (a lot of zeros after 'link' field) */
|
||||||
if (strncmp(th.magic, "ustar", 5) != 0 && memcmp(&th.magic, &empty[0], 512 - offsetof(TarHeader, magic)) != 0) {
|
if (strncmp(th.magic, "ustar", 5) != 0 && memcmp(&th.magic, &empty[0], 512 - offsetof(TarHeader, magic)) != 0) {
|
||||||
|
@ -629,7 +627,7 @@ void ChangeWorkingDirectory(const char *exe)
|
||||||
char *s = strrchr(exe, PATHSEPCHAR);
|
char *s = strrchr(exe, PATHSEPCHAR);
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
chdir(exe);
|
if (chdir(exe) != 0) DEBUG(misc, 0, "Directory with the binary does not exist?");
|
||||||
*s = PATHSEPCHAR;
|
*s = PATHSEPCHAR;
|
||||||
}
|
}
|
||||||
#ifdef WITH_COCOA
|
#ifdef WITH_COCOA
|
||||||
|
@ -671,14 +669,14 @@ void DetermineBasePaths(const char *exe)
|
||||||
#if defined(__MORPHOS__) || defined(__AMIGA__)
|
#if defined(__MORPHOS__) || defined(__AMIGA__)
|
||||||
_searchpaths[SP_WORKING_DIR] = NULL;
|
_searchpaths[SP_WORKING_DIR] = NULL;
|
||||||
#else
|
#else
|
||||||
getcwd(tmp, MAX_PATH);
|
if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
|
||||||
AppendPathSeparator(tmp, MAX_PATH);
|
AppendPathSeparator(tmp, MAX_PATH);
|
||||||
_searchpaths[SP_WORKING_DIR] = strdup(tmp);
|
_searchpaths[SP_WORKING_DIR] = strdup(tmp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Change the working directory to that one of the executable */
|
/* Change the working directory to that one of the executable */
|
||||||
ChangeWorkingDirectory((char*)exe);
|
ChangeWorkingDirectory((char*)exe);
|
||||||
getcwd(tmp, MAX_PATH);
|
if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
|
||||||
AppendPathSeparator(tmp, MAX_PATH);
|
AppendPathSeparator(tmp, MAX_PATH);
|
||||||
_searchpaths[SP_BINARY_DIR] = strdup(tmp);
|
_searchpaths[SP_BINARY_DIR] = strdup(tmp);
|
||||||
|
|
||||||
|
|
|
@ -595,7 +595,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
|
||||||
|
|
||||||
if (maptype == MAP_PACKET_NORMAL) {
|
if (maptype == MAP_PACKET_NORMAL) {
|
||||||
// We are still receiving data, put it to the file
|
// We are still receiving data, put it to the file
|
||||||
fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer);
|
if (fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer) != p->size - p->pos) {
|
||||||
|
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
|
||||||
|
return NETWORK_RECV_STATUS_SAVEGAME;
|
||||||
|
}
|
||||||
|
|
||||||
_network_join_kbytes = ftell(file_pointer) / 1024;
|
_network_join_kbytes = ftell(file_pointer) / 1024;
|
||||||
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
|
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ static uint ReadNoComp()
|
||||||
|
|
||||||
static void WriteNoComp(uint size)
|
static void WriteNoComp(uint size)
|
||||||
{
|
{
|
||||||
fwrite(_sl.buf, 1, size, _sl.fh);
|
if (fwrite(_sl.buf, 1, size, _sl.fh) != size) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool InitNoComp()
|
static bool InitNoComp()
|
||||||
|
|
Loading…
Reference in New Issue