[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.130,2.131

Guido van Rossum python-dev@python.org
2000年4月21日 14:54:48 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Modules
In directory eric:/projects/python/develop/guido/src/Modules
Modified Files:
	posixmodule.c 
Log Message:
Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
backslash from the pathname argument to stat() on Windows -- while on
Unix, stat("/bin/") succeeds and does the same thing as stat("/bin"),
on Windows, stat("\\windows\\") fails while stat("\\windows") succeeds.
This modified version of the patch recognizes both / and \.
(This is odd behavior of the MS C library, since
os.listdir("\\windows\\") succeeds!)
Index: posixmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.130
retrieving revision 2.131
diff -C2 -r2.130 -r2.131
*** posixmodule.c	2000年04月13日 15:20:40	2.130
--- posixmodule.c	2000年04月21日 18:54:45	2.131
***************
*** 550,555 ****
--- 550,583 ----
 	char *path;
 	int res;
+ 
+ #ifdef MS_WIN32
+ int pathlen;
+ char pathcopy[MAX_PATH];
+ #endif /* MS_WIN32 */
+ 
 	if (!PyArg_ParseTuple(args, format, &path))
 		return NULL;
+ 
+ #ifdef MS_WIN32
+ 	pathlen = strlen(path);
+ 	/* the library call can blow up if the file name is too long! */
+ 	if (pathlen > MAX_PATH) {
+ 		errno = ENAMETOOLONG;
+ 		return posix_error();
+ 	}
+ 
+ 	if ((pathlen > 0) && (path[pathlen-1] == '\\' || path[pathlen-1] == '/')) {
+ 		/* exception for drive root */
+ 		if (!((pathlen == 3) &&
+ 		 (path[1] == ':') &&
+ 		 (path[2] == '\\' || path[2] == '/')))
+ 		{
+ 			strncpy(pathcopy, path, pathlen);
+ 			pathcopy[pathlen-1] = '0円'; /* nuke the trailing backslash */
+ 			path = pathcopy;
+ 		}
+ 	}
+ #endif /* MS_WIN32 */
+ 
 	Py_BEGIN_ALLOW_THREADS
 	res = (*statfunc)(path, &st);

AltStyle によって変換されたページ (->オリジナル) /