Back to index

glibc  2.9
dup2.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <unistd.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


int __dup2 (int fd, int fd2)

Function Documentation

int __dup2 ( int  fd,
int  fd2 

Definition at line 27 of file dup2.c.

  int save;

  if (fd2 < 0
#ifdef OPEN_MAX
      || fd2 >= OPEN_MAX
      __set_errno (EBADF);
      return -1;

  /* Check if FD is kosher.  */
  if (fcntl (fd, F_GETFL) < 0)
    return -1;

  if (fd == fd2)
    return fd2;

  /* This is not atomic.  */

  save = errno;
  (void) close (fd2);
  __set_errno (save);

  return fcntl (fd, F_DUPFD, fd2);

Here is the call graph for this function:

Here is the caller graph for this function: