Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
os: make os.OpenFile() 'perm' argument variadic to match POSIX `open` signature #35647
What are you proposing?
Why are you proposing this?
The proposed change to the
Thanks for the suggestion.
This would break backward compatibility, so it's not something that can be done for Go1.
It may be considered for Go2, I guess.
I do not like this idea, personally. Variadic arguments in C are strictly seen as "additional arguments" and really don't have any additional meaning. This means that variadic arguments in C are used sometimes to express optional arguments, as they are with
In Go, variadic arguments are represented as a slice, which brings the convention that many arguments should be acceptable as a valid input. In this case, we would only want a single FileMode argument to be passed as a bitflag (if we want to keep it close to the POSIX syscall).
I think requiring the bitflag is a bit more "loyal" to the original syscall than allowing multiple FileModes to be passed.
@deanveloper doesn't the POSIX system call itself theoretically allow for multiple
For example, the following compiles and runs on Linux
I noticed that the interfaces for
@ALTree I wanted to ask about the 'backward compatibility' requirement mentioned in the link you provided for Go1.
If users invoke
For the line
You are not mistaken, that's pretty much spot on IIRC.
Note that if you supply any more than one argument for the variadic arguments, they will be ignored, and it's not really logical for them to be anything but that. This is because C does not specify a length for it's variadic arguments, just as it does with arrays. The way it can even tell that you supplied a variadic argument is if you specified the
That's getting a bit off topic though. Getting back to the proposal - I personally think it's better to leave OpenFile as-is, however I can see the justification for making it variadic.