home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / c / du.arc / SHOWBUG.C < prev   
C/C++ Source or Header  |  1987-12-26  |  2KB  |  80 lines

  1. /*
  2.  *    To show the bug associated with stat(), it works okay if the drive
  3.  *    letter entered is for the current drive.
  4.  */
  5.  
  6. #include    <stdio.h>
  7. #include    <dos.h>
  8. #include    <sys/types.h>
  9. #include    <sys/stat.h>
  10. #include    <strings.h>
  11. #include    <ctype.h>
  12. struct    stat        statb;
  13.  
  14. static    char    *extgetcwd();
  15. #define DOSI_GCDIR    0x47
  16. static    union REGS    reg, nreg;
  17. #if    defined(M_I86LM)
  18. static    struct SREGS    sreg;
  19. #endif
  20. #define    MAXPATHLEN    128
  21.  
  22. main()
  23. {
  24.     char    *s = ":\\tmp";
  25.     char    ss[MAXPATHLEN+1], dd[MAXPATHLEN+1];
  26.     char    c;
  27.  
  28.     printf ("Enter drive letter with directory \\tmp : ");
  29.     c = getchar();
  30.     if (isupper(c))
  31.         c += 'a' - 'A';
  32.     ss[0] = c;
  33.     ss[1] = NULL;
  34.     strcat (ss, s);
  35.     chdir(ss);
  36.     extgetcwd (c+1, ss, MAXPATHLEN);
  37.     printf ("Current directory before stat() = %s\n", ss);
  38.     dd[0] = c;
  39.     dd[1] = NULL;
  40.     strcat (dd, ":\\");
  41.     stat(dd, &statb);
  42.     extgetcwd (c+1, dd, MAXPATHLEN);
  43.     printf ("Current directory after stat() = %s\n", dd);
  44. }
  45.  
  46.  
  47. static    char    *extgetcwd(drive_id, buffer, buffer_size)
  48. /* Extended get current directory on specified drive.  Peter Lim 07-Dec-87. */
  49. unsigned char drive_id;
  50. char *buffer;
  51. int  buffer_size;
  52. {
  53.     char    tmpbuffer[MAXPATHLEN+1];
  54.  
  55.     if (!drive_id)
  56.         return (getcwd (buffer, buffer_size));
  57.     /* If it is current drive, use the standard getcwd() */
  58.  
  59.     reg.h.ah = DOSI_GCDIR;
  60.     reg.h.dl = drive_id;
  61. #if    defined(M_I86LM)
  62.     reg.x.si = FP_OFF(tmpbuffer);
  63.     sreg.ds = FP_SEG(tmpbuffer);
  64.     intdosx(®, &nreg, &sreg);
  65. #else
  66.     reg.x.si = (int) tmpbuffer;
  67.     intdos(®, &nreg);
  68. #endif
  69.     if (nreg.x.ax == 0xf)
  70.         return ((char *) NULL);
  71.         /* Invalid drive specification. */
  72.     else {
  73.         if (drive_id)
  74.             sprintf (buffer, "%c:\\%s", drive_id+'A'-1, tmpbuffer);
  75.         else
  76.             sprintf (buffer, "\\%s", tmpbuffer);
  77.         return (buffer);
  78.     }
  79. }
  80.