diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/CONTRIB/SNIP/getdcwd.c |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/CONTRIB/SNIP/getdcwd.c')
-rwxr-xr-x | reference/C/CONTRIB/SNIP/getdcwd.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/SNIP/getdcwd.c b/reference/C/CONTRIB/SNIP/getdcwd.c new file mode 100755 index 0000000..4b5ac6d --- /dev/null +++ b/reference/C/CONTRIB/SNIP/getdcwd.c @@ -0,0 +1,74 @@ +/*
+** GETDCWD.C - returns the current working directory for a specific drive
+**
+** public domain by Bob Jarvis, modified by Bob Stout
+*/
+
+#if defined(__ZTC__)
+ #define GetDrive(d) dos_getdrive(&d)
+ #define FAR _far
+#elif defined(__TURBOC__)
+ #define GetDrive(d) ((d) = getdisk() + 1)
+ #define FAR far
+#else /* assume MSC */
+ #define GetDrive(d) _dos_getdrive(&d)
+ #define FAR _far
+#endif
+
+#include <dos.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+
+char *getdcwd(unsigned int drive) /* 0 = current, 1 = A, 2 = B, etc */
+{
+ union REGS regs;
+ struct SREGS sregs;
+ char *retptr;
+
+ retptr = calloc(FILENAME_MAX + 4, sizeof(char));
+ if(retptr == NULL)
+ return NULL;
+
+ if(drive == 0) /* figure out which drive is current */
+ {
+ GetDrive(drive);
+ drive += 1;
+ }
+
+ *retptr = (char)((drive-1) + 'A');
+ *(retptr+1) = ':';
+ *(retptr+2) = '\\';
+
+ segread(&sregs);
+ regs.h.ah = 0x47;
+ regs.h.dl = (unsigned char)drive;
+ sregs.ds = FP_SEG((void FAR *)retptr);
+ regs.x.si = FP_OFF((void FAR *)retptr) + 3;
+
+ intdosx(®s, ®s, &sregs);
+ if (15 == regs.x.ax) /* drive number invalid */
+ {
+ free(retptr);
+ return NULL;
+ }
+ else return retptr;
+}
+
+#ifdef TEST
+
+void main(int argc, char *argv[])
+{
+ char *curpath;
+ unsigned int n;
+
+ if(argc > 1)
+ n = (tolower(*argv[1]) - 'a') + 1;
+ else GetDrive(n);
+
+ printf("curpath = '%s'\n", curpath = getdcwd(n));
+ if (curpath)
+ free(curpath);
+}
+
+#endif
|