Nios® V Processor Software Developer Handbook

ID 743810
Date 7/08/2024
Public
Document Table of Contents

16.1.1.67. open()

Prototype

int open (const char* pathname, int flags, mode_t mode)

Commonly Called By

C/C++ programs

Thread-safe

See description.

Available from ISR

No.

Include

<unistd.h>
<fcntl.h>

Description

The open() function opens a file or device and returns a file descriptor (a small, nonnegative integer for use in read, write, etc.)

flags is one of: O_RDONLY, O_WRONLY, or O_RDWR, which request opening the file in read-only, write-only, or read/write mode, respectively.

You can also bitwise-OR flags with O_NONBLOCK, which causes the file to be opened in nonblocking mode. Neither open() nor any subsequent operation on the returned file descriptor causes the calling function to wait.

Not all file systems/devices recognize this option.

mode specifies the permissions to use, if a new file is created. It is unused by current file systems, but is maintained for compatibility.

Calls to open() are thread-safe only if the implementation of open() provided by the driver that is manipulated is thread-safe.

Return

The return value is the new file descriptor, and –1 otherwise. If an error occurs, errno is set to indicate the cause.