Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

under cygwin, Unix.fstat on pipes always gives 0 for Unix.st_size #4154

Closed
vicuna opened this issue Nov 8, 2006 · 3 comments
Closed

under cygwin, Unix.fstat on pipes always gives 0 for Unix.st_size #4154

vicuna opened this issue Nov 8, 2006 · 3 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Nov 8, 2006

Original bug ID: 4154
Reporter: shawjef3
Status: closed (set by @damiendoligez on 2006-11-17T14:29:37Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 3.09.3
Category: ~DO NOT USE (was: OCaml general)

Bug description

Under cygwin, Unix.fstat gives the correct size for files opened with Unix.openfile but not for pipes. It prevents me from running an application that works fine under mac os x which marshals data between threads. This may be an issue with cygwin or ocaml, I don't know which for sure.

for a file:

let file = Unix.openfile "pipetest.ml" [Unix.O_RDONLY] 0;;

val file : Unix.file_descr =

(Unix.fstat file).Unix.st_size;;

  • : int = 1056

for a pipe:

$ ./ocamlunix
Objective Caml version 3.09.3

let pipe = Unix.pipe();;

val pipe : Unix.file_descr * Unix.file_descr = (, )

let buffer1 = String.make 10 ' ';;

val buffer1 : string = " "

Unix.write (snd pipe) buffer1 0 10;;

  • : int = 10

(Unix.fstat (fst pipe)).Unix.st_size;;

  • : int = 0

Unix.fstat (fst pipe);;

  • : Unix.stats =
    {Unix.st_dev = 254; Unix.st_ino = 0; Unix.st_kind = Unix.S_FIFO;
    Unix.st_perm = 292; Unix.st_nlink = 1; Unix.st_uid = 500; Unix.st_gid = 513;
    Unix.st_rdev = 254; Unix.st_size = 0; Unix.st_atime = 1163017327.;
    Unix.st_mtime = 1163017327.; Unix.st_ctime = 1163017327.}

let buffer2 = String.make 10 '+';;

val buffer2 : string = "++++++++++"

Unix.read (fst pipe) buffer2 0 10;;

  • : int = 10

buffer2;;

  • : string = " "
@vicuna
Copy link
Author

vicuna commented Nov 15, 2006

Comment author: @damiendoligez

It's not clear that the "size of a pipe" has any meaning.

Looks like a cygwin problem, if it is a problem at all.

@vicuna
Copy link
Author

vicuna commented Nov 16, 2006

Comment author: monate

This size of a pipe is undefined according to POSIX : see http://sources.redhat.com/ml/bug-glibc/2003-09/msg00098.html for example.

@vicuna
Copy link
Author

vicuna commented Nov 16, 2006

Comment author: shawjef3

I'm using the following so it works fine now:

let pipe_not_empty pipe =
match Unix.select [pipe] [] [] 0. with
([],,) -> false
| (,,_) -> true

Thanks for the info. I guess MacOS X is just being extra nice to tell me the amount of data in a pipe.

@vicuna vicuna closed this as completed Nov 17, 2006
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant