summaryrefslogtreecommitdiffstats
path: root/Mac/Compat/nfullpath.c
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1995-01-18 14:04:40 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1995-01-18 14:04:40 (GMT)
commit84fa5ecffffe23b6f39caf6f9cd43cdd1da33695 (patch)
tree402a1f31496b9ffcddcdeec91569b4064b7b045a /Mac/Compat/nfullpath.c
parentd50e4e1c544aae822fe50d1a4f953f6329dfc827 (diff)
downloadcpython-84fa5ecffffe23b6f39caf6f9cd43cdd1da33695.zip
cpython-84fa5ecffffe23b6f39caf6f9cd43cdd1da33695.tar.gz
cpython-84fa5ecffffe23b6f39caf6f9cd43cdd1da33695.tar.bz2
Initial version of FSSpec and Alias code. Non-functional as of now.
Diffstat (limited to 'Mac/Compat/nfullpath.c')
-rw-r--r--Mac/Compat/nfullpath.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/Mac/Compat/nfullpath.c b/Mac/Compat/nfullpath.c
new file mode 100644
index 0000000..6e7e1b6
--- /dev/null
+++ b/Mac/Compat/nfullpath.c
@@ -0,0 +1,76 @@
+/* GET FULL PATHNAME OF A FILE.
+** Original by Guido, modified by Jack to handle FSSpecs
+** (and only tested under MetroWerks, so far)
+*/
+
+#if defined(MPW) || defined(__MWERKS__)
+#include <Files.h>
+#endif
+#ifdef THINK_C_PRE_5_0
+#include <HFS.h>
+#endif
+
+#include "nfullpath.h"
+
+/* Mac file system parameters */
+#define MAXPATH 256 /* Max path name length+1 */
+#define SEP ':' /* Separator in path names */
+#define ROOTID 2 /* DirID of a volume's root directory */
+
+/* Macro to find out whether we can do HFS-only calls: */
+#define FSFCBLen (* (short *) 0x3f6)
+#define hfsrunning() (FSFCBLen > 0)
+
+int
+nfullpath(fsp, retbuf)
+ FSSpec *fsp;
+ char *retbuf;
+{
+ union {
+ HFileInfo f;
+ DirInfo d;
+ WDPBRec w;
+ VolumeParam v;
+ } pb;
+ static char cwd[2*MAXPATH];
+ unsigned char namebuf[MAXPATH];
+ short err;
+ int dir;
+ long dirid;
+ char *next= cwd + sizeof cwd - 1;
+ int len;
+
+
+ if (!hfsrunning())
+ return -1;
+
+ dir = fsp->vRefNum;
+ dirid = fsp->parID;
+ /* Stuff the filename into the buffer */
+ len = fsp->name[0];
+ *next = '\0';
+ next -= len+1;
+ memcpy(next, &fsp->name[1], len);
+
+ for (;;) {
+ pb.d.ioNamePtr= namebuf;
+ pb.d.ioVRefNum= dir;
+ pb.d.ioFDirIndex= -1;
+ pb.d.ioDrDirID= dirid;
+ err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0);
+ if (err != noErr) {
+ return err;
+ }
+ *--next= SEP;
+ len= namebuf[0];
+ if ( len + strlen(next) >= MAXPATH )
+ return -1;
+ next -= len;
+ memcpy(next, (char *)namebuf+1, len);
+ if (pb.d.ioDrDirID == ROOTID)
+ break;
+ dirid= pb.d.ioDrParID;
+ }
+ strcpy(retbuf, next);
+ return 0;
+}