]> granicus.if.org Git - python/commitdiff
Patch #494045: patches errno and stat to cope on plan9.
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 9 Mar 2002 12:07:51 +0000 (12:07 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 9 Mar 2002 12:07:51 +0000 (12:07 +0000)
Python/bltinmodule.c
Python/errors.c

index 41e906adb3e8dbc43a7acd41272dcd0d0ba4bfbc..1561a227b9a1f2e517e8a60b7e2fbdc92ec728ab 100644 (file)
@@ -536,9 +536,6 @@ builtin_execfile(PyObject *self, PyObject *args)
        FILE* fp = NULL;
        PyCompilerFlags cf;
        int exists;
-#ifndef RISCOS
-       struct stat s;
-#endif
 
        if (!PyArg_ParseTuple(args, "s|O!O!:execfile",
                        &filename,
@@ -560,25 +557,40 @@ builtin_execfile(PyObject *self, PyObject *args)
 
        exists = 0;
        /* Test for existence or directory. */
-#ifndef RISCOS
-       if (!stat(filename, &s)) {
-               if (S_ISDIR(s.st_mode))
-#if defined(PYOS_OS2) && defined(PYCC_VACPP)
-                       errno = EOS2ERR;
-#else
-                       errno = EISDIR;
-#endif
-               else
-                       exists = 1;
+#if defined(PLAN9)
+       {
+               Dir *d;
+
+               if ((d = dirstat(filename))!=nil) {
+                       if(d->mode & DMDIR)
+                               werrstr("is a directory");
+                       else
+                               exists = 1;
+                       free(d);
+               }
        }
-#else
+#elif defined(RISCOS)
        if (object_exists(filename)) {
                if (isdir(filename))
                        errno = EISDIR;
                else
                        exists = 1;
        }
-#endif /* RISCOS */
+#else  /* standard Posix */
+       {
+               struct stat s;
+               if (stat(filename, &s) == 0) {
+                       if (S_ISDIR(s.st_mode))
+#                              if defined(PY_OS2) && defined(PYCC_VACPP)
+                                       errno = EOS2ERR;
+#                              else
+                                       errno = EISDIR;
+#                              endif
+                       else
+                               exists = 1;
+               }
+       }
+#endif
 
         if (exists) {
                Py_BEGIN_ALLOW_THREADS
index 13b3d11ed6b1971f33a5af35ffc45d89f2fb03cb..3869b1cc5c3b4a3bf430ca4171ed425400bd71be 100644 (file)
@@ -264,6 +264,9 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename)
        PyObject *v;
        char *s;
        int i = errno;
+#ifdef PLAN9
+       char errbuf[ERRMAX];
+#endif
 #ifdef MS_WIN32
        char *s_buf = NULL;
 #endif
@@ -271,6 +274,10 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename)
        if (i == EINTR && PyErr_CheckSignals())
                return NULL;
 #endif
+#ifdef PLAN9
+       rerrstr(errbuf, sizeof errbuf);
+       s = errbuf;
+#else
        if (i == 0)
                s = "Error"; /* Sometimes errno didn't get set */
        else
@@ -305,7 +312,8 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename)
                                s[--len] = '\0';
                }
        }
-#endif
+#endif /* Unix/Windows */
+#endif /* PLAN 9*/
        if (filename != NULL)
                v = Py_BuildValue("(iss)", i, s, filename);
        else