jnr / jnr-posix

Java Posix layer
Other
239 stars 91 forks source link

O_DIRECTORY does not fail on open() #143

Open luxe opened 4 years ago

luxe commented 4 years ago

Problem:

I'm trying to use O_DIRECTORY with open(2). It says, if pathname is not a directory, cause the open to fail. jnr-posix does not seem to fail when opening a file with O_DIRECTORY.

Example:

mkdir dir_example;
touch file_example;

POSIX posix = POSIXFactory.getNativePOSIX();
int fd1 = posix.open("dir_example", OpenFlags.O_DIRECTORY.intValue(), 0444);
System.out.println(fd1);
int fd2 = posix.open(" file_example", OpenFlags.O_DIRECTORY.intValue(), 0444);
System.out.println(fd2);

Both fd1 and fd2 are non-negative integers. I would expect fd2 to be a negative indicating that the open failed. I see the correct behavior when using c directly.

I have also tried using:

POSIX posix = POSIXFactory.getPOSIX(new DefaultPOSIXHandler(), true);

Is this a bug?