Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1018157
  • 博文数量: 297
  • 博客积分: 11721
  • 博客等级: 上将
  • 技术积分: 3431
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 10:21
文章分类

全部博文(297)

文章存档

2016年(9)

2011年(71)

2010年(137)

2009年(80)

分类: LINUX

2010-02-24 11:17:44

/* 创建空洞文件 */
#include
#include
#include
#include

#define MAXLINE 4096

int main(int argc,char ** argv)
{
        int fd;
        char buf1[MAXLINE] = {'h','e','l','l','o'};
        char buf2[MAXLINE] = {'w','o','r','l','d'};
        fd = open("temp1",O_CREAT|O_RDWR,0644);
            
        write(fd,buf1,strlen(buf1));
        lseek(fd,1024,SEEK_SET);
        write(fd,buf2,strlen(buf2));
           
        return 0;
}

debian:/home/linux/unix# !cc
cc 3-2.c
debian:/home/linux/unix# ./a.out
debian:/home/linux/unix# ls -lt|grep temp
-rw-r--r-- 1 root root 1029 02-24 11:16 temp
debian:/home/linux/unix# od -c temp
0000000   h   e   l   l   o  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0002000   w   o   r   l   d
0002005
debian:/home/linux/unix#

阅读(676) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~