summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-03-01 01:30:56 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-03-01 01:30:56 (GMT)
commit430f5d401df053ebc458987b713c6d29f2b731f2 (patch)
treeded08e552706bcd4965b8a2180d69ccc46476901 /Python/import.c
parent694e1816c23707bc37f119053ad960bdae1f4dfa (diff)
downloadcpython-430f5d401df053ebc458987b713c6d29f2b731f2.zip
cpython-430f5d401df053ebc458987b713c6d29f2b731f2.tar.gz
cpython-430f5d401df053ebc458987b713c6d29f2b731f2.tar.bz2
In Steven's apparent absence, check in *something* with a non-zero chance
of making new-fangled Mac imports work again. May not work, and may not even compile on his boxes, but should be at worst very close on both.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/Python/import.c b/Python/import.c
index a5c5d4c..236a68d 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -833,40 +833,6 @@ extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **,
static int case_ok(char *, int, int, char *);
static int find_init_module(char *); /* Forward */
-#if 0 /* XXX was #ifdef HAVE_DIRENT_H; resolve whether we really need this */
-
-static int MatchFilename(char *pathname, char *filename);
-
-#include <sys/types.h>
-#include <dirent.h>
-
-static int MatchFilename(char *pathname, char *filename)
-{
- DIR *dirp;
- struct dirent *dp;
- int len = strlen(filename);
-
- if ((pathname == NULL) || (strlen(pathname) == 0))
- pathname = ".";
- dirp = opendir(pathname);
- if (dirp) {
- while ((dp = readdir(dirp)) != NULL) {
-#ifdef _DIRENT_HAVE_D_NAMELINE
- int namelen = dp->d_namlen;
-#else /* !_DIRENT_HAVE_D_NAMELINE */
- int namelen = strlen(dp->d_name);
-#endif /* _DIRENT_HAVE_D_NAMELINE */
- if (namelen == len && !strcmp(dp->d_name, filename)) {
- (void)closedir(dirp);
- return 1; /* Found */
- }
- }
- }
- (void)closedir(dirp);
- return 0 ; /* Not found */
-}
-#endif /* HAVE_DIRENT_H */
-
static struct filedescr *
find_module(char *realname, PyObject *path, char *buf, size_t buflen,
FILE **p_fp)
@@ -1036,7 +1002,6 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
*/
#if defined(MS_WIN32) || defined(__CYGWIN__)
#include <windows.h>
-#include <ctype.h>
#ifdef __CYGWIN__
#include <sys/cygwin.h>
#endif
@@ -1050,6 +1015,10 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
#include "TFileSpec.h" /* for Path2FSSpec() */
#endif
+#elif defined(__MACH__) && defined(__APPLE__)
+#include <sys/types.h>
+#include <dirent.h>
+
#endif
static int
@@ -1138,6 +1107,42 @@ case_ok(char *buf, int len, int namelen, char *name)
return fss.name[0] >= namelen &&
strncmp(name, (char *)fss.name+1, namelen) == 0;
+/* new-fangled macintosh */
+#elif defined(__MACH__) && defined(__APPLE__)
+ DIR *dirp;
+ struct dirent *dp;
+ char pathname[MAX_PATH + 1];
+ const int pathlen = len - namelen - 1; /* don't want trailing SEP */
+
+ /* Copy the path component into pathname; substitute "." if empty */
+ if (pathlen <= 0) {
+ pathname[0] = '.';
+ pathname[1] = '\0';
+ }
+ else {
+ assert(pathlen <= MAX_PATH);
+ memcpy(pathname, buf, pathlen);
+ pathname[pathlen] = '\0';
+ }
+ /* Open the directory and search the entries for an exact match. */
+ dirp = opendir(pathname);
+ if (dirp) {
+ while ((dp = readdir(dirp)) != NULL) {
+#ifdef _DIRENT_HAVE_D_NAMELEN
+ const int thislen = dp->d_namlen;
+#else
+ const int thislen = strlen(dp->d_name);
+#endif
+ if (thislen == namelen && !strcmp(dp->d_name, name)) {
+ (void)closedir(dirp);
+ return 1; /* Found */
+ }
+ }
+ }
+ (void)closedir(dirp);
+ return 0 ; /* Not found */
+}
+
/* assuming it's a case-sensitive filesystem, so there's nothing to do! */
#else
return 1;