-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Exporting ioctl #2946
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
Exporting ioctl #2946
Conversation
@swift-ci please test |
@@ -49,6 +50,16 @@ extern int _swift_Platform_fcntlPtr(int fd, int cmd, void* ptr) { | |||
return fcntl(fd, cmd, ptr); | |||
} | |||
|
|||
extern int | |||
_swift_Platform_ioctl(int fd, unsigned long int request, int value) { | |||
return fcntl(fd, request, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be ioctl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fixed and testing it locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests passed on OSX&Linux.
Is there anything that can be tested across most Linux systems? I'd be fine with a |
I've updated the PR:
Tested locally on both OSX and Linux (Ubuntu 15). |
Seems okay to me. @modocache, @gribozavr? @swift-ci Please test |
@uraimo Thank you! What about an overload for commands without an argument? |
var vptr = UnsafeMutablePointer<Void>(ptr) | ||
let io = ioctl(sock, UInt(SIOCGIFCONF), vptr); | ||
expectGE(io, 0) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be able to do this:
var ic = ifconf()
let io = ioctl(sock, UInt(SIOCGIFCONF), &ic);
expectGE(io, 0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, way better, that was a remnant of previous ioctl attempts.
Makes sense, added. |
@swift-ci Please test and merge |
What's in this pull request?
This pull request exports the variadic
ioctl
system call, needed to interact with device files on Linux and other Unix-like systems. At the moment, Linux Swift libraries that interact with a device driver need to implement a c wrapper forioctl
in a separate clang/llvm module (essentially the same c module is duplicated in every library that does something with devices).Having
ioctl
available in Swift would allow the creation of pure-Swift device libraries (more portable, easier to compile).The two new functions contained in this PR follow the same approach of the already exported
fcntl
, one function with an int parameter and one with a pointer. But unlikefcntl
i don't expectioctl
to be used internally in Foundation any time soon.On the testing side, the only thing that can be tested across platforms is the presence of the function, since aside from a few obscure commands related to tty devices, ioctl requests are heavily platform-dependent. I'm including a single test that tries an ioctl on a non-existing file (failure is expected).
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.