--- gop_fixup/gop_fixup.c Sun Feb 9 19:27:47 2003 +++ gop_fixup.new/gop_fixup.c Tue Apr 22 22:38:30 2003 @@ -1,8 +1,12 @@ #include +#include +#include #include -#include #include "sysdep.h" +#include #include +#include +#include int fixed=0; @@ -70,23 +74,58 @@ unsigned char b7=0xb7; unsigned char end[]={0x00,0x00,0x01,0xb7}; //unsigned char end[]="abcd"; - OFF_T eofpos, len, fpos; for (fi=1; fi len) + { + mmap_len = len - mmap_offset; + } + mem = mmap(NULL,mmap_len,PROT_READ|PROT_WRITE,MAP_SHARED,fd,mmap_offset); + if (mem == MAP_FAILED) + { + error(-1, errno, "mmap failed"); + } + + for (fpos=0; fpos= mmap_len) + { + off_t pagedloc; + /* handle the case where we need to look at memory that isn't mapped in! */ + pagedloc = (fpos + 4) / pagesize; + pagedloc *= pagesize; + mmap_offset += (fpos - pagedloc) + 4; + break; + } if ((mem[fpos]==0) && (mem[fpos+1]==0) && (mem[fpos+2]==1)) @@ -108,6 +147,16 @@ } } } + if (mmap_len + mmap_offset < len) + { + /* unmap the memory since we have more to process. */ + if(munmap(mem,mmap_len) != 0) + { + error(-1, errno, "munmap failed"); + } + } + mmap_offset += mmap_len; + } if (eofpos>0) { mem[eofpos] = 1; mem[eofpos+1] = 0xb7; @@ -115,7 +164,11 @@ printf("\nfinished %s \n",argv[fi]); printf("fixed %d GOP timestamps\n",fixed); fixed=0; - munmap(mem,len); + /* munmap(mem,mmap_len); */ + if(munmap(mem,mmap_len) != 0) + { + error(-1, errno, "munmap failed"); + } close(fd); if (eofpos==-1) { printf("Found no end-stamp. Adding...%s\n",end);