fclose

Closes a stream file.

Library:LibC
Classification:ANSI
Service:File and Directory I/O

Syntax

  #include <stdio.h> 
   
  int fclose (
     FILE   *fp);
  

Parameters

fp

(IN) Points to the file to close.

Return Values

If successful, returns 0. Otherwise, returns EOF and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The file descriptor is not valid.

12

ENOSPC

No free space remains on the device containing the file.

24

EAGAIN

The O_NONBLOCK flag is set for the file descriptor, and the process cannot immediately perform the write operation.

25

ENXIO

A request was made of a nonexistent device, or the request was outside the capabilities of the device.

28

EIO

The process is orphaned and cannot write to the file.

32

EPIPE

An attempt is made to write to a pipe or FIFO that is not open for reading by any process.

63

EINTR

A signal interrupted the fclose function.

71

EFBIG

An attempt was made to write a file that exceeds the maximum file size.

Remarks

The fclose function closes the file pointed to by fp. If there is unwritten buffered data for the file, it is written before the file is closed. Unread buffered data is discarded. If the associated buffer was automatically allocated, it is deallocated.

See Also