Opened 10 months ago
Last modified 10 months ago
#18809 new enhancement
Change `FD_CWD` to a different value
Reported by: | sunfishcode | Owned by: | nobody |
---|---|---|---|
Priority: | low | Milestone: | Unscheduled |
Component: | System/Kernel | Version: | |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
Currently in Haiku the constant FD_CWD
is defined to be -1:
Would it be possible to change this to -2, or any other negative number?
I maintain some code that uses -1 as a sentinel fd value, on the assumption that -1 is never a valid FD, because it's the error return value for open
. This code can hold the value of FD_CWD
on all platforms I can find, except for Haiku. Only Haiku defines FD_CWD
as -1.
I'm aware of the possibility that this value is not feasible to change; if that's the case, feel free to close this.
Change History (3)
comment:1 by , 10 months ago
Component: | - General → System/Kernel |
---|
comment:2 by , 10 months ago
If Haiku doesn't check for this value in the kernel, then perhaps AT_FDCWD
can indeed be changed. I've now submitted a patch implementing this:
https://review.haiku-os.org/c/haiku/+/7423
It may also be worth considering having Haiku reject -1 when passed as the fd to openat etc., to help catch code that forgets to check for errors, however that's a separate change.
comment:3 by , 10 months ago
Change merged in hrev57593. However, I am going to leave this open, as we should indeed reject -1; but not until we've rebuilt a lot of applications to use the new value.
Reading the source code, it looks like we don't even check for this value in the kernel, we just check for
fd < 0
. So you could already specify -2. But that means that passing -1 as an "invalid" FD would actually work in at least this one instance...I don't know if that's a problem or not?