- unsigned char c;
- read_buf(f,(char *)&c,1);
- return c;
-}
-
-
-static char last_byte;
-static int last_sparse;
-
-int sparse_end(int f)
-{
- if (last_sparse) {
- do_lseek(f,-1,SEEK_CUR);
- return (write(f,&last_byte,1) == 1 ? 0 : -1);
- }
- last_sparse = 0;
- return 0;
-}
-
-
-static int write_sparse(int f,char *buf,int len)
-{
- int l1=0,l2=0;
- int ret;
-
- for (l1=0;l1<len && buf[l1]==0;l1++) ;
- for (l2=0;l2<(len-l1) && buf[len-(l2+1)]==0;l2++) ;
-
- last_byte = buf[len-1];
-
- if (l1 == len || l2 > 0)
- last_sparse=1;
-
- if (l1 > 0)
- do_lseek(f,l1,SEEK_CUR);
-
- if (l1 == len)
- return len;
-
- if ((ret=write(f,buf+l1,len-(l1+l2))) != len-(l1+l2)) {
- if (ret == -1 || ret == 0) return ret;
- return (l1+ret);
- }
-
- if (l2 > 0)
- do_lseek(f,l2,SEEK_CUR);
-
- return len;