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.
This commit is contained in:
Tim Peters 2001-03-01 01:30:56 +00:00
parent 694e1816c2
commit 430f5d401d

View File

@ -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;