home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the DOOM Gurus / TricksOfTheDoomGurus.iso / bonus / linux / listlev / director.c next >
C/C++ Source or Header  |  1994-06-28  |  1KB  |  44 lines

  1.  
  2. #include "doomdefs.h"
  3. #include    "directory.h"
  4.  
  5. /* Find the first byte of the "directory" and move 'fd' to it. */
  6. int set_directory(int fd) {
  7.     four_byte dir_start;
  8.     char magic[4];
  9.  
  10.     /* Check for IWAD or PWAD magic */
  11.     if ( lseek(fd, 1, SEEK_SET) < 0 )
  12.         return(-1);
  13.     if ( read(fd, magic, 3) != 3 )
  14.         return(-1);
  15.     magic[3]='\0';
  16.     if ( strcmp(magic, "WAD") != 0 )
  17.         return(-1);
  18.     
  19.     /* Get the start of the directory from the WAD header */
  20.     if ( lseek(fd, 8, SEEK_SET) < 0 ) 
  21.         return(-1);
  22.     read(fd, (char *)&dir_start, 4);
  23.  
  24.     /* Go to it! */
  25.     if ( lseek(fd, dir_start, SEEK_SET) < 0 )
  26.         return(-1);
  27.     return(0);
  28. }
  29.  
  30. int get_entry(int fd, char *name, dir_entry *entry) {
  31.     while ( read(fd, (char *)entry, ENTRY_SIZE) == ENTRY_SIZE ) {
  32.         /* Null terminate the name */
  33.         entry->name[8]='\0';
  34.         /* Is it the entry we want? */
  35.         if ( strcasecmp(entry->name, name) == 0 )
  36.             return(0);
  37.         /* Have we reached the end of the entries? */
  38.         if ( strcasecmp(WADDIR_END, entry->name) == 0 )
  39.             break;
  40.     }
  41.     /* We didn't find the proper entry */
  42.     return(-1);
  43. }
  44.