set_lowest_fd()

Updated: April 19, 2023

Specify the lowest acceptable file descriptor

Synopsis:

#include <fcntl.h>

int set_lowest_fd( int fd );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Arguments:

fd
The minimum file descriptor that you want to get.

Description:

The set_lowest_fd() function sets the lowest file descriptor number that will be returned by open(), pipe(), and other functions that return file descriptors. A process with the setuid/setgid file permission bit set can use this function at the begining of main() to ensure that it never unexpectedly gets back a file descriptor equal to 0, 1, or 2, which malicious programmers sometimes cause to happen by closing stdin, stdout, or stderr before spawning the process.

Note: This function doesn't affect dup and dup2 because they're primarily used to set file descriptors 0, 1, and 2 for file-redirection purposes.

Returns:

The previous lowest number (0 for the first time it's called).

Classification:

QNX Neutrino

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread No