?
Solved

Couple of questions on Linux C

Posted on 2002-04-18
1
Medium Priority
?
194 Views
Last Modified: 2011-09-20
hello

Here are the questions:

1. Given a file pointer, how do i get the corresponding   file descriptor in Linux(kno how to do it in dos)

2.How do i lock a file using only file pointer ?

3.When going through the header files and sources, i came across many functions and variables beginning with underscore(_) and double underscore(__) What do these represent and what is their significance ?

4. Any good links on advanced pointer use.

Thanks in advance
0
Comment
Question by:konsole
[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
1 Comment
 
LVL 3

Accepted Solution

by:
marcjb earned 200 total points
ID: 6950752
1. You can use 'fileno' to get a file descriptor.
     int fileno( FILE *stream);

2. You might try using 'open' with the 'O_EXCL' flag to open the file exclusively.  Then, you can use 'fdopen' to associate a stream with the open file descriptor
     FILE *fdopen (int fildes, const char *mode);
This is kind of the opposite of 'fileno' in question one.

3. In Plauger's book on the C Standard he explains that in addition to the keywords in C (if, else, return ...), there are certain classes of names that are reserved for use by the implementors and you should not use in your programs.  He states, "Don't use:  Names of functions and data objects with external linkage that begin with an underscore, such as _abc or _DEF.  Names of macros that begin with an underscore followed by a second underscore or an uppercase letter, such as __abc or _DEF."

4. Dave Marshall has a good page here:
http://www.cs.cf.ac.uk/Dave/C/CE.html

Of course, there are loads of pages out there, but I happened to have this one bookmarked.

Hope this helps,

Marc
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

764 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