diff --git a/configure b/configure
index 70e18ea7d5a0678a1f2a963a21f30354a6adb7c1..83a54bc69116bd0e93f59612829ac70230530cd2 100755
--- a/configure
+++ b/configure
@@ -10543,6 +10543,12 @@ done
 
 
 
+# BSD/OS has a custom fseeko/ftello built on fsetpos/fgetpos
+# We override the previous test that said fseeko/ftello didn't exist
+case $host_os in bsdi*)
+ac_cv_func_fseeko=yes
+esac
+
 # Solaris has a very slow qsort in certain cases.
 case $host_os in
   solaris*) LIBOBJS="$LIBOBJS qsort.$ac_objext" ;;
@@ -11471,12 +11477,6 @@ fi
 done
 
 
-# BSD/OS has a custom fseeko/ftello built on fsetpos/fgetpos
-# We override the previous test that said fseeko/ftello didn't exist
-case $host_os in bsdi*)
-ac_cv_func_fseeko=yes
-esac
-
 echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5
 echo $ECHO_N "checking for _LARGEFILE_SOURCE value needed for large files... $ECHO_C" >&6
 if test "${ac_cv_sys_largefile_source+set}" = set; then
diff --git a/configure.in b/configure.in
index 1ca21844c5e00a379a3ef03fdbf2ee7a0073a67f..43942dd0d8c7577665d78d59819467f8ccd7954f 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.213 2002/10/23 20:59:03 momjian Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.214 2002/10/24 01:33:50 momjian Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -837,6 +837,12 @@ fi
 
 AC_REPLACE_FUNCS([fseeko gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
 
+# BSD/OS has a custom fseeko/ftello built on fsetpos/fgetpos
+# We override the previous test that said fseeko/ftello didn't exist
+case $host_os in bsdi*)
+ac_cv_func_fseeko=yes
+esac
+
 # Solaris has a very slow qsort in certain cases.
 case $host_os in 
   solaris*) AC_LIBOBJ(qsort) ;;
@@ -903,12 +909,6 @@ AC_CHECK_FUNCS(atexit, [],
                [AC_CHECK_FUNCS(on_exit, [],
                                [AC_MSG_ERROR([neither atexit() nor on_exit() found])])])
 
-# BSD/OS has a custom fseeko/ftello built on fsetpos/fgetpos
-# We override the previous test that said fseeko/ftello didn't exist
-case $host_os in bsdi*)
-ac_cv_func_fseeko=yes
-esac
-
 AC_FUNC_FSEEKO
 
 
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index c79d61cfbca826211497a20083528b1b8a9dd0f5..f67c9a64443b7181b7eb95f4b2120abf76e939b2 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.49 2002/10/23 19:23:56 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.50 2002/10/24 01:33:50 momjian Exp $
  */
 #include "postgres_fe.h"
 
@@ -25,6 +25,17 @@
 #include <sys/timeb.h>			/* for _ftime() */
 #endif
 
+#ifndef WIN32
+#include <sys/ioctl.h>			/* for ioctl() */
+#else
+#define popen(x,y) _popen(x,y)
+#define pclose(x) _pclose(x)
+#endif
+
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+
 #include "libpq-fe.h"
 #include "pqsignal.h"
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 7dfb594b435b8e15ef811a8420678c2a33323121..6e5323c01acb7f6dd3bfe9c8944b2703486ee5c6 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.59 2002/10/23 19:23:56 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.60 2002/10/24 01:33:50 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -14,7 +14,6 @@
 #include <errno.h>
 
 #ifndef WIN32
-#include <sys/ioctl.h>			/* for ioctl() */
 #ifdef HAVE_PWD_H
 #include <pwd.h>				/* for getpwuid() */
 #endif
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 565fe809d5cac478745b5dd24c4b75989227f57d..2457740c3099b131fb103a673de57bdbcdf29cfe 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.33 2002/10/23 19:23:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.34 2002/10/24 01:33:50 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -11,23 +11,12 @@
 
 #include <math.h>
 #include <signal.h>
-#ifndef WIN32
-#include <unistd.h>				/* for isatty() */
-#include <sys/ioctl.h>			/* for ioctl() */
-#else
-#define popen(x,y) _popen(x,y)
-#define pclose(x) _pclose(x)
-#endif
 
 #include "pqsignal.h"
 #include "libpq-fe.h"
 
 #include "settings.h"
 
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#endif
-
 #include "mbprint.h"
 
 /*************************/