zoukankan      html  css  js  c++  java
  • 程序3-2 创建一个具有空洞的文件

    /*
     ============================================================================
     Name        : test.c
     Author      : blank
     Version     :
     Copyright   : Your copyright notice
     Description : 程序3-2 创建一个具有空洞的文件
     ============================================================================
     */
    /*
     *
     */
    #include <stdio.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include "ourhdr.h"
    
    char buf1[] = "abcdefghij";
    char buf2[] = "ABCDEFGHIJ";
    
    int main(int argc, char *argv[])
    {
    	int    fd;
    	int    n;
    	if ((fd = creat("file.hole", FILE_MODE)) < 0){
    		err_sys("create file.hole error
    ");
    	}
    	/*
    	 * offset now = 10
    	 */
    	if (write(fd, buf1, 10) != 10){
    		err_sys("write buf1 to file.hole error
    ");
    	}
    
    	/*
    	 * offset now = 16384
    	 */
    	if (lseek(fd, 16384, SEEK_SET) == -1){
    		err_sys("lseek file.hole error
    ");
    	}
    
    	/*
    	 * offset now = 16394
    	 */
    	if (write(fd, buf2, 10) != 10){
    		err_sys("write buf2 to file.hole error
    ");
    	}
    
    	exit(0);
    }
    

     

  • 相关阅读:
    7、python数据类型之集合set
    python基本数据类型练习
    matplotlib
    numpy常用函数
    pillow包
    keras-tensorflow版本对应
    python-激活和切换运行环境
    端口监控
    numpy
    低风险创业笔记
  • 原文地址:https://www.cnblogs.com/blankqdb/p/3687608.html
Copyright © 2011-2022 走看看