#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; }
|
|
来自: 海漩涡 > 《applicationCode》