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


fcntl

Manipulates a file descriptor.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <fcntl.h>
int fcntl(int fildes, int cmd, ...);
Parameters:

Parameters for this facility are:

fildes  
int  
The file descriptor  
cmd  
int  
A command to the file system  
...  
 
A variable argument list  

Remarks:

This function performs the command specified in cmd on the file descriptor fildes.

In the Metrowerks ANSI library, fcntl() can perform only one command, F_DUPFD. This command returns a duplicate file descriptor for the file that fildes refers to. You must include a third argument in the function call. The new file descriptor is the lowest available file descriptor that is greater than or equal to the third argument.

Legal modes with fcntl():

Mode
Description
F_DUPFD  
Return a duplicate file descriptor.  

Return:

If it is successful, fcntl() returns a file descriptor. If it encounters an error, fcntl() returns -1.

See Also:

"fileno"

"open"

"fdopen".

Example of fcntl() usage.:
#include <unix.h>

int main(void)
{
	int fd1, fd2;

	fd1 = open("mytest", O_WRONLY | O_CREAT);

	write(fd1, "Hello world!\n", 13);
		/* Write to the original file descriptor.                      */
	
	fd2 = fcntl(fd1, F_DUPFD, 0);
		/* Create a duplicate file descriptor.                            */

	write(fd2, "How are you doing?\n", 19);
		/* Write to the duplicate file descriptor.                    */

	close(fd2);	

	return 0;
}

/*ReslutAfter you run this program, 
the file mytest contains the following:
Hello world!
How are you doing?
*/


[ 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