Solved

Couple of questions on Linux C

Posted on 2002-04-18
1
184 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
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 switch statements in the C programming language.

744 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

11 Experts available now in Live!

Get 1:1 Help Now