Nios® V Processor Software Developer Handbook

ID 743810
Date 10/02/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

7.7.1.1.1. Modifying the Global Error Status, errno

None of these functions directly modifies the global error status, errno. Instead, the return value is the negation of the appropriate error code provided in errno.h.

For example, the ioctl() function returns -ENOTTY if it cannot handle a request rather than set errno to ENOTTY directly. The HAL system routines that call these functions ensure that errno is set accordingly.

The function prototypes for these functions differ from their application level counterparts in that they each take an input file descriptor argument of type alt_fd* rather than int.

A new alt_fd structure is created on a call to open(). This structure instance is then passed as an input argument to all function calls made for the associated file descriptor.

The following code defines the alt_fd structure:

typedef struct
{ 
alt_dev* dev;
void* priv;
int fd_flags;
} alt_fd;

where:

  • dev is a pointer to the device structure for the device being used.
  • fd_flags is the value of flags passed to open().
  • priv is a reserved, implementation-dependent argument, defined by the driver. If the driver requires any special, non-HAL-defined values to be maintained for each file or stream, you can store them in a data structure, and use priv maintains a pointer to the structure. The HAL ignores priv.

    Allocate storage for the data structure in your open() function (pointed to by the alt_dev structure). Free the storage in your close() function.

Note: To avoid memory leaks, ensure that the close() function is called when the file or stream is no longer needed.