chapter 3 -- file hole 文件的黑洞
来源:互联网 发布:天海佑希 知乎 编辑:程序博客网 时间:2024/06/05 05:47
apue 里介绍了文洞(英文是hole,中文不知道怎么说,我理解为“文件的黑洞”,感觉它挺神秘的,像黑洞一样……),所以做了一个程序来产生一个有黑洞的文件,一个没有黑洞的文件。用法是
a.out filename1 filename2,filename1
代表有黑洞的文件名,filename2 代表没黑洞的文件名。注意设计程序的时候这个“黑洞”一定要给得足够大,否则看不见……
所以我的 DELTA 设置为 1000 了,一开始设置为 100,结果 ls -asl 的时候两个文件竟然是一模一样的……
#include <stdio.h>//#include <unistd.h>#include "apue.h"#include "myerr.c"//#include <pwd.h>#include <fcntl.h>#define BUFSIZE11#define DELTA1000intmain (int argc, char *argv[]){int i, fd;charbuf[BUFSIZE] = {"abcdefghij"} ;if (argc != 3)err_quit ("usage: a.out filename1 filename2\n") ;// write a holed fileif ((fd = open (argv[1], O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO)) == -1)err_sys ("holed file open error") ;//printf ("%d\n", fd) ;if (write (fd, buf, 10) != 10)err_sys ("holed file 1 write error") ;if (lseek (fd, 10 * DELTA, SEEK_SET) == -1)err_sys ("holed file lseek error") ;if (write (fd, buf, 10) != 10)err_sys ("holed file 2 write error") ;close (fd) ;// write a no hole fileif ((fd = open (argv[2], O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO)) == -1)err_sys ("noholed file open error") ;if (write (fd, buf, 10) != 10)err_sys ("noholed file 1 write error") ;for (i = 0 ; i < DELTA ; ++i) {if (write (fd, buf, 10) != 10)err_sys ("noholed file 2 write error") ;}close (fd) ; exit (0) ;}
- chapter 3 -- file hole 文件的黑洞
- Linux中的黑洞(black hole)-/dev/null
- Copy file with hole
- File I/O Chapter-3
- Chapter 8 File and Registry(文件和注册表)
- Chapter 3 文件I/O
- 《APUE》Chapter 3 File I/O(学习笔记加上自己的代码)
- Hole
- Chapter 11 File System
- PAT-B 1019. 数字黑洞(同PAT 1069. The Black Hole of Numbers)
- PAT 1069. The Black Hole of Numbers (20)(数字黑洞)
- 1019. 数字黑洞 (20)PAT乙级 &1069. The Black Hole of Numbers (20) PAT甲级
- 对黑洞的疑惑
- 一望无际的黑洞
- 黑洞漩涡的实现
- 黑洞
- 黑洞
- java 的File文件
- Memory Layout for Multiple and Virtual Inheritance
- 设计模式之—单例模式(Singleton)-Java实现
- 图片数据Base64编解码(java实现)
- 在Linux上建立MySQL 5.0镜像
- oracle物化视图的一般用法
- chapter 3 -- file hole 文件的黑洞
- 基于ADSP-BF561的H.264视频编码器的实现
- Perl 学习笔记 --- 04
- 交换机配置基本命令
- H.264的基本概念
- 电视信号码率计算
- Handler: 主线程如何通知子线程
- VS2010纯C语言链接MySQL
- 2012年2月斯坦福大学全球计算机方面公开课报名网址