Solved

fcntl system call

Posted on 1998-12-13
3
608 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complete beginner needs help making a cron job 9 116
format the code in java 6 93
modThree challenge 4 90
Unix Command -- Challenging  question 7 90
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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