Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
DUP(2)			      System Calls Manual			DUP(2)

NAME
       dup, dup2 - duplicate an	open file descriptor

SYNOPSIS
       dup(fildes)
       int fildes;

       dup2(fildes, fildes2)
       int fildes, fildes2;

DESCRIPTION
       Given  a	file descriptor	returned from an open, pipe, or	creat(2) call,
       dup allocates another file descriptor  synonymous  with	the  original.
       The new file descriptor is returned.

       In  the	second form of the call, fildes	is a file descriptor referring
       to an open file,	and fildes2 is a non-negative integer  less  than  the
       maximum	value  allowed	for file descriptors (approximately 19).  Dup2
       causes fildes2 to refer to the same file	as fildes.  If fildes2 already
       referred	to an open file, it is closed first.

RETURN VALUE
       Upon  successful	 completion,  a	 value of 0 is returned.  Otherwise, a
       value of	-1 is returned and errno is set	to indicate the	error.

ERRORS
       Dup and dup2 will fail if:

       [EBADF]		   Fildes  or  fildes2 is not a	valid active  descrip-
			   tor.

       [EMFILE]		   Too many descriptors	are active.

SEE ALSO
       close(2), creat(2), open(2), pipe(2)

ASSEMBLER
       (dup = 41.)
       (file descriptor	in r0)
       (new file descriptor in r1)
       sys dup
       (file descriptor	in r0)

       The dup2	entry is implemented by	adding 0100 to fildes.

3rd Berkeley Distribution						DUP(2)

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | SEE ALSO | ASSEMBLER

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=dup&sektion=2&manpath=2.9.1+BSD>

home | help