The fdInUse function passed in O_WRONLY | O_RDWR as flags and then checked fileFlags[fd] & flags == flags. This is only true if all of the bits set in flags are also set in fileFlags[fd]. Since O_WRONLY | O_RDWR are mutually exclusive the fdInUse function always returns false in this case and the write syscall fails.
I fixed the expression and passed in an enum instead to make it more explicit about what we are testing for.
The fdInUse function passed in O_WRONLY | O_RDWR as flags and then checked fileFlags[fd] & flags == flags. This is only true if all of the bits set in flags are also set in fileFlags[fd]. Since O_WRONLY | O_RDWR are mutually exclusive the fdInUse function always returns false in this case and the write syscall fails.
I fixed the expression and passed in an enum instead to make it more explicit about what we are testing for.