From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA21534; Tue, 7 Aug 2001 09:37:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA21528 for ; Tue, 7 Aug 2001 09:36:59 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f777ap511307; Tue, 7 Aug 2001 09:36:51 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA21526; Tue, 7 Aug 2001 09:36:51 +0200 (MET DST) Date: Tue, 7 Aug 2001 09:36:50 +0200 From: Xavier Leroy To: Johann Spies Cc: caml-list@inria.fr Subject: Re: [Caml-list] using open_out_gen, output_string and close_out Message-ID: <20010807093650.A21319@pauillac.inria.fr> References: <8766c12adu.fsf@adept.co.za> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <8766c12adu.fsf@adept.co.za>; from jhspies@adept.co.za on Mon, Aug 06, 2001 at 10:37:01PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > The following illustrates my problem: > ------------------------------- > $ocaml > Objective Caml version 3.00 > > # let l = open_out_gen [Open_creat;Open_append] 0o666 "/tmp/xx";; > val l : out_channel = > # close_out l;; > - : unit = () > # let l = open_out_gen [Open_creat;Open_append] 0o666 "/tmp/xx";; > val l : out_channel = > # output_string l "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb > ccccccccccccccccccccccccccccccccc";; > - : unit = () > # close_out l;; > Uncaught exception: Sys_error "Bad file descriptor". The Open_append flag does not imply write access, it's just a modifier saying "whatever writes you do, do them at the end of the file". So you need to specify Open_wronly as well. (Agreed, the documentation should state this.) Otherwise, as you found out, actual writes to the file will fail. (Since output is buffered, the "output_string" didn't perform an actual write to the file, hence no error, but "close_out" flushes the buffer to the file, hence the error pops up at that time.) - Xavier Leroy ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr