Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C : how can I change from file descriptor to FILE struct and vice versa?

Tags:

c

linux

Is there any way to change an int file descriptor to a FILE struct pointer or/and change FILE* to a file descriptor in C?

like image 881
trrrrrrm Avatar asked Nov 18 '10 02:11

trrrrrrm


People also ask

What does open () return in C?

The normal return value from open is a non-negative integer file descriptor. In the case of an error, a value of -1 is returned instead. In addition to the usual file name errors (see File Name Errors), the following errno error conditions are defined for this function: EACCES.

Which system call is used to change the location of file descriptor?

The lseek call is used to modify the file offset associated with the descriptor fd.


2 Answers

The function fdopen() returns a new (FILE *) associated with an open file descriptor.

The function fileno() returns the file descriptor associated with an open FILE *.

like image 193
Kamal Avatar answered Sep 28 '22 02:09

Kamal


Use "fileno()" for FILE->int.

Use "fdopen()" for int->FILE.

like image 24
user172818 Avatar answered Sep 28 '22 03:09

user172818