123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(**************************************************************************)(* *)(* OCaml *)(* *)(* Fabrice Le Fessant, INRIA Saclay *)(* *)(* Copyright 2012 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)openMisctypepers_flags=|Rectypes|Alertsofalerts|Opaque(* these type abbreviations are not exported;
they are used to provide consistency across
input_value and output_value usage. *)typesignature=Types.signature_itemlisttypeflags=pers_flagslisttypeheader=modname*signaturetypecmi_infos={cmi_name:modname;cmi_sign:signature;cmi_crcs:crcs;cmi_flags:flags;}letinput_cmiic=let(name,sign)=(input_valueic:header)inletcrcs=(input_valueic:crcs)inletflags=(input_valueic:flags)in{cmi_name=name;cmi_sign=sign;cmi_crcs=crcs;cmi_flags=flags;}letread_cmifilename=letopenMagic_numbers.Cmiinletic=open_in_binfilenameintryletbuffer=really_input_stringic(String.lengthConfig.cmi_magic_number)inifbuffer<>Config.cmi_magic_numberthenbeginclose_inic;letpre_len=String.lengthConfig.cmi_magic_number-3inifString.subbuffer0pre_len=String.subConfig.cmi_magic_number0pre_lenthenbeginraise(Error(Wrong_version_interface(filename,buffer)))endelsebeginraise(Error(Not_an_interfacefilename))endend;letcmi=input_cmiicinclose_inic;cmiwithEnd_of_file|Failure_->close_inic;raise(Error(Corrupted_interface(filename)))|Errore->close_inic;raise(Errore)letoutput_cmifilenameoccmi=ignore(filename,oc,cmi);""(*
(* beware: the provided signature must have been substituted for saving *)
output_string oc Config.cmi_magic_number;
Marshal.(to_channel oc ((cmi.cmi_name, cmi.cmi_sign) : header) [Compression]);
flush oc;
let crc = Digest.file filename in
let crcs = (cmi.cmi_name, Some crc) :: cmi.cmi_crcs in
output_value oc (crcs : crcs);
output_value oc (cmi.cmi_flags : flags);
crc
*)(* Error report moved to src/ocaml/typing/magic_numbers.ml *)