mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	Changes to setpythonpath():
Test for / as well as for SEP for MS filenames. Drop trailing separator from sys.path[0] for MS and Unix filenames.
This commit is contained in:
		
							parent
							
								
									688bbfc217
								
							
						
					
					
						commit
						cc88341e6d
					
				
					 1 changed files with 23 additions and 4 deletions
				
			
		|  | @ -367,14 +367,33 @@ setpythonargv(argc, argv) | ||||||
| 		fatal("can't assign sys.argv"); | 		fatal("can't assign sys.argv"); | ||||||
| 	if (path != NULL) { | 	if (path != NULL) { | ||||||
| 		char *p = NULL; | 		char *p = NULL; | ||||||
| 		int n; | 		int n = 0; | ||||||
| 		object *a; | 		object *a; | ||||||
|  | #if SEP == '\\' /* Special case for MS filename syntax */ | ||||||
|  | 		if (argc > 0 && argv[0] != NULL) { | ||||||
|  | 			char *q; | ||||||
|  | 			p = strrchr(argv[0], SEP); | ||||||
|  | 			/* Test for alternate separator */ | ||||||
|  | 			q = strrchr(p ? p : argv[0], '/'); | ||||||
|  | 			if (q != NULL) | ||||||
|  | 				p = q; | ||||||
|  | 			if (p != NULL) { | ||||||
|  | 				n = p + 1 - argv[0]; | ||||||
|  | 				if (n > 1 && p[-1] != ':') | ||||||
|  | 					n--; /* Drop trailing separator */ | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | #else /* All other filename syntaxes */ | ||||||
| 		if (argc > 0 && argv[0] != NULL) | 		if (argc > 0 && argv[0] != NULL) | ||||||
| 			p = strrchr(argv[0], SEP); | 			p = strrchr(argv[0], SEP); | ||||||
| 		if (p == NULL) | 		if (p != NULL) { | ||||||
| 			n = 0; |  | ||||||
| 		else |  | ||||||
| 			n = p + 1 - argv[0]; | 			n = p + 1 - argv[0]; | ||||||
|  | #if SEP == '/' /* Special case for Unix filename syntax */ | ||||||
|  | 			if (n > 1) | ||||||
|  | 				n--; /* Drop trailing separator */ | ||||||
|  | #endif /* Unix */ | ||||||
|  | 		} | ||||||
|  | #endif /* All others */ | ||||||
| 		a = newsizedstringobject(argv[0], n); | 		a = newsizedstringobject(argv[0], n); | ||||||
| 		if (a == NULL) | 		if (a == NULL) | ||||||
| 			fatal("no mem for sys.path insertion"); | 			fatal("no mem for sys.path insertion"); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum