这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 懂c的都来看看啊

共1条 1/1 1 跳转至

懂c的都来看看啊

菜鸟
2004-09-28 02:16:39     打赏

NDK中提供了一个嵌入式的文件系统,其中

// efs_fread // // Returns number of objects read (set size to 1 to read bytes) size_t efs_fread( void *ptr, size_t size, size_t nobj, EFS_FILE *stream ) { FILEPTR *pf = (FILEPTR *)stream; FILEHEADER *pfh = pf->pfh; UINT8 *pb = ptr; INT32 didread = 0; INT32 canread;

// Check for Bozo if( !size ) return(0);

for(;;) { // Get number of bytes we can read canread = pfh->Length - pf->Pos;

// Get number of objects we can read canread /= (INT32)size;

// Check for max user request if( (canread+didread) > (INT32)nobj ) canread = (INT32)nobj - didread;

// If done reading, return bytes read if( canread <= 0 ) return( (size_t)didread * size );

// Else "read" memcpy( pb, pfh->pData + pf->Pos, (size_t)canread*size );

// Bump pointers pb += canread*(INT32)size; pf->Pos += canread*(INT32)size; didread += canread; } }

我觉得这个函数写法好怪哦,为什么不这么写呢,

size_t efs_fread( void *ptr, size_t size, size_t nobj, EFS_FILE *stream ) { FILEPTR *pf = (FILEPTR *)stream; FILEHEADER *pfh = pf->pfh; UINT8 *pb = ptr; INT32 canreadsize;

// Check for Bozo if( !(size * nobj)) return(0);

// Get number of bytes we can read canreadsize = pfh->Length - pf->Pos;

if((canreadsize / (INT32)size) > (INT32)nobj){ canreadsize = nobj * size; } memcpy( pb, pfh->pData + pf->Pos, (size_t)canreadsize ); return(canread); }




关键词: 来看     看啊     INT32     canread    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]