From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 B43FD8027D for ; Sat, 14 Oct 2017 08:10:58 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=rich@annexia.org; spf=Pass smtp.mailfrom=rich@annexia.org; spf=Pass smtp.helo=postmaster@annexia.org Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of rich@annexia.org) identity=pra; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of rich@annexia.org designates 80.68.91.176 as permitted sender) identity=mailfrom; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of postmaster@annexia.org designates 80.68.91.176 as permitted sender) identity=helo; client-ip=80.68.91.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="postmaster@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" IronPort-PHdr: =?us-ascii?q?9a23=3AmAWnjR3gl/YGgdxJsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?segUKPad9pjvdHbS+e9qxAeQG96Eu7QZ06L/iOPJZy8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL3WbmHC57CYTFxPjLkI1?= =?us-ascii?q?Y72tQs+Buf+qzPi/8IH/ZABBhTz1Ie8jbUb+kQKEmsAIgIcqA6I10RzRujMcd/?= =?us-ascii?q?5fgGVlOkm7mhvg79ys9ZVgtS9XvqRy2dRHVPCwRaUzTbVCAHwZdUVzrO/ssxTY?= =?us-ascii?q?B0Pb/HoXUk0flBxFEwnMqhbgUcGi4WPBquNh1XzCboXNRrcuVGHnsv5m?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AXAgCDqeFZ/7BbRFBcGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFAEBAQEBAQEBAQEBBwEBAQEBgzRkbp1yPwEBBAaBK4JNlXYKI4UYAoR?= =?us-ascii?q?WQhUBAQEBAQEBAQEBAWoogjgFAR4GgjsBAQEBAgEyATsLEAsOCgkEDxIPLQkSB?= =?us-ascii?q?iWJcwMIBQwMrSWHQQODcgEBCAEBAQEkgy2CB4EJPoF0gyqKWSAFiC8MkCmIYwK?= =?us-ascii?q?HXYx/giFdiReHDJVvgTk1IoFZgQcISYJlCIRXP4lngVUBAQE?= X-IPAS-Result: =?us-ascii?q?A0AXAgCDqeFZ/7BbRFBcGgEBAQECAQEBAQgBAQEBFAEBAQE?= =?us-ascii?q?BAQEBAQEBBwEBAQEBgzRkbp1yPwEBBAaBK4JNlXYKI4UYAoRWQhUBAQEBAQEBA?= =?us-ascii?q?QEBAWoogjgFAR4GgjsBAQEBAgEyATsLEAsOCgkEDxIPLQkSBiWJcwMIBQwMrSW?= =?us-ascii?q?HQQODcgEBCAEBAQEkgy2CB4EJPoF0gyqKWSAFiC8MkCmIYwKHXYx/giFdiReHD?= =?us-ascii?q?JVvgTk1IoFZgQcISYJlCIRXP4lngVUBAQE?= X-IronPort-AV: E=Sophos;i="5.43,374,1503352800"; d="scan'208";a="240963068" Received: from annexia.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-GCM-SHA384; 14 Oct 2017 08:10:57 +0200 Received: from rich by annexia.org with local (Exim 4.89) (envelope-from ) id 1e3Fey-0000IG-Nm; Sat, 14 Oct 2017 07:10:56 +0100 Date: Sat, 14 Oct 2017 07:10:56 +0100 From: "Richard W.M. Jones" To: David Allsopp Cc: Laurent =?iso-8859-1?Q?Th=E9venoux?= , "caml-list@inria.fr" Message-ID: <20171014061056.dauqokuaulyuxwd3@annexia.org> References: <3380AF33-0E0F-46E9-BF03-E61B65E6B838@inria.fr> <20171013213741.ke5ptnxrq2w3n6oq@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [Caml-list] Interfacing C with OCaml and file descriptors On Fri, Oct 13, 2017 at 10:42:23PM +0000, David Allsopp wrote: > Richard W.M. Jones wrote: > > On Fri, Oct 13, 2017 at 12:57:33PM +0200, Laurent Thévenoux wrote: > > > Hi, > > > > > > I have a naive question about file descriptors and C interface (when > > interfacing C with OCaml). > > > > Firstly, you're confused about the difference between 'FILE *' and a file > > descriptor. They are not the same thing at all. Read some basic Unix > > texts about the difference. > > > > Once you've sorted that out, it turns out that you can (currently) cast a > > Unix.file_descr from OCaml directly into a C int file descriptor using > > Int_val: > > > > int fd = Int_val (fdv); > > read (fd, buf, len); > > FWIW, note that this is not portable - it won't work on Windows, since Unix.file_descr is a struct. Right, precisely my point. However it currently works on Unix which is what I (and the original poster) care about. Rich. > > It would be really nice if there was an official C function defined by > > OCaml to do this in a portable and future-proof way! > > One possibility might be to include the CRT_fd_val macro already in the win32unix version of unixsupport.h and make it an "official" conversion. > > > David > > > -- > 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 -- Richard Jones