Solved

Couple of questions on Linux C

Posted on 2002-04-18
1
185 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
1 Comment
 
LVL 3

Accepted Solution

by:
marcjb earned 50 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

920 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

16 Experts available now in Live!

Get 1:1 Help Now