Skip to content

O_DIRECTORY does not fail on open() #143

@luxe

Description

@luxe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions