home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
c
/
du.arc
/
SHOWBUG.C
< prev
Wrap
C/C++ Source or Header
|
1987-12-26
|
2KB
|
80 lines
/*
* To show the bug associated with stat(), it works okay if the drive
* letter entered is for the current drive.
*/
#include <stdio.h>
#include <dos.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <strings.h>
#include <ctype.h>
struct stat statb;
static char *extgetcwd();
#define DOSI_GCDIR 0x47
static union REGS reg, nreg;
#if defined(M_I86LM)
static struct SREGS sreg;
#endif
#define MAXPATHLEN 128
main()
{
char *s = ":\\tmp";
char ss[MAXPATHLEN+1], dd[MAXPATHLEN+1];
char c;
printf ("Enter drive letter with directory \\tmp : ");
c = getchar();
if (isupper(c))
c += 'a' - 'A';
ss[0] = c;
ss[1] = NULL;
strcat (ss, s);
chdir(ss);
extgetcwd (c+1, ss, MAXPATHLEN);
printf ("Current directory before stat() = %s\n", ss);
dd[0] = c;
dd[1] = NULL;
strcat (dd, ":\\");
stat(dd, &statb);
extgetcwd (c+1, dd, MAXPATHLEN);
printf ("Current directory after stat() = %s\n", dd);
}
static char *extgetcwd(drive_id, buffer, buffer_size)
/* Extended get current directory on specified drive. Peter Lim 07-Dec-87. */
unsigned char drive_id;
char *buffer;
int buffer_size;
{
char tmpbuffer[MAXPATHLEN+1];
if (!drive_id)
return (getcwd (buffer, buffer_size));
/* If it is current drive, use the standard getcwd() */
reg.h.ah = DOSI_GCDIR;
reg.h.dl = drive_id;
#if defined(M_I86LM)
reg.x.si = FP_OFF(tmpbuffer);
sreg.ds = FP_SEG(tmpbuffer);
intdosx(®, &nreg, &sreg);
#else
reg.x.si = (int) tmpbuffer;
intdos(®, &nreg);
#endif
if (nreg.x.ax == 0xf)
return ((char *) NULL);
/* Invalid drive specification. */
else {
if (drive_id)
sprintf (buffer, "%c:\\%s", drive_id+'A'-1, tmpbuffer);
else
sprintf (buffer, "\\%s", tmpbuffer);
return (buffer);
}
}