remove support for compiling on systems without getcwd()
Do we need a fallback implementation of getcwd() from 1991 that claims to support "really old Unix systems"? I don't think so.
This commit is contained in:
parent
12d5e0f016
commit
3a7dffa4ce
|
@ -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
|
||||
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")
|
||||
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)
|
||||
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)
|
||||
_create_and_do_getcwd(dirname)
|
||||
|
||||
finally:
|
||||
os.chdir(curdir)
|
||||
support.rmtree(base_path)
|
||||
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()")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 */
|
|
@ -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
|
||||
|
|
|
@ -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).])],
|
||||
|
|
|
@ -317,9 +317,6 @@
|
|||
/* 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
|
||||
|
||||
|
|
Loading…
Reference in New Issue