fsautoproc
Basic file transformation automation management utility
Loading...
Searching...
No Matches
fd.c File Reference

File descriptor output redirection implementation. More...

#include "fd.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "log.h"
Include dependency graph for fd.c:

Functions

static int openfd (const char *name, const unsigned int id)
 Opens, or creates, a truncated file using a formatted path derived from the provided name and id arguments.
 
int fdinit (struct fdset_s *fds, const unsigned int id)
 Initializes stdout/stderr files used for redirecting output from a child process. The file descriptors are stored in the provided file descriptor set. The files are opened in write-only mode and are created if they do not exist. If either file fails to open, the function will return -1 and both file descriptors will be set to -1.
 
void fdclose (struct fdset_s *fds)
 Closes the stdout and stderr file descriptors in the provided file descriptor set using close(2). If either file descriptor is already closed, the function will not attempt to close it again.
 

Detailed Description

File descriptor output redirection implementation.

Function Documentation

◆ fdclose()

void fdclose ( struct fdset_s * fds)

Closes the stdout and stderr file descriptors in the provided file descriptor set using close(2). If either file descriptor is already closed, the function will not attempt to close it again.

Parameters
fdsThe file descriptor set to close
Note
The file descriptors must be initialized with fdinit before calling this function.
Here is the caller graph for this function:

◆ fdinit()

int fdinit ( struct fdset_s * fds,
unsigned int id )

Initializes stdout/stderr files used for redirecting output from a child process. The file descriptors are stored in the provided file descriptor set. The files are opened in write-only mode and are created if they do not exist. If either file fails to open, the function will return -1 and both file descriptors will be set to -1.

Parameters
fdsThe file descriptor set to initialize
idUnique identifier to append to the file name
Returns
0 if both files were opened successfully, otherwise -1
Here is the call graph for this function:
Here is the caller graph for this function:

◆ openfd()

static int openfd ( const char * name,
const unsigned int id )
static

Opens, or creates, a truncated file using a formatted path derived from the provided name and id arguments.

Parameters
nameThe base name of the file to open
idThe unique identifier to append to the file name
Returns
The file descriptor of the opened file, or -1 on error
Note
Due to a fixed-size buffer, the formatted file path has a maximum length of 31 characters.
Here is the caller graph for this function: