Skip to content

Commit

Permalink
Make fcntl defined on all platforms (#13495)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored May 24, 2023
1 parent 93cb352 commit 61a2c52
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/crystal/system/wasi/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ module Crystal::System::FileDescriptor
raise NotImplementedError.new "Crystal::System::FileDescriptor.pipe"
end

def self.fcntl(fd, cmd, arg = 0)
r = LibC.fcntl(fd, cmd, arg)
raise IO::Error.from_errno("fcntl() failed") if r == -1
r
end

private def system_blocking_init(value)
end

Expand Down
4 changes: 4 additions & 0 deletions src/crystal/system/win32/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ module Crystal::System::FileDescriptor
false
end

def self.fcntl(fd, cmd, arg = 0)
raise NotImplementedError.new "Crystal::System::FileDescriptor.fcntl"
end

private def windows_handle
FileDescriptor.windows_handle!(fd)
end
Expand Down
4 changes: 1 addition & 3 deletions src/crystal/system/win32/socket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,7 @@ module Crystal::System::Socket
end

def self.fcntl(fd, cmd, arg = 0)
ret = LibC.fcntl fd, cmd, arg
raise Socket::Error.from_errno("fcntl() failed") if ret == -1
ret
raise NotImplementedError.new "Crystal::System::Socket.fcntl"
end

private def system_tty?
Expand Down
14 changes: 6 additions & 8 deletions src/io/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ class IO::FileDescriptor < IO
self.system_close_on_exec = value
end

{% unless flag?(:win32) %}
def self.fcntl(fd, cmd, arg = 0)
Crystal::System::FileDescriptor.fcntl(fd, cmd, arg)
end
def self.fcntl(fd, cmd, arg = 0)
Crystal::System::FileDescriptor.fcntl(fd, cmd, arg)
end

def fcntl(cmd, arg = 0)
Crystal::System::FileDescriptor.fcntl(fd, cmd, arg)
end
{% end %}
def fcntl(cmd, arg = 0)
Crystal::System::FileDescriptor.fcntl(fd, cmd, arg)
end

# Returns a `File::Info` object for this file descriptor, or raises
# `IO::Error` in case of an error.
Expand Down

0 comments on commit 61a2c52

Please sign in to comment.