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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 3FB7581799 for ; Sat, 27 Jul 2013 10:38:45 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of adrien@notk.org) identity=pra; client-ip=91.121.71.147; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="adrien@notk.org"; x-sender="adrien@notk.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of adrien@notk.org designates 91.121.71.147 as permitted sender) identity=mailfrom; client-ip=91.121.71.147; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="adrien@notk.org"; x-sender="adrien@notk.org"; 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@nautica.notk.org) identity=helo; client-ip=91.121.71.147; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="adrien@notk.org"; x-sender="postmaster@nautica.notk.org"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AisDAAOG81FbeUeTgWdsb2JhbABagzuDX7pOgRUWDgEBFiYogiQBAQQBI1YFCwsYAgIFEw4CAg8FGB0BE4gdCginMpEugSiOVQeCYzNvA5deAYEpkzk6 X-IPAS-Result: AisDAAOG81FbeUeTgWdsb2JhbABagzuDX7pOgRUWDgEBFiYogiQBAQQBI1YFCwsYAgIFEw4CAg8FGB0BE4gdCginMpEugSiOVQeCYzNvA5deAYEpkzk6 X-IronPort-AV: E=Sophos;i="4.89,756,1367964000"; d="scan'208";a="27504701" Received: from nautica.notk.org ([91.121.71.147]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 27 Jul 2013 10:38:44 +0200 Received: by nautica.notk.org (Postfix, from userid 1003) id 5B233C009; Sat, 27 Jul 2013 10:38:44 +0200 (CEST) Date: Sat, 27 Jul 2013 10:38:44 +0200 From: Adrien Nader To: Florent Monnier Cc: caml-list@inria.fr Message-ID: <20130727083844.GA17235@notk.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: [Caml-list] Re: portable truncate On Fri, Jul 26, 2013, Florent Monnier wrote: > 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. Yes, they are. > 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 The compiler differs but otherwise the differences are small. The libc that is used on Windows is Microsoft's (actually called CRT); mingw* provide some additions to that and apparently, ftruncate is provided. In otherlibs/win32unix/unix.ml, you have: let ftruncate fd len = invalid_arg "Unix.ftruncate not implemented" And in unistd.h, you have: #ifndef FTRUNCATE_DEFINED #define FTRUNCATE_DEFINED /* This is defined as a real library function to allow autoconf to verify its existence. */ #if !defined(NO_OLDNAMES) || defined(_POSIX) int ftruncate(int, off32_t); int ftruncate64(int, off64_t); int truncate(const char *, off32_t); int truncate64(const char *, off64_t); #ifndef __CRT__NO_INLINE __CRT_INLINE int ftruncate(int __fd, off32_t __length) { return _chsize (__fd, __length); } #endif /* !__CRT__NO_INLINE */ #else int ftruncate(int, _off_t); int ftruncate64(int, _off64_t); int truncate(const char *, _off_t); int truncate64(const char *, _off64_t); #ifndef __CRT__NO_INLINE __CRT_INLINE int ftruncate(int __fd, _off_t __length) { return _chsize (__fd, __length); } #endif /* !__CRT__NO_INLINE */ #endif #endif /* FTRUNCATE_DEFINED */ Considering this, you should probably make a patch to add a file win32unix/ftruncate.c which use the implementation above and replace the implementation of ftruncate* in win32unix/unix.ml. I don't know what is the purpose of the __CRT_NO_INLINE define; I've already asked and will propagate the answer when I get it. It would be good to have truncate*() too. (and submit it to the bug tracker :-) ) -- Adrien Nader