Solved

fcntl system call

Posted on 1998-12-13
3
633 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
repeatSeparator  java  challenge 13 59
Folder Comparison 12 55
Detect CR LF to each line 12 183
Authenticate using sesu from script 7 152
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

736 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