Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > dup2() function use method
【标  题】:dup2() function use method
【关键字】:dup2,function,use,method
【来  源】:http://www.cublog.cn/u/24196/showart.php?id=179248

dup2() function use method

Your Ad Here #include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    int fd;
    char filename[] = "/home/xuzhengyang/2.c", buf[] = "happy new year!\n";

    if ( (fd = open(filename, O_WRONLY)) == -1) {
        perror("open");
        exit(1);
    }
    
    /* duplicate fd file descriptor */
    if (dup2(fd, STDOUT_FILENO) == -1) {
        perror("dup2");
        exit(1);
    }

    /* output data to fd and STDOUT_FILENO */
    if (write(fd, buf, strlen(buf)) != strlen(buf)) {
        perror("write");
        exit(1);
    }
   
    if (write(STDOUT_FILENO, buf, strlen(buf)) != strlen(buf)) {
        perror("write");
        exit(1);
    }

    exit(0);
}

 
C语言指针:【上一篇】
openlog(),syslog(),closelog() function use method:【下一篇】
【相关文章】
  • More useful GDB usage
  • [乱弹] Anonymous Method - Lambda Expression - *LINQ
  • gethostbyaddr() function use
  • Template Method
  • select() function use method
  • pselect() function use method
  • poll() function use method
  • getprotobyname() function use method!
  • 关于Loadrunner,c vuser中的参数化问题
  • appfuse配置文件解读
  • 【随机文章】
  • 2004年9月全国计算机等级考试四级笔试试卷
  • Lpar安装手册
  • 一个用CLR写存储过程的项目回顾 (三) 心得总结
  • Ogre的Singleton实现以及改进
  • CppUnit使用指南
  • Visual C++实现Flash动画播放
  • 实习报告
  • 实现聊天室的悄悄话功能(中)
  • 在freebsd下如何打开PDF文件
  • Maya 4.0 动画的基础知识-创建关键帧
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.