nobody
全部博文(293)
分类:
2010-09-19 21:03:04
{
int src_fd = 0;
int dest_fd = 0;
char * buffer = NULL;
struct stat sb;
int ret = DROP_ERROR;
if((0==len)||
(0!=stat(file_name,&sb))||
(!S_ISREG(sb.st_mode))||
(len>=sb.st_len)||
(src_fd=open(file_name,O_RDONLY)<0)||
(dest_fd=open(file_name,O_WRONLY)<0)||
(NULL==(buffer = malloc(BUF_LEN)))||
(-1==lseek(src_fd,drop_len,SEEK_SET)))/*设置src_fd的file pointer*/
goto out;
/*余下的就是read from src_fd and write to dest_fd*/
while(1)
{
read(src_fd,buffer, ret);
write(dest_fd,buffer,ret);
if(xxx)
break;
}
if(ftruncate(dest_fd,sb.st_size-drop)<0) /*设置文件长度*/
goto out;
ret = DROP_OK;
out:
if(NULL!=buffer)
free(buffer);
return ret;
}