#include #include #include #include int contains_byte(char *path, unsigned char byte); int main(int argc, char *argv[]) { if (argc <= 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } int byte = strtoul(argv[2], NULL, 0); if (contains_byte(argv[1],byte)){ printf("Contains byte 0x%x\n", byte); } else { printf("Does not contain byte 0x%x\n", byte); } return 0; } // Return 1 of the given file contains the given byte. // Return 0 otherwise int contains_byte(char *path, unsigned char byte) { int f = open(path, O_RDONLY); if (f < 0) { perror(""); exit(1); } //read each byte and compare unsigned char c; while ((read(f, &c, 1) > 0)){ if (c == byte) { close(f); return 1; } } close(f); return 0; }