12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273(*
* Copyright (c) 2012-2019 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2019 Romain Calascibetta <romain.calascibetta@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)include(Cstruct:moduletypeofCstructwithtypet:=Cstruct.t)type'ard=<rd:unit;..>as'atype'awr=<wr:unit;..>as'atype'at=Cstruct.ttyperdwr=<rd:unit;wr:unit;>typero=<rd:unit;>typewo=<wr:unit;>externalro:'ardt->rot="%identity"externalwo:'awrt->wot="%identity"letof_string=Cstruct.of_string?allocator:Noneletof_bytes=Cstruct.of_bytes?allocator:Noneletppppft=Cstruct.hexdump_ppppftletlength=Cstruct.lengthletblitsrc~src_offdst~dst_off~len=Cstruct.blitsrcsrc_offdstdst_offlen[@@inline]letblit_from_stringsrc~src_offdst~dst_off~len=Cstruct.blit_from_stringsrcsrc_offdstdst_offlen[@@inline]letblit_from_bytessrc~src_offdst~dst_off~len=Cstruct.blit_from_bytessrcsrc_offdstdst_offlen[@@inline]letblit_to_bytessrc~src_offdst~dst_off~len=Cstruct.blit_to_bytessrcsrc_offdstdst_offlen[@@inline]letsubt~off~len=Cstruct.subtofflen[@@inline]letsub_copyt~off~len=Cstruct.sub_copytofflen[@@inline]letunsafe_to_bigarray=Cstruct.to_bigarrayletconcatvss=letres=create_unsafe(Cstruct.sum_lengths~caller:"Cstruct.Cap.concat"vss)inletgooffv=letlen=Cstruct.lengthvinCstruct.blitv0resofflen;off+leninletlen=List.fold_leftgo0vssinassert(len=Cstruct.lengthres);res