home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / SRC / msdos_diskaccess.lzh / MS_DISK_ACCESS / isdir.c < prev    next >
Text File  |  1990-05-10  |  1KB  |  53 lines

  1. /*
  2.  * Test to see if a filename is a directory.  Subdir() has to be
  3.  * run first...  Returns 1 if true.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "msdos.h"
  8.  
  9. extern int dir_entries;
  10.  
  11. int
  12. isdir(path)
  13. char *path;
  14. {
  15.     register int entry;
  16.     char *newname, *unixname(), *strncpy(), name[9], ext[4];
  17.     struct directory *dir, *search();
  18.     void free();
  19.                     /* no path */
  20.     if (*path == '\0')
  21.         return(0);
  22.  
  23.     for (entry=0; entry<dir_entries; entry++) {
  24.         dir = search(entry);
  25.                     /* if empty */
  26.         if (dir->name[0] == 0x0)
  27.             break;
  28.                     /* if erased */
  29.         if (dir->name[0] == 0xe5)
  30.             continue;
  31.                     /* skip if not a directory */
  32.         if (!(dir->attr & 0x10))
  33.             continue;
  34.  
  35.         strncpy(name, (char *) dir->name, 8);
  36.         strncpy(ext, (char *) dir->ext, 3);
  37.         name[8] = '\0';
  38.         ext[3] = '\0';
  39.  
  40.         newname = unixname(name, ext);
  41.         if (!strcmp(newname, path)) {
  42.             free(newname);
  43.             return(1);
  44.         }
  45.         free(newname);
  46.     }
  47.                     /* if "." or ".." fails, then root */
  48.     if (!strcmp(path, ".") || !strcmp(path, ".."))
  49.         return(1);
  50.  
  51.     return(0);
  52. }
  53.