fcntl

Performs operations on an open file.

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

Syntax

  #include <fcntl.h> 
   
  int fcntl (
     int   fildes,   
     int   cmd, 
     ...);
  

Parameters

fildes

(IN) Specifies a file descriptor to be operated on by cmd.

cmd

(IN) Specifies which command to execute on the specified file descriptor. See Command Modes.

...

(IN) Specifies an argument specific to the cmd parameter. See Command Modes.

Return Values

If successful, returns a positive integer value. Otherwise, returns -1 and sets errno to one of the following.

Decimal

Constant

Description

4

EBADF

The specified file descriptor is not valid.

6

EACCES

The requested lock conflicts with another lock on the file.

9

EINVAL

Invalid parameter.

11

EMFILE

Either too many file are already opened, or no file descriptors are available that are equal to or greater than the requested value.

15

EDEADLK

Waiting for this lock would cause a deadlock.

63

EINTR

The function was interrupted.

74

ENOLCK

No locks are available.

81

EOVERFLOW

The operation would overflow its buffer.

Remarks

The fcntl function has commands for duplicating a file descriptor, setting and getting file descriptor flags, and getting and setting advisory locks. Advisory locks can only be used by the threads within the same virtual machine and cannot be shared with another virtual machine. See Command Modes for more information.

See Also