Solved

fcntl system call

Posted on 1998-12-13
3
620 Views
Last Modified: 2013-12-26
I've been studying Stevens' "Unix Network Programming", and I decided to write a program to investigate the fcntl system call. The program below is supposed to print the status flags for the file in question. It in fact prints 0. Is this likely to be correct? Stevens is not specific as to what the third argument for fcntl should be.

Thanks,

David King.


#include <fcntl.h>
#include <errno.h>

#define      thisprog      "/home/vexil/fcntltest"

main()
{
      int value, fd;
      if ((fd = open(thisprog, 0)) < 0)
            {
            printf("Error with open\n");
            exit(errno);
            }
      if ((value = fcntl(fd, F_GETFL, 0)) <  0)
            {
            printf("Error with fcntl\n");
            exit(errno);
            }
      printf("Status flags are: %d\n", value);
}
0
Comment
Question by:sevrin
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1294801
try setting a few flags:
(fd = open(thisprog, O_APPEND|O_RDWR|O_NDELAY))
0
 
LVL 2

Accepted Solution

by:
rdelfino earned 50 total points
ID: 1294802

It's not wrong, what happened was that the file descriptor didn't have any flag set.
As ozo already said try setting some flags.

About the third argument, actualy you don't have to pass anything. You could use

flags = fcntl(fd, F_GETFL);

The third argument is used in other fcntl requests such as F_SETFL

I hope it helps

Reginaldo

0
 

Author Comment

by:sevrin
ID: 1294803
Really these point should be split with ozo... but as you *answered* the question first, they're yours. Thanks,

David King
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 63
while loop over for loop 7 115
Annoying "thing" blocks my view 4 117
Way to decrease size of apk file 9 88
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question