Create FIL_ConvertTextFileToBinary

This commit is contained in:
Louis-Antoine 2020-05-19 20:00:58 +02:00
parent 06d3af6716
commit 34c5da39e2
2 changed files with 40 additions and 0 deletions

View File

@ -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.

View File

@ -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);