Home TechnologyProgramming Subscribe to RSS
 

What Is The Purpose Of Using Fcntl Function?

kindly explain its syntax

Answer Question

2 Answers - Sort by: Date | Rating

    This function is used for file descriptor manipulation. It is used for changing the attributes of an opened file. The syntax of this file is as follows:
       int fcntl(int file_descriptor, int cmd, int arg)
    The header files sys/types, unistd and fcntl have to be included to use this function.
    It returns –1 in case of some error however the return on success depends on the value of second argument.
       file_descriptor is the file descriptor on which some operation is to be performed.
       cmd is some command code that specifies what operation is to be carried out.
       Arg is the optional argument and its value depends on the command provided as th second argument. It default value is 0.
    It is meant for five purposes.

    1. Duplicating file descriptor
    2. To obtain or set the file descriptor flags
    3. To obtain or set file status flags
    4. Get or Set I/O ownership
    5. Get or Set record locks
    Following are the command codes that are given as the second argument:
      F_DUPED is used for duplicating the file descriptor provided as the first argument.
      F_GETFD and F_SETFD are used to get/set the file descriptor flags.
      F_GETFL and F_SETFL are used to get/set file status flags.
      F_GETOWN and F_SETOWN are used to get or set I/O ownership
      F_GETLK, F_STELK and F_SETLKW are used for locking records.
    0 0

    Raaga 

    answered 3 years ago

      The basic use of this function is that it offers the control of open file in many different ways for example it supports F_DUPFD etc.
      0 0

      Smrks 

      answered 3 years ago

        Answer Question - Answers are editable for 5 min.

        If you do not Sign-in or Register your answers will be anonymous,

        your answers may also be checked before going online.

        More

           
           

          Ask a Question via Twitter

          Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

          Blurtit Store

          Get T-shirts, hoodies, caps and more at the Blurtit store

          Blurtit International