File pointer to file handle

A

Apollyon

I'm trying to figure out if there's a function that takes a file pointer
(FILE *) and will return a HANDLE type ... I'm trying to modify some code
and I've looked everywhere to no avail.

Thanks
 
J

Joona I Palaste

Apollyon said:
I'm trying to figure out if there's a function that takes a file pointer
(FILE *) and will return a HANDLE type ... I'm trying to modify some code
and I've looked everywhere to no avail.

Seeing as HANDLE is not a standard C type, your question is off-topic
here. Please ask in a newsgroup dedicated to your own operating system.

An answer that would work within the contents of this newsgroup would
be:

#include <stdio.h>
typedef FILE *HANDLE;
HANDLE convert_file_ptr_to_handle(FILE *ptr) {
return ptr;
}
 
A

Apollyon

Yes, I know, I had tried there and wasn't getting a very rapid response so I
figured I'd try here too. Oh well.
 
M

Malcolm

Apollyon said:
I'm trying to figure out if there's a function that takes a file pointer
(FILE *) and will return a HANDLE type ... I'm trying to modify
some code and I've looked everywhere to no avail.
On older implementations you often have low-level, unbuffered IO and
functions like open(), read(), and write().
These are not ANSI, are not supported on all platforms, and are virtually
obsolete on a modern hosted system, because it is no longer possible to get
significant performance increases by messing with the buffering.
If you mix the fopen() family of functions with another IO family then you
risk having problems, such as the stdio functions buffering input so it gets
written in the wrong order.
However if you are determined, there will probably be a function that gets a
"handle" from a FILE *. If not, look at the structure members and one of
them will probably be what you are looking for. However you are now leaving
ANSI C land.
 
M

Mark McIntyre

Yes, I know, I had tried there and wasn't getting a very rapid response so I
figured I'd try here too. Oh well.

the obvious way to do this would be to use some platform-specific functions
to find out the filename from the FILE*, then re-open it using the right
platform-specific function.
However you're going to have to read your compiler docs to find out how to
do that.
 
C

CBFalconer

Apollyon said:
I'm trying to figure out if there's a function that takes a file
pointer (FILE *) and will return a HANDLE type ... I'm trying to
modify some code and I've looked everywhere to no avail.

There is no such thing as a HANDLE type in C, unless you define it
yourself. Some systems have a non-standard function called
"fileno(FILE *)", which you might look up on your system. The
results are no-longer portable, and thus off-topic here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top