[Python-checkins] CVS: python/dist/src/Python import.c,2.165,2.166
Tim Peters
tim_one@users.sourceforge.net
Wed, 28 Feb 2001 17:30:58 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv31512/python/dist/src/Python
Modified Files:
import.c
Log Message:
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.
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.165
retrieving revision 2.166
diff -C2 -r2.165 -r2.166
*** import.c 2001/02/28 05:57:51 2.165
--- import.c 2001/03/01 01:30:56 2.166
***************
*** 834,871 ****
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,
--- 834,837 ----
***************
*** 1037,1041 ****
#if defined(MS_WIN32) || defined(__CYGWIN__)
#include <windows.h>
- #include <ctype.h>
#ifdef __CYGWIN__
#include <sys/cygwin.h>
--- 1003,1006 ----
***************
*** 1051,1054 ****
--- 1016,1023 ----
#endif
+ #elif defined(__MACH__) && defined(__APPLE__)
+ #include <sys/types.h>
+ #include <dirent.h>
+
#endif
***************
*** 1138,1141 ****
--- 1107,1146 ----
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! */