Esempio n. 1
0
/*
 * brief    :   Get File and Save to RAM
 * param    :   
 *              unsigned int *pFileLen: the lenght of the file.
 * return   :   0 -- OK
 *              -1 -- ERROR
 */
int CUpdate::SaveFiletoRAM(unsigned int *pFileLen, CString &filePath)
{
    if (FALSE == PathFileExists(filePath))
    {
        MSG("请选择正确的文件路径\r\n");
		return -1;
    }

    CFile bin_file( filePath,
                    CFile::modeRead);
    if (NULL == bin_file)
    {
        MSG("请确保文件存在\r\n");
		return -1;
    }
    unsigned int file_len = (unsigned int)bin_file.GetLength();

    pFileRamAddr = (BYTE *)malloc(file_len);
    if (NULL == pFileRamAddr)
    {
        MSG("malloc出错\r\n");
        bin_file.Close();
		return -1;
    }
    bin_file.SeekToBegin();//移到文件头
    bin_file.Read(pFileRamAddr, file_len);
    bin_file.Close();
    *pFileLen = file_len;
    return 0;
}
Esempio n. 2
0
int
grep_bin_file(file_t *f)
{
	if (f->noseek)
		return 0;

	switch (f->type) {
	case FILE_STDIO:
		return bin_file(f->f);
	case FILE_MMAP:
		return mmbin_file(f->mmf);
#ifndef NOZ
	case FILE_GZIP:
		return gzbin_file(f->gzf);
#endif
	default:
		/* can't happen */
		errx(2, "invalid file type");
	}
}