Converts a file descriptor to a stream.
Compatibility:This function is compatible with the following targets:
|
EMB/RTOS
|
|
#include <stdio.h>
FILE *fdopen(int fildes, char *mode);
NOTE
Parameters for this facility are:
If it is successful, fdopen() returns a stream. If it encounters an error, fdopen() returns NULL.
#include <stdio.h>
#include <unix.h>
int main(void)
{
int fd;
FILE *str;
fd = open("mytest", O_WRONLY | O_CREAT);
/* Write to the file descriptor */
write(fd, "Hello world!\n", 13);
/* Convert the file descriptor to a stream */
str = fdopen(fd,"w");
/* Write to the stream */
fprintf(str, "My name is %s.\n", getlogin());
/* Close the stream. */
fclose(str);
/* Close the file descriptor */
close(fd);
return 0;
}