mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Fix pgxs for spaces in file names on Win32
Dave Page
This commit is contained in:
		@@ -17,7 +17,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 | 
					 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.13 2005/09/27 17:39:33 tgl Exp $
 | 
					 * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.14 2005/10/05 12:16:28 momjian Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *-------------------------------------------------------------------------
 | 
					 *-------------------------------------------------------------------------
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@@ -30,6 +30,64 @@ static const char *progname;
 | 
				
			|||||||
static char		mypath[MAXPGPATH];
 | 
					static char		mypath[MAXPGPATH];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This function cleans up the paths for use with either cmd.exe or Msys
 | 
				
			||||||
 | 
					 * on Windows. We need them to use double backslashes and filenames without
 | 
				
			||||||
 | 
					 * spaces (for which a short filename is the safest equivalent) eg:
 | 
				
			||||||
 | 
					 * C:\\Progra~1\\
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This can fail in 2 ways - if the path doesn't exist, or short names are
 | 
				
			||||||
 | 
					 * disabled. In the first case, don't return any path. In the second case, 
 | 
				
			||||||
 | 
					 * we leave the path in the long form. In this case, it does still seem to
 | 
				
			||||||
 | 
					 * fix elements containing spaces which is all we actually need.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					cleanup_path(char *path)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#ifdef WIN32
 | 
				
			||||||
 | 
						int	x=0, y=0;
 | 
				
			||||||
 | 
						char	temp[MAXPGPATH];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (GetShortPathName(path, path, MAXPGPATH - 1) == 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							/* Ignore ERROR_INVALID_PARAMETER as it almost certainly 
 | 
				
			||||||
 | 
							 * means that short names are disabled
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if (GetLastError() != ERROR_INVALID_PARAMETER)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								path[0] = '\0';
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Replace '\' with '\\'. */
 | 
				
			||||||
 | 
						for (x = 0; x < strlen(path); x++)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
							if (path[x] == '/' || path[x] == '\\')
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								temp[y] = '\\';
 | 
				
			||||||
 | 
								y++;
 | 
				
			||||||
 | 
								temp[y] = '\\';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								temp[y] = path[x];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							y++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Bail out if we're too close to MAXPGPATH */
 | 
				
			||||||
 | 
							if (y >= MAXPGPATH - 2)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						temp[y] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						strncpy(path, temp, MAXPGPATH - 1);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * For each piece of information known to pg_config, we define a subroutine
 | 
					 * For each piece of information known to pg_config, we define a subroutine
 | 
				
			||||||
 * to print it.  This is probably overkill, but it avoids code duplication
 | 
					 * to print it.  This is probably overkill, but it avoids code duplication
 | 
				
			||||||
@@ -47,8 +105,11 @@ show_bindir(bool all)
 | 
				
			|||||||
	/* assume we are located in the bindir */
 | 
						/* assume we are located in the bindir */
 | 
				
			||||||
	strcpy(path, mypath);
 | 
						strcpy(path, mypath);
 | 
				
			||||||
	lastsep = strrchr(path, '/');
 | 
						lastsep = strrchr(path, '/');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (lastsep)
 | 
						if (lastsep)
 | 
				
			||||||
		*lastsep = '\0';
 | 
							*lastsep = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -60,6 +121,7 @@ show_docdir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("DOCDIR = ");
 | 
							printf("DOCDIR = ");
 | 
				
			||||||
	get_doc_path(mypath, path);
 | 
						get_doc_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -71,6 +133,7 @@ show_includedir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("INCLUDEDIR = ");
 | 
							printf("INCLUDEDIR = ");
 | 
				
			||||||
	get_include_path(mypath, path);
 | 
						get_include_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -82,6 +145,7 @@ show_pkgincludedir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("PKGINCLUDEDIR = ");
 | 
							printf("PKGINCLUDEDIR = ");
 | 
				
			||||||
	get_pkginclude_path(mypath, path);
 | 
						get_pkginclude_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -93,6 +157,7 @@ show_includedir_server(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("INCLUDEDIR-SERVER = ");
 | 
							printf("INCLUDEDIR-SERVER = ");
 | 
				
			||||||
	get_includeserver_path(mypath, path);
 | 
						get_includeserver_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -104,6 +169,7 @@ show_libdir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("LIBDIR = ");
 | 
							printf("LIBDIR = ");
 | 
				
			||||||
	get_lib_path(mypath, path);
 | 
						get_lib_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -115,6 +181,7 @@ show_pkglibdir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("PKGLIBDIR = ");
 | 
							printf("PKGLIBDIR = ");
 | 
				
			||||||
	get_pkglib_path(mypath, path);
 | 
						get_pkglib_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -126,6 +193,7 @@ show_localedir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("LOCALEDIR = ");
 | 
							printf("LOCALEDIR = ");
 | 
				
			||||||
	get_locale_path(mypath, path);
 | 
						get_locale_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -137,6 +205,7 @@ show_mandir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("MANDIR = ");
 | 
							printf("MANDIR = ");
 | 
				
			||||||
	get_man_path(mypath, path);
 | 
						get_man_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -148,6 +217,7 @@ show_sharedir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("SHAREDIR = ");
 | 
							printf("SHAREDIR = ");
 | 
				
			||||||
	get_share_path(mypath, path);
 | 
						get_share_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -159,6 +229,7 @@ show_sysconfdir(bool all)
 | 
				
			|||||||
	if (all)
 | 
						if (all)
 | 
				
			||||||
		printf("SYSCONFDIR = ");
 | 
							printf("SYSCONFDIR = ");
 | 
				
			||||||
	get_etc_path(mypath, path);
 | 
						get_etc_path(mypath, path);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -171,6 +242,7 @@ show_pgxs(bool all)
 | 
				
			|||||||
		printf("PGXS = ");
 | 
							printf("PGXS = ");
 | 
				
			||||||
	get_pkglib_path(mypath, path);
 | 
						get_pkglib_path(mypath, path);
 | 
				
			||||||
	strncat(path, "/pgxs/src/makefiles/pgxs.mk", MAXPGPATH - 1);
 | 
						strncat(path, "/pgxs/src/makefiles/pgxs.mk", MAXPGPATH - 1);
 | 
				
			||||||
 | 
						cleanup_path(path);
 | 
				
			||||||
	printf("%s\n", path);
 | 
						printf("%s\n", path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user