dup()

来源:互联网 发布:弹奏音乐的软件 编辑:程序博客网 时间:2024/05/29 11:18


dup它有多种意义,包括Linux c 函数、C语言函数DUP、汇编指令、化学物质DUP。
中文名
dup
意义1
Linux c 函数
意义2
C语言函数DUP
程序示例
#include <string.h>
所属库
io.h

目录

  1. 1Linux c 函数
  2. 2C语言函数DUP
  3. 函数简介
  4. 程序示例
  5. 3汇编指令
  6. 4化学物质DUP

Linux c 函数

编辑
#include<unistd.h>
int dup(int fd);
int dup2(int fd1,int fd2);
两个均为复制一个现存的文件的描述
两个函数的返回:若成功为新的文件描述,若出错为-1;
由dup返回的新文件描述符一定是当前可用文件描述中的最小数值。用dup2则可以用fd2参数指定新的描述符数值。如果fd2已经打开,则先关闭。若fd1=fd2,则dup2返回fd2,而不关闭它。通常使用这两个系统调用来重定向一个打开的文件描述符。

C语言函数DUP

编辑

函数简介

函数名: _dup
功 能: 复制一个文件句柄
用 法: int _dup(int handle);
相关函数:_dup2、fdopen、freopen、_mbsdup、_wcsdup、_strdup

程序示例

#include <string.h>
#include <stdio.h>
#include <conio.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);
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 (重复的内容)
0 0