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 9455E81799 for ; Fri, 26 Jul 2013 14:02:56 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of monnier.florent@gmail.com) identity=pra; client-ip=209.85.212.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="monnier.florent@gmail.com"; x-sender="monnier.florent@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of monnier.florent@gmail.com designates 209.85.212.171 as permitted sender) identity=mailfrom; client-ip=209.85.212.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="monnier.florent@gmail.com"; x-sender="monnier.florent@gmail.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@mail-wi0-f171.google.com) identity=helo; client-ip=209.85.212.171; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="monnier.florent@gmail.com"; x-sender="postmaster@mail-wi0-f171.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgECAJFk8lHRVdSrjWdsb2JhbABagztQvUSBDggWDgEBAQEHCwsJEgYkgiUBBScZARseAwwGBQs7IgERAQUBHIgWAQMPDJsvjE+Cf4RXChknDWSHdAEFDI94hAUDl1+BKY4+FimEPDo X-IPAS-Result: AgECAJFk8lHRVdSrjWdsb2JhbABagztQvUSBDggWDgEBAQEHCwsJEgYkgiUBBScZARseAwwGBQs7IgERAQUBHIgWAQMPDJsvjE+Cf4RXChknDWSHdAEFDI94hAUDl1+BKY4+FimEPDo X-IronPort-AV: E=Sophos;i="4.89,751,1367964000"; d="scan'208";a="22341126" Received: from mail-wi0-f171.google.com ([209.85.212.171]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 26 Jul 2013 14:02:56 +0200 Received: by mail-wi0-f171.google.com with SMTP id hj3so755539wib.10 for ; Fri, 26 Jul 2013 05:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=fuObfxjpJ8xUKw+A5/vK7jnfmCCt8pNnsHXGRzIkq5s=; b=YaTuJ/GIBw3+yxeoyjZIpRvkZHRYfApCodgvPxaV+PJKFfShdxGaGNlv/8uUqKs8Zf 1Whl6qcZkIelSKbv5SuXw/LHso4NJ0snYLu6VxMePuZiBPCxqjYv00cAQo74mVZ/B3ER BJ3mYkoQu9wsmVS2preRKbxtaUox0TpTvB2jXU1LAajOnzbW9WlboNMxoqOM/nrg9Jit 5/wGzvsRCB/KmIdEO7ZwsN1gx2HE3XcjyHGHJw3JvAeXgMSoTbtPrMUWqX/TqmAtEzWz PmKlS/7vRXBRtJz6qYI/oKfgBMjFNQc1X/XxqdP3B32oD1jQD/LI07ujh8zvQdQ04nMa W/Qg== MIME-Version: 1.0 X-Received: by 10.180.83.163 with SMTP id r3mr5529193wiy.10.1374840175737; Fri, 26 Jul 2013 05:02:55 -0700 (PDT) Received: by 10.194.80.36 with HTTP; Fri, 26 Jul 2013 05:02:55 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Jul 2013 14:02:55 +0200 Message-ID: From: Florent Monnier To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Validation-by: monnier.florent@gmail.com Subject: [Caml-list] Re: portable truncate Hi, 2013/07/26, Florent Monnier wrote: [...] > 1) I thought that the module Unix only contains portable things for > Windows, so it's not true? This page indeed gives a list of unimplemented functions at the end: [1] http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual036.html but it depends which ocaml variants is used. This page above says: "The Cygwin port of OCaml fully implements all functions from the Unix module. The native Win32 ports implement a subset of them." So this page talks about 2 ocaml variants: - Cygwin ocaml, - and native Win32 ocaml. This other page, gives informations for 3 ocanl variants: [2] http://caml.inria.fr/ocaml/portability.en.html which are - native Microsoft - native MinGW - and Cygwin I should probably understand frm this that both "native Microsoft" and "native MinGW" are native Win32 ocaml. I made the error to think that native Win32 port only refers to ocaml compiled with MSVC, while it seems that it also include protz's ocaml that is a MinGW variant. I'm still not sure though that compiling with MSVC or MinGW can be considered equivalent. And actually they seem not considering this page: [2] http://caml.inria.fr/ocaml/portability.en.html And considering the small test (called "MyUnix" below), it shows that it seems that the function truncate() could work just fine. [...] > I tryed to replicate these stubs without the macro that removes these > functions but I still get the exception from MyUnix.ftruncate: Failure > "ftruncate" > > But if I use MyUnix.truncate instead (the input is then the filename, > not the Unix.file_descr as I would like), then it works. > [...] > > /* Xavier Leroy, projet Cristal, INRIA Rocquencourt > Copyright 1996 Institut National de Recherche en Informatique et > en Automatique. All rights reserved. This file is distributed > under the terms of the GNU Library General Public License, with > the special exception on linking described in the file LICENSE of OCaml. > */ > #include > #include > #include > #include > #include "unixsupport.h" > #include > > CAMLprim value myunix_ftruncate(value fd, value len) > { > if (ftruncate(Int_val(fd), Long_val(len)) == -1) > caml_failwith("ftruncate"); > return Val_unit; > } > > CAMLprim value myunix_ftruncate_64(value fd, value len) > { > if (ftruncate(Int_val(fd), Int64_val(len)) == -1) > caml_failwith("ftruncate64"); > return Val_unit; > } > > CAMLprim value myunix_truncate(value path, value len) > { > if (truncate(String_val(path), Long_val(len)) == -1) > caml_failwith("truncate"); > return Val_unit; > } > > CAMLprim value myunix_truncate_64(value path, value len) > { > if (truncate(String_val(path), Int64_val(len)) == -1) > caml_failwith("truncate64"); > return Val_unit; > } > > > $ cat myUnix.ml > > (* Xavier Leroy, projet Cristal, INRIA Rocquencourt > Copyright 1996 Institut National de Recherche en Informatique et > en Automatique. All rights reserved. This file is distributed > under the terms of the GNU Library General Public License, with > the special exception on linking described the file LICENSE of OCaml. > *) > > type file_descr = Unix.file_descr > > external ftruncate : file_descr -> int -> unit = "myunix_ftruncate" > external truncate : string -> int -> unit = "myunix_truncate" > > module LargeFile = struct > external ftruncate : file_descr -> int64 -> unit = "myunix_ftruncate_64" > external truncate : string -> int64 -> unit = "myunix_truncate_64" > end > > > $ export CC='/bin/i686-w64-mingw32-gcc' > $ $CC -c -I c:/OCaml/lib/caml ftruncate.c > $ ocamlc -c myUnix.mli > $ ocamlc -c myUnix.ml > $ ocamlmklib -o myunix myUnix.cmo ftruncate.o > With this test, the function MyUnix.truncate DOES WORK. I'm still in hope to find a workaround for ftruncate() that could work with MinGW's toolchain. -- Cheers