NXClose

Closes an open file, console, FIFO, device, etc.

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

Syntax

  #include <nks/fsio.h> 
  
  int NXClose (
     NXHandle_t   handle); 
  

Parameters

handle

(IN) Specifies a file handle, which refers to a system-maintained state description for a file.

Return Values

If successful, returns 0. Otherwise, returns a nonzero error code and the status of the description associated with the handle parameter is undefined.

Decimal

Hex

Constant

Description

4

0x04

NX_EBADF

The handle parameter does not refer to a valid description of an open file or device.

Remarks

NXClose dismantles the system-maintained state information associated with the passed-in file descriptor and frees any resources allocated to maintain such information. Any advisory locks that you hold on the file associated with handle are also removed.

If the file is marked for a deferred removal (see NXRemove), it is removed after the last file handle that refers to the file is closed.

The library handles any race conditions when closing a descriptor that multiple threads are using. When one or more threads are still actively performing I/O on a descriptor while yet another thread calls NXClose, the descriptor is removed from the table. NXClose then awaits for the I/O being performed by the other threads to finish before finalizing the file close operation.

See Also