]> granicus.if.org Git - python/commitdiff
remove support for compiling on systems without getcwd()
authorBenjamin Peterson <benjamin@python.org>
Sat, 24 Aug 2013 02:01:48 +0000 (21:01 -0500)
committerBenjamin Peterson <benjamin@python.org>
Sat, 24 Aug 2013 02:01:48 +0000 (21:01 -0500)
Do we need a fallback implementation of getcwd() from 1991 that claims to
support "really old Unix systems"? I don't think so.

Lib/test/test_posix.py
Misc/NEWS
Modules/posixmodule.c
Python/getcwd.c [deleted file]
configure
configure.ac
pyconfig.h.in

index 4856083dc8d89c241bfe8f444e69800682acfed0..3fd8f115cbdb39f3bd6eb19e03ecad6cc9a1e6b9 100644 (file)
@@ -664,41 +664,39 @@ class PosixTester(unittest.TestCase):
             self.assertEqual(type(v), item_type)
 
     def test_getcwd_long_pathnames(self):
-        if hasattr(posix, 'getcwd'):
-            dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
-            curdir = os.getcwd()
-            base_path = os.path.abspath(support.TESTFN) + '.getcwd'
+        dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'
+        curdir = os.getcwd()
+        base_path = os.path.abspath(support.TESTFN) + '.getcwd'
 
-            try:
-                os.mkdir(base_path)
-                os.chdir(base_path)
-            except:
-#               Just returning nothing instead of the SkipTest exception,
-#               because the test results in Error in that case.
-#               Is that ok?
-#                raise unittest.SkipTest("cannot create directory for testing")
-                return
-
-                def _create_and_do_getcwd(dirname, current_path_length = 0):
-                    try:
-                        os.mkdir(dirname)
-                    except:
-                        raise unittest.SkipTest("mkdir cannot create directory sufficiently deep for getcwd test")
-
-                    os.chdir(dirname)
-                    try:
-                        os.getcwd()
-                        if current_path_length < 1027:
-                            _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
-                    finally:
-                        os.chdir('..')
-                        os.rmdir(dirname)
-
-                _create_and_do_getcwd(dirname)
+        try:
+            os.mkdir(base_path)
+            os.chdir(base_path)
+        except:
+            #  Just returning nothing instead of the SkipTest exception, because
+            #  the test results in Error in that case.  Is that ok?
+            #  raise unittest.SkipTest("cannot create directory for testing")
+            return
 
-            finally:
-                os.chdir(curdir)
-                support.rmtree(base_path)
+            def _create_and_do_getcwd(dirname, current_path_length = 0):
+                try:
+                    os.mkdir(dirname)
+                except:
+                    raise unittest.SkipTest("mkdir cannot create directory sufficiently deep for getcwd test")
+
+                os.chdir(dirname)
+                try:
+                    os.getcwd()
+                    if current_path_length < 1027:
+                        _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
+                finally:
+                    os.chdir('..')
+                    os.rmdir(dirname)
+
+            _create_and_do_getcwd(dirname)
+
+        finally:
+            os.chdir(curdir)
+            support.rmtree(base_path)
 
     @unittest.skipUnless(hasattr(posix, 'getgrouplist'), "test needs posix.getgrouplist()")
     @unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()")
index 125d604697cf4ae1df264bdbfd78a2eb3dc92bdc..53255250e6328c4b0486ce55969efdc3a846e0e6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ Projected Release date: 2013-09-08
 Core and Builtins
 -----------------
 
+- Remove supporting for compiling on systems without getcwd().
+
 - Issue #18774: Remove last bits of GNU PTH thread code and thread_pth.h.
 
 - Issue #18771: Add optimization to set object lookups to reduce the cost
index ab3e9f0b033fc65a34c5b7888bc66cc0345b6a66..fde675284b05bfa35e1dd34b84f1d9ac138ea09c 100644 (file)
@@ -140,21 +140,18 @@ corresponding Unix manual entries for more information on calls.");
 /* Various compilers have only certain posix functions */
 /* XXX Gosh I wish these were all moved into pyconfig.h */
 #if defined(__WATCOMC__) && !defined(__QNX__)           /* Watcom compiler */
-#define HAVE_GETCWD     1
 #define HAVE_OPENDIR    1
 #define HAVE_SYSTEM     1
 #include <process.h>
 #else
 #ifdef __BORLANDC__             /* Borland compiler */
 #define HAVE_EXECV      1
-#define HAVE_GETCWD     1
 #define HAVE_OPENDIR    1
 #define HAVE_PIPE       1
 #define HAVE_SYSTEM     1
 #define HAVE_WAIT       1
 #else
 #ifdef _MSC_VER         /* Microsoft compiler */
-#define HAVE_GETCWD     1
 #define HAVE_GETPPID    1
 #define HAVE_GETLOGIN   1
 #define HAVE_SPAWNV     1
@@ -174,7 +171,6 @@ corresponding Unix manual entries for more information on calls.");
 #if defined(__USLC__) && defined(__SCO_VERSION__)       /* SCO UDK Compiler */
 #define HAVE_FORK1      1
 #endif
-#define HAVE_GETCWD     1
 #define HAVE_GETEGID    1
 #define HAVE_GETEUID    1
 #define HAVE_GETGID     1
@@ -3179,7 +3175,6 @@ posix_lchown(PyObject *self, PyObject *args)
 #endif /* HAVE_LCHOWN */
 
 
-#ifdef HAVE_GETCWD
 static PyObject *
 posix_getcwd(int use_bytes)
 {
@@ -3251,7 +3246,6 @@ posix_getcwd_bytes(PyObject *self)
 {
     return posix_getcwd(1);
 }
-#endif
 
 #if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS))
 #define HAVE_LINK 1
@@ -10710,12 +10704,10 @@ static PyMethodDef posix_methods[] = {
 #ifdef HAVE_CTERMID
     {"ctermid",         posix_ctermid, METH_NOARGS, posix_ctermid__doc__},
 #endif
-#ifdef HAVE_GETCWD
     {"getcwd",          (PyCFunction)posix_getcwd_unicode,
     METH_NOARGS, posix_getcwd__doc__},
     {"getcwdb",         (PyCFunction)posix_getcwd_bytes,
     METH_NOARGS, posix_getcwdb__doc__},
-#endif
 #if defined(HAVE_LINK) || defined(MS_WINDOWS)
     {"link",            (PyCFunction)posix_link,
                         METH_VARARGS | METH_KEYWORDS,
diff --git a/Python/getcwd.c b/Python/getcwd.c
deleted file mode 100644 (file)
index 4bedbd1..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/* Two PD getcwd() implementations.
-   Author: Guido van Rossum, CWI Amsterdam, Jan 1991, <guido@cwi.nl>. */
-
-#include <stdio.h>
-#include <errno.h>
-
-#ifdef HAVE_GETWD
-
-/* Version for BSD systems -- use getwd() */
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-
-#ifndef MAXPATHLEN
-#if defined(PATH_MAX) && PATH_MAX > 1024
-#define MAXPATHLEN PATH_MAX
-#else
-#define MAXPATHLEN 1024
-#endif
-#endif
-
-extern char *getwd(char *);
-
-char *
-getcwd(char *buf, int size)
-{
-    char localbuf[MAXPATHLEN+1];
-    char *ret;
-
-    if (size <= 0) {
-        errno = EINVAL;
-        return NULL;
-    }
-    ret = getwd(localbuf);
-    if (ret != NULL && strlen(localbuf) >= (size_t)size) {
-        errno = ERANGE;
-        return NULL;
-    }
-    if (ret == NULL) {
-        errno = EACCES; /* Most likely error */
-        return NULL;
-    }
-    strncpy(buf, localbuf, size);
-    return buf;
-}
-
-#else /* !HAVE_GETWD */
-
-/* Version for really old UNIX systems -- use pipe from pwd */
-
-#ifndef PWD_CMD
-#define PWD_CMD "/bin/pwd"
-#endif
-
-char *
-getcwd(char *buf, int size)
-{
-    FILE *fp;
-    char *p;
-    int sts;
-    if (size <= 0) {
-        errno = EINVAL;
-        return NULL;
-    }
-    if ((fp = popen(PWD_CMD, "r")) == NULL)
-        return NULL;
-    if (fgets(buf, size, fp) == NULL || (sts = pclose(fp)) != 0) {
-        errno = EACCES; /* Most likely error */
-        return NULL;
-    }
-    for (p = buf; *p != '\n'; p++) {
-        if (*p == '\0') {
-            errno = ERANGE;
-            return NULL;
-        }
-    }
-    *p = '\0';
-    return buf;
-}
-
-#endif /* !HAVE_GETWD */
index 55fa2a6957fa93471b27fbbd1bf951a3e3283258..0f9ba0f46eb5d3abc2510e864144f6566889a3e0 100755 (executable)
--- a/configure
+++ b/configure
@@ -11379,19 +11379,6 @@ esac
 
 fi
 
-ac_fn_c_check_func "$LINENO" "getcwd" "ac_cv_func_getcwd"
-if test "x$ac_cv_func_getcwd" = xyes; then :
-  $as_echo "#define HAVE_GETCWD 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" getcwd.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS getcwd.$ac_objext"
- ;;
-esac
-
-fi
-
 ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup"
 if test "x$ac_cv_func_strdup" = xyes; then :
   $as_echo "#define HAVE_STRDUP 1" >>confdefs.h
index 47f5c5792424f93cce90180185d24313e0601da7..e329c214cbaf758f4541d5ccdfcf4f5ddd5d62df 100644 (file)
@@ -3094,7 +3094,7 @@ AC_CHECK_FUNCS(memmove)
 # check for long file support functions
 AC_CHECK_FUNCS(fseek64 fseeko fstatvfs ftell64 ftello statvfs)
 
-AC_REPLACE_FUNCS(dup2 getcwd strdup)
+AC_REPLACE_FUNCS(dup2 strdup)
 AC_CHECK_FUNCS(getpgrp, 
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]], [[getpgrp(0);]])],
     [AC_DEFINE(GETPGRP_HAVE_ARG, 1, [Define if getpgrp() must be called as getpgrp(0).])],
index ee5451582ac71d1ad3a74d7527b5c01ab400dd75..6dd92505bb1bfb8cab7bf655d5c32752dc38cce0 100644 (file)
 /* Define if you have the getaddrinfo function. */
 #undef HAVE_GETADDRINFO
 
-/* Define to 1 if you have the `getcwd' function. */
-#undef HAVE_GETCWD
-
 /* Define this if you have flockfile(), getc_unlocked(), and funlockfile() */
 #undef HAVE_GETC_UNLOCKED