更新时间:2023-11-13 18:41:34
我倾向于将整个缓冲区作为原始内存块加载到内存中,然后自己进行解析.这样我就可以***地控制标准库在多个平台上的作用.
I tend to just load the entire buffer as a raw memory chunk into memory and do the parsing on my own. That way I have best control over what the standard lib does on multiple platforms.
这是我用于此的存根.您可能还想检查 fseek、ftell 和 fread 的错误代码.(为清楚起见省略).
This is a stub I use for this. you may also want to check the error-codes for fseek, ftell and fread. (omitted for clarity).
char * buffer = 0;
long length;
FILE * f = fopen (filename, "rb");
if (f)
{
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = malloc (length);
if (buffer)
{
fread (buffer, 1, length, f);
}
fclose (f);
}
if (buffer)
{
// start to process your data / extract strings here...
}