HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/qlibs/man/fd.3
.TH qlibs: fd 3
.SH NAME
fd \- duplicate, move or close a file descriptor
.SH SYNTAX
.B #include \(dqfd.h\(dq

int \fBfd_copy\fP(int \fIto\fR,int \fIfrom\fR);
.br
int \fBfd_move\fP(int \fIto\fR,int \fIfrom\fR);
.br
int \fBfd_coe\fP(int \fIfd\fR);
.SH DESCRIPTION
.B fd_copy
copies 
descriptor
.I from
to descriptor
.IR to .
If
.I to
was already open,
.B fd_copy
closes it.
.B fd_copy
always leaves
.I from
intact;
if
.I to
and
.I from
are the same number,
.B fd_copy
does nothing.
.B fd_copy
does not guarantee that
.I to
will remain open, if it was open, in case of error.

.B fd_move
moves
descriptor
.I from
to descriptor
.IR to .
If
.I to
was already open,
.B fd_move
closes it.
If the move is successful,
.B fd_move
closes
.IR from .
Exception:
if
.I to
and
.I from
are the same number,
.B fd_move
does nothing.

.B fd_coe
closes
.IR fd .
.SH "RETURN CODES"
.BR fd_copy ,
.BR fd_move ,
and
.B fd_coe
return 
.I 0 
on success, 
and 
.I -1 
on error.
.SH "SEE ALSO"
dup(2), fcntl(2)