Changes for MinGW/WIN32:
authorBruce Momjian <bruce@momjian.us>
Sun, 7 Sep 2003 03:43:57 +0000 (03:43 +0000)
committerBruce Momjian <bruce@momjian.us>
Sun, 7 Sep 2003 03:43:57 +0000 (03:43 +0000)
        o allow configure to see include/port/win32 include files
        o add matching Win32 accept() prototype
        o allow pg_id to compile with native Win32 API
        o fix invalide mbvalidate() function calls (existing bug)
        o allow /scripts to compile with native Win32 API
        o add win32.c to Win32 compiles (already in *.mak files)

config/ac_func_accept_argtypes.m4
configure
configure.in
src/bin/pg_id/pg_id.c
src/bin/pg_resetxlog/pg_resetxlog.c
src/bin/psql/describe.c
src/bin/psql/mbprint.c
src/bin/scripts/Makefile
src/bin/scripts/common.c
src/include/pg_config.h.in
src/interfaces/libpq/Makefile

index f22d90565991bd8646ee7242955597d2618a8fdd..c0fd06d2ecccd66b83d56814496967a585f831b3 100644 (file)
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/config/ac_func_accept_argtypes.m4,v 1.4 2002/03/29 17:32:53 petere Exp $
+# $Header: /cvsroot/pgsql/config/ac_func_accept_argtypes.m4,v 1.5 2003/09/07 03:43:53 momjian Exp $
 # This comes from the official Autoconf macro archive at
 # <http://research.cys.de/autoconf-archive/>
 # (I removed the $ before the Id CVS keyword below.)
@@ -7,9 +7,10 @@
 dnl @synopsis AC_FUNC_ACCEPT_ARGTYPES
 dnl
 dnl Checks the data types of the three arguments to accept(). Results are
-dnl placed into the symbols ACCEPT_TYPE_ARG[123], consistent with the
-dnl following example:
+dnl placed into the symbols ACCEPT_TYPE_RETURN and ACCEPT_TYPE_ARG[123], 
+dnl consistent with the following example:
 dnl
+dnl       #define ACCEPT_TYPE_RETURN int
 dnl       #define ACCEPT_TYPE_ARG1 int
 dnl       #define ACCEPT_TYPE_ARG2 struct sockaddr *
 dnl       #define ACCEPT_TYPE_ARG3 socklen_t
@@ -36,24 +37,29 @@ dnl
 # Solaris 7 and 8 have arg3 as 'void *' (disguised as 'Psocklen_t'
 # which is *not* 'socklen_t *').  If we detect that, then we assume
 # 'int' as the result, because that ought to work best.
+#
+# On Win32, accept() returns 'unsigned int PASCAL' 
 
 AC_DEFUN([AC_FUNC_ACCEPT_ARGTYPES],
 [AC_MSG_CHECKING([types of arguments for accept()])
- AC_CACHE_VAL(ac_cv_func_accept_arg1,dnl
- [AC_CACHE_VAL(ac_cv_func_accept_arg2,dnl
-  [AC_CACHE_VAL(ac_cv_func_accept_arg3,dnl
-   [for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
-     for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
-      for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
-       AC_TRY_COMPILE(
+ AC_CACHE_VAL(ac_cv_func_accept_return,dnl
+ [AC_CACHE_VAL(ac_cv_func_accept_arg1,dnl
+  [AC_CACHE_VAL(ac_cv_func_accept_arg2,dnl
+   [AC_CACHE_VAL(ac_cv_func_accept_arg3,dnl
+    [for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL'; do
+      for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
+       for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
+        for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
+         AC_TRY_COMPILE(
 [#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
-extern int accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *);],
-        [], [ac_not_found=no; break 3], [ac_not_found=yes])
+extern $ac_cv_func_accept_return accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *);],
+         [], [ac_not_found=no; break 4], [ac_not_found=yes])
+       done
       done
      done
     done
@@ -63,10 +69,13 @@ extern int accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func
     if test "$ac_cv_func_accept_arg3" = "void"; then
       ac_cv_func_accept_arg3=int
     fi
+    ])dnl AC_CACHE_VAL
    ])dnl AC_CACHE_VAL
   ])dnl AC_CACHE_VAL
  ])dnl AC_CACHE_VAL
- AC_MSG_RESULT([$ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *])
+ AC_MSG_RESULT([$ac_cv_func_accept_return, $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *])
+ AC_DEFINE_UNQUOTED(ACCEPT_TYPE_RETURN, $ac_cv_func_accept_return,
+                    [Define to the return type of 'accept'])
  AC_DEFINE_UNQUOTED(ACCEPT_TYPE_ARG1, $ac_cv_func_accept_arg1,
                     [Define to the type of arg 1 of 'accept'])
  AC_DEFINE_UNQUOTED(ACCEPT_TYPE_ARG2, $ac_cv_func_accept_arg2,
index 15ab9cdcf16babc83e0bca9a1829f9746fcec9e3..be06d57d51d06917a00629380b5cb516217516f7 100755 (executable)
--- a/configure
+++ b/configure
@@ -2370,6 +2370,12 @@ fi
 { echo "$as_me:$LINENO: using CFLAGS=$CFLAGS" >&5
 echo "$as_me: using CFLAGS=$CFLAGS" >&6;}
 
+# We already have this in Makefile.win32, but configure needs it too
+if test "$PORTNAME" = "win32"
+then
+       CPPFLAGS="$CPPFLAGS -Isrc/include/port/win32"
+fi
+
 # Check if the compiler still works with the template settings
 echo "$as_me:$LINENO: checking whether the C compiler still works" >&5
 echo $ECHO_N "checking whether the C compiler still works... $ECHO_C" >&6
@@ -10810,19 +10816,23 @@ _ACEOF
 fi
 echo "$as_me:$LINENO: checking types of arguments for accept()" >&5
 echo $ECHO_N "checking types of arguments for accept()... $ECHO_C" >&6
- if test "${ac_cv_func_accept_arg1+set}" = set; then
+ if test "${ac_cv_func_accept_return+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-   if test "${ac_cv_func_accept_arg2+set}" = set; then
+   if test "${ac_cv_func_accept_arg1+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-    if test "${ac_cv_func_accept_arg3+set}" = set; then
+    if test "${ac_cv_func_accept_arg2+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
-     for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
-     for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
-      for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
-       cat >conftest.$ac_ext <<_ACEOF
+     if test "${ac_cv_func_accept_arg3+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+      for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL'; do
+      for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
+       for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
+        for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
+         cat >conftest.$ac_ext <<_ACEOF
 #line $LINENO "configure"
 #include "confdefs.h"
 #ifdef HAVE_SYS_TYPES_H
@@ -10831,7 +10841,7 @@ else
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
-extern int accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *);
+extern $ac_cv_func_accept_return accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *);
 #ifdef F77_DUMMY_MAIN
 #  ifdef __cplusplus
      extern "C"
@@ -10858,13 +10868,14 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_not_found=no; break 3
+  ac_not_found=no; break 4
 else
   echo "$as_me: failed program was:" >&5
 cat conftest.$ac_ext >&5
 ac_not_found=yes
 fi
 rm -f conftest.$ac_objext conftest.$ac_ext
+       done
       done
      done
     done
 fi
 
 fi
- echo "$as_me:$LINENO: result: $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *" >&5
-echo "${ECHO_T}$ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *" >&6
+
+fi
+ echo "$as_me:$LINENO: result: $ac_cv_func_accept_return, $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *" >&5
+echo "${ECHO_T}$ac_cv_func_accept_return, $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *" >&6
+
+cat >>confdefs.h <<_ACEOF
+#define ACCEPT_TYPE_RETURN $ac_cv_func_accept_return
+_ACEOF
+
 
 cat >>confdefs.h <<_ACEOF
 #define ACCEPT_TYPE_ARG1 $ac_cv_func_accept_arg1
index 1c4ca7fecaf77d7152a252620b568ba80cfe02ca..f08da97faf9ae78ac0a7f71a3c0249578b433fd3 100644 (file)
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.284 2003/09/07 03:36:02 tgl Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.285 2003/09/07 03:43:52 momjian Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -238,6 +238,12 @@ if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
 fi
 AC_MSG_NOTICE([using CFLAGS=$CFLAGS])
 
+# We already have this in Makefile.win32, but configure needs it too
+if test "$PORTNAME" = "win32"
+then
+       CPPFLAGS="$CPPFLAGS -Isrc/include/port/win32"
+fi
+
 # Check if the compiler still works with the template settings
 AC_MSG_CHECKING([whether the C compiler still works])
 AC_TRY_LINK([], [return 0;],
index 739c47a27a3c91dcf8d8e8620255518ee551d666..743bc3d42f2fd4ec84c2f2792276a5217982906f 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/pg_id.c,v 1.23 2003/09/06 01:41:56 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/pg_id.c,v 1.24 2003/09/07 03:43:53 momjian Exp $
  */
 #include "postgres_fe.h"
 
@@ -28,10 +28,19 @@ main(int argc, char *argv[])
                                use_real_uid_flag = 0,
                                limit_user_info = 0;
        const char *username = NULL;
-
+       extern int      optind;
+#ifndef WIN32
        struct passwd *pw;
+#else
+       struct passwd_win32
+       {
+               int pw_uid;
+               char pw_name[128];
+       } pass_win32;
+       struct passwd_win32 *pw = &pass_win32;
 
-       extern int      optind;
+       pw->pw_uid = 1;
+#endif
 
        while ((c = getopt(argc, argv, "nru")) != -1)
        {
@@ -47,13 +56,24 @@ main(int argc, char *argv[])
                                limit_user_info = 1;
                                break;
                        default:
+#ifndef WIN32
                                fprintf(stderr, "Usage: %s [-n] [-r] [-u] [username]\n", argv[0]);
+#else
+                               fprintf(stderr, "Usage: %s [-n] [-r] [-u]\n", argv[0]);
+#endif
                                exit(1);
                }
        }
 
        if (argc - optind >= 1)
+#ifndef WIN32
                username = argv[optind];
+#else
+       {
+               fprintf(stderr, "%s: specifying a username is not supported on this platform\n", argv[0]);
+               exit(1);
+       }       
+#endif
 
        if (name_only_flag && !limit_user_info)
        {
@@ -66,7 +86,7 @@ main(int argc, char *argv[])
                exit(1);
        }
 
-
+#ifndef WIN32
        if (username)
        {
                pw = getpwnam(username);
@@ -86,6 +106,15 @@ main(int argc, char *argv[])
                perror(argv[0]);
                exit(1);
        }
+#else
+       if (!use_real_uid_flag)
+       {
+               fprintf(stderr, "%s: -r must be used on this platform\n", argv[0]);
+               exit(1);
+       }
+
+       GetUserName(pw->pw_name, sizeof(pw->pw_name)-1);
+#endif
 
        if (!limit_user_info)
                printf("uid=%d(%s)\n", (int) pw->pw_uid, pw->pw_name);
index a97460975b6587a2dcc606b52a288734b6809726..49afecc6486dc9acb8ddc6ccd272c042ec3f862b 100644 (file)
@@ -23,7 +23,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.12 2003/08/04 02:40:09 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.13 2003/09/07 03:43:53 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,7 +41,6 @@
 #include "catalog/catversion.h"
 #include "catalog/pg_control.h"
 
-
 /******************** stuff copied from xlog.c ********************/
 
 /* Increment an xlogid/segment pair */
@@ -81,6 +80,8 @@ static void KillExistingXLOG(void);
 static void WriteEmptyXLOG(void);
 static void usage(void);
 
+extern char *optarg;
+
 
 
 int
index 188cc3adf359fbca04c074e62fd2511985f5b11d..fa1743f1001c2b5d4f520a7b27bf2fbe1b46c15c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.84 2003/08/09 01:21:54 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.85 2003/09/07 03:43:53 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "describe.h"
@@ -765,7 +765,7 @@ describeOneTableDetails(const char *schemaname,
        {
                /* Name */
 #ifdef WIN32
-               cells[i * cols + 0] = mbvalidate(PQgetvalue(res, i, 0));
+               cells[i * cols + 0] = mbvalidate(PQgetvalue(res, i, 0), myopt.encoding);
 #else
                cells[i * cols + 0] = PQgetvalue(res, i, 0);    /* don't free this
                                                                                                                 * afterwards */
@@ -773,7 +773,7 @@ describeOneTableDetails(const char *schemaname,
 
                /* Type */
 #ifdef WIN32
-               cells[i * cols + 1] = mbvalidate(PQgetvalue(res, i, 1));
+               cells[i * cols + 1] = mbvalidate(PQgetvalue(res, i, 1), myopt.encoding);
 #else
                cells[i * cols + 1] = PQgetvalue(res, i, 1);    /* don't free this
                                                                                                                 * either */
@@ -797,7 +797,7 @@ describeOneTableDetails(const char *schemaname,
                        }
 
 #ifdef WIN32
-                       cells[i * cols + 2] = xstrdup(mbvalidate(tmpbuf.data));
+                       cells[i * cols + 2] = xstrdup(mbvalidate(tmpbuf.data, myopt.encoding));
 #else
                        cells[i * cols + 2] = xstrdup(tmpbuf.data);
 #endif
@@ -806,7 +806,7 @@ describeOneTableDetails(const char *schemaname,
                /* Description */
                if (verbose)
 #ifdef WIN32
-                       cells[i * cols + cols - 1] = mbvalidate(PQgetvalue(res, i, 5));
+                       cells[i * cols + cols - 1] = mbvalidate(PQgetvalue(res, i, 5), myopt.encoding);
 #else
                        cells[i * cols + cols - 1] = PQgetvalue(res, i, 5);
 #endif
index 8075dfe21ab4ae386eeb5720952ced6c1b205623..ca4ba820f7c1b5410943189857f217f9bd1cf8d4 100644 (file)
@@ -3,10 +3,13 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.10 2003/09/05 02:31:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.11 2003/09/07 03:43:54 momjian Exp $
  */
 
 #include "postgres_fe.h"
+#ifndef PGSCRIPTS
+#include "settings.h"
+#endif
 #include "mbprint.h"
 
 #include "mb/pg_wchar.h"
@@ -334,7 +337,7 @@ mbvalidate(unsigned char *pwcs, int encoding)
                return mb_utf_validate(pwcs);
        else
        {
-#ifdef WIN32
+#if defined(WIN32) && !defined(PGSCRIPTS)
                /*
                 * translate characters to DOS console encoding, e.g. needed for
                 * German umlauts
index 48908645e2d1949b8fbf623847d6af68ad77ac45..ff51db5e3b65cf8be2b3022e101a7b26d75e7d3f 100644 (file)
@@ -5,7 +5,7 @@
 # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/bin/scripts/Makefile,v 1.22 2003/08/08 04:52:21 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Makefile,v 1.23 2003/09/07 03:43:55 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
 
 PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb
 
-override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
+override CPPFLAGS := -DPGSCRIPTS -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
 
 all: submake-libpq submake-backend $(PROGRAMS)
 
index dc27a94477646c93cd4474969e14e8420c3c7107..bb191734d456ef1fa490cd053cbae958f131d8e7 100644 (file)
@@ -5,7 +5,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/bin/scripts/common.c,v 1.4 2003/08/04 00:43:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/scripts/common.c,v 1.5 2003/09/07 03:43:55 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,6 +23,7 @@
 const char *
 get_user_name(const char *progname)
 {
+#ifndef WIN32
        struct passwd *pw;
 
        pw = getpwuid(getuid());
@@ -32,6 +33,12 @@ get_user_name(const char *progname)
                exit(1);
        }
        return pw->pw_name;
+#else
+       static char username[128];      /* remains after function exit */
+
+       GetUserName(username, sizeof(username)-1);
+       return username;
+#endif 
 }
 
 
index 2aa62ea8dc5aeea71065c16971beda00876d5bcf..03874772cd0b38ecf26fb3c4137c738b980b93cd 100644 (file)
@@ -9,6 +9,9 @@
 /* Define to the type of arg 3 of 'accept' */
 #undef ACCEPT_TYPE_ARG3
 
+/* Define to the return type of 'accept' */
+#undef ACCEPT_TYPE_RETURN
+
 /* The alignment requirement of a `double'. */
 #undef ALIGNOF_DOUBLE
 
index cb5d8123f2149c5fced1e4f65ebe35a7ad6cb614..1f7fc77fdd3d2dc02d87eee0f7af5a41d372bb28 100644 (file)
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.92 2003/08/23 04:21:59 petere Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.93 2003/09/07 03:43:57 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -24,6 +24,9 @@ OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
       fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
       dllist.o md5.o ip.o wchar.o encnames.o \
       $(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS))
+ifeq ($(PORTNAME), win32)
+OBJS+=win32.o
+endif
 
 
 # Add libraries that libpq depends (or might depend) on into the