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


fdopen

Associates a file descriptor with a stream.

Compatibility:

This function is compatible with the following targets:

ANSI
BeOS
EMB/RTOS

Mac OS

Palm OS

Win32


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

Parameters for this facility are:

fildes  
int  
The file descriptor  
mode  
char *  
The file open 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 pointer to 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;
}

Result: File mytest has: 
Hello world!
My name is Ron Liechty.


[ 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