[syslinux] port syslinux isohybrid perl script to C

H. Peter Anvin hpa at zytor.com
Sat May 1 09:11:32 PDT 2010


On 05/01/2010 04:52 AM, P J P wrote:
> --- On Sat, 1/5/10, H. Peter Anvin <hpa at zytor.com> wrote:
>>> The function get_hex_data() will ALLWAYS return MBRSIZE,
>>> there will be NEVER 'errx(1, "bad MBR code: %d", tmp);'
>> Not to mention that it is just a glorified memcpy()...
> 
>   Hmmn..okay, just a small clarification...why is the for loop there?
> 

There is no point in having a for loop there in a C version.
>    for (i = 0; i <= (hd0 + 3 * partok); i++)
>        memcpy(mbr, hexdata[i * MBRSIZE], MBRSIZE);

I'd do:
	nmbr = hd0 + 3*partok;
	memcpy(mbr, &hexdata[nmbr*MBRSIZE], MBRSIZE);

Better yet would be to make hexdata a three-dimensional array and do:

	memcpyu(mbr, &hexdata[partok][hd0], MBRSIZE);

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.




More information about the Syslinux mailing list