/* hd.c by Michael Thorpe 2009-02-01 */ #include #include #include #include #include #define BUFSIZE 8192 unsigned char buffer[BUFSIZE]; size_t bufstart,bufstop; int infile=0; unsigned int breakchar=-1; unsigned int linelen=16; unsigned int maxline=16; /* * I wrote a replacement read function for two reasons: * 1. I want to flush stdout before calling read(2). * 2. stdio usually line-buffers even on a short read. */ size_t myread(int fd,void *buf,size_t count) { size_t l; if(!infile) { bufstart=bufstop=0; infile=1; } l=bufstop-bufstart; if(l==0) { if(bufstart==BUFSIZE) bufstart=0; fflush(stdout); l=read(fd,buffer+bufstart,BUFSIZE-bufstart); if(l==-1 || l==0) { infile=0; return(l); } bufstop=bufstart+l; } if(l] [-l ] [ [...]]\n",argv[0]); return(1); } } else { didone=1; f=fopen(argv[i],"rb"); if(!f) fprintf(stderr,"%s: couldn't open %s\n",argv[0],argv[i]); else { if(doit(fileno(f))) return(1); if(fclose(f)) { perror("close"); return(1); } } } } if(!didone) if(doit(0)) return(1); return(0); }