]> granicus.if.org Git - python/commitdiff
Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
authorJack Jansen <jack.jansen@cwi.nl>
Mon, 10 Sep 2001 22:00:39 +0000 (22:00 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Mon, 10 Sep 2001 22:00:39 +0000 (22:00 +0000)
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.

Mac/Include/macglue.h
Mac/Modules/macfsmodule.c
Mac/Modules/macosmodule.c
Mac/Python/macgetargv.c
Mac/Python/macgetpath.c
Python/mactoolboxglue.c

index 8057c28e4fa36d5f0ebf5b19b675bd4d505bcf40..eb0c9a1c7e8b935dad78813af3691ae8eff7504d 100644 (file)
@@ -62,7 +62,6 @@ extern short PyMac_AppRefNum;                 /* RefNum of application rsrcfork (from macmain.
 extern FSSpec PyMac_ApplicationFSSpec;         /* Application location (from macargv.c) */
 extern char PyMac_ApplicationPath[];           /* Application location (from macargv.c) */
 extern OSErr PyMac_init_application_location(void);    /* Init the above */
-extern OSErr PyMac_GetFullPath(FSSpec *, char *); /* convert fsspec->path (macargv.c) */
 extern int PyMac_GetArgv(char ***, int);       /* Get argc, argv (from macargv.c) */
 extern int PyMac_AppearanceCompliant;  /* True if in appearance support mode */
 
index 2c20e89705dc641effa263aeaad4ad6bfb100b10..15d9f30857d50838bdbb815c32b681d64c197c27 100644 (file)
@@ -51,6 +51,12 @@ extern PyObject *_PyMac_BuildFSRef(FSRef *);
 #endif
 static PyObject *ErrorObject;
 
+#ifdef TARGET_API_MAC_OSX
+#define PATHNAMELEN 1024
+#else
+#define PATHNAMELEN 256
+#endif
+
 /* ----------------------------------------------------- */
 /* Declarations for objects of type Alias */
 
@@ -449,22 +455,17 @@ PyMac_SetFileDates(FSSpec *fss, unsigned long crdat, unsigned long mddat,
 static PyObject *
 mfss_as_pathname(mfssobject *self, PyObject *args)
 {
-#if TARGET_API_MAC_OSX
-       PyErr_SetString(PyExc_NotImplementedError, "FSSpec.as_pathname not supported on this platform");
-       return 0;
-#else
-       char strbuf[257];
+       char strbuf[PATHNAMELEN];
        OSErr err;
 
        if (!PyArg_ParseTuple(args, ""))
                return NULL;
-       err = PyMac_GetFullPath(&self->fsspec, strbuf);
+       err = PyMac_GetFullPathname(&self->fsspec, strbuf, PATHNAMELEN);
        if ( err ) {
                PyErr_Mac(ErrorObject, err);
                return NULL;
        }
        return PyString_FromString(strbuf);
-#endif
 }
 
 static PyObject *
index 0b8d8561b10992e9ef26dd48a31a3b29d4164c3e..6b8b87def3722ba87eba1d76999a4277d3a98979 100644 (file)
@@ -40,6 +40,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 static PyObject *MacOS_Error; /* Exception MacOS.Error */
 
+#ifdef TARGET_API_MAC_OSX
+#define PATHNAMELEN 1024
+#else
+#define PATHNAMELEN 256
+#endif
+
 #ifdef MPW
 #define bufferIsSmall -607     /*error returns from Post and Accept */
 #endif
@@ -596,15 +602,14 @@ MacOS_openrf(PyObject *self, PyObject *args)
                
        err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
        
-#if !TARGET_API_MAC_OSX
        if ( err == fnfErr ) {
                /* In stead of doing complicated things here to get creator/type
                ** correct we let the standard i/o library handle it
                */
                FILE *tfp;
-               char pathname[257];
+               char pathname[PATHNAMELEN];
                
-               if ( err=PyMac_GetFullPath(&fss, pathname) ) {
+               if ( err=PyMac_GetFullPathname(&fss, pathname, PATHNAMELEN) ) {
                        PyMac_Error(err);
                        Py_DECREF(fp);
                        return NULL;
@@ -618,7 +623,6 @@ MacOS_openrf(PyObject *self, PyObject *args)
                fclose(tfp);
                err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
        }
-#endif
        if ( err ) {
                Py_DECREF(fp);
                PyMac_Error(err);
index c5af0ecc8d68dbb69b01d32a7f0c788107fb3cee..8fdbad508726f26ca36abe556aae7e84b9db0ad9 100644 (file)
@@ -54,10 +54,16 @@ typedef unsigned long refcontype;
 #include "Python.h"
 #include "macglue.h"
 
+#ifdef TARGET_API_MAC_OSX
+#define PATHNAMELEN 1024
+#else
+#define PATHNAMELEN 256
+#endif
+
 static int arg_count;
 static char *arg_vector[256];
 FSSpec PyMac_ApplicationFSSpec;
-char PyMac_ApplicationPath[256];
+char PyMac_ApplicationPath[PATHNAMELEN];
 
 /* Duplicate a string to the heap. We also export this since it isn't standard
 ** and others use it
@@ -73,22 +79,6 @@ strdup(const char *src)
 }
 #endif
 
-#if TARGET_API_MAC_OSX
-OSErr
-PyMac_GetFullPath(FSSpec *fss, char *path)
-{
-       FSRef fsr;
-       OSErr err;
-       
-       *path = '\0';
-       err = FSpMakeFSRef(fss, &fsr);
-       if ( err ) return err;
-       err = (OSErr)FSRefMakePath(&fsr, path, 1024);
-       if ( err ) return err;
-       return 0;
-}
-#endif /* TARGET_API_MAC_OSX */
-
 
 #if !TARGET_API_MAC_OSX
 /* Initialize FSSpec and full name of current application */
@@ -109,7 +99,7 @@ PyMac_init_process_location(void)
        info.processAppSpec = &PyMac_ApplicationFSSpec;
        if ( err=GetProcessInformation(&currentPSN, &info))
                return err;
-       if ( err=PyMac_GetFullPath(&PyMac_ApplicationFSSpec, PyMac_ApplicationPath) )
+       if ( err=PyMac_GetFullPathname(&PyMac_ApplicationFSSpec, PyMac_ApplicationPath, PATHNAMELEN) )
                return err;
        applocation_inited = 1;
        return 0;
@@ -170,7 +160,7 @@ handle_open_doc(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype r
        DescType rttype;
        long i, ndocs, size;
        FSSpec fss;
-       char path[1024];
+       char path[PATHNAMELEN];
        
        got_one = 1;
        if ((err = AEGetParamDesc(theAppleEvent,
@@ -185,7 +175,7 @@ handle_open_doc(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype r
                                  &keywd, &rttype, &fss, sizeof(fss), &size);
                if (err)
                        break;
-               PyMac_GetFullPath(&fss, path);
+               PyMac_GetFullPathname(&fss, path, PATHNAMELEN);
                arg_vector[arg_count++] = strdup(path);
        }
        return err;
index 83117edcbfaf9a0ffe1aa6683e331733dd1828f2..e08702377812ed1f73a64e90d3cd648636710c10 100644 (file)
@@ -38,6 +38,11 @@ PERFORMANCE OF THIS SOFTWARE.
 #include <unistd.h>
 #endif
 
+#ifdef TARGET_API_MAC_OSX
+#define PATHNAMELEN 1024
+#else
+#define PATHNAMELEN 256
+#endif
 
 /* Return the initial python search path.  This is called once from
 ** initsys() to initialize sys.path.
@@ -244,7 +249,7 @@ char *
 PyMac_GetPythonDir()
 {
        static int diditbefore = 0;
-       static char name[256] = {':', '\0'};
+       static char name[PATHNAMELEN] = {':', '\0'};
        AliasHandle handle;
        FSSpec dirspec;
        Boolean modified = 0;
@@ -285,7 +290,7 @@ PyMac_GetPythonDir()
        if ( prefrh != -1 ) CloseResFile(prefrh);
        UseResFile(oldrh);
 
-       if ( PyMac_GetFullPath(&dirspec, name) == 0 ) {
+       if ( PyMac_GetFullPathname(&dirspec, name, PATHNAMELEN) == 0 ) {
                strcat(name, ":");
        } else {
                /* If all fails, we return the current directory */
index 0781a3b6954f4cbbd0d53bdd7dd9fd7979a7da9a..52ff00b470ad173e7869389dae3f5a9efe8cbfa7 100644 (file)
@@ -93,7 +93,7 @@ PyObject *PyMac_OSErrException;
 
 /* Initialize and return PyMac_OSErrException */
 PyObject *
-PyMac_GetOSErrException()
+PyMac_GetOSErrException(void)
 {
        if (PyMac_OSErrException == NULL)
                PyMac_OSErrException = PyString_FromString("MacOS.Error");
@@ -127,6 +127,46 @@ PyMac_Error(OSErr err)
        return PyErr_Mac(PyMac_GetOSErrException(), err);
 }
 
+
+#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
 PyMac_GetOSType(PyObject *v, OSType *pr)