caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] using open_out_gen, output_string and close_out
@ 2001-08-06 20:37 Johann Spies
  2001-08-07  7:36 ` Xavier Leroy
  0 siblings, 1 reply; 5+ messages in thread
From: Johann Spies @ 2001-08-06 20:37 UTC (permalink / raw)
  To: caml-list

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 = <abstr>
# close_out l;;
- : unit = ()
# let l = open_out_gen [Open_creat;Open_append] 0o666 "/tmp/xx";;
val l : out_channel = <abstr>
# output_string l "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
  ccccccccccccccccccccccccccccccccc";;
- : unit = ()
# close_out l;;
Uncaught exception: Sys_error "Bad file descriptor".
#
------------------------------------------------------

What is happening here?  After exiting ocaml, the file /tmp/xx was
empty.

Johann
-- 
J.H. Spies - Tel. 082 782 0336 / 021-808 4036(w)  
             Posbus 4668, Tygervallei 7536
     "Be still before the LORD and wait patiently for him;
      do not fret when men succeed in their ways, when they
      carry out their wicked schemes." 
                            Psalms 37:7 
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] using open_out_gen, output_string and close_out
  2001-08-06 20:37 [Caml-list] using open_out_gen, output_string and close_out Johann Spies
@ 2001-08-07  7:36 ` Xavier Leroy
  2001-08-07 10:46   ` Johann Spies
  0 siblings, 1 reply; 5+ messages in thread
From: Xavier Leroy @ 2001-08-07  7:36 UTC (permalink / raw)
  To: Johann Spies; +Cc: caml-list

> 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 = <abstr>
> # close_out l;;
> - : unit = ()
> # let l = open_out_gen [Open_creat;Open_append] 0o666 "/tmp/xx";;
> val l : out_channel = <abstr>
> # 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] using open_out_gen, output_string and close_out
  2001-08-07  7:36 ` Xavier Leroy
@ 2001-08-07 10:46   ` Johann Spies
  0 siblings, 0 replies; 5+ messages in thread
From: Johann Spies @ 2001-08-07 10:46 UTC (permalink / raw)
  To: caml-list

Xavier Leroy <Xavier.Leroy@inria.fr> writes:

> 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.)

Thanks Xavier.  That solved it.


Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "If ye be reproached for the name of Christ, happy are 
      ye; for the spirit of glory and of God resteth upon 
      you; on their part He is spoken evil of, but on your 
      part He is glorified."                 I Peter 4:14 
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] using open_out_gen, output_string and close_out
@ 2001-08-07  8:33 Johann Spies
  0 siblings, 0 replies; 5+ messages in thread
From: Johann Spies @ 2001-08-07  8:33 UTC (permalink / raw)
  To: ocaml mailing list

"Jeremy Fincher" <tweedgeezer@hotmail.com> writes:

> I believe your permissions are wrong.  I can't tell you what
> algorithm to use to determine the permissions number, but I know it
> has to include some bits for the file type (plain file, socket,
> pipe, directory, etc.)
> 
> When I want 0644 I use 33188.  That's all I can tell you.  I found
> that number by looking at the ST_MODE return value of the stat(2)
> call on a regular file that i knew was 0644 :)

I think the following illustrates that the permissions is are not the
problem:

# let l = open_out_gen [Open_creat; Open_append] 33188 "/tmp/xx";;
val l : out_channel = <abstr>
# let skryf = output_string l "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  bbbbbbbbbbbbbbbbbbbbbbbbbbb
  ccccccccccccccccccccccccccc";;
    val skryf : unit = ()
# close_out l;;
Uncaught exception: Sys_error "Bad file descriptor".
#

-rw-r--r--    1 js       js              0 Aug  7 08:27 xx


# let k = open_out_gen [Open_creat; Open_append] 0o644 "/tmp/yy";;
val k : out_channel = <abstr>
# output_string k "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  bbbbbbbbbbbbbbbbbbbbbbbbbbb
  ccccccccccccccccccccccccccc";;
    - : unit = ()
# close_out k;;
Uncaught exception: Sys_error "Bad file descriptor".

-rw-r--r--    1 js       js              0 Aug  7 08:29 yy



Johann
-- 
Johann Spies          Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

     "If ye be reproached for the name of Christ, happy are 
      ye; for the spirit of glory and of God resteth upon 
      you; on their part He is spoken evil of, but on your 
      part He is glorified."                 I Peter 4:14 
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] using open_out_gen, output_string and close_out
@ 2001-08-07  0:36 Jeremy Fincher
  0 siblings, 0 replies; 5+ messages in thread
From: Jeremy Fincher @ 2001-08-07  0:36 UTC (permalink / raw)
  To: jhspies, caml-list

I believe your permissions are wrong.  I can't tell you what algorithm to 
use to determine the permissions number, but I know it has to include some 
bits for the file type (plain file, socket, pipe, directory, etc.)

When I want 0644 I use 33188.  That's all I can tell you.  I found that 
number by looking at the ST_MODE return value of the stat(2) call on a 
regular file that i knew was 0644 :)

Jeremy

># let l = open_out_gen [Open_creat;Open_append] 0o666 "/tmp/xx";;

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-08-07  8:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-06 20:37 [Caml-list] using open_out_gen, output_string and close_out Johann Spies
2001-08-07  7:36 ` Xavier Leroy
2001-08-07 10:46   ` Johann Spies
2001-08-07  0:36 Jeremy Fincher
2001-08-07  8:33 Johann Spies

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).