From e9ad14f9f4a8b3eb2c7497e5cee7a444c3469784 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Fri, 14 May 2010 00:13:38 +0000
Subject: [PATCH] Use NAMEDATALEN instead of local define.

Modify path separators for Win32.

Per ideas from Takahiro Itagaki
---
 contrib/pg_upgrade/exec.c            |  6 +++---
 contrib/pg_upgrade/file.c            |  6 ------
 contrib/pg_upgrade/option.c          |  8 ++++++--
 contrib/pg_upgrade/pg_upgrade.h      | 18 +++++++-----------
 contrib/pg_upgrade/version_old_8_3.c |  4 ++--
 5 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/contrib/pg_upgrade/exec.c b/contrib/pg_upgrade/exec.c
index 2543763cbc4..a8797be9d7c 100644
--- a/contrib/pg_upgrade/exec.c
+++ b/contrib/pg_upgrade/exec.c
@@ -138,7 +138,7 @@ check_exec(migratorContext *ctx, const char *dir, const char *cmdName)
 	char		path[MAXPGPATH];
 	const char *errMsg;
 
-	snprintf(path, sizeof(path), "%s%c%s", dir, pathSeparator, cmdName);
+	snprintf(path, sizeof(path), "%s/%s", dir, cmdName);
 
 	if ((errMsg = validate_exec(path)) == NULL)
 		return 1;				/* 1 -> first alternative OK */
@@ -286,8 +286,8 @@ check_data_dir(migratorContext *ctx, const char *pg_data)
 	{
 		struct stat statBuf;
 
-		snprintf(subDirName, sizeof(subDirName), "%s%c%s", pg_data,
-				 pathSeparator, requiredSubdirs[subdirnum]);
+		snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
+				 requiredSubdirs[subdirnum]);
 
 		if ((stat(subDirName, &statBuf)) != 0)
 		{
diff --git a/contrib/pg_upgrade/file.c b/contrib/pg_upgrade/file.c
index 3ffea54ef26..f035a6ad2f6 100644
--- a/contrib/pg_upgrade/file.c
+++ b/contrib/pg_upgrade/file.c
@@ -13,12 +13,6 @@
 #include <windows.h>
 #endif
 
-#ifndef WIN32
-char		pathSeparator = '/';
-#else
-char		pathSeparator = '\\';
-#endif
-
 
 static int	copy_file(const char *fromfile, const char *tofile, bool force);
 
diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c
index f95cb4c70d5..4d97da05aba 100644
--- a/contrib/pg_upgrade/option.c
+++ b/contrib/pg_upgrade/option.c
@@ -308,9 +308,13 @@ validateDirectoryOption(migratorContext *ctx, char **dirpath,
 	/*
 	 * Trim off any trailing path separators
 	 */
-	if ((*dirpath)[strlen(*dirpath) - 1] == pathSeparator)
+#ifndef WIN32
+	if ((*dirpath)[strlen(*dirpath) - 1] == '/')
+#else
+	if ((*dirpath)[strlen(*dirpath) - 1] == '/' ||
+	    (*dirpath)[strlen(*dirpath) - 1] == '\\')
+#endif
 		(*dirpath)[strlen(*dirpath) - 1] = 0;
-
 }
 
 
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
index 773ff6c88c2..e6f4d3ea11a 100644
--- a/contrib/pg_upgrade/pg_upgrade.h
+++ b/contrib/pg_upgrade/pg_upgrade.h
@@ -16,8 +16,6 @@
 #include "libpq-fe.h"
 
 /* Allocate for null byte */
-#define NAMEDATASIZE		(NAMEDATALEN + 1)
-
 #define USER_NAME_SIZE		128
 
 #define MAX_STRING			1024
@@ -73,15 +71,13 @@ extern int  pgunlink(const char *path);
 extern void copydir(char *fromdir, char *todir, bool recurse);
 extern bool rmtree(const char *path, bool rmtopdir);
 
-extern char pathSeparator;
-
 /*
  * Each relation is represented by a relinfo structure.
  */
 typedef struct
 {
-	char		nspname[NAMEDATASIZE];		/* namespace name */
-	char		relname[NAMEDATASIZE];		/* relation name */
+	char		nspname[NAMEDATALEN];		/* namespace name */
+	char		relname[NAMEDATALEN];		/* relation name */
 	Oid			reloid;			/* relation oid				 */
 	Oid			relfilenode;	/* relation relfile node	 */
 	Oid			toastrelid;		/* oid of the toast relation */
@@ -103,10 +99,10 @@ typedef struct
 	Oid			new;			/* Relfilenode of the new relation */
 	char		old_file[MAXPGPATH];
 	char		new_file[MAXPGPATH];
-	char		old_nspname[NAMEDATASIZE];	/* old name of the namespace */
-	char		old_relname[NAMEDATASIZE];	/* old name of the relation */
-	char		new_nspname[NAMEDATASIZE];	/* new name of the namespace */
-	char		new_relname[NAMEDATASIZE];	/* new name of the relation */
+	char		old_nspname[NAMEDATALEN];	/* old name of the namespace */
+	char		old_relname[NAMEDATALEN];	/* old name of the relation */
+	char		new_nspname[NAMEDATALEN];	/* new name of the namespace */
+	char		new_relname[NAMEDATALEN];	/* new name of the relation */
 } FileNameMap;
 
 /*
@@ -115,7 +111,7 @@ typedef struct
 typedef struct
 {
 	Oid			db_oid;			/* oid of the database */
-	char		db_name[NAMEDATASIZE];	/* database name */
+	char		db_name[NAMEDATALEN];	/* database name */
 	char		db_tblspace[MAXPGPATH]; /* database default tablespace path */
 	RelInfoArr	rel_arr;		/* array of all user relinfos */
 } DbInfo;
diff --git a/contrib/pg_upgrade/version_old_8_3.c b/contrib/pg_upgrade/version_old_8_3.c
index f15f5613cf8..8d56893f778 100644
--- a/contrib/pg_upgrade/version_old_8_3.c
+++ b/contrib/pg_upgrade/version_old_8_3.c
@@ -318,8 +318,8 @@ old_8_3_rebuild_tsvector_tables(migratorContext *ctx, bool check_mode,
 	{
 		PGresult   *res;
 		bool		db_used = false;
-		char		old_nspname[NAMEDATASIZE] = "",
-					old_relname[NAMEDATASIZE] = "";
+		char		old_nspname[NAMEDATALEN] = "",
+					old_relname[NAMEDATALEN] = "";
 		int			ntups;
 		int			rowno;
 		int			i_nspname,
-- 
GitLab