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

Error: undefined fun 'isatty' for LibC on Windows #13165

Closed
Blacksmoke16 opened this issue Mar 9, 2023 · 4 comments · Fixed by #13175
Closed

Error: undefined fun 'isatty' for LibC on Windows #13165

Blacksmoke16 opened this issue Mar 9, 2023 · 4 comments · Fixed by #13175
Assignees
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:system

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Mar 9, 2023

Bug Report

Discovered as part of https://github.com/athena-framework/athena/actions/runs/4370118689/jobs/7644691322 within the framework tests:

Creating library C:\Users\runneradmin\AppData\Local\crystal\cache\D-a-_temp-crystal-nightly-true-undefined-src-ecr-process.cr\macro_run.lib and object C:\Users\runneradmin\AppData\Local\crystal\cache\D-a-_temp-crystal-nightly-true-undefined-src-ecr-process.cr\macro_run.exp
Showing last frame. Use --error-trace for full trace.
  
In D:\a\_temp\crystal-nightly-true-undefined\src\crystal\system\win32\socket.cr:338:10
  
 338 | LibC.isatty(fd) == 1

Error: Error: undefined fun 'isatty' for LibC

I haven't manually confirmed it, but I'd assume this is a resume of doing like STDIN.tty? on windows.

Seems the actual binding for that function was missed in #10784 and this is first time someone tried using IO#tty? on windows?

@Blacksmoke16 Blacksmoke16 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:system labels Mar 9, 2023
@Blacksmoke16
Copy link
Member Author

Okay no, STDIN.tty? works just fine. But it does fail if you actually require socket:

require "socket"

pp STDIN.tty?
 339 | LibC.isatty(fd) == 1
            ^-----
Error: undefined fun 'isatty' for LibC

@HertzDevil
Copy link
Contributor

Easiest to just copy Crystal::System::FileDescriptor#system_tty?, which uses LibC._isatty instead, to Crystal::System::Socket#system_tty?

@straight-shoota
Copy link
Member

I don't think a socket on Windows can ever be a tty. Unlike on POSIX platforms, they're disparate handles. And AFAIK you cannot turn a console handle into a socket handle somehow.

So perhaps the trivial solution is for Socket#system_tty? to return false on windows?

@Blacksmoke16
Copy link
Member Author

Based on what I read that's probably worth a try. It'll at least get things compiling and can always revisit if someone ever comes across a case where it could be true. Will see what CI things. I pushed up another commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants