Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Couple of questions on Linux C

Posted on 2002-04-18
1
Medium Priority
?
195 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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

636 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