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

Unix.fstat behaves surprisingly under OCaml 4.03.0/windows, Unix.isatty is broken #7265

vicuna opened this Issue May 27, 2016 · 1 comment


None yet
2 participants
Copy link

commented May 27, 2016

Original bug ID: 7265
Reporter: aha
Assigned to: @diml
Status: closed (set by @xavierleroy on 2017-09-24T15:33:23Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0
Fixed in version: 4.04.0 +dev / +beta1 / +beta2
Category: platform support (windows, cross-compilation, etc)
Monitored by: @gasche @diml

Bug description

Unix.fstat now throws an exception for file handles of FILE_TYPE_CHAR. And it reports the wrong file kind for FILE_TYPE_PIPE.

Because Unix.isatty is implemented with Unix.fstat, it's broken (and therefore utop and all similar software, that either use Unix.isatty or pass something of FILE_TYPE_CHAR to it)

Steps to reproduce

4.02.3 behavior on windows (identical to *nix)

let a,b = Unix.pipe () ;;
assert ( (Unix.fstat a).Unix.st_kind = Unix.S_FIFO );;
assert ( (Unix.fstat Unix.stdin).Unix.st_kind = Unix.S_CHR );; (* if Unix.stdin is a terminal, of course *)

4.03.0 behaviour on windows

let a,b = Unix.pipe () ;;
assert ( (Unix.fstat a).Unix.st_kind = Unix.S_REG );;
assert ( try ignore(Unix.fstat Unix.stdin); false with | Unix.Unix_error(Unix.EBADF,"fstat",_) -> true);;

Additional information

Note, if you start the ocaml toplevel from within cygwin (mintty,urxvt), cygwin adds its magic. Unix.stdin/stdout/stderr will be of type FILE_TYPE_PIPE, not FILE_TYPE_CHAR. So the steps to reproduce wont work as intended.


This comment has been minimized.

Copy link
Collaborator Author

commented Aug 19, 2016

Comment author: @diml

Fixed in trunk (9d4833d) and 4.04 (3767d78)

@vicuna vicuna closed this Sep 24, 2017

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.