#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char **argv, char **envp, char **auxv)
{
   int fd;
   size_t x;
   char c[1];
   size_t pos;
   struct stat st;

   if (argc == 1) {
      fprintf(stderr, "Usage: %s <fname>\n", argv[0]);
      return 1;
   }

   if ((fd = open(argv[1], O_RDONLY)) <= (-1)) {
      perror("open");
      return 1;
   }
   if (stat(argv[1], &st) == -1) {
      perror("stat");
      return 1;
   }
   pos = 0;
   while ((x = read(fd, c, 1))) {
      pos++;
    funstuff:
      if (c[0] == 0x16) {
	 if ((x = read(fd, c, 1))) {
	    pos++;
	    if (c[0] == 0x0) {
	       if ((x = read(fd, c, 1))) {
		  pos++;
		  if (c[0] == 0x0) {
		     if ((x = read(fd, c, 1))) {
			pos++;
			if (c[0] == 0x0) {
			   printf("TEXTREL maybe at pos[%lu] of size[%lu] with tail[%lu] %s\n", 
				pos - 4, st.st_size, st.st_size - (pos - 4), basename(argv[1]));
			} else {
			   if (c[0] == 0x16)
			      goto funstuff;
			}
		     }
		  } else {
		     if (c[0] == 0x16)
			goto funstuff;
		  }
	       }
	    } else {
	       if (c[0] == 0x16)
		  goto funstuff;
	    }
	 }
      }
   }
   close(fd);
   return 0;
}
