mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-20 01:43:50 +00:00
Create FIL_ConvertTextFileToBinary
This commit is contained in:
parent
06d3af6716
commit
34c5da39e2
2 changed files with 40 additions and 0 deletions
38
src/m_misc.c
38
src/m_misc.c
|
@ -297,6 +297,44 @@ size_t FIL_ReadFileTag(char const *name, UINT8 **buffer, INT32 tag)
|
|||
return length;
|
||||
}
|
||||
|
||||
/** Makes a copy of a text file with all newlines converted into LF newlines.
|
||||
*
|
||||
* \param textfilename The name of the source file
|
||||
* \param binfilename The name of the destination file
|
||||
*/
|
||||
boolean FIL_ConvertTextFileToBinary(const char *textfilename, const char *binfilename)
|
||||
{
|
||||
FILE *textfile;
|
||||
FILE *binfile;
|
||||
UINT8 buffer[1024];
|
||||
size_t count;
|
||||
boolean success;
|
||||
|
||||
textfile = fopen(textfilename, "r");
|
||||
if (!textfile)
|
||||
return false;
|
||||
|
||||
binfile = fopen(binfilename, "wb");
|
||||
if (!binfile)
|
||||
{
|
||||
fclose(textfile);
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
count = fread(buffer, 1, sizeof(buffer), textfile);
|
||||
fwrite(buffer, 1, count, binfile);
|
||||
} while (count);
|
||||
|
||||
success = !(ferror(textfile) || ferror(binfile));
|
||||
|
||||
fclose(textfile);
|
||||
fclose(binfile);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/** Check if the filename exists
|
||||
*
|
||||
* \param name Filename to check.
|
||||
|
|
|
@ -48,6 +48,8 @@ boolean FIL_WriteFile(char const *name, const void *source, size_t length);
|
|||
size_t FIL_ReadFileTag(char const *name, UINT8 **buffer, INT32 tag);
|
||||
#define FIL_ReadFile(n, b) FIL_ReadFileTag(n, b, PU_STATIC)
|
||||
|
||||
boolean FIL_ConvertTextFileToBinary(const char *textfilename, const char *binfilename);
|
||||
|
||||
boolean FIL_FileExists(const char *name);
|
||||
boolean FIL_WriteFileOK(char const *name);
|
||||
boolean FIL_ReadFileOK(char const *name);
|
||||
|
|
Loading…
Reference in a new issue