home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume15 / vtree / direct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-23  |  970 b   |  47 lines

  1. /* direct.c
  2.   
  3.    SCCS ID    @(#)direct.c    1.6    7/9/87
  4.   
  5.  *
  6.  *    My own substitution for the berkeley reading routines,
  7.  *    for use on System III machines that don't have any other
  8.  *    alternative.
  9.  */
  10.  
  11. #define NAMELENGTH    14
  12. #define opendir(name)    fopen(name, "r")
  13. #define closedir(fp)    fclose(fp)
  14.  
  15. struct dir_entry {        /* What the system uses internally. */
  16.     ino_t           d_ino;
  17.     char            d_name[NAMELENGTH];
  18. };
  19.  
  20. struct direct {            /* What these routines return. */
  21.     ino_t           d_ino;
  22.     char            d_name[NAMELENGTH];
  23.     char            terminator;
  24. };
  25.  
  26.  
  27.  /*
  28.   * Read a directory, returning the next (non-empty) slot. 
  29.   */
  30.  
  31. READ           *
  32. readdir(dp)
  33.     OPEN           *dp;
  34. {
  35.     static READ     direct;
  36.  
  37.     /* This read depends on direct being similar to dir_entry. */
  38.  
  39.     while (fread(&direct, sizeof(struct dir_entry), 1, dp) != 0) {
  40.     direct.terminator = '\0';
  41.     if (INO(direct) != 0)
  42.         return &direct;
  43.     };
  44.  
  45.     return (READ *) NULL;
  46. }
  47.