84 Chapter 4
36
37 int magic; // The file's magic number
38
39 // Size of the header read
40 int read_size =
41 read(fd, &magic, sizeof(magic));
42
43 if (read_size != sizeof(magic)) {
44 close(fd);
45 continue;
46 }
47
48 if (magic == MAGIC) {
49 close(fd);
50 return (cur_ent->d_name);
51 }
52 close(fd);
53 }
54 }
55 /************************************************
56 * scan_dir -- Scan a directory for the files *
57 * we want. *
58 ************************************************/
59 char *scan_dir(
60 const char dir_name[] // Directory name to use
61){
62 // Directory to scan
63 DIR *dir_info = opendir(dir_name);
64 if (dir_info == NULL)
65 return (NULL);
66
67 chdir(dir_name);
68
69 // Name of the file we just found
70 char *name = next_file(dir_info);
71 closedir(dir_inf ...