From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5176F8027D for ; Fri, 13 Oct 2017 13:10:59 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=nicolas.ojeda.bar@lexifi.com; spf=SoftFail smtp.mailfrom=nicolas.ojeda.bar@lexifi.com; spf=None smtp.helo=postmaster@vrout10.yaziba.net Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of nicolas.ojeda.bar@lexifi.com) identity=pra; client-ip=185.56.204.35; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="nicolas.ojeda.bar@lexifi.com"; x-conformance=sidf_compatible Received-SPF: SoftFail (mail3-smtp-sop.national.inria.fr: domain of nicolas.ojeda.bar@lexifi.com is inclined to not designate 185.56.204.35 as permitted sender) identity=mailfrom; client-ip=185.56.204.35; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="nicolas.ojeda.bar@lexifi.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@vrout10.yaziba.net) identity=helo; client-ip=185.56.204.35; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="postmaster@vrout10.yaziba.net"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3Ae/4VFxevQMF3zy8A0satBtHllGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc65bR7h7PlgxGXEQZ/co6odzbGJ4+a9ASQp2tWojjMrSNR0TRgLiM?= =?us-ascii?q?EbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpRZbIBj0NBJ0?= =?us-ascii?q?K+LpAcaSyp3vj6HhzabOeB1FjyaRZrZ7LRP+7VmA95pevYw3Dq8s0BbPvkx0e2?= =?us-ascii?q?VIyGVvOELbyxL1+929+oIl7yRdpf8n8NNQeaT8ZaUxC7JCWmcIKWcwsevqvh7H?= =?us-ascii?q?xBC4wXkRXmwhuJZSS1zD7Rr9Wp7q9Cz4u+Z0niOTJ+XyQKA1VzXk5KBuHky7wB?= =?us-ascii?q?wbPiI0pTmEwvd7i7hW9Vf8/hE=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CIAAB4nuBZhyPMOLleGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFAEBAQEBAQEBAQEBBwEBAQEBhBhuJweDc4E2iV2QNBGCPJNyggQKI4U?= =?us-ascii?q?YAoRIShQBAQEBAQEBAQEBARIBAQEKCwkIKC+COAUBHgaCPAECAgEjBEcLBQsJA?= =?us-ascii?q?gQHGh0CAiISAQUBChIGExKJcwMNCAQBC40AkRtAjAyBbTqHPgODeQEBAQEBBQE?= =?us-ascii?q?BAQEBASKDLYVCgyqETYNLgkEgBYgvDJkKh1+NDIJxkCGVWxQFH4ETAg8nY4EXe?= =?us-ascii?q?l41BoIpCYIaORAMgWl0iQ+BVQEBAQ?= X-IPAS-Result: =?us-ascii?q?A0CIAAB4nuBZhyPMOLleGgEBAQECAQEBAQgBAQEBFAEBAQE?= =?us-ascii?q?BAQEBAQEBBwEBAQEBhBhuJweDc4E2iV2QNBGCPJNyggQKI4UYAoRIShQBAQEBA?= =?us-ascii?q?QEBAQEBARIBAQEKCwkIKC+COAUBHgaCPAECAgEjBEcLBQsJAgQHGh0CAiISAQU?= =?us-ascii?q?BChIGExKJcwMNCAQBC40AkRtAjAyBbTqHPgODeQEBAQEBBQEBAQEBASKDLYVCg?= =?us-ascii?q?yqETYNLgkEgBYgvDJkKh1+NDIJxkCGVWxQFH4ETAg8nY4EXel41BoIpCYIaORA?= =?us-ascii?q?MgWl0iQ+BVQEBAQ?= X-IronPort-AV: E=Sophos;i="5.43,370,1503352800"; d="scan'208,217";a="240887644" Received: from vrout30-bl.yaziba.net (HELO vrout10.yaziba.net) ([185.56.204.35]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 13 Oct 2017 13:10:58 +0200 Received: from mtaout10.int.yaziba.net (mtaout10.int.yaziba.net [10.4.20.36]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by vrout10.yaziba.net (mx10.yaziba.net) with ESMTPS id 910C352036; Fri, 13 Oct 2017 13:10:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mtaout10.int.yaziba.net (Postfix) with ESMTP id 8C8C01610BF; Fri, 13 Oct 2017 13:10:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at Received: from mtaout10.int.yaziba.net ([127.0.0.1]) by localhost (mtaout10.int.yaziba.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id MkHCdyn6MGds; Fri, 13 Oct 2017 13:10:57 +0200 (CEST) Received: from mail-qt0-f180.google.com (mail-qt0-f180.google.com [209.85.216.180]) by mtaout10.int.yaziba.net (Postfix) with ESMTPSA id 456861600C6; Fri, 13 Oct 2017 13:10:57 +0200 (CEST) Received: by mail-qt0-f180.google.com with SMTP id z28so16386671qtz.13; Fri, 13 Oct 2017 04:10:57 -0700 (PDT) X-Gm-Message-State: AMCzsaXUbAk7EqzjbcTHhDwORt0TZ8CtZ3rbeNOolPB89GTzWgQQulWF CNtvFloQPUdeVnfyZb2KXSm0S8DRAnVHoY8Tqg8= X-Google-Smtp-Source: AOwi7QDYdl/oxBcn51Sn13Ln+bbgGbX4GHyLFd5HEWocylc+q+ZsDIb1pEmmXXvyc52pG1BBI0vbzT+DK4PzjQnc/mQ= X-Received: by 10.200.43.193 with SMTP id n1mr1438323qtn.101.1507893055973; Fri, 13 Oct 2017 04:10:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.46.85 with HTTP; Fri, 13 Oct 2017 04:10:35 -0700 (PDT) In-Reply-To: <3380AF33-0E0F-46E9-BF03-E61B65E6B838@inria.fr> References: <3380AF33-0E0F-46E9-BF03-E61B65E6B838@inria.fr> From: =?UTF-8?Q?Nicol=C3=A1s_Ojeda_B=C3=A4r?= Date: Fri, 13 Oct 2017 13:10:35 +0200 X-Gmail-Original-Message-ID: Message-ID: To: =?UTF-8?Q?Laurent_Th=C3=A9venoux?= Cc: OCaml Mailing List Content-Type: multipart/alternative; boundary="001a1140642af5f016055b6bb5a5" X-DRWEB-SCAN: ok X-VRSPAM-SCORE: -51 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrtdeigdefkecutefuodetggdotefrucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegoufhushhpvggtthffohhmrghinhculdegledmnecujfgurhepjghfhfffkffuvfgtsegrtderredttdejnecuhfhrohhmpefpihgtohhljohspgfqjhgvuggrpgeumohruceonhhitgholhgrshdrohhjvggurgdrsggrrheslhgvgihifhhirdgtohhmqeenucffohhmrghinhepihhnrhhirgdrfhhrpdhfihhlvgdrmhhlpdihrghhohhordgtohhmnecukfhppedvtdelrdekhedrvdduiedrudektdenucfrrghrrghmpehmohguvgepshhmthhpohhuth X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht Subject: Re: [Caml-list] Interfacing C with OCaml and file descriptors --001a1140642af5f016055b6bb5a5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Dear Laurent, Underlying OCaml I/O channels are Unix file descriptors, not FILE *'s. But you can use the POSIX function fdopen to get a FILE* form the file descriptor of the channel, which you can access by Channel(channel)->fd (see for the precise definition of the channel struct). That said, it is always tricky when different buffering mechanisms (OCaml's and libc's) interact, so caveat emptor! Best wishes, Nicol=C3=A1s -- Nicol=C3=A1s Ojeda B=C3=A4r LexiFi 892, rue Yves Kermen F-92100 Boulogne-Billancourt IT support: +33 1 41 10 02 67 On Fri, Oct 13, 2017 at 12:57 PM, Laurent Th=C3=A9venoux < laurent.thevenoux@inria.fr> wrote: > Hi, > > I have a naive question about file descriptors and C interface (when > interfacing C with OCaml). > > For instance, a file.ml file which looks like: > > > external my_c_interface : out_channel -> int =3D c_function > > > where c_function writes something to a file and return the number of > written char. > The c_function takes a FILE* file descriptor, as for example: > > > CAMLprim value c_function (value channel) > { > CAMLparam1 (channel); > FILE* fd =3D ???; > CAMLreturn (Val_int (call_to_c_func (fd))); > } > > > So, if possible, how to convert the =E2=80=98value channel=E2=80=99 to a = =E2=80=98FILE*=E2=80=99? > > Thanks for your help, > Laurent > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs --001a1140642af5f016055b6bb5a5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Dear Laurent,

Underlying OCaml I/O chan= nels are Unix file descriptors, not FILE *'s. But you can use the POSIX= function fdopen to get a FILE* form the file descriptor of the channel, wh= ich you can access by Channel(channel)->fd (see <caml/io.h> for th= e precise definition of the channel struct).

That = said, it is always tricky when different buffering mechanisms (OCaml's = and libc's) interact, so caveat emptor!

Best w= ishes,
Nicol=C3=A1s


--
Nicol=C3=A1s Ojeda B=C3=A4= r
LexiFi
892, rue Yves Kermen
F-92100 Boulogne-Billancourt
IT s= upport: +33 1 41 10 02 67

On Fri, Oct 13, 2017 at 12:57 PM, Laurent Th= =C3=A9venoux <laurent.thevenoux@inria.fr> wrote:
Hi,

I have a naive question about file descriptors and C interface (when interf= acing C with OCaml).

For instance, a file.ml file which looks like:


external my_c_interface : out_channel -> int =3D c_function


where c_function writes something to a file and return the number of writte= n char.
The c_function takes a FILE* file descriptor, as for example:


CAMLprim value c_function (value channel)
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 CAMLparam1 (channel);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 FILE* fd =3D ???;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 CAMLreturn (Val_int (call_to_c_func (fd)));
}


So, if possible, how to convert the =E2=80=98value channel=E2=80=99 to a = =E2=80=98FILE*=E2=80=99?

Thanks for your help,
Laurent

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--001a1140642af5f016055b6bb5a5--