Path separator - Mailing list pgsql-hackers

From Magnus Hagander
Subject Path separator
Date
Msg-id 49C0BDC5.4010002@hagander.net
Whole thread Raw
Responses Re: Path separator  (Dave Page <dpage@pgadmin.org>)
Re: Path separator  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I've seen a couple of reports that the new SSL error messages on windows
look strange with paths the wrong way. For example:

root certificate file "C:\Documents and Settings\<SNIP>\Application
Data/postgresql/root.crt" does not exist.

The issue being the mix of forward and backwards slashes. Attached patch
should fix this.

Is this worth doing? Comments?

//Magnus
diff --git a/src/include/port.h b/src/include/port.h
index 0557dd2..951f5ac 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -100,6 +100,12 @@ extern BOOL AddUserToDacl(HANDLE hProcess);
 #define DEVTTY "/dev/tty"
 #endif

+#if defined(WIN32) || defined(__CYGWIN__)
+#define PATH_SEPARATOR "\\"
+#else
+#define PATH_SEPARATOR "/"
+#endif
+
 /*
  *    Win32 needs double quotes at the beginning and end of system()
  *    strings.  If not, it gets confused with multiple quoted strings.
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 0833603..9f46c99 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -3964,7 +3964,7 @@ pqGetHomeDirectory(char *buf, int bufsize)
     ZeroMemory(tmppath, sizeof(tmppath));
     if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, tmppath) != S_OK)
         return false;
-    snprintf(buf, bufsize, "%s/postgresql", tmppath);
+    snprintf(buf, bufsize, "%s\\postgresql", tmppath);
     return true;
 #endif
 }
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 7c229c3..1b14f90 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -578,7 +578,7 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
     if (conn->sslcert)
         strncpy(fnbuf, conn->sslcert, sizeof(fnbuf));
     else
-        snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, USER_CERT_FILE);
+        snprintf(fnbuf, sizeof(fnbuf), "%s" PATH_SEPARATOR "%s", homedir, USER_CERT_FILE);

     /*
      * OpenSSL <= 0.9.8 lacks error stack handling, which means it's likely to
@@ -693,7 +693,7 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
     else
     {
         /* No PGSSLKEY specified, load default file */
-        snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, USER_KEY_FILE);
+        snprintf(fnbuf, sizeof(fnbuf), "%s" PATH_SEPARATOR "%s", homedir, USER_KEY_FILE);
     }

     if (fnbuf[0] != '\0')
@@ -998,7 +998,7 @@ initialize_SSL(PGconn *conn)
     if (conn->sslrootcert)
         strncpy(fnbuf, conn->sslrootcert, sizeof(fnbuf));
     else
-        snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, ROOT_CERT_FILE);
+        snprintf(fnbuf, sizeof(fnbuf), "%s" PATH_SEPARATOR "%s", homedir, ROOT_CERT_FILE);

     if (stat(fnbuf, &buf) == 0)
     {
@@ -1020,7 +1020,7 @@ initialize_SSL(PGconn *conn)
             if (conn->sslcrl)
                 strncpy(fnbuf, conn->sslcrl, sizeof(fnbuf));
             else
-                snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, ROOT_CRL_FILE);
+                snprintf(fnbuf, sizeof(fnbuf), "%s" PATH_SEPARATOR "%s", homedir, ROOT_CRL_FILE);

             /* setting the flags to check against the complete CRL chain */
             if (X509_STORE_load_locations(cvstore, fnbuf, NULL) == 1)

pgsql-hackers by date:

Previous
From: Sergey Burladyan
Date:
Subject: gettext, plural form and translation
Next
From: Dave Page
Date:
Subject: Re: Path separator