#include
int dup(int fd);
int dup2(int fd1,int fd2);
两个均为复制一个现存的文件的描述
两个函数的返回:若成功为新的文件描述,若出错为-1;
由dup返回的新文件描述符一定是当前可用文件描述中的最小数值。用dup2则可以用fd2参数指定新的描述符数值。如果fd2已经打开,则先关闭。若fd1=fd2,则dup2返回fd2,而不关闭它。通常使用这两个系统调用来重定向一个打开的文件描述符。
函数简介
函数名:_dup
功能:复制一个文件句柄
用法:int _dup(int handle);
相关函数:_dup2、fdopen、freopen、_mbsdup、_wcsdup、_strdup
程序示例
#include
#include
#include
#include
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);
clrscr();
printf("Press any key to flush \
DUMMY.FIL:");
getch();
/* flush the data to DUMMY.FIL without
closing it */
flush(fp);
printf("\nFile was flushed, Press any \
key to quit:");
getch();
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);
}
dup在汇编中是一条伪指令,用来重复初始化数据
用法举例:
str1 db 10 dup('!@#');这就是十个!@#
格式:db重复的次数dup(重复的内容)。
DUP是1,2-苯二甲酸二正十一酯,不溶于水,主要是作为增塑剂来使用的,溶于酯类。