Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. File I/O: Further Details > Open File Status Flags

Open File Status Flags

One use of fcntl() is to retrieve or modify the access mode and open file status flags of an open file. (These are the values set by the flags argument specified in the call to open().) To retrieve these settings, we specify cmd as F_GETFL:

int flags, accessMode;

flags = fcntl(fd, F_GETFL);         /* Third argument is not required */
if (flags == -1)
    errExit("fcntl");

After the above piece of code, we could test if the file was opened for synchronized writes as follows:

if (flags & O_SYNC)
    printf("writes are synchronized\n");

Note

SUSv3 requires that only status flags that were specified during an open() or a later fcntl() F_SETFL should be set on an open file. However, Linux deviates from this in one respect: if an application was compiled using one of the techniques described in I/O on Large Files for opening large files, then O_LARGEFILE will always be set in the flags retrieved by F_GETFL.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint