分享

test_write.c

 海漩涡 2016-04-11
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>

#define MAX_SIZE 1024*80

int main(int argc, char *argv[])
{

int odd_num, i;

int file_len;
int len,write_len, n;

char *buf = (char *)malloc(MAX_SIZE);
int fd;
char file_name[] = {"/record/hd01//qh00015.dat"};
fd = open(file_name, O_RDWR | O_CREAT);
if(-1 == fd)
{
printf("TTT-----open fail \n");
return -1;
}

len = MAX_SIZE;
file_len = 0;
odd_num = 0;
lseek(fd, 0, SEEK_SET);
while(1)
{
#if 1
if(odd_num < 20*1024)
{
odd_num += 1024;
}
else
{
odd_num = 0;
}

/*
if(odd_num < 1024)
{
odd_num += 1;
}
else
{
odd_num = 0;
}
*/
#endif

//-------------------------------------------------------------------------------------------------------------------
//lseek(fd, file_len, SEEK_SET);
write_len = len - odd_num;
n = write(fd, buf, write_len);
if(n < 0)
{
printf("TTT--22222222222--write error \n");
}
else
{
printf("TTT----write_len[%d]--------write-return[%d]-------odd_num[%d]---file_name[%s]  \n", write_len, n, odd_num, file_name);
}
file_len += n;
//-------------------------------------------------------------------------------------------------------------------
if(512*1024*1024 <= file_len)
{
lseek(fd, 0, SEEK_SET);
file_len = 0;
printf("TTT----lseek(fd, 0, SEEK_SET)---\n");
}

usleep(1000*100);
}
return 0;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多