Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Doing memcpy from an entire struct is truly evil :-). First of all the data might be aligned differently depending on architecture. What if the architecture is different on the other side? Also using keywords such as __packed isn't portable between different compilers.</p> <p>The best, as I know, is to use an API like the PHP pack/unpack. This makes the code truly portable without using compiler specific ugly keywords such as __packed.</p> <p>I didn't find any pack/unpack for C on the net so I wrote my own.</p> <p>For example to unpack two words from binary data:</p> <pre><code> pbuf_unpack(p_bts, "ww", &amp;hdr, &amp;ver); </code></pre> <p>Where </p> <pre><code> p_bts is binary data "ww" describes the data structure hdr and ver is where to put the datause an API like the PHP pack/unpack. </code></pre> <p>Another more extensive example:</p> <pre><code> pbuf_unpack(p_entry, "bbbbbbbbww", &amp;atrb_mbr.def_boot_par, &amp;atrb_mbr.head_start, &amp;atrb_mbr.sec_start, &amp;atrb_mbr.cyl_start, &amp;atrb_mbr.type, &amp;atrb_mbr.head_end, &amp;atrb_mbr.sec_end, &amp;atrb_mbr.cyl_end, &amp;atrb_mbr.start_sec_pbr, &amp;atrb_mbr.sec_per_par); </code></pre> <p>Packing is very easy:</p> <pre><code> pbuf_pack(boot_buf, "sdsdhbhbhhbhhhwwbbbwsdsd", sizeof(fat_jmp_boot_t), boot.jmp, sizeof(fat_oem_nm_t), boot.oem_nm, boot.n_bps, boot.n_spc, boot.n_rs, boot.n_fs, boot.n_rde, boot.n_ts16, boot.media_des, boot.n_fatsz16, boot.n_spt, boot.n_hds, boot.n_hs, boot.n_ts32, boot.drv_no, boot.rsrvd1, boot.boot_sig, boot.vol_id, sizeof(fat_vol_lbl_t), boot.lbl, sizeof(fat_vol_type_t), boot.type); </code></pre> <p>Not only does it create portable code but it's also beautiful;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload