[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

fcntl system call

Posted on 1998-12-13
3
Medium Priority
?
655 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 150 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 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