[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


fdopen

Converts a file descriptor to a stream.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
FILE *fdopen(int fildes, char *mode);

NOTE

fdopen() for the Macintosh is defined in the unix.h header.
Parameters:

Parameters for this facility are:

fildes  
int  
A file descriptor  
mode  
char *  
The file opening mode  

Remarks:

This function creates a stream for the file descriptor fildes. You can use the stream with such standard I/O functions as fprintf() and getchar(). In Metrowerks C/C++, it ignores the value of the mode argument.

Return:

If it is successful, fdopen() returns a stream. If it encounters an error, fdopen() returns NULL.

See Also:

"fileno"

"open"

Example of fdopen() usage.:
#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;
}


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000