From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id DBCA68027D for ; Sat, 14 Oct 2017 17:18:25 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mmatalka@gmail.com; spf=Pass smtp.mailfrom=mmatalka@gmail.com; spf=None smtp.helo=postmaster@mail-pf0-f182.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of mmatalka@gmail.com) identity=pra; client-ip=209.85.192.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of mmatalka@gmail.com designates 209.85.192.182 as permitted sender) identity=mailfrom; client-ip=209.85.192.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pf0-f182.google.com) identity=helo; client-ip=209.85.192.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="postmaster@mail-pf0-f182.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AI6kMWBPi98XSuzWXtwYl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0KPz6rarrMEGX3/hxlliBBdydsK0UzbeO+4nbGkU+or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6aijSI4DUTAhTyMxZu?= =?us-ascii?q?bqSwQ9aKzpf/6+fnsafSaAVBnjb1XvVXal2UqgPcrYNe1ZFjIaYZwx3Pr2tJcq?= =?us-ascii?q?JR32w+dnyJmBOpw86095ln9mx1su4o881JGfH/eq0kRLhbBRwpNmk04IvgshyV?= =?us-ascii?q?HljH3WcVTmhDykkAOAPC9hyvG86p6iY=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CkAADIKeJZhrbAVdFTCRoBAQEBAgEBA?= =?us-ascii?q?QEIAQEBARQBAQEBAQEBAQEBAQcBAQEBAYUtg3qZUYF2iTWMeoIUCoU7AoRWQBc?= =?us-ascii?q?BAQEBAQEBAQEBARIBAQEICwsIKC+COAUBHgEFgjsBAQEDASMdARsdAQMBCwYFC?= =?us-ascii?q?w0CAgUhAgIPAQQPEQEFASITigQBAw0IBJ5ZQIwMggUFARyDCQWDYwoZJw1YgxA?= =?us-ascii?q?BAQEBAQEEAQEBAQEBGgIGCQEIfIIfgTZRgVGBaoMqhFsqgxOCQSAFoUiUa4IUi?= =?us-ascii?q?T81hw6VQgIEAgQFAgYUJIEVIQOCDDQhCB0VSTWCL4JNH4FzdokkgVUBAQE?= X-IPAS-Result: =?us-ascii?q?A0CkAADIKeJZhrbAVdFTCRoBAQEBAgEBAQEIAQEBARQBAQE?= =?us-ascii?q?BAQEBAQEBAQcBAQEBAYUtg3qZUYF2iTWMeoIUCoU7AoRWQBcBAQEBAQEBAQEBA?= =?us-ascii?q?RIBAQEICwsIKC+COAUBHgEFgjsBAQEDASMdARsdAQMBCwYFCw0CAgUhAgIPAQQ?= =?us-ascii?q?PEQEFASITigQBAw0IBJ5ZQIwMggUFARyDCQWDYwoZJw1YgxABAQEBAQEEAQEBA?= =?us-ascii?q?QEBGgIGCQEIfIIfgTZRgVGBaoMqhFsqgxOCQSAFoUiUa4IUiT81hw6VQgIEAgQ?= =?us-ascii?q?FAgYUJIEVIQOCDDQhCB0VSTWCL4JNH4FzdokkgVUBAQE?= X-IronPort-AV: E=Sophos;i="5.43,377,1503352800"; d="scan'208";a="296204852" Received: from mail-pf0-f182.google.com ([209.85.192.182]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 14 Oct 2017 17:18:24 +0200 Received: by mail-pf0-f182.google.com with SMTP id d28so12605740pfe.2; Sat, 14 Oct 2017 08:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=9kpq3on4Y4sf/HTZJdxspbmqBN2/UTNUtNPUI194Xbk=; b=BIZadENV3OjPzt0nqGbcEO/zJqZUxrd4itEh5Bfuv68BNL/46n2JwOBHIfBNOwiUvt azrFWW5BnA2Mv6LQLbJBnmGKareGSwOKIAZJFROV1IoSvl1jWUFnJxhCPrF77VqewDLQ 4/cgyWI72vafqdCPSufkA7pCoD457B9bFnUZi2aOKja5byP5w1HMr0VG7fY8ezQYcLSA z6WCaCTsL6hnL6fyO3a+Cep62H2A+NIwXzXcfKFU8ZwGQdzA7cxOPq5ZtqhZKkzCtgek F3aOrY9oYQOQepuoRRCkOC7vSaL/W7vR31quq1bfYdMcxPCPSyB1hD9otimXtVWQjoeS IszQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=9kpq3on4Y4sf/HTZJdxspbmqBN2/UTNUtNPUI194Xbk=; b=tp2ZVidyU9zsj06DomJImsqMk9vhKyYg2Lk6YDtEeCQAhUggShLKWqB7J/LZZkxTGX BPcznTe5/0VpKsEqPiKfaZ2MRrYUNgiJQHU+8OgJQBFOhlH1OY5RHZKfdRLMpEQI9HCc 2a7LA23dKusRcfs+0F4r7qkPirbBJUwxQffDWVEiwGqv5/BgnnJkogMOc/6Dcd9OqjdM cz1LAJuYI13W3nB/q9En4lc1FVeLE1yMQApiAhCIo9W6B8yt4ujEXfUDdQm70+LG86hv UoozpK7E6JTtyGRu8TpmNGHfrokBObDT6LSPBJg2EaARN7mfVK9D+Kt3Esaq/oKqjs4U dMCA== X-Gm-Message-State: AMCzsaVrNz9N960+9RBMTrZYEQmZt8R1oxAxbmW9vOjnbDUaS1xFrbyL uGWie2zdRN9/m/De6T296VMfQyxg X-Google-Smtp-Source: AOwi7QAaxn/NsAlTyyzUMzTtG9uiqJ/r1+Nzp6TiZK5/VcB/U5vMAFjPQeGmBQCJvygHTPGlAwDR6g== X-Received: by 10.159.216.145 with SMTP id s17mr4274573plp.297.1507994303045; Sat, 14 Oct 2017 08:18:23 -0700 (PDT) Received: from localhost ([37.153.108.22]) by smtp.gmail.com with ESMTPSA id y83sm7867439pfa.31.2017.10.14.08.18.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Oct 2017 08:18:21 -0700 (PDT) From: Malcolm Matalka To: "Richard W.M. Jones" Cc: Laurent =?utf-8?Q?Th=C3=A9venoux?= , caml-list@inria.fr References: <3380AF33-0E0F-46E9-BF03-E61B65E6B838@inria.fr> <20171013213741.ke5ptnxrq2w3n6oq@annexia.org> Date: Sat, 14 Oct 2017 15:18:16 +0000 In-Reply-To: <20171013213741.ke5ptnxrq2w3n6oq@annexia.org> (Richard W. M. Jones's message of "Fri, 13 Oct 2017 22:37:41 +0100") Message-ID: <86r2u5yczr.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Interfacing C with OCaml and file descriptors "Richard W.M. Jones" writes: > On Fri, Oct 13, 2017 at 12:57:33PM +0200, Laurent Th=C3=A9venoux wrote: >> Hi, >>=20 >> I have a naive question about file descriptors and C interface (when int= erfacing 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 =3D Int_val (fdv); > read (fd, buf, len); > > 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! > > Rich. I do a similar thing but I abuse "%identity" for it and do it in Ocaml. In my case I do it for my kqueue bindings so it should be safe, assuming Unix.file_descr is guaranteed not to change, but it does make me feel dirty.