mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-27 04:41:23 +00:00
Merge branch 'ferror-errno-yareyare' into 'master'
Fix false file error reporting See merge request KartKrew/Kart-Public!162
This commit is contained in:
commit
e4766bbaf1
6 changed files with 25 additions and 10 deletions
|
@ -768,7 +768,7 @@ void SV_FileSendTicker(void)
|
||||||
if (ram)
|
if (ram)
|
||||||
M_Memcpy(p->data, &f->id.ram[transfer[i].position], size);
|
M_Memcpy(p->data, &f->id.ram[transfer[i].position], size);
|
||||||
else if (fread(p->data, 1, size, transfer[i].currentfile) != size)
|
else if (fread(p->data, 1, size, transfer[i].currentfile) != size)
|
||||||
I_Error("SV_FileSendTicker: can't read %s byte on %s at %d because %s", sizeu1(size), f->id.filename, transfer[i].position, strerror(ferror(transfer[i].currentfile)));
|
I_Error("SV_FileSendTicker: can't read %s byte on %s at %d because %s", sizeu1(size), f->id.filename, transfer[i].position, M_FileError(transfer[i].currentfile));
|
||||||
p->position = LONG(transfer[i].position);
|
p->position = LONG(transfer[i].position);
|
||||||
// Put flag so receiver knows the total size
|
// Put flag so receiver knows the total size
|
||||||
if (transfer[i].position + size == f->size)
|
if (transfer[i].position + size == f->size)
|
||||||
|
@ -847,7 +847,7 @@ void Got_Filetxpak(void)
|
||||||
// We can receive packet in the wrong order, anyway all os support gaped file
|
// We can receive packet in the wrong order, anyway all os support gaped file
|
||||||
fseek(file->file, pos, SEEK_SET);
|
fseek(file->file, pos, SEEK_SET);
|
||||||
if (fwrite(netbuffer->u.filetxpak.data,size,1,file->file) != 1)
|
if (fwrite(netbuffer->u.filetxpak.data,size,1,file->file) != 1)
|
||||||
I_Error("Can't write to %s: %s\n",filename, strerror(ferror(file->file)));
|
I_Error("Can't write to %s: %s\n",filename, M_FileError(file->file));
|
||||||
file->currentsize += size;
|
file->currentsize += size;
|
||||||
|
|
||||||
// Finished?
|
// Finished?
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "doomdef.h"
|
#include "doomdef.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "m_argv.h"
|
#include "m_argv.h"
|
||||||
|
#include "m_misc.h"
|
||||||
|
|
||||||
/** \brief number of arg
|
/** \brief number of arg
|
||||||
*/
|
*/
|
||||||
|
@ -166,7 +167,7 @@ void M_FindResponseFile(void)
|
||||||
if (!file)
|
if (!file)
|
||||||
I_Error("No more free memory for the response file");
|
I_Error("No more free memory for the response file");
|
||||||
if (fread(file, size, 1, handle) != 1)
|
if (fread(file, size, 1, handle) != 1)
|
||||||
I_Error("Couldn't read response file because %s", strerror(ferror(handle)));
|
I_Error("Couldn't read response file because %s", M_FileError(handle));
|
||||||
fclose(handle);
|
fclose(handle);
|
||||||
|
|
||||||
// keep all the command line arguments following @responsefile
|
// keep all the command line arguments following @responsefile
|
||||||
|
|
12
src/m_misc.c
12
src/m_misc.c
|
@ -23,6 +23,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
// Extended map support.
|
// Extended map support.
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
@ -2363,3 +2365,13 @@ void M_SetupMemcpy(void)
|
||||||
M_Memcpy = cpu_cpy;
|
M_Memcpy = cpu_cpy;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the appropriate message for a file error or end of file.
|
||||||
|
*/
|
||||||
|
const char *M_FileError(FILE *fp)
|
||||||
|
{
|
||||||
|
if (ferror(fp))
|
||||||
|
return strerror(errno);
|
||||||
|
else
|
||||||
|
return "end-of-file";
|
||||||
|
}
|
||||||
|
|
|
@ -100,6 +100,8 @@ void strcatbf(char *s1, const char *s2, const char *s3);
|
||||||
|
|
||||||
void M_SetupMemcpy(void);
|
void M_SetupMemcpy(void);
|
||||||
|
|
||||||
|
const char *M_FileError(FILE *handle);
|
||||||
|
|
||||||
// counting bits, for weapon ammo code, usually
|
// counting bits, for weapon ammo code, usually
|
||||||
FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
|
FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
|
||||||
|
|
||||||
|
|
|
@ -1435,7 +1435,7 @@ static boolean LoadSong(void *data, size_t lumplength, size_t selectpos)
|
||||||
|
|
||||||
if (fwrite(data, lumplength, 1, midfile) == 0)
|
if (fwrite(data, lumplength, 1, midfile) == 0)
|
||||||
{
|
{
|
||||||
CONS_Printf(M_GetText("Couldn't write music into file %s because %s\n"), tempname, strerror(ferror(midfile)));
|
CONS_Printf(M_GetText("Couldn't write music into file %s because %s\n"), tempname, M_FileError(midfile));
|
||||||
Z_Free(data);
|
Z_Free(data);
|
||||||
fclose(midfile);
|
fclose(midfile);
|
||||||
return false;
|
return false;
|
||||||
|
|
12
src/w_wad.c
12
src/w_wad.c
|
@ -366,7 +366,7 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
|
||||||
// read the header
|
// read the header
|
||||||
if (fread(&header, 1, sizeof header, handle) < sizeof header)
|
if (fread(&header, 1, sizeof header, handle) < sizeof header)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("Can't read wad header because %s\n"), strerror(ferror(handle)));
|
CONS_Alert(CONS_ERROR, M_GetText("Can't read wad header because %s\n"), M_FileError(handle));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
|
||||||
if (fseek(handle, header.infotableofs, SEEK_SET) == -1
|
if (fseek(handle, header.infotableofs, SEEK_SET) == -1
|
||||||
|| fread(fileinfo, 1, i, handle) < i)
|
|| fread(fileinfo, 1, i, handle) < i)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("Corrupt wadfile directory (%s)\n"), strerror(ferror(handle)));
|
CONS_Alert(CONS_ERROR, M_GetText("Corrupt wadfile directory (%s)\n"), M_FileError(handle));
|
||||||
free(fileinfov);
|
free(fileinfov);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,7 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen
|
||||||
handle) < sizeof realsize)
|
handle) < sizeof realsize)
|
||||||
{
|
{
|
||||||
I_Error("corrupt compressed file: %s; maybe %s", /// \todo Avoid the bailout?
|
I_Error("corrupt compressed file: %s; maybe %s", /// \todo Avoid the bailout?
|
||||||
filename, strerror(ferror(handle)));
|
filename, M_FileError(handle));
|
||||||
}
|
}
|
||||||
realsize = LONG(realsize);
|
realsize = LONG(realsize);
|
||||||
if (realsize != 0)
|
if (realsize != 0)
|
||||||
|
@ -548,7 +548,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
|
||||||
fseek(handle, -4, SEEK_CUR);
|
fseek(handle, -4, SEEK_CUR);
|
||||||
if (fread(&zend, 1, sizeof zend, handle) < sizeof zend)
|
if (fread(&zend, 1, sizeof zend, handle) < sizeof zend)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, "Corrupt central directory (%s)\n", strerror(ferror(handle)));
|
CONS_Alert(CONS_ERROR, "Corrupt central directory (%s)\n", M_FileError(handle));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
numlumps = zend.entries;
|
numlumps = zend.entries;
|
||||||
|
@ -565,7 +565,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
|
||||||
|
|
||||||
if (fread(zentry, 1, sizeof(zentry_t), handle) < sizeof(zentry_t))
|
if (fread(zentry, 1, sizeof(zentry_t), handle) < sizeof(zentry_t))
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", strerror(ferror(handle)));
|
CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", M_FileError(handle));
|
||||||
Z_Free(lumpinfo);
|
Z_Free(lumpinfo);
|
||||||
free(zentry);
|
free(zentry);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -585,7 +585,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp)
|
||||||
fullname = malloc(zentry->namelen + 1);
|
fullname = malloc(zentry->namelen + 1);
|
||||||
if (fgets(fullname, zentry->namelen + 1, handle) != fullname)
|
if (fgets(fullname, zentry->namelen + 1, handle) != fullname)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", strerror(ferror(handle)));
|
CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", M_FileError(handle));
|
||||||
Z_Free(lumpinfo);
|
Z_Free(lumpinfo);
|
||||||
free(zentry);
|
free(zentry);
|
||||||
free(fullname);
|
free(fullname);
|
||||||
|
|
Loading…
Reference in a new issue