.TH close() "" "" "System Call (libc)"
.PC "Close a file"
.B "#include <unistd.h>"
\fBint close(\fIfd\^\fB) int \fIfd\^\fB;\fR
.PP
.B close()
closes the file identified by the file descriptor
\fIfd\fR,
which was returned by
\fBcreat()\fR,
\fBdup()\fR,
\fBopen()\fR, or \fBpipe()\fR.
.B close()
also frees the associated file descriptor.
.PP
Because each program can have only a limited number of files open
at any given time, programs that process many files should
.B close()
files whenever possible.
The function
.B exit()
automatically calls
.B fclose()
for all open files; however, the system call
.B _exit()
does not.
.SH Example
For an example of this function, see the entry for
.BR open() .
.SH "See Also"
.Xr "creat()," creat
.Xr "libc," libc
.Xr "open()," open
.Xr "unistd.h" unistd.h
.br
\*(AS, \(sc4.9.3
.br
\*(PX Standard, \(sc6.3.1
.SH Diagnostics
.B close()
returns \-1 if an error occurs,
such as its being handed a bad file descriptor;
otherwise, it returns zero.
