]> granicus.if.org Git - postgresql/blobdiff - src/bin/initdb/initdb.c
Fix HAVE_OPTRESET to be HAVE_INT_OPTRESET. Typos spotted by Lorne Sunley.
[postgresql] / src / bin / initdb / initdb.c
index da698e55dee807a49183b9a2194ddbae6200511a..a0b2f3357eb8358d5d9f25de3598dfce25ee5faa 100644 (file)
@@ -39,7 +39,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  * Portions taken from FreeBSD.
  *
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.61 2004/10/12 21:54:42 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.68 2004/11/27 18:51:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -60,7 +60,7 @@
 #include "mb/pg_wchar.h"
 #include "getopt_long.h"
 
-#ifndef HAVE_OPTRESET
+#ifndef HAVE_INT_OPTRESET
 int                    optreset;
 #endif
 
@@ -407,6 +407,9 @@ readfile(char *path)
 
 /*
  * write an array of lines to a file
+ *
+ * This is only used to write text files.  Use fopen "w" not PG_BINARY_W
+ * so that the resulting configuration files are nicely editable on Windows.
  */
 static void
 writefile(char *path, char **lines)
@@ -414,7 +417,7 @@ writefile(char *path, char **lines)
        FILE       *out_file;
        char      **line;
 
-       if ((out_file = fopen(path, PG_BINARY_W)) == NULL)
+       if ((out_file = fopen(path, "w")) == NULL)
        {
                fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
                                progname, path, strerror(errno));
@@ -1990,7 +1993,7 @@ setlocales(void)
        if (strlen(lc_monetary) == 0 || !chklocale(lc_monetary))
                lc_monetary = xstrdup(setlocale(LC_MONETARY, NULL));
        if (strlen(lc_messages) == 0 || !chklocale(lc_messages))
-#ifdef LC_MESSAGES
+#if defined(LC_MESSAGES) && !defined(WIN32)
        {
                /* when available get the current locale setting */
                lc_messages = xstrdup(setlocale(LC_MESSAGES, NULL));
@@ -2197,7 +2200,7 @@ main(int argc, char *argv[])
        if (authmethod == NULL || !strlen(authmethod))
        {
                authwarning = _("\nWARNING: enabling \"trust\" authentication for local connections\n"
-                                               "You can change this by editing pg_hba.conf or using the -A flag the\n"
+                                               "You can change this by editing pg_hba.conf or using the -A option the\n"
                                                "next time you run initdb.\n");
                authmethod = "trust";
        }
@@ -2268,18 +2271,24 @@ main(int argc, char *argv[])
        if ((ret = find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
                                                           backend_exec)) < 0)
        {
+               char full_path[MAXPGPATH];
+
+               if (find_my_exec(argv[0], full_path) < 0)
+                       StrNCpy(full_path, progname, MAXPGPATH);
+
                if (ret == -1)
                        fprintf(stderr,
                                        _("The program \"postgres\" is needed by %s "
-                                  "but was not found in the same directory as \"%s\".\n"
+                                         "but was not found in the\n"
+                                         "same directory as \"%s\".\n"
                                          "Check your installation.\n"),
-                                       progname, progname);
+                                       progname, full_path);
                else
                        fprintf(stderr,
-                                       _("The program \"postgres\" was found by %s "
-                                         "but was not the same version as \"%s\".\n"
+                                       _("The program \"postgres\" was found by \"%s\"\n"
+                                         "but was not the same version as %s.\n"
                                          "Check your installation.\n"),
-                                       progname, progname);
+                                       full_path, progname);
                exit(1);
        }
 
@@ -2463,7 +2472,8 @@ main(int argc, char *argv[])
 
                        if (chmod(pg_data, 0700) != 0)
                        {
-                               perror(pg_data);
+                               fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
+                                               progname, pg_data, strerror(errno));
                                exit_nicely();
                        }
                        else
@@ -2484,7 +2494,8 @@ main(int argc, char *argv[])
 
                default:
                        /* Trouble accessing directory */
-                       perror(pg_data);
+                       fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
+                                       progname, pg_data, strerror(errno));
                        exit_nicely();
        }