TSG-1723 日志中填写“设备编号”字段

This commit is contained in:
fengweihao
2020-05-21 17:15:40 +08:00
parent 481f754275
commit 55ecb52ad0
8 changed files with 109 additions and 58 deletions

View File

@@ -103,3 +103,55 @@ int tfe_scandir(const char *dir, struct dirent ***namelist,
}
char *tfe_read_file(const char *filename, size_t *filelen)
{
FILE *file = NULL;
long length = 0;
char *content = NULL;
size_t read_chars = 0;
file = fopen(filename, "rb");
if (file == NULL)
{
goto cleanup;
}
if (fseek(file, 0, SEEK_END) != 0)
{
goto cleanup;
}
length = ftell(file);
if (length < 0)
{
goto cleanup;
}
if (fseek(file, 0, SEEK_SET) != 0)
{
goto cleanup;
}
/* allocate content buffer */
content = (char*)malloc((size_t)length + sizeof(""));
if (content == NULL)
{
goto cleanup;
}
/* read the file into memory */
read_chars = fread(content, sizeof(char), (size_t)length, file);
if ((long)read_chars != length)
{
free(content);
content = NULL;
goto cleanup;
}
*filelen = read_chars;
content[read_chars] = '\0';
cleanup:
if (file != NULL)
{
fclose(file);
}
return content;
}