Header File
io.h
Category
Input/output Routines
Prototype
int dup(int handle);
Description
Duplicates a file handle.
Return Value
Upon successful completion, dup returns the new file handle, a nonnegative integer; otherwise, dup returns -1.
In the event of error, the global variable errno is set to one of the following values:
EBADF |
Bad file number |
EMFILE |
Too many open files |
Example
#include <string.h> #include <stdio.h> #include <io.h> void flush(FILE *stream); int main(void) { FILE *fp; char msg[] = "This is a test"; /* create a file */ fp = fopen("DUMMY.FIL", "w"); /* write some data to the file */ fwrite(msg, strlen(msg), 1, fp); printf("Press ENTER to flush DUMMY.FIL:"); getchar(); /* flush the data to DUMMY.FIL without closing it */ flush(fp); printf("\nFile was flushed, Press ENTER to quit:"); getchar(); return 0; } void flush(FILE *stream) { int duphandle; /* flush TC's internal buffer */ fflush(stream); /* make a duplicate file handle */ duphandle = dup(fileno(stream)); /* close the duplicate handle to flush the DOS buffer */ close(duphandle); }
Portability
POSIX |
Win32 |
ANSI C |
ANSI C++ |
+ |
+ |
|
|
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|