Index: src/backend/utils/fmgr/dfmgr.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/fmgr/dfmgr.c,v
retrieving revision 1.71
diff -c -r1.71 dfmgr.c
*** src/backend/utils/fmgr/dfmgr.c	9 Mar 2004 05:06:45 -0000	1.71
--- src/backend/utils/fmgr/dfmgr.c	25 Mar 2004 00:46:31 -0000
***************
*** 363,381 ****
  		replacement = PKGLIBDIR;
  #else
  	{
! 		char *p;
! 		if (GetModuleFileName(NULL,basename,MAXPGPATH) == 0)
  			ereport(FATAL,
! 					(errmsg("GetModuleFileName failed (%i)",(int)GetLastError())));
! 
! 		canonicalize_path(basename);
! 		if ((p = last_path_separator(basename)) == NULL)
! 			ereport(FATAL,
! 					(errmsg("unexpected failure in determining PKGLIBDIR (%s)",basename)));
! 		else
! 			*p = '\0';
! 
! 		strcat(basename,"/../lib");
  		replacement = basename;
  	}
  #endif
--- 363,371 ----
  		replacement = PKGLIBDIR;
  #else
  	{
! 		if (!get_win32_install_dir(basename,MAXPGPATH,"lib"))
  			ereport(FATAL,
! 					(errmsg("unexpected failure in determining PKGLIBDIR")));
  		replacement = basename;
  	}
  #endif
Index: src/bin/initdb/initdb.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/initdb/initdb.c,v
retrieving revision 1.23
diff -c -r1.23 initdb.c
*** src/bin/initdb/initdb.c	9 Mar 2004 04:49:02 -0000	1.23
--- src/bin/initdb/initdb.c	25 Mar 2004 00:46:33 -0000
***************
*** 2051,2056 ****
--- 2051,2061 ----
  	char	   *exe;			/* location of exe suffix in progname */
  #endif
  
+ #ifdef WIN32
+ 	char win32_bindir[MAXPGPATH];
+ 	char win32_datadir[MAXPGPATH];
+ #endif
+ 
  	init_nls();
  
  	/* parse argv[0] - detect explicit path if there was one */
***************
*** 2068,2073 ****
--- 2073,2089 ----
  		/* strip .exe suffix, regardless of case */
  		*exe = '\0';
  	}
+ #endif
+ 
+ #ifdef WIN32
+ 	if (!(get_win32_install_dir(win32_bindir ,MAXPGPATH,"bin") &&
+ 		  get_win32_install_dir(win32_datadir,MAXPGPATH,"share")))
+ 	{
+ 		fprintf(stderr, _("%s: unable to determine installation dirs\n"), progname);
+ 		exit(1);
+ 	}
+ 	bindir  = win32_bindir;
+ 	datadir = win32_datadir;
  #endif
  
  	if (lastsep)
Index: src/include/port.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/include/port.h,v
retrieving revision 1.23
diff -c -r1.23 port.h
*** src/include/port.h	24 Mar 2004 03:54:16 -0000	1.23
--- src/include/port.h	25 Mar 2004 00:46:33 -0000
***************
*** 26,31 ****
--- 26,34 ----
  extern char *last_path_separator(const char *filename);
  extern void canonicalize_path(char *path);
  extern char *get_progname(char *argv0);
+ #ifdef WIN32
+ extern bool get_win32_install_dir(char* basename, int len, const char *offset);
+ #endif
  
  /* Portable delay handling */
  extern void pg_usleep(long microsec);
Index: src/port/path.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/port/path.c,v
retrieving revision 1.5
diff -c -r1.5 path.c
*** src/port/path.c	9 Mar 2004 04:49:02 -0000	1.5
--- src/port/path.c	25 Mar 2004 00:46:35 -0000
***************
*** 121,123 ****
--- 121,155 ----
  	else
  		return last_path_separator(argv0) + 1;
  }
+ 
+ #ifdef WIN32
+ 
+ /*
+  * Determine the directory of installed files, on the assumption that
+  * win32 will have a common root directory for all pgsql subdirectories
+  * (eg. lib, bin, share, etc).
+  */
+ bool
+ get_win32_install_dir(char* basename, int len, const char *offset)
+ {
+ 	char *p;
+ 	if (GetModuleFileName(NULL,basename,len) == 0)
+ 		return false;
+ 
+ 	canonicalize_path(basename);
+ 
+ 	if ((p = last_path_separator(basename)) == NULL)
+ 		return false;
+ 	*p = '\0';
+ 
+ 	/* Also, takes care of cases where GetModuleFileName truncates the string */
+ 	if ((strlen(basename) + strlen("/../") + (offset ? strlen(offset) : 0)) >= len)
+ 		return false;
+ 
+ 	strcat(basename,"/../");
+ 	if (offset)
+ 		strcat(basename,offset);
+ 	return true;
+ }
+ 
+ #endif
