[PATCH] support kernels without __ARCH_WANT_SYSCALL_NO_FLAGS
dalias at aerifal.cx
Fri Apr 27 00:23:25 UTC 2012
On Thu, Apr 26, 2012 at 07:44:37PM -0400, Mark Salter wrote:
> > > http://old.nabble.com/-PATCH--dup2:-Fix-return-value-with-oldfd-%3D%3D-newfd-and-invalid-fd-td23488867.html
> > >
> > No that isn't it. There is a semantic difference in how dup2 and dup3
> > handles the case of fd1 == fd2. dup3 unconditionally sets errno to
> > EINVAL. dup2 checks if the fd is valid and sets EBADF if not, or returns
> > the fd if it is valid. So the intent in that case is to let fcntl
> > validate the fd in that case to emulate dup2 behavior.
OK, thanks for the info. I was unfamiliar with how dup3 works.
> Thinking about this some more, it'd probably be better to do something
> like this so that fcntl is only in the error path:
Is there a reason to prefer this version? I suspect the code size is
slightly larger and the performance difference (dominated by the
syscall) should not be measurable.
BTW, I would use INLINE_SYSCALL for fcntl too if possible. It should
generate smaller code.
More information about the uClibc