Mercurial > cpython-lru_cache-weakref
annotate Mac/Compat/nfullpath.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 810bc15e18f9 |
| children |
| rev | line source |
|---|---|
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
1 /* GET FULL PATHNAME OF A FILE. |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
2 ** Original by Guido, modified by Jack to handle FSSpecs |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
3 */ |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
4 |
|
2186
95cb52b85f78
ported to THINK C (not tested yet)
Guido van Rossum <guido@python.org>
parents:
2180
diff
changeset
|
5 #include <string.h> |
|
95cb52b85f78
ported to THINK C (not tested yet)
Guido van Rossum <guido@python.org>
parents:
2180
diff
changeset
|
6 |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
7 #include <Files.h> |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
8 |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
9 #include "nfullpath.h" |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
10 |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
11 /* Mac file system parameters */ |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
12 #define MAXPATH 256 /* Max path name length+1 */ |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
13 #define SEP ':' /* Separator in path names */ |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
14 |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
15 /* Macro to find out whether we can do HFS-only calls: */ |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
16 #define FSFCBLen (* (short *) 0x3f6) |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
17 #define hfsrunning() (FSFCBLen > 0) |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
18 |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
19 int |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
20 nfullpath(fsp, retbuf) |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
21 FSSpec *fsp; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
22 char *retbuf; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
23 { |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
24 union { |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
25 HFileInfo f; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
26 DirInfo d; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
27 WDPBRec w; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
28 VolumeParam v; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
29 } pb; |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
30 char cwd[2*MAXPATH]; |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
31 unsigned char namebuf[MAXPATH]; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
32 short err; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
33 int dir; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
34 long dirid; |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
35 char *next = cwd + sizeof cwd - 1; |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
36 int len; |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
37 int need_sep = 1; |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
38 |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
39 if (!hfsrunning()) |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
40 return -1; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
41 |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
42 dir = fsp->vRefNum; |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
43 dirid = fsp->parID; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
44 /* Stuff the filename into the buffer */ |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
45 len = fsp->name[0]; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
46 *next = '\0'; |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
47 next -= len; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
48 memcpy(next, fsp->name+1, len); |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
49 |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
50 while (dirid != fsRtParID) { |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
51 pb.d.ioNamePtr = namebuf; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
52 pb.d.ioVRefNum = dir; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
53 pb.d.ioFDirIndex = -1; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
54 pb.d.ioDrDirID = dirid; |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
55 err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0); |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
56 if (err != noErr) |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
57 return err; |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
58 *--next = SEP; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
59 len = namebuf[0]; |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
60 if ( len + strlen(next) >= MAXPATH ) |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
61 return -1; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
62 next -= len; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
63 memcpy(next, (char *)namebuf+1, len); |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
64 dirid = pb.d.ioDrParID; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
65 need_sep = 0; |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
66 } |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
67 |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
68 strcpy(retbuf, next); |
|
2413
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
69 if (need_sep) { |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
70 next = strchr(retbuf, '\0'); |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
71 *next++ = SEP; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
72 *next++ = '\0'; |
|
810bc15e18f9
fix bug with volume root
Guido van Rossum <guido@python.org>
parents:
2186
diff
changeset
|
73 } |
|
2180
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
74 return 0; |
|
9b451c84a7bf
Initial version of FSSpec and Alias code. Non-functional as of now.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
75 } |
