[Python-checkins] CVS: python/dist/src/Python mactoolboxglue.c,1.5,1.6
Jack Jansen
jackjansen@users.sourceforge.net
Mon, 10 Sep 2001 15:00:41 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv10457/Python
Modified Files:
mactoolboxglue.c
Log Message:
Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
parameter for the return string (as unix pathnames are not limited
by the 255 char pstring limit).
Implemented the function for MachO-Python, where it returns unix pathnames.
Index: mactoolboxglue.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/mactoolboxglue.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** mactoolboxglue.c 2001/09/01 23:39:43 1.5
--- mactoolboxglue.c 2001/09/10 22:00:39 1.6
***************
*** 94,98 ****
/* Initialize and return PyMac_OSErrException */
PyObject *
! PyMac_GetOSErrException()
{
if (PyMac_OSErrException == NULL)
--- 94,98 ----
/* Initialize and return PyMac_OSErrException */
PyObject *
! PyMac_GetOSErrException(void)
{
if (PyMac_OSErrException == NULL)
***************
*** 128,131 ****
--- 128,171 ----
}
+
+ #if TARGET_API_MAC_OSX
+ OSErr
+ PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
+ {
+ FSRef fsr;
+ OSErr err;
+
+ *path = '\0';
+ err = FSpMakeFSRef(fss, &fsr);
+ if ( err == fnfErr ) {
+ /* FSSpecs can point to non-existing files, fsrefs can't. */
+ FSSpec fss2;
+ int tocopy;
+
+ err = FSMakeFSSpec(fss->vRefNum, fss->parID, "", &fss2);
+ if ( err ) return err;
+ err = FSpMakeFSRef(&fss2, &fsr);
+ if ( err ) return err;
+ err = (OSErr)FSRefMakePath(&fsr, path, len-1);
+ if ( err ) return err;
+ /* This part is not 100% safe: we append the filename part, but
+ ** I'm not sure that we don't run afoul of the various 8bit
+ ** encodings here. Will have to look this up at some point...
+ */
+ strcat(path, "/");
+ tocopy = fss->name[0];
+ if ( strlen(path) + tocopy >= len )
+ tocopy = len - strlen(path) - 1;
+ if ( tocopy > 0 )
+ strncat(path, fss->name+1, tocopy);
+ } else {
+ if ( err ) return err;
+ err = (OSErr)FSRefMakePath(&fsr, path, len);
+ if ( err ) return err;
+ }
+ return 0;
+ }
+
+ #endif /* TARGET_API_MAC_OSX */
/* Convert a 4-char string object argument to an OSType value */
int