mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	fix bug with volume root
This commit is contained in:
		
							parent
							
								
									24a45e3c18
								
							
						
					
					
						commit
						f74c36c9dc
					
				
					 1 changed files with 22 additions and 20 deletions
				
			
		| 
						 | 
					@ -1,6 +1,5 @@
 | 
				
			||||||
/* GET FULL PATHNAME OF A FILE.
 | 
					/* GET FULL PATHNAME OF A FILE.
 | 
				
			||||||
** Original by Guido, modified by Jack to handle FSSpecs 
 | 
					** Original by Guido, modified by Jack to handle FSSpecs 
 | 
				
			||||||
** (and only tested under MetroWerks, so far)
 | 
					 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
| 
						 | 
					@ -12,7 +11,6 @@
 | 
				
			||||||
/* Mac file system parameters */
 | 
					/* Mac file system parameters */
 | 
				
			||||||
#define MAXPATH 256	/* Max path name length+1 */
 | 
					#define MAXPATH 256	/* Max path name length+1 */
 | 
				
			||||||
#define SEP ':'		/* Separator in path names */
 | 
					#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: */
 | 
					/* Macro to find out whether we can do HFS-only calls: */
 | 
				
			||||||
#define FSFCBLen (* (short *) 0x3f6)
 | 
					#define FSFCBLen (* (short *) 0x3f6)
 | 
				
			||||||
| 
						 | 
					@ -29,45 +27,49 @@ nfullpath(fsp, retbuf)
 | 
				
			||||||
		WDPBRec w;
 | 
							WDPBRec w;
 | 
				
			||||||
		VolumeParam v;
 | 
							VolumeParam v;
 | 
				
			||||||
	} pb;
 | 
						} pb;
 | 
				
			||||||
	static char cwd[2*MAXPATH];
 | 
						char cwd[2*MAXPATH];
 | 
				
			||||||
	unsigned char namebuf[MAXPATH];
 | 
						unsigned char namebuf[MAXPATH];
 | 
				
			||||||
	short err;
 | 
						short err;
 | 
				
			||||||
	int dir;
 | 
						int dir;
 | 
				
			||||||
	long dirid;
 | 
						long dirid;
 | 
				
			||||||
	char *next= cwd + sizeof cwd - 1;
 | 
						char *next = cwd + sizeof cwd - 1;
 | 
				
			||||||
	int len;
 | 
						int len;
 | 
				
			||||||
	
 | 
						int need_sep = 1;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	if (!hfsrunning())
 | 
						if (!hfsrunning())
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	dir  = fsp->vRefNum;
 | 
						dir = fsp->vRefNum;
 | 
				
			||||||
	dirid = fsp->parID;
 | 
						dirid = fsp->parID;
 | 
				
			||||||
	/* Stuff the filename into the buffer */
 | 
						/* Stuff the filename into the buffer */
 | 
				
			||||||
	len = fsp->name[0];
 | 
						len = fsp->name[0];
 | 
				
			||||||
	*next = '\0';
 | 
						*next = '\0';
 | 
				
			||||||
	next -= len+1;
 | 
						next -= len;
 | 
				
			||||||
	memcpy(next, &fsp->name[1], len);
 | 
						memcpy(next, fsp->name+1, len);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	for (;;) {
 | 
						while (dirid != fsRtParID) {
 | 
				
			||||||
		pb.d.ioNamePtr= namebuf;
 | 
							pb.d.ioNamePtr = namebuf;
 | 
				
			||||||
		pb.d.ioVRefNum= dir;
 | 
							pb.d.ioVRefNum = dir;
 | 
				
			||||||
		pb.d.ioFDirIndex= -1;
 | 
							pb.d.ioFDirIndex = -1;
 | 
				
			||||||
		pb.d.ioDrDirID= dirid;
 | 
							pb.d.ioDrDirID = dirid;
 | 
				
			||||||
		err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0);
 | 
							err= PBGetCatInfo((CInfoPBPtr)&pb.d, 0);
 | 
				
			||||||
		if (err != noErr) {
 | 
							if (err != noErr)
 | 
				
			||||||
			return err;
 | 
								return err;
 | 
				
			||||||
		}
 | 
							*--next = SEP;
 | 
				
			||||||
		*--next= SEP;
 | 
							len = namebuf[0];
 | 
				
			||||||
		len= namebuf[0];
 | 
					 | 
				
			||||||
		if ( len + strlen(next) >= MAXPATH )
 | 
							if ( len + strlen(next) >= MAXPATH )
 | 
				
			||||||
			return -1;
 | 
								return -1;
 | 
				
			||||||
		next -= len;
 | 
							next -= len;
 | 
				
			||||||
		memcpy(next, (char *)namebuf+1, len);
 | 
							memcpy(next, (char *)namebuf+1, len);
 | 
				
			||||||
		if (pb.d.ioDrDirID == ROOTID)
 | 
							dirid = pb.d.ioDrParID;
 | 
				
			||||||
			break;
 | 
							need_sep = 0;
 | 
				
			||||||
		dirid= pb.d.ioDrParID;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	strcpy(retbuf, next);
 | 
						strcpy(retbuf, next);
 | 
				
			||||||
 | 
						if (need_sep) {
 | 
				
			||||||
 | 
							next = strchr(retbuf, '\0');
 | 
				
			||||||
 | 
							*next++ = SEP;
 | 
				
			||||||
 | 
							*next++ = '\0';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue