close_fds - 1Fr3aK2/Cub3d GitHub Wiki
📝 close_fds
This function closes all open file descriptors starting from descriptor 3 up to FOPEN_MAX - 1.
⚙️ Parameters
| Parameter | Type | Description |
|---|---|---|
i |
int |
An integer parameter (ignored in the function, used internally). |
🔁 Returns
| Return value | Description |
|---|---|
void |
This function does not return a value. It closes file descriptors. |
📖 Description
The close_fds function iterates through all possible file descriptors from 3 up to FOPEN_MAX - 1 and closes each one using the close system call. File descriptors 0, 1, and 2 (standard input, output, and error) are not closed.
- The input parameter
iis overwritten internally and does not affect the function's behavior. - This function is useful for cleaning up open file descriptors before executing a new process, to prevent descriptor leaks.
💡 Example Usage
// Close all non-standard file descriptors before executing a child process
int fd = open("example.txt", O_RDONLY);
close_fds(fd);