#include #include #include #include #include #include /* Read a file and return a buffer with the file contents */ unsigned char *readfile(const char *filename,int *len) { int fd = open(filename,O_RDONLY); struct stat st; if(fd<0) err(1,filename); if(fstat(fd,&st)) err(1,"fstat"); *len = st.st_size; unsigned char *buf = (unsigned char *)malloc(st.st_size); if(!buf) err(1,"malloc 1"); if(read(fd,buf,st.st_size)<0) err(1,"read1"); close(fd); return buf; } main(int argc, char **argv) { if(argc!=3){ fprintf(stderr,"usage: %s \n"); exit(0); } int len1; unsigned char *buf1 = readfile(argv[1],&len1); int len2; unsigned char *buf2 = readfile(argv[2],&len2); int len = len1127){ ch='.'; bad++; } if(ch<32 && ch!=10){ ch='.'; bad++; } putchar(ch); } putchar('\n'); if(bad>0){ printf("%d non-printing characters are shown as periods.\n",bad); } printf("\n\nOutput in hex:\n"); for(i=0;i=32 && ch<=127)){ putchar(ch); } else { putchar('.'); } } putchar('\n'); } putchar('\n'); putchar('\n'); } }