
Everyday Problems 69
Program 48: File Follies
The following program works just fine for a while, and then it refuses to rec-
ognize files that contain the magic number:
1 /************************************************
2 * scan -- Scan a directory tree for files that *
3 * begin with a magic number. *
4 ************************************************/
5 #include <iostream>
6 #include <dirent.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9
10 // Linux executable magic #
11 const long int MAGIC = 0x464c457f;
12
13 /************************************************
14 * next_file -- find a list of files with *
15 * magic numbers that match the given *
16 * number ...