Solved

fcntl system call

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 73
Complete beginner needs help making a cron job 9 104
centeredAverage challenge 8 123
FizzBuzz challenge 9 73
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now