Back to index

nagios-plugins  1.4.16
Functions
dup2.c File Reference
#include <config.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>

Go to the source code of this file.

Functions

static int dupfd (int fd, int desired_fd)
int dup2 (int fd, int desired_fd)

Function Documentation

int dup2 ( int  fd,
int  desired_fd 
)

Definition at line 109 of file dup2.c.

{
  int result = fcntl (fd, F_GETFL) < 0 ? -1 : fd;
  if (result == -1 || fd == desired_fd)
    return result;
  close (desired_fd);
# ifdef F_DUPFD
  result = fcntl (fd, F_DUPFD, desired_fd);
#  if REPLACE_FCHDIR
  if (0 <= result)
    result = _gl_register_dup (fd, result);
#  endif
# else
  result = dupfd (fd, desired_fd);
# endif
  if (result == -1 && (errno == EMFILE || errno == EINVAL))
    errno = EBADF;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int dupfd ( int  fd,
int  desired_fd 
) [static]

Definition at line 92 of file dup2.c.

{
  int duplicated_fd = dup (fd);
  if (duplicated_fd < 0 || duplicated_fd == desired_fd)
    return duplicated_fd;
  else
    {
      int r = dupfd (fd, desired_fd);
      int e = errno;
      close (duplicated_fd);
      errno = e;
      return r;
    }
}

Here is the caller graph for this function: