Listing 1. Buffer Management for Mail Piece Recognition
struct { long start, size; } ch;
int inj = open("dev/rpsi0",O_RDONLY,0);
long size;
ioctl(inj,RPSI_GET_SIZE,&size);
char *imageBufPtr = mmap(0,size,…,inj,0);
for (;;) {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(inj,&readfds);
select(sizeof(fd_set)*8,&readfds,0,0,0);
if (!FD_ISSET(inj,&readfds)) continue;
int ret = ioctl(inj,RPSI_GET_LAST,(void*)&ch);
if (ret < 0) { // handle over flow }
// otherwise image is at imageBufPtr + ch.start and
// contains ch.size bytes
};