#include #include #include // If the file, // Is a regular file // Contains a given byte // Is group readable. int check_metadata(char *path, unsigned char byte); 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; } unsigned char byte = strtoul(argv[2], NULL, 0); if (check_metadata(argv[1],byte)){ printf("Valid file\n"); } else { printf("Not Valid file\n"); } return 0; } // If the file, // is a regular file, // is publically readable. // contains a given byte, int check_metadata(char *path, unsigned char byte) { struct stat st; if (stat(path, &st) == 0){ if (S_ISREG(st.st_mode) && (st.st_mode & S_IROTH) && contains_byte(path, byte)){ return 1; } } return 0; } int contains_byte(char *path, unsigned char byte) { FILE *f = fopen(path, "r"); if (f == NULL) { perror(""); exit(1); } //read each byte and compare int curr_byte; while ((curr_byte = fgetc(f)) != EOF){ if (curr_byte == byte) { fclose(f); return 1; } } fclose(f); return 0; }