Solved

Couple of questions on Linux C

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Binary Bomb: Phase 4 func4 3 342
How to organize data in excel ? 2 115
Why adding test code changes the build ? 11 132
How to create frequencies of a variable from SAS dataset? 10 133
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 recursion 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.

808 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