.\" -*- nroff -*- .\" .\" This manpage is Copyright (C) 1992 Drew Eckhardt; .\" 1993 Michael Haardt, Ian Jackson. .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" Modified Wed Jul 21 22:45:39 1993 by Rik Faith .\" Modified 21 Aug 1994 by Michael Chastain : .\" Fixed typoes. .\" Modified Fri Jan 31 16:23:46 1997 by Eric S. Raymond .\" .TH DUP 2 "21/08/1994" "Linux 1.1.46" "Manual do Programador Linux" .SH NOME dup, dup2 \- duplica um descritor de arquivos .SH SINOPSE .nf .B #include .sp .BI "int dup(int " oldfd ); .BI "int dup2(int " oldfd ", int " newfd ); .fi .SH DESCRIÇÃO .BR dup " e " dup2 criam uma cópia do descritor de arquivos .IR oldfd . Depois do retorno bem sucedido de \fBdup\fR ou \fBdup2\fR, o velho e o novo descritores podem ser usados sem distinção. Eles compartilham travamento, posicionamento do arquivo, ponteiros e sinalizadores; por exemplo, se a posição do arquivo é modificada usando-se .B lseek em um dos descritores, a posição é, também, alterada para o outro. De qualquer forma, Os dois descritores não dividem o sinalizador close-on-exec. .B dup usa o mais baixo número não usado de descritor para o novo descritor. .B dup2 .RI "makes " newfd " ser a cópia de " oldfd ", closing " newfd primeiro se necesário. .SH "VALORES RETORNADOS" .BR dup " e " dup2 retorna o novo descritor, ou \-1 se um erro occurrido (neste caso, .I errno é selecionado adequadamente). .SH ERROS .TP .B EBADF .I oldfd não é um descritor de arquivo aberto, ou .I newfd está fora do intervalo permitido para descritores de arquivos. .TP .B EMFILE O processo tem um número máximo de descritores de arquivos abertos e tenta abrir um novo. .SH ADVERTÊNCIA O erro retornado por .B dup2 é diferente que aquele retornado por .BR fcntl( "..., " F_DUPFD ", ..." ) quando .I newfd está fora do intervalo. Em muitos sistemas .B dup2 também retorna às vezes .B EINVAL como .BR F_DUPFD . .SH "DE ACORDO COM" SVr4, SVID, POSIX, X/OPEN, BSD 4.3. SVr4 documenta condições de erros adicionais EINTR e ENOLINK. POSIX.1 adiciona EINTR. .SH "VEJA TAMBÉM" .BR fcntl (2), .BR open (2), .BR close (2)