Thread: Win32 patch to allow compilation

Win32 patch to allow compilation

From
Bruce Momjian
Date:
I have applied the following patch to allow Win32 compilation under
MinGW.  The patch includes the following changes:

    Win32 port is now called 'win32' rather than 'win'
    add -lwsock32 on Win32
    make gethostname() be only used when kerberos4 is enabled
    use /port/getopt.c
    new /port/opendir.c routines
    disable GUC unix_socket_group on Win32
    convert some keywords.c symbols to KEYWORD_P to prevent conflict
    create new FCNTL_NONBLOCK macro to turn off socket blocking
    create new /include/port.h file that has /port prototypes, move
      out of c.h
    new /include/port/win32_include dir to hold missing include files
    work around ERROR being defined in Win32 includes

As I said on hackers, these changes are minor.

This patch passes all compile/regression tests under Unix.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure
===================================================================
RCS file: /cvsroot/pgsql-server/configure,v
retrieving revision 1.258
diff -c -c -r1.258 configure
*** configure    10 May 2003 04:03:36 -0000    1.258
--- configure    15 May 2003 16:16:51 -0000
***************
*** 1393,1399 ****
      hpux*) template=hpux ;;
      irix*) template=irix5 ;;
     linux*) template=linux ;;
!    mingw*) template=win ;;
    netbsd*) template=netbsd ;;
  nextstep*) template=nextstep ;;
   openbsd*) template=openbsd ;;
--- 1393,1399 ----
      hpux*) template=hpux ;;
      irix*) template=irix5 ;;
     linux*) template=linux ;;
!    mingw*) template=win32 ;;
    netbsd*) template=netbsd ;;
  nextstep*) template=nextstep ;;
   openbsd*) template=openbsd ;;
***************
*** 2808,2814 ****
  done
  IFS=$ac_save_IFS

-
  #
  # Tcl/Tk
  #
--- 2808,2813 ----
***************
*** 5236,5241 ****
--- 5235,5299 ----

  fi

+
+ echo "$as_me:$LINENO: checking for main in -lwsock32" >&5
+ echo $ECHO_N "checking for main in -lwsock32... $ECHO_C" >&6
+ if test "${ac_cv_lib_wsock32_main+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   ac_check_lib_save_LIBS=$LIBS
+ LIBS="-lwsock32  $LIBS"
+ cat >conftest.$ac_ext <<_ACEOF
+ #line $LINENO "configure"
+ #include "confdefs.h"
+
+
+ #ifdef F77_DUMMY_MAIN
+ #  ifdef __cplusplus
+      extern "C"
+ #  endif
+    int F77_DUMMY_MAIN() { return 1; }
+ #endif
+ int
+ main ()
+ {
+ main ();
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext conftest$ac_exeext
+ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+   (eval $ac_link) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+          { ac_try='test -s conftest$ac_exeext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   ac_cv_lib_wsock32_main=yes
+ else
+   echo "$as_me: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ ac_cv_lib_wsock32_main=no
+ fi
+ rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+ LIBS=$ac_check_lib_save_LIBS
+ fi
+ echo "$as_me:$LINENO: result: $ac_cv_lib_wsock32_main" >&5
+ echo "${ECHO_T}$ac_cv_lib_wsock32_main" >&6
+ if test $ac_cv_lib_wsock32_main = yes; then
+   cat >>confdefs.h <<_ACEOF
+ #define HAVE_LIBWSOCK32 1
+ _ACEOF
+
+   LIBS="-lwsock32 $LIBS"
+
+ fi
+
  echo "$as_me:$LINENO: checking for library containing getopt_long" >&5
  echo $ECHO_N "checking for library containing getopt_long... $ECHO_C" >&6
  if test "${ac_cv_search_getopt_long+set}" = set; then
***************
*** 6072,6077 ****
--- 6130,6214 ----
     { (exit 1); exit 1; }; }
  fi

+
+ for ac_func in gethostname
+ do
+ as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ echo "$as_me:$LINENO: checking for $ac_func" >&5
+ echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+ if eval "test \"\${$as_ac_var+set}\" = set"; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   cat >conftest.$ac_ext <<_ACEOF
+ #line $LINENO "configure"
+ #include "confdefs.h"
+ /* System header to define __stub macros and hopefully few prototypes,
+     which can conflict with char $ac_func (); below.  */
+ #include <assert.h>
+ /* Override any gcc2 internal prototype to avoid an error.  */
+ #ifdef __cplusplus
+ extern "C"
+ #endif
+ /* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+ char $ac_func ();
+ char (*f) ();
+
+ #ifdef F77_DUMMY_MAIN
+ #  ifdef __cplusplus
+      extern "C"
+ #  endif
+    int F77_DUMMY_MAIN() { return 1; }
+ #endif
+ int
+ main ()
+ {
+ /* The GNU C library defines this for functions which it implements
+     to always fail with ENOSYS.  Some functions are actually named
+     something starting with __ and the normal name is an alias.  */
+ #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+ choke me
+ #else
+ f = $ac_func;
+ #endif
+
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext conftest$ac_exeext
+ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+   (eval $ac_link) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+          { ac_try='test -s conftest$ac_exeext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   eval "$as_ac_var=yes"
+ else
+   echo "$as_me: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ eval "$as_ac_var=no"
+ fi
+ rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+ fi
+ echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+ echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+ if test `eval echo '${'$as_ac_var'}'` = yes; then
+   cat >>confdefs.h <<_ACEOF
+ #define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+ _ACEOF
+
+ else
+   LIBOBJS="$LIBOBJS $ac_func.$ac_objext"
+ fi
+ done
+
+
  fi

  if test "$with_krb5" = yes ; then
***************
*** 11080,11086 ****



! for ac_func in crypt fseeko gethostname getopt_long getrusage inet_aton random rint srandom strcasecmp strdup
strerrorstrtol strtoul 
  do
  as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
  echo "$as_me:$LINENO: checking for $ac_func" >&5
--- 11217,11223 ----



! for ac_func in crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror
strtolstrtoul 
  do
  as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
  echo "$as_me:$LINENO: checking for $ac_func" >&5
***************
*** 11258,11266 ****
  esac

  # Win32 can't to rename or unlink on an open file
! case $host_os in win32*)
! LIBOBJS="$LIBOBJS dirmod.$ac_objext"
! LIBOBJS="$LIBOBJS opendir.$ac_objext" ;;
  esac

  if test "$with_readline" = yes; then
--- 11395,11402 ----
  esac

  # Win32 can't to rename or unlink on an open file
! case $host_os in win32*|mingw*)
! LIBOBJS="$LIBOBJS dirmod.$ac_objext" ;;
  esac

  if test "$with_readline" = yes; then
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.249
diff -c -c -r1.249 configure.in
*** configure.in    10 May 2003 04:03:37 -0000    1.249
--- configure.in    15 May 2003 16:16:52 -0000
***************
*** 65,71 ****
      hpux*) template=hpux ;;
      irix*) template=irix5 ;;
     linux*) template=linux ;;
!    mingw*) template=win ;;
    netbsd*) template=netbsd ;;
  nextstep*) template=nextstep ;;
   openbsd*) template=openbsd ;;
--- 65,71 ----
      hpux*) template=hpux ;;
      irix*) template=irix5 ;;
     linux*) template=linux ;;
!    mingw*) template=win32 ;;
    netbsd*) template=netbsd ;;
  nextstep*) template=nextstep ;;
   openbsd*) template=openbsd ;;
***************
*** 319,325 ****
  done
  IFS=$ac_save_IFS

-
  #
  # Tcl/Tk
  #
--- 319,324 ----
***************
*** 607,612 ****
--- 606,612 ----
  AC_CHECK_LIB(gen,      main)
  AC_CHECK_LIB(PW,       main)
  AC_CHECK_LIB(resolv,   main)
+ AC_CHECK_LIB(wsock32,   main)
  AC_SEARCH_LIBS(getopt_long, [getopt gnugetopt])
  # QNX:
  AC_CHECK_LIB(unix, main)
***************
*** 639,644 ****
--- 639,645 ----
  if test "$with_krb4" = yes ; then
    AC_CHECK_LIB(des, des_encrypt, [], [AC_MSG_ERROR([library 'des' is required for Kerberos 4])])
    AC_CHECK_LIB(krb, krb_sendauth, [], [AC_MSG_ERROR([library 'krb' is required for Kerberos 4])])
+   AC_REPLACE_FUNCS([gethostname])
  fi

  if test "$with_krb5" = yes ; then
***************
*** 839,845 ****
    AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
  fi

! AC_REPLACE_FUNCS([crypt fseeko gethostname getopt_long getrusage inet_aton random rint srandom strcasecmp strdup
strerrorstrtol strtoul]) 

  # system's version of getaddrinfo(), if any, may be used only if we found
  # a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
--- 840,846 ----
    AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
  fi

! AC_REPLACE_FUNCS([crypt fseeko getopt getopt_long getrusage inet_aton random rint srandom strcasecmp strdup strerror
strtolstrtoul]) 

  # system's version of getaddrinfo(), if any, may be used only if we found
  # a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
***************
*** 862,870 ****
  esac

  # Win32 can't to rename or unlink on an open file
! case $host_os in win32*)
! AC_LIBOBJ(dirmod)
! AC_LIBOBJ(opendir) ;;
  esac

  if test "$with_readline" = yes; then
--- 863,870 ----
  esac

  # Win32 can't to rename or unlink on an open file
! case $host_os in win32*|mingw*)
! AC_LIBOBJ(dirmod) ;;
  esac

  if test "$with_readline" = yes; then
Index: doc/TODO
===================================================================
RCS file: /cvsroot/pgsql-server/doc/TODO,v
retrieving revision 1.1031
diff -c -c -r1.1031 TODO
*** doc/TODO    2 Apr 2003 22:44:50 -0000    1.1031
--- doc/TODO    15 May 2003 16:16:54 -0000
***************
*** 1,6 ****
  TODO list for PostgreSQL
  ========================
! Last updated:        Wed Apr  2 17:44:34 EST 2003

  Current maintainer:    Bruce Momjian (pgman@candle.pha.pa.us)

--- 1,6 ----
  TODO list for PostgreSQL
  ========================
! Last updated:        Thu May 15 12:10:39 EDT 2003

  Current maintainer:    Bruce Momjian (pgman@candle.pha.pa.us)

Index: src/backend/libpq/be-secure.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/libpq/be-secure.c,v
retrieving revision 1.31
diff -c -c -r1.31 be-secure.c
*** src/backend/libpq/be-secure.c    25 Apr 2003 04:37:23 -0000    1.31
--- src/backend/libpq/be-secure.c    15 May 2003 16:16:55 -0000
***************
*** 85,100 ****
  #include "libpq/libpq.h"
  #include "miscadmin.h"

- #ifdef WIN32
- #include "win32.h"
- #else
  #include <sys/socket.h>
  #include <unistd.h>
  #include <netdb.h>
  #include <netinet/in.h>
  #ifdef HAVE_NETINET_TCP_H
  #include <netinet/tcp.h>
- #endif
  #include <arpa/inet.h>
  #endif

--- 85,96 ----
Index: src/backend/libpq/pqcomm.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/libpq/pqcomm.c,v
retrieving revision 1.152
diff -c -c -r1.152 pqcomm.c
*** src/backend/libpq/pqcomm.c    25 Apr 2003 01:24:00 -0000    1.152
--- src/backend/libpq/pqcomm.c    15 May 2003 16:16:56 -0000
***************
*** 357,362 ****
--- 357,365 ----
      Assert(Unix_socket_group);
      if (Unix_socket_group[0] != '\0')
      {
+ #ifdef WIN32
+         elog(FATAL, "Config value 'unix_socket_group' not supported on this platform");
+ #else
          char       *endptr;
          unsigned long int val;
          gid_t        gid;
***************
*** 385,390 ****
--- 388,394 ----
                   sock_path, strerror(errno));
              return STATUS_ERROR;
          }
+ #endif
      }

      if (chmod(sock_path, Unix_socket_permissions) == -1)
Index: src/backend/main/main.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/main/main.c,v
retrieving revision 1.56
diff -c -c -r1.56 main.c
*** src/backend/main/main.c    8 Nov 2002 20:23:56 -0000    1.56
--- src/backend/main/main.c    15 May 2003 16:16:56 -0000
***************
*** 159,171 ****
                strcmp(argv[1], "--version") == 0 ||
                strcmp(argv[1], "-V") == 0)))
      {
          /*
           * Make sure we are not running as root.
           *
           * BeOS currently runs everything as root :-(, so this check must be
           * temporarily disabled there...
           */
- #ifndef __BEOS__
          if (geteuid() == 0)
          {
              fprintf(stderr, gettext(
--- 159,172 ----
                strcmp(argv[1], "--version") == 0 ||
                strcmp(argv[1], "-V") == 0)))
      {
+ #ifndef WIN32
+ #ifndef __BEOS__
          /*
           * Make sure we are not running as root.
           *
           * BeOS currently runs everything as root :-(, so this check must be
           * temporarily disabled there...
           */
          if (geteuid() == 0)
          {
              fprintf(stderr, gettext(
***************
*** 176,182 ****
                                      ));
              exit(1);
          }
! #endif   /* __BEOS__ */

          /*
           * Also make sure that real and effective uids are the same.
--- 177,183 ----
                                      ));
              exit(1);
          }
! #endif   /* !__BEOS__ */

          /*
           * Also make sure that real and effective uids are the same.
***************
*** 193,198 ****
--- 194,200 ----
                      argv[0]);
              exit(1);
          }
+ #endif    /* !WIN32 */
      }

      /*
***************
*** 221,226 ****
--- 223,229 ----
       * specifying current userid as the "authenticated" Postgres user
       * name.
       */
+ #ifndef WIN32
      pw = getpwuid(geteuid());
      if (pw == NULL)
      {
***************
*** 230,235 ****
--- 233,250 ----
      }
      /* Allocate new memory because later getpwuid() calls can overwrite it */
      pw_name_persist = strdup(pw->pw_name);
+ #else
+     {
+         long namesize = 256 /* UNLEN */ + 1;
+
+         pw_name_persist = malloc(namesize);
+         if (!GetUserName(pw_name_persist, &namesize))
+         {
+             fprintf(stderr, "%s: GetUserName failed\n", argv[0]);
+             exit(1);
+         }
+     }
+ #endif

      exit(PostgresMain(argc, new_argv, pw_name_persist));
  }
Index: src/backend/parser/gram.y
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/parser/gram.y,v
retrieving revision 2.413
diff -c -c -r2.413 gram.y
*** src/backend/parser/gram.y    4 May 2003 00:03:55 -0000    2.413
--- src/backend/parser/gram.y    15 May 2003 16:17:01 -0000
***************
*** 322,333 ****
   */

  /* ordinary key words in alphabetical order */
! %token <keyword> ABORT_P ABSOLUTE ACCESS ACTION ADD AFTER
      AGGREGATE ALL ALTER ANALYSE ANALYZE AND ANY ARRAY AS ASC
      ASSERTION ASSIGNMENT AT AUTHORIZATION

      BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
!     BOOLEAN BOTH BY

      CACHE CALLED CASCADE CASE CAST CHAIN CHAR_P
      CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
--- 322,333 ----
   */

  /* ordinary key words in alphabetical order */
! %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD AFTER
      AGGREGATE ALL ALTER ANALYSE ANALYZE AND ANY ARRAY AS ASC
      ASSERTION ASSIGNMENT AT AUTHORIZATION

      BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
!     BOOLEAN_P BOTH BY

      CACHE CALLED CASCADE CASE CAST CHAIN CHAR_P
      CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
***************
*** 336,344 ****
      CREATEUSER CROSS CURRENT_DATE CURRENT_TIME
      CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE

!     DATABASE DAY_P DEALLOCATE DEC DECIMAL DECLARE DEFAULT
      DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS
!     DESC DISTINCT DO DOMAIN_P DOUBLE DROP

      EACH ELSE ENCODING ENCRYPTED END_P ESCAPE EXCEPT
      EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
--- 336,344 ----
      CREATEUSER CROSS CURRENT_DATE CURRENT_TIME
      CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE

!     DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT
      DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS
!     DESC DISTINCT DO DOMAIN_P DOUBLE_P DROP

      EACH ELSE ENCODING ENCRYPTED END_P ESCAPE EXCEPT
      EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
***************
*** 351,358 ****
      HANDLER HAVING HOLD HOUR_P

      ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCREMENT
!     INDEX INHERITS INITIALLY INNER_P INOUT INPUT
!     INSENSITIVE INSERT INSTEAD INT INTEGER INTERSECT
      INTERVAL INTO INVOKER IS ISNULL ISOLATION

      JOIN
--- 351,358 ----
      HANDLER HAVING HOLD HOUR_P

      ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCREMENT
!     INDEX INHERITS INITIALLY INNER_P INOUT INPUT_P
!     INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT
      INTERVAL INTO INVOKER IS ISNULL ISOLATION

      JOIN
***************
*** 373,390 ****
      ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNER

      PARTIAL PASSWORD PATH_P PENDANT PLACING POSITION
!     PRECISION PRESERVE PREPARE PRIMARY PRIOR PRIVILEGES PROCEDURAL
!     PROCEDURE

!     READ REAL RECHECK REFERENCES REINDEX RELATIVE RENAME REPLACE
      RESET RESTART RESTRICT RETURNS REVOKE RIGHT ROLLBACK ROW ROWS
      RULE

      SCHEMA SCROLL SECOND_P SECURITY SELECT SEQUENCE
      SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
      SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT
!     STATISTICS STDIN STDOUT STORAGE STRICT SUBSTRING
!     SYSID

      TABLE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP
      TO TOAST TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
--- 373,389 cvs server: src/backend/port/dynloader/win.c was removed, no comparison available----
      ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNER

      PARTIAL PASSWORD PATH_P PENDANT PLACING POSITION
!     PRECISION PRESERVE PREPARE PRIMARY
!     PRIOR PRIVILEGES PROCEDURAL PROCEDURE

!     READ REAL RECHECK REFERENCES REINDEX RELATIVE_P RENAME REPLACE
      RESET RESTART RESTRICT RETURNS REVOKE RIGHT ROLLBACK ROW ROWS
      RULE

      SCHEMA SCROLL SECOND_P SECURITY SELECT SEQUENCE
      SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
      SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT
!     STATISTICS STDIN STDOUT STORAGE STRICT_P SUBSTRING SYSID

      TABLE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP
      TO TOAST TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
***************
*** 2675,2688 ****
                      n->howMany = -1;
                      $$ = (Node *)n;
                  }
!             | ABSOLUTE fetch_count
                  {
                      FetchStmt *n = makeNode(FetchStmt);
                      n->direction = FETCH_ABSOLUTE;
                      n->howMany = $2;
                      $$ = (Node *)n;
                  }
!             | RELATIVE fetch_count
                  {
                      FetchStmt *n = makeNode(FetchStmt);
                      n->direction = FETCH_RELATIVE;
--- 2674,2687 ----
                      n->howMany = -1;
                      $$ = (Node *)n;
                  }
!             | ABSOLUTE_P fetch_count
                  {
                      FetchStmt *n = makeNode(FetchStmt);
                      n->direction = FETCH_ABSOLUTE;
                      n->howMany = $2;
                      $$ = (Node *)n;
                  }
!             | RELATIVE_P fetch_count
                  {
                      FetchStmt *n = makeNode(FetchStmt);
                      n->direction = FETCH_RELATIVE;
***************
*** 3146,3160 ****
                  {
                      $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
                  }
!             | CALLED ON NULL_P INPUT
                  {
                      $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
                  }
!             | RETURNS NULL_P ON NULL_P INPUT
                  {
                      $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
                  }
!             | STRICT
                  {
                      $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
                  }
--- 3145,3159 ----
                  {
                      $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
                  }
!             | CALLED ON NULL_P INPUT_P
                  {
                      $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
                  }
!             | RETURNS NULL_P ON NULL_P INPUT_P
                  {
                      $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
                  }
!             | STRICT_P
                  {
                      $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
                  }
***************
*** 5077,5083 ****
   * Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
   * - thomas 1997-09-18
   */
! Numeric:    INT
                  {
                      $$ = SystemTypeName("int4");
                  }
--- 5076,5082 ----
   * Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
   * - thomas 1997-09-18
   */
! Numeric:    INT_P
                  {
                      $$ = SystemTypeName("int4");
                  }
***************
*** 5101,5111 ****
                  {
                      $$ = $2;
                  }
!             | DOUBLE PRECISION
                  {
                      $$ = SystemTypeName("float8");
                  }
!             | DECIMAL opt_decimal
                  {
                      $$ = SystemTypeName("numeric");
                      $$->typmod = $2;
--- 5100,5110 ----
                  {
                      $$ = $2;
                  }
!             | DOUBLE_P PRECISION
                  {
                      $$ = SystemTypeName("float8");
                  }
!             | DECIMAL_P opt_decimal
                  {
                      $$ = SystemTypeName("numeric");
                      $$->typmod = $2;
***************
*** 5120,5126 ****
                      $$ = SystemTypeName("numeric");
                      $$->typmod = $2;
                  }
!             | BOOLEAN
                  {
                      $$ = SystemTypeName("bool");
                  }
--- 5119,5125 ----
                      $$ = SystemTypeName("numeric");
                      $$->typmod = $2;
                  }
!             | BOOLEAN_P
                  {
                      $$ = SystemTypeName("bool");
                  }
***************
*** 7179,7185 ****
   */
  unreserved_keyword:
                ABORT_P
!             | ABSOLUTE
              | ACCESS
              | ACTION
              | ADD
--- 7178,7184 ----
   */
  unreserved_keyword:
                ABORT_P
!             | ABSOLUTE_P
              | ACCESS
              | ACTION
              | ADD
***************
*** 7222,7228 ****
              | DELIMITER
              | DELIMITERS
              | DOMAIN_P
!             | DOUBLE
              | DROP
              | EACH
              | ENCODING
--- 7221,7227 ----
              | DELIMITER
              | DELIMITERS
              | DOMAIN_P
!             | DOUBLE_P
              | DROP
              | EACH
              | ENCODING
***************
*** 7248,7254 ****
              | INDEX
              | INHERITS
              | INOUT
!             | INPUT
              | INSENSITIVE
              | INSERT
              | INSTEAD
--- 7247,7253 ----
              | INDEX
              | INHERITS
              | INOUT
!             | INPUT_P
              | INSENSITIVE
              | INSERT
              | INSTEAD
***************
*** 7299,7305 ****
              | READ
              | RECHECK
              | REINDEX
!             | RELATIVE
              | RENAME
              | REPLACE
              | RESET
--- 7298,7304 ----
              | READ
              | RECHECK
              | REINDEX
!             | RELATIVE_P
              | RENAME
              | REPLACE
              | RESET
***************
*** 7328,7335 ****
              | STDIN
              | STDOUT
              | STORAGE
-             | STRICT
              | SYSID
              | TEMP
              | TEMPLATE
              | TEMPORARY
--- 7327,7334 ----
              | STDIN
              | STDOUT
              | STORAGE
              | SYSID
+             | STRICT_P
              | TEMP
              | TEMPLATE
              | TEMPORARY
***************
*** 7374,7390 ****
  col_name_keyword:
                BIGINT
              | BIT
!             | BOOLEAN
              | CHAR_P
              | CHARACTER
              | COALESCE
              | CONVERT
              | DEC
!             | DECIMAL
              | EXISTS
              | EXTRACT
              | FLOAT_P
!             | INT
              | INTEGER
              | INTERVAL
              | NCHAR
--- 7373,7389 ----
  col_name_keyword:
                BIGINT
              | BIT
!             | BOOLEAN_P
              | CHAR_P
              | CHARACTER
              | COALESCE
              | CONVERT
              | DEC
!             | DECIMAL_P
              | EXISTS
              | EXTRACT
              | FLOAT_P
!             | INT_P
              | INTEGER
              | INTERVAL
              | NCHAR
Index: src/backend/parser/keywords.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/parser/keywords.c,v
retrieving revision 1.138
diff -c -c -r1.138 keywords.c
*** src/backend/parser/keywords.c    8 Apr 2003 23:20:02 -0000    1.138
--- src/backend/parser/keywords.c    15 May 2003 16:17:01 -0000
***************
*** 31,37 ****
  static const ScanKeyword ScanKeywords[] = {
      /* name, value */
      {"abort", ABORT_P},
!     {"absolute", ABSOLUTE},
      {"access", ACCESS},
      {"action", ACTION},
      {"add", ADD},
--- 31,37 ----
  static const ScanKeyword ScanKeywords[] = {
      /* name, value */
      {"abort", ABORT_P},
!     {"absolute", ABSOLUTE_P},
      {"access", ACCESS},
      {"action", ACTION},
      {"add", ADD},
***************
*** 57,63 ****
      {"bigint", BIGINT},
      {"binary", BINARY},
      {"bit", BIT},
!     {"boolean", BOOLEAN},
      {"both", BOTH},
      {"by", BY},
      {"cache", CACHE},
--- 57,63 ----
      {"bigint", BIGINT},
      {"binary", BINARY},
      {"bit", BIT},
!     {"boolean", BOOLEAN_P},
      {"both", BOTH},
      {"by", BY},
      {"cache", CACHE},
***************
*** 99,105 ****
      {"day", DAY_P},
      {"deallocate", DEALLOCATE},
      {"dec", DEC},
!     {"decimal", DECIMAL},
      {"declare", DECLARE},
      {"default", DEFAULT},
      {"deferrable", DEFERRABLE},
--- 99,105 ----
      {"day", DAY_P},
      {"deallocate", DEALLOCATE},
      {"dec", DEC},
!     {"decimal", DECIMAL_P},
      {"declare", DECLARE},
      {"default", DEFAULT},
      {"deferrable", DEFERRABLE},
***************
*** 112,118 ****
      {"distinct", DISTINCT},
      {"do", DO},
      {"domain", DOMAIN_P},
!     {"double", DOUBLE},
      {"drop", DROP},
      {"each", EACH},
      {"else", ELSE},
--- 112,118 ----
      {"distinct", DISTINCT},
      {"do", DO},
      {"domain", DOMAIN_P},
!     {"double", DOUBLE_P},
      {"drop", DROP},
      {"each", EACH},
      {"else", ELSE},
***************
*** 157,167 ****
      {"initially", INITIALLY},
      {"inner", INNER_P},
      {"inout", INOUT},
!     {"input", INPUT},
      {"insensitive", INSENSITIVE},
      {"insert", INSERT},
      {"instead", INSTEAD},
!     {"int", INT},
      {"integer", INTEGER},
      {"intersect", INTERSECT},
      {"interval", INTERVAL},
--- 157,167 ----
      {"initially", INITIALLY},
      {"inner", INNER_P},
      {"inout", INOUT},
!     {"input", INPUT_P},
      {"insensitive", INSENSITIVE},
      {"insert", INSERT},
      {"instead", INSTEAD},
!     {"int", INT_P},
      {"integer", INTEGER},
      {"intersect", INTERSECT},
      {"interval", INTERVAL},
***************
*** 246,252 ****
      {"recheck", RECHECK},
      {"references", REFERENCES},
      {"reindex", REINDEX},
!     {"relative", RELATIVE},
      {"rename", RENAME},
      {"replace", REPLACE},
      {"reset", RESET},
--- 246,252 ----
      {"recheck", RECHECK},
      {"references", REFERENCES},
      {"reindex", REINDEX},
!     {"relative", RELATIVE_P},
      {"rename", RENAME},
      {"replace", REPLACE
cvs server: src/backend/port/dynloader/win.h was removed, no comparison available
cvs server: src/backend/port/dynloader/win32.c is a new entry, no comparison available
cvs server: src/backend/port/dynloader/win32.h is a new entry, no comparison available
},
      {"reset", RESET},
***************
*** 283,289 ****
      {"stdin", STDIN},
      {"stdout", STDOUT},
      {"storage", STORAGE},
!     {"strict", STRICT},
      {"substring", SUBSTRING},
      {"sysid", SYSID},
      {"table", TABLE},
--- 283,289 ----
      {"stdin", STDIN},
      {"stdout", STDOUT},
      {"storage", STORAGE},
!     {"strict", STRICT_P},
      {"substring", SUBSTRING},
      {"sysid", SYSID},
      {"table", TABLE},
Index: src/backend/port/Makefile
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/port/Makefile,v
retrieving revision 1.18
diff -c -c -r1.18 Makefile
*** src/backend/port/Makefile    27 Jul 2002 20:10:05 -0000    1.18
--- src/backend/port/Makefile    15 May 2003 16:17:01 -0000
***************
*** 26,32 ****
  OBJS+=$(TAS)

  ifeq ($(PORTNAME), qnx4)
! OBJS+=getrusage.o qnx4/SUBSYS.o
  endif
  ifeq ($(PORTNAME), beos)
  OBJS+=beos/SUBSYS.o
--- 26,32 ----
  OBJS+=$(TAS)

  ifeq ($(PORTNAME), qnx4)
! OBJS+=qnx4/SUBSYS.o
  endif
  ifeq ($(PORTNAME), beos)
  OBJS+=beos/SUBSYS.o
***************
*** 34,39 ****
--- 34,42 ----
  ifeq ($(PORTNAME), darwin)
  OBJS+=darwin/SUBSYS.o
  endif
+ ifeq ($(PORTNAME), win32)
+ OBJS+=win32/SUBSYS.o
+ endif

  all: SUBSYS.o

***************
*** 55,60 ****
--- 58,68 ----
  darwin.dir:
      $(MAKE) -C darwin all

+ win32/SUBSYS.o: win32.dir
+
+ win32.dir:
+     $(MAKE) -C win32 all
+
  tas.o: tas.s
      $(CC) $(CFLAGS) -c $<

***************
*** 67,69 ****
--- 75,79 ----
      $(MAKE) -C beos clean
      $(MAKE) -C darwin clean
      $(MAKE) -C qnx4 clean
+     $(MAKE) -C win32 clean
+
Index: src/backend/port/win32/sema.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/port/win32/sema.c,v
retrieving revision 1.1
diff -c -c -r1.1 sema.c
*** src/backend/port/win32/sema.c    24 Apr 2003 21:23:01 -0000    1.1
--- src/backend/port/win32/sema.c    15 May 2003 16:17:01 -0000
***************
*** 10,16 ****

  #include "postgres.h"
  #include "storage/shmem.h"
- #include "sema.h"

  #include <errno.h>

--- 10,15 ----
***************
*** 131,137 ****
      Size        sem_set_size = sizeof(win32_sem_set_hdr) + semNum * (sizeof(HANDLE) + sizeof(int));
      HANDLE       *sem_handles = NULL;
      int           *sem_counts = NULL;
!
      sec_attrs.nLength = sizeof(sec_attrs);
      sec_attrs.lpSecurityDescriptor = NULL;
      sec_attrs.bInheritHandle = TRUE;
--- 130,137 ----
      Size        sem_set_size = sizeof(win32_sem_set_hdr) + semNum * (sizeof(HANDLE) + sizeof(int));
      HANDLE       *sem_handles = NULL;
      int           *sem_counts = NULL;
!     int            i;
!
      sec_attrs.nLength = sizeof(sec_attrs);
      sec_attrs.lpSecurityDescriptor = NULL;
      sec_attrs.bInheritHandle = TRUE;
***************
*** 158,164 ****
      sem_handles = (HANDLE *) ((off_t) new_set + new_set->m_semaphoreHandles);
      sem_counts = (int *) ((off_t) new_set + new_set->m_semaphoreCounts);

!     for (int i = 0; i < semNum && ans; ++i)
      {
          strcpy(num_part, _itoa(i, cur_num, 10));

--- 158,164 ----
      sem_handles = (HANDLE *) ((off_t) new_set + new_set->m_semaphoreHandles);
      sem_counts = (int *) ((off_t) new_set + new_set->m_semaphoreCounts);

!     for (i = 0; i < semNum && ans; ++i)
      {
          strcpy(num_part, _itoa(i, cur_num, 10));

***************
*** 186,193 ****
          return MAKE_OFFSET(new_set);
      else
      {
          /* Blow away what we've got right now... */
!         for (int i = 0; i < semNum; ++i)
          {
              if (sem_handles[i])
                  CloseHandle(sem_handles[i]);
--- 186,194 ----
          return MAKE_OFFSET(new_set);
      else
      {
+         int i;
          /* Blow away what we've got right now... */
!         for (i = 0; i < semNum; ++i)
          {
              if (sem_handles[i])
                  CloseHandle(sem_handles[i]);
Index: src/backend/postmaster/pgstat.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/postmaster/pgstat.c,v
retrieving revision 1.35
diff -c -c -r1.35 pgstat.c
*** src/backend/postmaster/pgstat.c    27 Apr 2003 20:09:44 -0000    1.35
--- src/backend/postmaster/pgstat.c    15 May 2003 16:17:03 -0000
***************
*** 217,223 ****
       * messages will be discarded; backends won't block waiting to send
       * messages to the collector.
       */
!     if (fcntl(pgStatSock, F_SETFL, O_NONBLOCK) < 0)
      {
          elog(LOG, "PGSTAT: fcntl() failed: %m");
          goto startup_failed;
--- 217,223 ----
       * messages will be discarded; backends won't block waiting to send
       * messages to the collector.
       */
!     if (FCNTL_NONBLOCK(pgStatSock) < 0)
      {
          elog(LOG, "PGSTAT: fcntl() failed: %m");
          goto startup_failed;
***************
*** 1520,1526 ****
       * Set the write pipe to nonblock mode, so that we cannot block when
       * the collector falls behind.
       */
!     if (fcntl(writePipe, F_SETFL, O_NONBLOCK) < 0)
      {
          elog(LOG, "PGSTATBUFF: fcntl() failed: %m");
          exit(1);
--- 1520,1526 ----
       * Set the write pipe to nonblock mode, so that we cannot block when
       * the collector falls behind.
       */
!     if (FCNTL_NONBLOCK(writePipe) < 0)
      {
          elog(LOG, "PGSTATBUFF: fcntl() failed: %m");
          exit(1);
Index: src/backend/postmaster/postmaster.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v
retrieving revision 1.327
diff -c -c -r1.327 postmaster.c
*** src/backend/postmaster/postmaster.c    10 May 2003 18:15:42 -0000    1.327
--- src/backend/postmaster/postmaster.c    15 May 2003 16:17:05 -0000
***************
*** 211,216 ****
--- 211,221 ----
  bool        Log_connections = false;
  bool        Db_user_namespace = false;

+ /* For FNCTL_NONBLOCK */
+ #if defined(WIN32) || defined(__BEOS__)
+ long ioctlsocket_ret;
+ #endif
+
  /* list of library:init-function to be preloaded */
  char       *preload_libraries_string = NULL;

***************
*** 1708,1713 ****
--- 1713,1721 ----
  {
      int            save_errno = errno;

+ #ifdef WIN32
+ #warning fix waidpid for Win32
+ #else
  #ifdef HAVE_WAITPID
      int            status;            /* backend exit status */

***************
*** 1807,1812 ****
--- 1815,1821 ----
          CleanupProc(pid, exitstatus);

      } /* loop over pending child-death reports */
+ #endif

      if (FatalError)
      {
***************
*** 2141,2163 ****
  {
      char        buffer[1000];

- #ifdef __BEOS__
-     int            on = 1;
- #endif
-
      /* Format the error message packet */
      snprintf(buffer, sizeof(buffer), "E%s%s\n",
               gettext("Server process fork() failed: "),
               strerror(errnum));

      /* Set port to non-blocking.  Don't do send() if this fails */
! #ifdef __BEOS__
!     if (ioctl(port->sock, FIONBIO, &on) != 0)
          return;
- #else
-     if (fcntl(port->sock, F_SETFL, O_NONBLOCK) < 0)
-         return;
- #endif

      send(port->sock, buffer, strlen(buffer) + 1, 0);
  }
--- 2150,2163 ----
  {
      char        buffer[1000];

      /* Format the error message packet */
      snprintf(buffer, sizeof(buffer), "E%s%s\n",
               gettext("Server process fork() failed: "),
               strerror(errnum));

      /* Set port to non-blocking.  Don't do send() if this fails */
!     if (FCNTL_NONBLOCK(port->sock) < 0)
          return;

      send(port->sock, buffer, strlen(buffer) + 1, 0);
  }
Index: src/backend/storage/lmgr/proc.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/storage/lmgr/proc.c,v
retrieving revision 1.129
diff -c -c -r1.129 proc.c
*** src/backend/storage/lmgr/proc.c    18 Feb 2003 02:13:24 -0000    1.129
--- src/backend/storage/lmgr/proc.c    15 May 2003 16:17:07 -0000
***************
*** 944,949 ****
--- 944,952 ----
  bool
  enable_sig_alarm(int delayms, bool is_statement_timeout)
  {
+ #ifdef WIN32
+ # warning add Win32 timer
+ #else
      struct timeval fin_time;
  #ifndef __BEOS__
      struct itimerval timeval;
***************
*** 1012,1018 ****
      if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
          return false;
  #endif
!
      return true;
  }

--- 1015,1021 ----
      if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
          return false;
  #endif
! #endif
      return true;
  }

***************
*** 1026,1031 ****
--- 1029,1037 ----
  bool
  disable_sig_alarm(bool is_statement_timeout)
  {
+ #ifdef WIN32
+ #warning add Win32 timer
+ #else
      /*
       * Always discvs server: src/include/port.h is a new entry, no comparison available
able the interrupt if it is active; this avoids being
       * interrupted by the signal handler and thereby possibly getting
***************
*** 1065,1071 ****
          if (!CheckStatementTimeout())
              return false;
      }
!
      return true;
  }

--- 1071,1077 ----
          if (!CheckStatementTimeout())
              return false;
      }
! #endif
      return true;
  }

***************
*** 1098,1103 ****
--- 1104,1112 ----
      else
      {
          /* Not time yet, so (re)schedule the interrupt */
+ #ifdef WIN32
+ #warning add win32 timer
+ #else
  #ifndef __BEOS__
          struct itimerval timeval;

***************
*** 1120,1125 ****
--- 1129,1135 ----
              (statement_fin_time.tv_usec - now.tv_usec);
          if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
              return false;
+ #endif
  #endif
      }

Index: src/backend/utils/init/findbe.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/utils/init/findbe.c,v
retrieving revision 1.32
diff -c -c -r1.32 findbe.c
*** src/backend/utils/init/findbe.c    4 Apr 2003 20:42:12 -0000    1.32
--- src/backend/utils/init/findbe.c    15 May 2003 16:17:07 -0000
***************
*** 44,52 ****
--- 44,54 ----
  ValidateBinary(char *path)
  {
      struct stat buf;
+ #ifndef WIN32
      uid_t        euid;
      struct group *gp;
      struct passwd *pwp;
+ #endif
      int            i;
      int            is_r = 0;
      int            is_x = 0;
***************
*** 82,87 ****
--- 84,94 ----
       * Ensure that the file is both executable and readable (required for
       * dynamic loading).
       */
+ #ifdef WIN32
+         is_r = buf.st_mode & S_IRUSR;
+         is_x = buf.st_mode & S_IXUSR;
+         return is_x ? (is_r ? 0 : -2) : -1;
+ #else
      euid = geteuid();
      if (euid == buf.st_uid)
      {
***************
*** 125,130 ****
--- 132,138 ----
          elog(DEBUG2, "ValidateBinary: \"%s\" is not other read/execute",
               path);
      return is_x ? (is_r ? 0 : -2) : -1;
+ #endif
  }

  /*
Index: src/backend/utils/mb/encnames.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/utils/mb/encnames.c,v
retrieving revision 1.12
diff -c -c -r1.12 encnames.c
*** src/backend/utils/mb/encnames.c    10 Mar 2003 22:28:18 -0000    1.12
--- src/backend/utils/mb/encnames.c    15 May 2003 16:17:07 -0000
***************
*** 13,23 ****
  #include "utils/builtins.h"
  #endif

- #ifdef WIN32
- #include "win32.h"
- #else
  #include <unistd.h>
- #endif

  #include "mb/pg_wchar.h"
  #include <ctype.h>
--- 13,19 ----
Index: src/include/c.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/c.h,v
retrieving revision 1.144
diff -c -c -r1.144 c.h
*** src/include/c.h    9 May 2003 16:59:43 -0000    1.144
--- src/include/c.h    15 May 2003 16:17:09 -0000
***************
*** 52,58 ****

  #include "pg_config.h"
  #include "pg_config_manual.h"    /* must be after pg_config.h */
- #include "pg_config_os.h"
  #include "postgres_ext.h"

  #include <stdio.h>
--- 52,57 ----
***************
*** 66,76 ****
  #include <sys/types.h>

  #include <errno.h>
! #include <sys/fcntl.h>            /* ensure O_BINARY is available */
  #ifdef HAVE_SUPPORTDEFS_H
  #include <SupportDefs.h>
  #endif

  /* Must be before gettext() games below */
  #include <locale.h>

--- 65,78 ----
  #include <sys/types.h>

  #include <errno.h>
! #include <fcntl.h>            /* ensure O_BINARY is available */
  #ifdef HAVE_SUPPORTDEFS_H
  #include <SupportDefs.h>
  #endif

+ /* Must be here so we can redefine some functions on Win32 */
+ #include "pg_config_os.h"
+
  /* Must be before gettext() games below */
  #include <locale.h>

***************
*** 696,759 ****
  #define PG_BINARY_W "w"
  #endif

! #if defined(sun) && defined(__sparc__) && !defined(__SVR4)
! #include <unistd.h>
  #endif
!
! /* Portable path handling for Unix/Win32 */
! bool is_absolute_path(const char *filename);
! char *first_path_separator(const char *filename);
! char *last_path_separator(const char *filename);
! char *get_progname(char *argv0);
!
! #if defined(bsdi) || defined(netbsd)
! int fseeko(FILE *stream, off_t offset, int whence);
! off_t ftello(FILE *stream);
  #endif
-
- /*
-  * Win32 doesn't have reliable rename/unlink during concurrent access
-  */
- #if defined(WIN32) && !defined(FRONTEND)
- int pgrename(const char *from, const char *to);
- int pgunlink(const char *path);
- #define rename(path)        pgrename(path)
- #define unlink(from, to)    pgunlink(from, to)
  #endif

! /*
!  * Win32 doesn't have opendir/readdir/closedir()
!  */
! #ifdef WIN32
! struct dirent {
!     ino_t d_ino;                    /* inode (always 1 on WIN32) */
!     char d_name[MAX_PATH + 1];    /* filename (null terminated) */
! };
!
! typedef struct {
!     HANDLE handle;                /* handle for FindFirstFile or
!                                  * FindNextFile */
!     long offset;                /* offset into directory */
!     int finished;                /* 1 if there are not more files */
!     WIN32_FIND_DATA finddata;    /* file data FindFirstFile or FindNextFile
!                                  * returns */
!     char *dir;                    /* the directory path we are reading */
!     struct dirent ent;            /* the dirent to return */
! } DIR;
!
! extern DIR *opendir(const char *);
! extern struct dirent *readdir(DIR *);
! extern int closedir(DIR *);
  #endif

- /*
-  *    Win32 requires a special close for sockets and pipes, while on Unix
-  *    close() does them all.
-  */
- #ifndef WIN32
- #define    closesocket close
- #endif
-
  /* These are for things that are one way on Unix and another on NT */
  #define NULL_DEV        "/dev/null"

--- 698,720 ----
  #define PG_BINARY_W "w"
  #endif

! #if !defined(WIN32) && !defined(__BEOS__)
! #define FCNTL_NONBLOCK(sock)    fcntl(sock, F_SETFL, O_NONBLOCK)
! #else
! extern long ioctlsocket_ret;
! /* Returns non-0 on failure, while fcntl() returns -1 on failure */
! #ifdef WIN32
! #define FCNTL_NONBLOCK(sock)    ((ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0) ? 0 : -1)
  #endif
! #ifdef __BEOS__
! #define FCNTL_NONBLOCK(sock)    ((ioctl(sock, FIONBIO, &ioctlsocket_ret) == 0) ? 0 : -1)
  #endif
  #endif

! #if defined(sun) && defined(__sparc__) && !defined(__SVR4)
! #include <unistd.h>
  #endif

  /* These are for things that are one way on Unix and another on NT */
  #define NULL_DEV        "/dev/null"

***************
*** 795,831 ****
  #endif

  /*
-  * Default "extern" declarations or macro substitutes for library routines.
-  * When necessary, these routines are provided by files in src/port/.
-  */
- #ifndef HAVE_CRYPT
- char *crypt(const char *key, const char *setting);
- #endif
-
- #ifndef HAVE_FSEEKO
- #define fseeko(a, b, c) fseek((a), (b), (c))
- #define ftello(a) ftell((a))
- #endif
-
- #ifndef HAVE_ISINF
- extern int isinf(double x);
- #endif
-
- #ifndef HAVE_GETHOSTNAME
- extern int gethostname(char *name, int namelen);
- #endif
-
- #ifndef HAVE_RINT
- extern double rint(double x);
- #endif
-
- #ifndef HAVE_INET_ATON
- # include <netinet/in.h>
- # include <arpa/inet.h>
- extern int inet_aton(const char *cp, struct in_addr * addr);
- #endif
-
- /*
   * When there is no sigsetjmp, its functionality is provided by plain
   * setjmp. Incidentally, nothing provides setjmp's functionality in
   * that case.
--- 756,761 ----
***************
*** 836,857 ****
  # define siglongjmp longjmp
  #endif

- #ifndef HAVE_STRCASECMP
- extern int strcasecmp(char *s1, char *s2);
- #endif
-
- #ifndef HAVE_STRDUP
- extern char *strdup(char const *);
- #endif
-
- #ifndef HAVE_RANDOM
- extern long random(void);
- #endif
-
- #ifndef HAVE_SRANDOM
- extern void srandom(unsigned int seed);
- #endif
-
  #if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
  extern int fdatasync(int fildes);
  #endif
--- 766,771 ----
***************
*** 867,871 ****
--- 781,788 ----
  # define strtoull strtouq
  # define HAVE_STRTOULL 1
  #endif
+
+ /* /port compatibility functions */
+ #include "port.h"

  #endif   /* C_H */
Index: src/include/pg_config_manual.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/pg_config_manual.h,v
retrieving revision 1.2
diff -c -c -r1.2 pg_config_manual.h
*** src/include/pg_config_manual.h    18 Apr 2003 01:03:42 -0000    1.2
--- src/include/pg_config_manual.h    15 May 2cvs server: src/include/port/win.h was removed, no comparison available
cvs server: src/include/port/win32_include/dlfcn.h is a new entry, no comparison available
cvs server: src/include/port/win32_include/grp.h is a new entry, no comparison available
cvs server: src/include/port/win32_include/netdb.h is a new entry, no comparison available
cvs server: src/include/port/win32_include/pwd.h is a new entry, no comparison available
cvs server: src/include/port/win32_include/netinet/in.h is a new entry, no comparison available
cvs server: src/include/port/win32_include/sys/socket.h is a new entry, no comparison available
cvs server: src/include/port/win32_include/sys/wait.h is a new entry, no comparison available
cvs server: src/makefiles/Makefile.win was removed, no comparison available
cvs server: src/makefiles/Makefile.win32 is a new entry, no comparison available
cvs server: src/port/opendir.c was removed, no comparison available
003 16:17:09 -0000
***************
*** 130,136 ****
   * Define this if your operating system supports AF_UNIX family
   * sockets.
   */
! #if !defined(__QNX__) && !defined(__BEOS__)
  # define HAVE_UNIX_SOCKETS 1
  #endif

--- 130,136 ----
   * Define this if your operating system supports AF_UNIX family
   * sockets.
   */
! #if !defined(__QNX__) && !defined(__BEOS__) && !defined(WIN32)
  # define HAVE_UNIX_SOCKETS 1
  #endif

Index: src/include/rusagestub.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/rusagestub.h,v
retrieving revision 1.10
diff -c -c -r1.10 rusagestub.h
*** src/include/rusagestub.h    20 Jun 2002 20:29:42 -0000    1.10
--- src/include/rusagestub.h    15 May 2003 16:17:09 -0000
***************
*** 15,21 ****
--- 15,23 ----
  #define RUSAGESTUB_H

  #include <sys/time.h>            /* for struct timeval */
+ #ifndef WIN32
  #include <sys/times.h>            /* for struct tms */
+ #endif
  #include <limits.h>                /* for CLK_TCK */

  #define RUSAGE_SELF        0
Index: src/include/port/win32.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/port/win32.h,v
retrieving revision 1.9
diff -c -c -r1.9 win32.h
*** src/include/port/win32.h    29 Apr 2003 18:25:54 -0000    1.9
--- src/include/port/win32.h    15 May 2003 16:17:09 -0000
***************
*** 1,5 ****
--- 1,16 ----
  /* $Header: /cvsroot/pgsql-server/src/include/port/win32.h,v 1.9 2003/04/29 18:25:54 momjian Exp $ */

+ /* undefine and redefine after #include */
+ #undef mkdir
+
+ #undef ERROR
+ #include <windows.h>
+ #undef near
+
+ /* Must be here to avoid conflicting with prototype in windows.h */
+ #define mkdir(a,b)    mkdir(a)
+
+
  #define USES_WINSOCK
  #define NOFILE          100

***************
*** 33,38 ****
--- 44,52 ----
  /*
   *    IPC defines
   */
+ #undef HAVE_UNION_SEMUN
+ #define HAVE_UNION_SEMUN 1
+
  #define IPC_RMID 256
  #define IPC_CREAT 512
  #define IPC_EXCL 1024
***************
*** 40,45 ****
--- 54,67 ----
  #define IPC_NOWAIT    2048
  #define IPC_STAT 4096

+ #define EACCESS 2048
+ #define EIDRM 4096
+
+ #define SETALL 8192
+ #define GETNCNT 16384
+ #define GETVAL 65536
+ #define SETVAL 131072
+ #define GETPID 262144

  /*
   *    Shared memory
***************
*** 77,82 ****
--- 99,128 ----
  int      semget(int semKey, int semNum, int flags);
  int      semop(int semId, struct sembuf * sops, int flag);

+ #define sleep(sec)    (Sleep(sec * 1000), /* no return value */ 0)
+
+ /* Some extra signals */
+ #define SIGHUP                1
+ #define SIGQUIT             3
+ #define SIGTRAP             5
+ #define SIGABRT             22      /* Set to match W32 value -- not UNIX value */
+ #define SIGKILL             9
+ #define SIGPIPE             13
+ #define SIGALRM             14
+ #define SIGSTOP             17
+ #define SIGCONT             19
+ #define SIGCHLD             20
+ #define SIGTTIN             21
+ #define SIGTTOU             22      /* Same as SIGABRT -- no problem, I hope */
+ #define SIGWINCH              28
+ #define SIGUSR1             30
+ #define SIGUSR2             31
+
+ struct timezone
+ {
+     int tz_minuteswest;         /* Minutes west of GMT.  */
+     int tz_dsttime;             /* Nonzero if DST is ever in effect.  */
+ };

  /* FROM SRA */

***************
*** 130,134 ****
   */
  #define snprintf _snprintf
  #define vsnprintf _vsnprintf
-
-
--- 176,178 ----
Index: src/include/utils/elog.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/utils/elog.h,v
retrieving revision 1.41
diff -c -c -r1.41 elog.h
*** src/include/utils/elog.h    24 Apr 2003 21:16:44 -0000    1.41
--- src/include/utils/elog.h    15 May 2003 16:17:10 -0000
***************
*** 35,40 ****
--- 35,49 ----
  #define WARNING        19            /* Warnings */
  #define ERROR        20            /* user error - abort transaction; return
                                   * to known state */
+ #define ERROR        20            /* user error - abort transaction; return
+                                  * to known state */
+ /* Save ERROR value in PGERROR so it can bve restored when Win32 includes
+  * modify it.  We have to use a constant rather than ERROR because macros
+  * are expanded only when referenced outside macros.
+  */
+ #ifdef WIN32
+ #define PGERROR        20
+ #endif
  #define FATAL        21            /* fatal error - abort process */
  #define PANIC        22            /* take down the other backends with me */

Index: src/interfaces/libpq/fe-auth.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/fe-auth.c,v
retrieving revision 1.76
diff -c -c -r1.76 fe-auth.c
*** src/interfaces/libpq/fe-auth.c    19 Apr 2003 00:02:30 -0000    1.76
--- src/interfaces/libpq/fe-auth.c    15 May 2003 16:17:11 -0000
***************
*** 386,395 ****
      /*
       * libpq uses a non-blocking socket. But kerberos needs a blocking
       * socket, and we have to block somehow to do mutual authentication
!      * anyway. So we temporarily make it blocking.
       */
      flags = fcntl(sock, F_GETFL);
!     if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK)))
      {
          snprintf(PQerrormsg, PQERRORMSG_LENGTH,
                   libpq_gettext("could not set socket to blocking mode: %s\n"), strerror(errno));
--- 386,395 ----
      /*
       * libpq uses a non-blocking socket. But kerberos needs a blocking
       * socket, and we have to block somehow to do mutual authentication
!      * anyway. So we temporarily make it blocking.  Win32 doesn't support this.
       */
      flags = fcntl(sock, F_GETFL);
!     if (flags < 0 || fcntl(sock, F_SETFL, flags & ~O_NONBLOCK)))
      {
          snprintf(PQerrormsg, PQERRORMSG_LENGTH,
                   libpq_gettext("could not set socket to blocking mode: %s\n"), strerror(errno));
Index: src/interfaces/libpq/fe-connect.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.240
diff -c -c -r1.240 fe-connect.c
*** src/interfaces/libpq/fe-connect.c    5 May 2003 00:44:56 -0000    1.240
--- src/interfaces/libpq/fe-connect.c    15 May 2003 16:17:13 -0000
***************
*** 719,735 ****
  static int
  connectMakeNonblocking(PGconn *conn)
  {
! #if defined(WIN32) || defined(__BEOS__)
!     int            on = 1;
! #endif
!
! #if defined(WIN32)
!     if (ioctlsocket(conn->sock, FIONBIO, &on) != 0)
! #elif defined(__BEOS__)
!         if (ioctl(conn->sock, FIONBIO, &on) != 0)
! #else
!     if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
! #endif
      {
          printfPQExpBuffer(&conn->errorMessage,
          libpq_gettext("could not set socket to non-blocking mode: %s\n"),
--- 719,725 ----
  static int
  connectMakeNonblocking(PGconn *conn)
  {
!     if (FCNTL_NONBLOCK(conn->sock) < 0)
      {
          printfPQExpBuffer(&conn->errorMessage,
          libpq_gettext("could not set socket to non-blocking mode: %s\n"),
Index: src/port/dirmod.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/port/dirmod.c,v
retrieving revision 1.2
diff -c -c -r1.2 dirmod.c
*** src/port/dirmod.c    24 Apr 2003 16:40:17 -0000    1.2
--- src/port/dirmod.c    15 May 2003 16:17:13 -0000
***************
*** 6,11 ****
--- 6,13 ----

  #ifndef TEST_VERSION

+ #include "postgres.h"
+
  #undef rename
  #undef unlink

Index: src/port/getopt.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/port/getopt.c,v
retrieving revision 1.3
diff -c -c -r1.3 getopt.c
*** src/port/getopt.c    6 Jan 2003 18:53:25 -0000    1.3
--- src/port/getopt.c    15 May 2003 16:17:13 -0000
***************
*** 30,38 ****
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-  * SUCH DAMAGE.
   */

  #if defined(LIBC_SCCS) && !defined(lint)
  static char sccsid[] = "@(#)getopt.c    8.3 (Berkeley) 4/27/95";
  #endif   /* LIBC_SCCS and not lint */
--- 30,40 ----
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   */

+ #include "postgres.h"
+
+
  #if defined(LIBC_SCCS) && !defined(lint)
  statcvs server: src/template/win32 is a new entry, no comparison available
ic char sccsid[] = "@(#)getopt.c    8.3 (Berkeley) 4/27/95";
  #endif   /* LIBC_SCCS and not lint */
***************
*** 92,98 ****
              ++optind;
          if (opterr && *ostr != ':')
              (void) fprintf(stderr,
!                        "%s: illegal option -- %c\n", argv[0], optopt);
          return BADCH;
      }
      if (*++oli != ':')
--- 94,100 ----
              ++optind;
          if (opterr && *ostr != ':')
              (void) fprintf(stderr,
!                        "illegal option -- %c\n", optopt);
          return BADCH;
      }
      if (*++oli != ':')
***************
*** 112,119 ****
                  return BADARG;
              if (opterr)
                  (void) fprintf(stderr,
!                                "%s: option requires an argument -- %c\n",
!                                argv[0], optopt);
              return BADCH;
          }
          else
--- 114,121 ----
                  return BADARG;
              if (opterr)
                  (void) fprintf(stderr,
!                                "option requires an argument -- %c\n",
!                                optopt);
              return BADCH;
          }
          else
Index: src/port/getrusage.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/port/getrusage.c,v
retrieving revision 1.1
diff -c -c -r1.1 getrusage.c
*** src/port/getrusage.c    18 Jul 2002 04:13:59 -0000    1.1
--- src/port/getrusage.c    15 May 2003 16:17:13 -0000
***************
*** 2,7 ****
--- 2,9 ----

  #include <stdio.h>
  #include <errno.h>
+
+ #include "postgres.h"
  #include "rusagestub.h"

  /* This code works on:
***************
*** 19,24 ****
--- 21,30 ----
  int
  getrusage(int who, struct rusage * rusage)
  {
+ #ifdef WIN32
+     if (rusage)
+         memset(rusage, 0, sizeof(rusage));
+ #else
      struct tms    tms;
      int            tick_rate = CLK_TCK;    /* ticks per second */
      clock_t        u,
***************
*** 54,58 ****
--- 60,65 ----
      rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate);
      rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate);
      rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate);
+ #endif
      return 0;
  }

Re: Win32 patch to allow compilation

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> I have applied the following patch to allow Win32 compilation under
> MinGW.  The patch includes the following changes:
>
>     Win32 port is now called 'win32' rather than 'win'

I think this is wrong-headed.  What's the reason?

>     new /include/port/win32_include dir to hold missing include files

For the other ports we have simply named this directory after the name of
the port.  Appending "_include" is redundant.

--
Peter Eisentraut   peter_e@gmx.net


Re: Win32 patch to allow compilation

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > I have applied the following patch to allow Win32 compilation under
> > MinGW.  The patch includes the following changes:
> >
> >     Win32 port is now called 'win32' rather than 'win'
>
> I think this is wrong-headed.  What's the reason?

I don't think 'win' is unique enough.  Win32 seems the more official
designation.

> >     new /include/port/win32_include dir to hold missing include files
>
> For the other ports we have simply named this directory after the name of
> the port.  Appending "_include" is redundant.

Well, we don't have any other port directories under /include/port, but
I see your point that they are include files, so why add _include.  I
will make the change.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Win32 patch to allow compilation

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > I don't think 'win' is unique enough.  Win32 seems the more official
> > designation.
>
> We've lived with a "win" port for years and no one complained about that.
> And what will happen when "win64" comes around?  The official designation
> is Windows anyway.

OK, I have renamed win32_include to win32.  I used win32 because that is
the symbol we test for in the C code, so it seemed it made sense to be
consistent.  How about MSWIN?  That is more unique than win.  What
symbol do we test for in the C code?  __mswin__?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Win32 patch to allow compilation

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> I don't think 'win' is unique enough.  Win32 seems the more official
> designation.

We've lived with a "win" port for years and no one complained about that.
And what will happen when "win64" comes around?  The official designation
is Windows anyway.

> Well, we don't have any other port directories under /include/port,

Hmm, there used to be some.  Maybe they aren't needed anymore.

--
Peter Eisentraut   peter_e@gmx.net