lseek
来源:互联网 发布:开源中国app源码下载 编辑:程序博客网 时间:2024/05/21 14:10
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define FILE_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";
int main(void)
{
pid_t fd;
//creat file if do not exit
if((fd = open("file.hole",O_RDWR|O_CREAT|O_TRUNC,FILE_MODE)) < 0)
{
printf("creat error\n");
exit(1);
}
if(write(fd,buf1,10) != 10)
printf("buf1 write error\n");
if(lseek(fd,40,SEEK_SET) == -1)
printf("lseek error\n");
if(write(fd,buf2,10) != 10)
printf("buf2 write error\n");
exit(0);
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define FILE_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";
int main(void)
{
pid_t fd;
//creat file if do not exit
if((fd = open("file.hole",O_RDWR|O_CREAT|O_TRUNC,FILE_MODE)) < 0)
{
printf("creat error\n");
exit(1);
}
if(write(fd,buf1,10) != 10)
printf("buf1 write error\n");
if(lseek(fd,40,SEEK_SET) == -1)
printf("lseek error\n");
if(write(fd,buf2,10) != 10)
printf("buf2 write error\n");
exit(0);
}
$ od -c file.hole
0000000 a b c d e f g h i j \0 \0 \0 \0 \0 \0
0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000040 \0 \0 \0 \0 \0 \0 \0 \0 A B C D E F G H
0000060 I J
0000062
- lseek
- lseek
- lseek
- lseek
- lseek
- lseek()
- lseek()
- lseek
- lseek()详解
- IO lseek
- lseek函数
- lseek函数
- lseek函数
- 三十八 lseek()
- lseek 出错
- linux lseek
- lseek函数
- lseek Function
- 优化屏障和内存屏障
- dedecms调用文章排行榜的方法
- 先对oracle 体系结构有个总体的认识
- 偶然找到的线段树集合哦~
- ICMP报文的类型说明
- lseek
- 未来技术展望---无线充电技术
- dedecms 5.7 文章不能上传图片的解决方法(Upload filetype not allow)
- 强烈建议CSDN加上软件测试模块
- 第三部分 资源管理(条款13-17)
- VC环境下的多线程API
- 对运算符号进行重载,进行复数运算
- Android Mms 专题——PDU介绍
- wordpress多站点(MU)用二级域名(SUBDOMAIN)的单点登录(SSO)问题