Package: util-linux
Version: 2.11x
Author: Guillem Jover <guillem@hadrons.org>
Status: obsolete
Description:
 Full Hurd port including the Debian part.

diff -Naur util-linux-2.11x/configure util-linux-2.11x-debian-patched/configure
--- util-linux-2.11x/configure	2002-07-08 21:14:03.000000000 +0200
+++ util-linux-2.11x-debian-patched/configure	2002-11-27 22:42:34.000000000 +0100
@@ -40,6 +40,7 @@
 # 12. For hwclock.c: does struct tm have a field tm_gmtoff?
 # 13. For nfsmount: does the output of rpcgen compile?
 # 14. For fsck.cramfs, mkfs.cramfs: do we have libz?
+# 15. For lib/get_blocks.c: does struct stat have a field st_blocks?
 
 rm -f make_include defines.h
 
@@ -273,6 +274,7 @@
 
 #
 # F6. For agetty.c: is updwtmp() available?
+# F7. For mcookie.c: is gettimeofday() available?
 #
 echo '
 #include <string.h>
@@ -485,6 +487,28 @@
 fi
 rm -f conftest conftest.c
 
+#
+# F7. For mcookie.c: is gettimeofday() available?
+#
+echo '
+#include <sys/time.h>
+#include <unistd.h>
+main(int a, char **v){
+  struct timeval    tv;
+  struct timezone   tz;
+  gettimeofday( &tv, &tz );
+  exit(0);
+}
+' > conftest.c
+eval $compile
+if test -s conftest && ./conftest 2>/dev/null; then
+        echo "#define HAVE_gettimeofday" >> defines.h
+        echo "You have gettimeofday()"
+else
+        echo "You don't have gettimeofday()"
+fi
+rm -f conftest conftest.c
+
 
 #
 # 7. Does xgettext exist and take the option --foreign-user?
@@ -681,3 +705,27 @@
 fi
 rm -f conftest conftest.c
 
+#
+# 15. For lib/get_blocks.c: does struct stat have a field st_blocks?
+#
+echo "
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+int main()
+{
+    struct stat st;
+    fstat(0, &st);
+    st.st_blocks = 0;
+    return 0;
+}
+" >conftest.c
+eval $compile
+if test -s conftest; then
+        echo "#define HAVE_st_blocks" >> defines.h
+        echo "You have a st_blocks field in struct stat"
+else
+        echo "You don't have a st_blocks field in struct stat"
+fi
+rm -f conftest conftest.c
+
diff -Naur util-linux-2.11x/disk-utils/fsck.minix.c util-linux-2.11x-debian-patched/disk-utils/fsck.minix.c
--- util-linux-2.11x/disk-utils/fsck.minix.c	2001-11-30 15:59:57.000000000 +0100
+++ util-linux-2.11x-debian-patched/disk-utils/fsck.minix.c	2002-11-27 22:42:34.000000000 +0100
@@ -103,10 +103,6 @@
 #define HAVE_MINIX2 1
 #endif
 
-#ifndef __linux__
-#define volatile
-#endif
-
 #define ROOT_INO 1
 
 #define UPPER(size,n) ((size+((n)-1))/(n))
diff -Naur util-linux-2.11x/disk-utils/Makefile util-linux-2.11x-debian-patched/disk-utils/Makefile
--- util-linux-2.11x/disk-utils/Makefile	2002-11-02 14:52:47.000000000 +0100
+++ util-linux-2.11x-debian-patched/disk-utils/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -8,24 +8,34 @@
 
 # Where to put man pages?
 
-MAN8= 	blockdev.8 fdformat.8 isosize.8 mkfs.8 mkswap.8 elvtune.8 \
-	fsck.minix.8 mkfs.minix.8 mkfs.bfs.8
+MAN8= 	isosize.8 mkfs.8 mkswap.8 fsck.minix.8 mkfs.minix.8 mkfs.bfs.8
+ifeq "$(OS)" "linux"
+MAN8:=$(MAN8) fdformat.8 blockdev.8 elvtune.8
+endif
 
 # Where to put binaries?
 # See the "install" rule for the links. . .
 
-SBIN= 	mkfs mkswap blockdev elvtune fsck.minix mkfs.minix mkfs.bfs
+SBIN= 	mkfs mkswap fsck.minix mkfs.minix mkfs.bfs
+ifeq "$(OS)" "linux"
+SBIN:=$(SBIN) blockdev elvtune
+endif
 
-USRBIN=	fdformat isosize
+USRBIN=	isosize
+ifeq "$(OS)" "linux"
+USRBIN:=$(USRBIN) fdformat
+endif
 
 ETC=	fdprm
 
 MAYBE=  setfdprm raw fsck.cramfs mkfs.cramfs
 
+ifeq "$(OS)" "linux"
 ifneq "$(HAVE_FDUTILS)" "yes"
 USRBIN:=$(USRBIN) setfdprm
 MAN8:=$(MAN8) setfdprm.8
 endif
+endif
 
 ifeq "$(HAVE_RAW_H)" "yes"
 USRBIN:=$(USRBIN) raw
@@ -50,13 +60,17 @@
 
 fsck.minix.o mkfs.minix.o: bitops.h minix.h
 
+mkfs.minix mkfs.bfs mkswap: $(LIB)/get_blocks.o
+
 install: all
 	$(INSTALLDIR) $(SBINDIR) $(USRBINDIR) $(ETCDIR)
 	$(INSTALLBIN) $(SBIN) $(SBINDIR)
 	$(INSTALLBIN) $(USRBIN) $(USRBINDIR)
+ifeq "$(OS)" "linux"
 ifneq "$(HAVE_FDUTILS)" "yes"
 	$(INSTALLDAT) $(ETC) $(ETCDIR)
 endif
+endif
 	$(INSTALLDIR) $(MAN8DIR)
 	$(INSTALLMAN) $(MAN8) $(MAN8DIR)
 
diff -Naur util-linux-2.11x/disk-utils/mkfs.bfs.c util-linux-2.11x-debian-patched/disk-utils/mkfs.bfs.c
--- util-linux-2.11x/disk-utils/mkfs.bfs.c	2002-03-08 23:58:05.000000000 +0100
+++ util-linux-2.11x-debian-patched/disk-utils/mkfs.bfs.c	2002-11-27 22:42:34.000000000 +0100
@@ -10,17 +10,12 @@
 #include <stdarg.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/ioctl.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 #include <time.h>
 #include "nls.h"
-
-/* cannot include <linux/fs.h> */
-#ifndef BLKGETSIZE
-#define BLKGETSIZE _IO(0x12,96)    /* return device size */
-#endif
+#include "get_blocks.h"
 
 #define BFS_ROOT_INO		2
 #define BFS_NAMELEN		14
@@ -181,13 +176,9 @@
 	else if (optind != argc)
 		usage();
 
-	if (ioctl(fd, BLKGETSIZE, &total_blocks) == -1) {
-		if (!user_specified_total_blocks) {
-			perror("BLKGETSIZE");
-			fatal(_("cannot get size of %s"), device);
-		}
-		total_blocks = user_specified_total_blocks;
-	} else if (user_specified_total_blocks) {
+	total_blocks = get_blocks(fd);
+
+	if (user_specified_total_blocks) {
 		if (user_specified_total_blocks > total_blocks)
 			fatal(_("blocks argument too large, max is %lu"),
 			      total_blocks);
diff -Naur util-linux-2.11x/disk-utils/mkfs.c util-linux-2.11x-debian-patched/disk-utils/mkfs.c
--- util-linux-2.11x/disk-utils/mkfs.c	2002-03-08 23:58:15.000000000 +0100
+++ util-linux-2.11x-debian-patched/disk-utils/mkfs.c	2002-11-27 22:42:34.000000000 +0100
@@ -36,7 +36,7 @@
 
 int main(int argc, char *argv[])
 {
-  char progname[NAME_MAX];
+  char *progname;
   char *fstype = NULL;
   int i, more = 0, verbose = 0;
   char *oldpath, *newpath;
@@ -92,7 +92,12 @@
   }
   sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
   putenv(newpath);
-  snprintf(progname, sizeof(progname), PROGNAME, fstype);
+  progname = (char *) malloc(sizeof(PROGNAME) + strlen(fstype) + 1);
+  if (!progname) {
+    fprintf(stderr, _("%s: Out of memory!\n"), "mkfs");
+    exit(1);
+  }
+  sprintf(progname, PROGNAME, fstype);
   argv[--optind] = progname;
 
   if (verbose) {
diff -Naur util-linux-2.11x/disk-utils/mkfs.minix.c util-linux-2.11x-debian-patched/disk-utils/mkfs.minix.c
--- util-linux-2.11x/disk-utils/mkfs.minix.c	2002-10-26 00:25:15.000000000 +0200
+++ util-linux-2.11x-debian-patched/disk-utils/mkfs.minix.c	2002-11-27 22:42:34.000000000 +0100
@@ -68,16 +68,12 @@
 #include <stdlib.h>
 #include <termios.h>
 #include <sys/stat.h>
-#include <sys/ioctl.h>
 #include <mntent.h>
 #include <getopt.h>
 
 #include "minix.h"
 #include "nls.h"
-
-#ifndef BLKGETSIZE
-#define BLKGETSIZE _IO(0x12,96)    /* return device size */
-#endif
+#include "get_blocks.h"
 
 #ifdef MINIX2_SUPER_MAGIC2
 #define HAVE_MINIX2 1
@@ -200,37 +196,6 @@
 }
 
 static long
-valid_offset (int fd, int offset) {
-	char ch;
-
-	if (lseek (fd, offset, 0) < 0)
-		return 0;
-	if (read (fd, &ch, 1) < 1)
-		return 0;
-	return 1;
-}
-
-static int
-count_blocks (int fd) {
-	int high, low;
-
-	low = 0;
-	for (high = 1; valid_offset (fd, high); high *= 2)
-		low = high;
-	while (low < high - 1)
-	{
-		const int mid = (low + high) / 2;
-
-		if (valid_offset (fd, mid))
-			low = mid;
-		else
-			high = mid;
-	}
-	valid_offset (fd, 0);
-	return (low + 1);
-}
-
-static int
 get_size(const char  *file) {
 	int	fd;
 	long	size;
@@ -240,12 +205,8 @@
 		perror(file);
 		exit(1);
 	}
-	if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
-		close(fd);
-		return (size * 512);
-	}
-		
-	size = count_blocks(fd);
+	size = get_blocks(fd);
+
 	close(fd);
 	return size;
 }
@@ -695,8 +656,10 @@
      }
   }
 
-  if (device_name && !BLOCKS)
-    BLOCKS = get_size (device_name) / 1024;
+  if (device_name && !BLOCKS) {
+    int sectors_per_block = 1024 / 512;
+    BLOCKS = get_size (device_name) / sectors_per_block;
+  }
   if (!device_name || BLOCKS<10) {
     usage();
   }
diff -Naur util-linux-2.11x/disk-utils/mkswap.c util-linux-2.11x-debian-patched/disk-utils/mkswap.c
--- util-linux-2.11x/disk-utils/mkswap.c	2002-11-01 02:52:29.000000000 +0100
+++ util-linux-2.11x-debian-patched/disk-utils/mkswap.c	2002-11-27 22:42:34.000000000 +0100
@@ -36,10 +36,12 @@
 #include <string.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <sys/ioctl.h>		/* for _IO */
+#ifdef __linux__
 #include <sys/utsname.h>
+#endif /* __linux__ */
 #include <sys/stat.h>
 #include "nls.h"
+#include "get_blocks.h"
 
 /* Try to get PAGE_SIZE from libc or kernel includes */
 #ifdef HAVE_sys_user_h
@@ -52,14 +54,6 @@
 #endif
 #endif
 
-#ifndef _IO
-/* pre-1.3.45 */
-#define BLKGETSIZE 0x1260
-#else
-/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
-#define BLKGETSIZE _IO(0x12,96)
-#endif
-
 static char * program_name = "mkswap";
 static char * device_name = NULL;
 static int DEV = -1;
@@ -68,6 +62,7 @@
 static int badpages = 0;
 static int version = -1;
 
+#ifdef __linux__
 #define MAKE_VERSION(p,q,r)	(65536*(p) + 256*(q) + (r))
 
 static int
@@ -83,6 +78,7 @@
 	}
 	return 0;
 }
+#endif /* __linux__ */
 
 #ifdef __sparc__
 # ifdef __arch64__
@@ -382,39 +378,11 @@
 		printf(_("%d bad pages\n"), badpages);
 }
 
-static long
-valid_offset (int fd, off_t offset) {
-	char ch;
-
-	if (lseek (fd, offset, 0) < 0)
-		return 0;
-	if (read (fd, &ch, 1) < 1)
-		return 0;
-	return 1;
-}
-
-static off_t
-find_size (int fd) {
-	off_t high, low;
-
-	low = 0;
-	for (high = 1; high > 0 && valid_offset (fd, high); high *= 2)
-		low = high;
-	while (low < high - 1) {
-		const off_t mid = (low + high) / 2;
-
-		if (valid_offset (fd, mid))
-			low = mid;
-		else
-			high = mid;
-	}
-	return (low + 1);
-}
-
 /* return size in pages, to avoid integer overflow */
 static long
 get_size(const char  *file) {
 	int	fd;
+	int	sectors_per_page = pagesize / 512;
 	long	size;
 
 	fd = open(file, O_RDONLY);
@@ -422,14 +390,10 @@
 		perror(file);
 		exit(1);
 	}
-	if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
-		int sectors_per_page = pagesize/512;
-		size /= sectors_per_page;
-	} else {
-		size = find_size(fd) / pagesize;
-	}
+	size = get_blocks(fd);
+
 	close(fd);
-	return size;
+	return (size / sectors_per_page);
 }
 
 static int
@@ -527,8 +491,10 @@
 		/* use version 1 as default, if possible */
 		if (PAGES <= V0_MAX_PAGES && PAGES > V1_MAX_PAGES)
 			version = 0;
+#ifdef __linux__
 		else if (linux_version_code() < MAKE_VERSION(2,1,117))
 			version = 0;
+#endif
 		else if (pagesize < 2048)
 			version = 0;
 		else
@@ -549,12 +515,17 @@
 
 	if (version == 0)
 		maxpages = V0_MAX_PAGES;
+#ifdef __linux__
 	else if (linux_version_code() >= MAKE_VERSION(2,3,4))
 		maxpages = PAGES;
 	else if (linux_version_code() >= MAKE_VERSION(2,2,1))
 		maxpages = V1_MAX_PAGES;
-	else
+#endif
+	else {
 		maxpages = V1_OLD_MAX_PAGES;
+		if (maxpages > V1_MAX_PAGES)
+			maxpages = V1_MAX_PAGES;
+	}
 
 	if (PAGES > maxpages) {
 		PAGES = maxpages;
diff -Naur util-linux-2.11x/fdisk/cfdisk.c util-linux-2.11x-debian-patched/fdisk/cfdisk.c
--- util-linux-2.11x/fdisk/cfdisk.c	2002-10-25 17:03:40.000000000 +0200
+++ util-linux-2.11x-debian-patched/fdisk/cfdisk.c	2002-11-27 22:42:34.000000000 +0100
@@ -75,11 +75,14 @@
 #include <math.h>
 #include <string.h>
 #include <sys/stat.h>
+#ifdef __linux__
 #include <sys/ioctl.h>
 #include <linux/types.h>
+#endif
 
 #include "nls.h"
 #include "xstrncpy.h"
+#include "get_blocks.h"
 #include "common.h"
 
 #if defined(__GNUC__) || defined(HAS_LONG_LONG)
@@ -93,8 +96,13 @@
 
 #define VERSION UTIL_LINUX_VERSION
 
+#ifdef __GNU__
+#define DEFAULT_DEVICE "/dev/hd0"
+#define ALTERNATE_DEVICE "/dev/sd0"
+#else
 #define DEFAULT_DEVICE "/dev/hda"
 #define ALTERNATE_DEVICE "/dev/sda"
+#endif
 
 /* With K=1024 we have `binary' megabytes, gigabytes, etc.
    Some misguided hackers like that.
@@ -1607,6 +1615,7 @@
 	 opentype = O_RDWR;
     opened = TRUE;
 
+#ifdef __linux__
     /* Blocks are visible in more than one way:
        e.g. as block on /dev/hda and as block on /dev/hda3
        By a bug in the Linux buffer cache, we will see the old
@@ -1616,9 +1625,9 @@
        so this only plays a role if we want to show volume labels. */
     ioctl(fd, BLKFLSBUF);	/* ignore errors */
 				/* e.g. Permission Denied */
+#endif
 
-    if (ioctl(fd, BLKGETSIZE, &actual_size))
-	fatal(_("Cannot get disk size"), 3);
+    actual_size = get_blocks(fd);
 
     read_sector(buffer.c.b, 0);
 
@@ -1824,12 +1833,14 @@
 	}
 
     if (is_bdev) {
+#ifdef __linux__
 	 sync();
 	 sleep(2);
 	 if (!ioctl(fd,BLKRRPART))
 	      changed = TRUE;
 	 sync();
 	 sleep(4);
+#endif
 
 	 clear_warning();
 	 if (changed)
@@ -2925,6 +2936,19 @@
 	disk_device = ALTERNATE_DEVICE;
     else close(fd);
 
+#ifdef __GNU__
+    /* XXX Temporal hack to force user or partition table to supply
+     * what the system cannot
+     */
+    if (!use_partition_table_geometry
+	&& (!user_cylinders || !user_heads || !user_sectors)) {
+	fprintf(stderr, "%s: %s\n", argv[0],
+		_("Geometry must be supplied, by the user (-c -h -s) or\n"
+		  "by the existing partition table (-g)\n"));
+    	exit(1);
+    }
+#endif
+
     if (print_only) {
 	fill_p_info();
 	if (print_only & PRINT_RAW_TABLE)
diff -Naur util-linux-2.11x/fdisk/fdiskaixlabel.h util-linux-2.11x-debian-patched/fdisk/fdiskaixlabel.h
--- util-linux-2.11x/fdisk/fdiskaixlabel.h	2000-02-20 17:50:51.000000000 +0100
+++ util-linux-2.11x-debian-patched/fdisk/fdiskaixlabel.h	2002-11-27 22:42:34.000000000 +0100
@@ -1,4 +1,3 @@
-#include <linux/types.h>   /* for __u32 etc */
 /*
  * Copyright (C) Andreas Neuper, Sep 1998.
  *	This file may be redistributed under
diff -Naur util-linux-2.11x/fdisk/fdiskbsdlabel.c util-linux-2.11x-debian-patched/fdisk/fdiskbsdlabel.c
--- util-linux-2.11x/fdisk/fdiskbsdlabel.c	2002-10-31 14:43:42.000000000 +0100
+++ util-linux-2.11x-debian-patched/fdisk/fdiskbsdlabel.c	2002-11-27 22:42:34.000000000 +0100
@@ -52,7 +52,6 @@
 #include <errno.h>
 #include "nls.h"
 
-#include <sys/ioctl.h>
 #include <sys/param.h>
 
 #include "common.h"
@@ -515,7 +514,7 @@
 xbsd_write_bootstrap (void)
 {
   char *bootdir = BSD_LINUX_BOOTDIR;
-  char path[MAXPATHLEN];
+  char *path;
   char *dkbasename;
   struct xbsd_disklabel dl;
   char *d, *p, *e;
@@ -532,9 +531,15 @@
     line_ptr[strlen (line_ptr)-1] = '\0';
     dkbasename = line_ptr;
   }
-  snprintf (path, sizeof(path), "%s/%sboot", bootdir, dkbasename);
-  if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize))
+  path = (char *) malloc (sizeof("/boot") + 1 + strlen (bootdir) +
+			  strlen (dkbasename));
+  if (!path)
+    fatal (out_of_memory);
+  sprintf (path, "%s/%sboot", bootdir, dkbasename);
+  if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize)) {
+    free (path);
     return;
+  }
 
   /* We need a backup of the disklabel (xbsd_dlabel might have changed). */
   d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE];
@@ -543,10 +548,13 @@
   /* The disklabel will be overwritten by 0's from bootxx anyway */
   bzero (d, sizeof (struct xbsd_disklabel));
 
+  sprintf (path, "%s/boot%s", bootdir, dkbasename);
   snprintf (path, sizeof(path), "%s/boot%s", bootdir, dkbasename);
   if (!xbsd_get_bootstrap (path, &disklabelbuffer[xbsd_dlabel.d_secsize],
-			  (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize))
+			  (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) {
+    free(path);
     return;
+  }
 
   e = d + sizeof (struct xbsd_disklabel);
   for (p=d; p < e; p++)
@@ -579,6 +587,8 @@
 #endif
 
   sync_disks ();
+
+  free(path);
 }
 
 static void
diff -Naur util-linux-2.11x/fdisk/fdiskbsdlabel.h util-linux-2.11x-debian-patched/fdisk/fdiskbsdlabel.h
--- util-linux-2.11x/fdisk/fdiskbsdlabel.h	2002-10-31 14:45:34.000000000 +0100
+++ util-linux-2.11x-debian-patched/fdisk/fdiskbsdlabel.h	2002-11-27 22:42:34.000000000 +0100
@@ -31,10 +31,10 @@
  * SUCH DAMAGE.
  */
 
-#include <linux/types.h>	/* for __u32, __u16, __u8, __s16 */
+#include <stdint.h>	/* for uint32_t, uint16_t, uint8_t, int16_t */
 
 #ifndef BSD_DISKMAGIC
-#define BSD_DISKMAGIC     ((__u32) 0x82564557)
+#define BSD_DISKMAGIC     ((uint32_t) 0x82564557)
 #endif
 
 #ifndef BSD_MAXPARTITIONS
@@ -60,31 +60,31 @@
 #define	BSD_SBSIZE        8192		/* max size of fs superblock */
 
 struct xbsd_disklabel {
-	__u32	d_magic;		/* the magic number */
-	__s16	d_type;			/* drive type */
-	__s16	d_subtype;		/* controller/d_type specific */
-	char	d_typename[16];		/* type name, e.g. "eagle" */
-	char	d_packname[16];			/* pack identifier */ 
+	uint32_t	d_magic;		/* the magic number */
+	int16_t		d_type;			/* drive type */
+	int16_t		d_subtype;		/* controller/d_type specific */
+	char		d_typename[16];		/* type name, e.g. "eagle" */
+	char		d_packname[16];		/* pack identifier */ 
 			/* disk geometry: */
-	__u32	d_secsize;		/* # of bytes per sector */
-	__u32	d_nsectors;		/* # of data sectors per track */
-	__u32	d_ntracks;		/* # of tracks per cylinder */
-	__u32	d_ncylinders;		/* # of data cylinders per unit */
-	__u32	d_secpercyl;		/* # of data sectors per cylinder */
-	__u32	d_secperunit;		/* # of data sectors per unit */
+	uint32_t	d_secsize;		/* # of bytes per sector */
+	uint32_t	d_nsectors;		/* # of data sectors per track */
+	uint32_t	d_ntracks;		/* # of tracks per cylinder */
+	uint32_t	d_ncylinders;		/* # of data cylinders per unit */
+	uint32_t	d_secpercyl;		/* # of data sectors per cylinder */
+	uint32_t	d_secperunit;		/* # of data sectors per unit */
 	/*
 	 * Spares (bad sector replacements) below
 	 * are not counted in d_nsectors or d_secpercyl.
 	 * Spare sectors are assumed to be physical sectors
 	 * which occupy space at the end of each track and/or cylinder.
 	 */
-	__u16	d_sparespertrack;	/* # of spare sectors per track */
-	__u16	d_sparespercyl;		/* # of spare sectors per cylinder */
+	uint16_t	d_sparespertrack;	/* # of spare sectors per track */
+	uint16_t	d_sparespercyl;		/* # of spare sectors per cylinder */
 	/*
 	 * Alternate cylinders include maintenance, replacement,
 	 * configuration description areas, etc.
 	 */
-	__u32	d_acylinders;		/* # of alt. cylinders per unit */
+	uint32_t	d_acylinders;		/* # of alt. cylinders per unit */
 
 			/* hardware characteristics: */
 	/*
@@ -103,30 +103,30 @@
 	 * Finally, d_cylskew is the offset of sector 0 on cylinder N
 	 * relative to sector 0 on cylinder N-1.
 	 */
-	__u16	d_rpm;			/* rotational speed */
-	__u16	d_interleave;		/* hardware sector interleave */
-	__u16	d_trackskew;		/* sector 0 skew, per track */
-	__u16	d_cylskew;		/* sector 0 skew, per cylinder */
-	__u32	d_headswitch;		/* head switch time, usec */
-	__u32	d_trkseek;		/* track-to-track seek, usec */
-	__u32	d_flags;		/* generic flags */
+	uint16_t	d_rpm;			/* rotational speed */
+	uint16_t	d_interleave;		/* hardware sector interleave */
+	uint16_t	d_trackskew;		/* sector 0 skew, per track */
+	uint16_t	d_cylskew;		/* sector 0 skew, per cylinder */
+	uint32_t	d_headswitch;		/* head switch time, usec */
+	uint32_t	d_trkseek;		/* track-to-track seek, usec */
+	uint32_t	d_flags;		/* generic flags */
 #define NDDATA 5
-	__u32	d_drivedata[NDDATA];	/* drive-type specific information */
+	uint32_t	d_drivedata[NDDATA];	/* drive-type specific information */
 #define NSPARE 5
-	__u32	d_spare[NSPARE];	/* reserved for future use */
-	__u32	d_magic2;		/* the magic number (again) */
-	__u16	d_checksum;		/* xor of data incl. partitions */
+	uint32_t	d_spare[NSPARE];	/* reserved for future use */
+	uint32_t	d_magic2;		/* the magic number (again) */
+	uint16_t	d_checksum;		/* xor of data incl. partitions */
 			/* filesystem and partition information: */
-	__u16	d_npartitions;	        /* number of partitions in following */
-	__u32	d_bbsize;	        /* size of boot area at sn0, bytes */
-	__u32	d_sbsize;	        /* max size of fs superblock, bytes */
+	uint16_t	d_npartitions;	        /* number of partitions in following */
+	uint32_t	d_bbsize;	        /* size of boot area at sn0, bytes */
+	uint32_t	d_sbsize;	        /* max size of fs superblock, bytes */
 	struct xbsd_partition	 {	/* the partition table */
-		__u32	p_size;	        /* number of sectors in partition */
-		__u32	p_offset;       /* starting sector */
-		__u32	p_fsize;        /* filesystem basic fragment size */
-		__u8	p_fstype;       /* filesystem type, see below */
-		__u8	p_frag;	        /* filesystem fragments per block */
-		__u16	p_cpg;	        /* filesystem cylinders per group */
+		uint32_t	p_size;	        /* number of sectors in partition */
+		uint32_t	p_offset;       /* starting sector */
+		uint32_t	p_fsize;        /* filesystem basic fragment size */
+		uint8_t		p_fstype;       /* filesystem type, see below */
+		uint8_t		p_frag;	        /* filesystem fragments per block */
+		uint16_t	p_cpg;	        /* filesystem cylinders per group */
 	} d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
 };
 
diff -Naur util-linux-2.11x/fdisk/fdisk.c util-linux-2.11x-debian-patched/fdisk/fdisk.c
--- util-linux-2.11x/fdisk/fdisk.c	2002-10-31 14:02:17.000000000 +0100
+++ util-linux-2.11x-debian-patched/fdisk/fdisk.c	2002-11-27 22:42:34.000000000 +0100
@@ -31,6 +31,7 @@
 
 #include "nls.h"
 #include "common.h"
+#include "get_blocks.h"
 #include "fdisk.h"
 
 #include "fdisksunlabel.h"
@@ -725,6 +726,7 @@
 	get_boot(create_empty_dos);
 }
 
+#ifdef __linux__
 #include <sys/utsname.h>
 #define MAKE_VERSION(p,q,r)     (65536*(p) + 256*(q) + (r))
 
@@ -742,10 +744,11 @@
         }
         return kernel_version;
 }
+#endif
 
 static void
 get_sectorsize(int fd) {
-#if defined(BLKSSZGET)
+#if defined(BLKSSZGET) && defined(__linux__)
 	if (!user_set_sector_size &&
 	    linux_version_code() >= MAKE_VERSION(2,3,3)) {
 		int arg;
@@ -828,8 +831,7 @@
 		pt_sectors ? pt_sectors :
 		kern_sectors ? kern_sectors : 63;
 
-	if (ioctl(fd, BLKGETSIZE, &longsectors))
-		longsectors = 0;
+	longsectors = get_blocks(fd);
 
 	sector_offset = 1;
 	if (dos_compatible_flag)
@@ -2090,6 +2092,7 @@
 	int error = 0;
 	int i;
 
+#ifdef __linux__
 	printf(_("Calling ioctl() to re-read partition table.\n"));
 	sync();
 	sleep(2);
@@ -2104,6 +2107,10 @@
                 if ((i = ioctl(fd, BLKRRPART)) != 0)
                         error = errno;
         }
+#else
+	error = ENOSYS;
+	i = 1;
+#endif
 
 	if (i) {
 		printf(_("\nWARNING: Re-reading the partition table "
@@ -2495,8 +2502,7 @@
 			disk_device = argv[j];
 			if ((fd = open(disk_device, type_open)) < 0)
 				fatal(unable_to_open);
-			if (ioctl(fd, BLKGETSIZE, &size))
-				fatal(ioctl_error);
+			size = get_blocks(fd);
 			close(fd);
 			if (opts == 1)
 				printf("%ld\n", size/2);
diff -Naur util-linux-2.11x/fdisk/fdisksgilabel.c util-linux-2.11x-debian-patched/fdisk/fdisksgilabel.c
--- util-linux-2.11x/fdisk/fdisksgilabel.c	2002-05-09 01:51:31.000000000 +0200
+++ util-linux-2.11x-debian-patched/fdisk/fdisksgilabel.c	2002-11-27 22:42:34.000000000 +0100
@@ -13,13 +13,11 @@
 #include <stdlib.h>             /* uint */
 #include <string.h>             /* strstr */
 #include <unistd.h>             /* write */
-#include <sys/ioctl.h>          /* ioctl */
 #include <sys/stat.h>           /* stat */
 #include <assert.h>             /* assert */
 
 #include <endian.h>
 #include "nls.h"
-#include <linux/major.h>        /* FLOPPY_MAJOR */
 
 #include "common.h"
 #include "fdisk.h"
@@ -98,12 +96,12 @@
 
 static inline unsigned short
 __swap16(unsigned short x) {
-        return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8);
+        return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
 }
 
-static inline __u32
-__swap32(__u32 x) {
-        return (((__u32)(x) & 0xFF) << 24) | (((__u32)(x) & 0xFF00) << 8) | (((__u32)(x) & 0xFF0000) >> 8) | (((__u32)(x) & 0xFF000000) >> 24);
+static inline uint32_t
+__swap32(uint32_t x) {
+        return (((uint32_t)(x) & 0xFF) << 24) | (((uint32_t)(x) & 0xFF00) << 8) | (((uint32_t)(x) & 0xFF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24);
 }
 
 static int
@@ -220,8 +218,8 @@
 	   w + 1, _("Device"));
     for (i = 0 ; i < partitions; i++) {
 	    if( sgi_get_num_sectors(i) || debug ) {
-	    __u32 start = sgi_get_start_sector(i);
-	    __u32 len = sgi_get_num_sectors(i);
+	    uint32_t start = sgi_get_start_sector(i);
+	    uint32_t len = sgi_get_num_sectors(i);
 	    kpi++;		/* only count nonempty partitions */
 	    printf(
 		"%2d: %s %4s %9ld %9ld %9ld  %2x  %s\n",
@@ -244,8 +242,8 @@
     {
 	if (sgilabel->directory[i].vol_file_size)
 	{
-	    __u32 start = SSWAP32(sgilabel->directory[i].vol_file_start);
-	    __u32 len = SSWAP32(sgilabel->directory[i].vol_file_size);
+	    uint32_t start = SSWAP32(sgilabel->directory[i].vol_file_start);
+	    uint32_t len = SSWAP32(sgilabel->directory[i].vol_file_size);
 	    char*name = sgilabel->directory[i].vol_file_name;
 	    printf(_("%2d: %-10s sector%5u size%8u\n"),
 		    i, name, (unsigned int) start, (unsigned int) len);
@@ -723,7 +721,7 @@
 void
 create_sgilabel(void)
 {
-    struct hd_geometry geometry;
+    struct geom geometry;
     struct { int start;
 	     int nsect;
 	     int sysid; } old[4];
@@ -735,16 +733,8 @@
 
     other_endian = (BYTE_ORDER == LITTLE_ENDIAN);
 
-#ifdef HDIO_REQ
-    if (!ioctl(fd, HDIO_REQ, &geometry))
-#else
-    if (!ioctl(fd, HDIO_GETGEO, &geometry))
-#endif
-    {
-	heads = geometry.heads;
-	sectors = geometry.sectors;
-	cylinders = geometry.cylinders;
-    }
+    get_geometry(fd, &geometry);
+
     for (i = 0; i < 4; i++)
     {
 	old[i].sysid = 0;
diff -Naur util-linux-2.11x/fdisk/fdisksgilabel.h util-linux-2.11x-debian-patched/fdisk/fdisksgilabel.h
--- util-linux-2.11x/fdisk/fdisksgilabel.h	2001-02-20 11:26:53.000000000 +0100
+++ util-linux-2.11x-debian-patched/fdisk/fdisksgilabel.h	2002-11-27 22:42:34.000000000 +0100
@@ -1,4 +1,4 @@
-#include <linux/types.h>   /* for __u32 etc */
+#include <stdint.h>	/* for uint32_t, uint16_t, uint8_t, int16_t */
 /*
  * Copyright (C) Andreas Neuper, Sep 1998.
  *	This file may be modified and redistributed under
@@ -96,9 +96,9 @@
 #define	SGI_INFO_MAGIC		0x00072959
 #define	SGI_INFO_MAGIC_SWAPPED	0x59290700
 #define SSWAP16(x) (other_endian ? __swap16(x) \
-                                 : (__u16)(x))
+                                 : (uint16_t)(x))
 #define SSWAP32(x) (other_endian ? __swap32(x) \
-                                 : (__u32)(x))
+                                 : (uint32_t)(x))
 
 /* fdisk.c */
 #define sgilabel ((sgi_partition *)MBRbuffer)
diff -Naur util-linux-2.11x/fdisk/fdisksunlabel.c util-linux-2.11x-debian-patched/fdisk/fdisksunlabel.c
--- util-linux-2.11x/fdisk/fdisksunlabel.c	2002-11-01 02:55:25.000000000 +0100
+++ util-linux-2.11x-debian-patched/fdisk/fdisksunlabel.c	2002-11-27 22:42:34.000000000 +0100
@@ -27,7 +27,9 @@
 #include <scsi/scsi.h>		/* SCSI_IOCTL_GET_IDLUN */
 #undef u_char
 #endif
+#ifdef __linux__
 #include <linux/major.h>	/* FLOPPY_MAJOR */
+#endif
 
 #include "common.h"
 #include "fdisk.h"
@@ -60,10 +62,10 @@
 };
 
 static inline unsigned short __swap16(unsigned short x) {
-        return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8);
+        return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
 }
-static inline __u32 __swap32(__u32 x) {
-        return (((__u32)(x) & 0xFF) << 24) | (((__u32)(x) & 0xFF00) << 8) | (((__u32)(x) & 0xFF0000) >> 8) | (((__u32)(x) & 0xFF000000) >> 24);
+static inline uint32_t __swap32(uint32_t x) {
+        return (((uint32_t)(x) & 0xFF) << 24) | (((uint32_t)(x) & 0xFF00) << 8) | (((uint32_t)(x) & 0xFF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24);
 }
 
 int
@@ -71,18 +73,21 @@
 	return SSWAP32(p.num_sectors);
 }
 
+#ifdef __linux__
 #ifndef IDE0_MAJOR
 #define IDE0_MAJOR 3
 #endif
 #ifndef IDE1_MAJOR
 #define IDE1_MAJOR 22
 #endif
+#endif
 void guess_device_type(int fd) {
 	struct stat bootstat;
 
 	if (fstat (fd, &bootstat) < 0) {
                 scsi_disk = 0;
                 floppy = 0;
+#ifdef __linux__
 	} else if (S_ISBLK(bootstat.st_mode)
 		   && (major(bootstat.st_rdev) == IDE0_MAJOR ||
 		       major(bootstat.st_rdev) == IDE1_MAJOR)) {
@@ -92,6 +97,7 @@
 		   && major(bootstat.st_rdev) == FLOPPY_MAJOR) {
                 scsi_disk = 0;
                 floppy = 1;
+#endif
 	} else {
                 scsi_disk = 1;
                 floppy = 0;
@@ -249,7 +255,7 @@
 
 void create_sunlabel(void)
 {
-	struct hd_geometry geometry;
+	struct geom geometry;
 	unsigned int ndiv;
 	int i;
 	unsigned char c;
@@ -296,19 +302,8 @@
 	    }
 	}
 	if (!p || floppy) {
-#ifdef HDIO_REQ
-	    if (!ioctl(fd, HDIO_REQ, &geometry)) {
-#else
-	    if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
-#endif
-	        heads = geometry.heads;
-	        sectors = geometry.sectors;
-	        cylinders = geometry.cylinders;
-	    } else {
-	        heads = 0;
-	        sectors = 0;
-	        cylinders = 0;
-	    }
+	    get_geometry(fd, &geometry);
+
 	    if (floppy) {
 	        sunlabel->nacyl = 0;
 	        sunlabel->pcylcount = SSWAP16(cylinders);
@@ -677,8 +672,8 @@
 	       w + 1, _("Device"));
 	for (i = 0 ; i < partitions; i++) {
 		if (sunlabel->partitions[i].num_sectors) {
-			__u32 start = SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
-			__u32 len = SSWAP32(sunlabel->partitions[i].num_sectors);
+			uint32_t start = SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
+			uint32_t len = SSWAP32(sunlabel->partitions[i].num_sectors);
 			printf(
 			    "%s %c%c %9ld %9ld %9ld%c  %2x  %s\n",
 /* device */		  partname(disk_device, i+1, w),
diff -Naur util-linux-2.11x/fdisk/fdisksunlabel.h util-linux-2.11x-debian-patched/fdisk/fdisksunlabel.h
--- util-linux-2.11x/fdisk/fdisksunlabel.h	2000-10-02 23:42:10.000000000 +0200
+++ util-linux-2.11x-debian-patched/fdisk/fdisksunlabel.h	2002-11-27 22:42:34.000000000 +0100
@@ -1,4 +1,4 @@
-#include <linux/types.h>   /* for __u16, __u32 */
+#include <stdint.h>	/* for uint32_t, uint16_t, uint8_t, int16_t */
 
 typedef struct {
 	unsigned char info[128];   /* Informative text string */
@@ -21,8 +21,8 @@
 	unsigned short nsect;      /* Sectors per track */
 	unsigned char spare3[4];   /* Even more magic... */
 	struct sun_partition {
-		__u32 start_cylinder;
-		__u32 num_sectors;
+		uint32_t start_cylinder;
+		uint32_t num_sectors;
 	} partitions[8];
 	unsigned short magic;      /* Magic number */
 	unsigned short csum;       /* Label xor'd checksum */
@@ -32,9 +32,9 @@
 #define SUN_LABEL_MAGIC_SWAPPED  0xBEDA
 #define sunlabel ((sun_partition *)MBRbuffer)
 #define SSWAP16(x) (other_endian ? __swap16(x) \
-				 : (__u16)(x))
+				 : (uint16_t)(x))
 #define SSWAP32(x) (other_endian ? __swap32(x) \
-				 : (__u32)(x))
+				 : (uint32_t)(x))
 				 
 /* fdisk.c */
 extern char MBRbuffer[MAX_SECTOR_SIZE];
diff -Naur util-linux-2.11x/fdisk/Makefile util-linux-2.11x-debian-patched/fdisk/Makefile
--- util-linux-2.11x/fdisk/Makefile	2002-10-08 17:42:11.000000000 +0200
+++ util-linux-2.11x-debian-patched/fdisk/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -39,7 +39,7 @@
 endif
 endif
 
-cfdisk: cfdisk.o llseek.o i386_sys_types.o $(LIB)/xstrncpy.o
+cfdisk: cfdisk.o llseek.o i386_sys_types.o $(LIB)/xstrncpy.o $(LIB)/get_blocks.o
 ifeq "$(HAVE_SLANG)" "yes"
 	$(CC) $(LDFLAGS) $^ -o $@ $(LIBSLANG)
 else
@@ -56,14 +56,14 @@
 	ln -s sfdisk activate
 
 fdisk: fdisk.o llseek.o fdiskbsdlabel.o fdisksgilabel.o fdisksunlabel.o \
-	fdiskaixlabel.o i386_sys_types.o partname.o
+	fdiskaixlabel.o i386_sys_types.o partname.o $(LIB)/get_blocks.o
 fdisk.o: fdisk.c fdisk.h
 fdiskbsdlabel.o: fdiskbsdlabel.c fdisk.h fdiskbsdlabel.h
 fdisksunlabel.o: fdisksunlabel.c fdisksunlabel.h fdisk.h
 fdiskaixlabel.o: fdiskaixlabel.c fdiskaixlabel.h fdisk.h
 fdisk.o cfdisk.o sfdisk.o fdiskbsdlabel.o fdisksunlabel.o \
 	fdisksgilabel.o fdiskaixlabel.o i386_sys_types.o partname.o: common.h
-sfdisk: sfdisk.o i386_sys_types.o partname.o
+sfdisk: sfdisk.o i386_sys_types.o partname.o $(LIB)/get_blocks.o
 
 install: all
 	$(INSTALLDIR) $(SBINDIR)
diff -Naur util-linux-2.11x/fdisk/sfdisk.c util-linux-2.11x-debian-patched/fdisk/sfdisk.c
--- util-linux-2.11x/fdisk/sfdisk.c	2002-10-31 14:49:29.000000000 +0100
+++ util-linux-2.11x-debian-patched/fdisk/sfdisk.c	2002-11-27 22:42:34.000000000 +0100
@@ -46,9 +46,12 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
+#ifdef __linux__
 #include <linux/unistd.h>	/* _syscall */
+#endif
 #include "nls.h"
 #include "common.h"
+#include "get_blocks.h"
 
 #define SIZE(a)	(sizeof(a)/sizeof(a[0]))
 
@@ -130,7 +133,7 @@
  *
  * Note: we use 512-byte sectors here, irrespective of the hardware ss.
  */
-#if !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__)
+#if defined(__linux__) && !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__)
 static
 _syscall5(int,  _llseek,  uint,  fd, ulong, hi, ulong, lo,
        loff_t *, res, uint, wh);
@@ -142,7 +145,7 @@
     in = ((loff_t) s << 9);
     out = 1;
 
-#if !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__)
+#if defined(__linux__) && !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) && !defined (__s390x__)
     if (_llseek (fd, in>>32, in & 0xffffffff, &out, SEEK_SET) != 0) {
 #else
     if ((out = lseek(fd, in, SEEK_SET)) != in) {
@@ -395,25 +398,31 @@
 
 static struct geometry
 get_geometry(char *dev, int fd, int silent) {
+#ifdef __linux__    
     struct hd_geometry g;
+#endif    
     long size;
     struct geometry R;
 
-    if (ioctl(fd, BLKGETSIZE, &size)) {
-	size = 0;
+    size = get_blocks(fd);
+    if (!size) {
 	if (!silent)
 	    printf(_("Disk %s: cannot get size\n"), dev);
     }
-    if (ioctl(fd, HDIO_GETGEO, &g)) {
-	g.heads = g.sectors = g.cylinders = g.start = 0;
+#ifdef __linux__
+    if (ioctl(fd, HDIO_GETGEO, &g) >= 0) {
+	R.heads = g.heads;
+	R.sectors = g.sectors;
+	R.cylindersize = R.heads * R.sectors;
+	R.cylinders = (R.cylindersize ? size / R.cylindersize : 0);
+	R.start = g.start;
+    } else
+#endif
+    {
+ 	R.heads = R.sectors = R.cylindersize = R.cylinders = R.start = 0;
 	if (!silent)
 	    printf(_("Disk %s: cannot get geometry\n"), dev);
     }
-    R.heads = g.heads;
-    R.sectors = g.sectors;
-    R.cylindersize = R.heads * R.sectors;
-    R.cylinders = (R.cylindersize ? size / R.cylindersize : 0);
-    R.start = g.start;
     return R;
 }
 
@@ -721,11 +730,12 @@
 /* tell the kernel to reread the partition tables */
 static int
 reread_ioctl(int fd) {
-    if(ioctl(fd, BLKRRPART)) {
-	perror("BLKRRPART");
-	return -1;
-    }
-    return 0;
+#ifdef __linux__
+    if(!ioctl(fd, BLKRRPART))
+	return 0;
+    perror("BLKRRPART");
+#endif
+    return -1;
 }
 
 static int
@@ -1428,6 +1438,7 @@
 	z->partno = pno;
 }
 
+#ifdef __linux__
 #define MAKE_VERSION(p,q,r)     (65536*(p) + 256*(q) + (r))
 
 static int
@@ -1443,6 +1454,7 @@
         }
         return 0;
 }
+#endif
 
 static int
 msdos_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
@@ -1452,7 +1464,11 @@
     struct sector *s;
     struct part_desc *partitions = &(z->partitions[0]);
     int pno = z->partno;
+#ifdef __linux__   
     int bsd_later = (linux_version_code() >= MAKE_VERSION(2,3,40));
+#else
+    int bsd_later = 0;
+#endif
 
     if (!(s = get_sector(dev, fd, start)))
 	return 0;
@@ -2668,10 +2684,11 @@
     if (fd < 0)
 	return;
 
-    if(ioctl(fd, BLKGETSIZE, &size)) {
+    size = get_blocks(fd);
+    if (!size) {
 	if(!silent) {
 	    perror(dev);
-	    fatal(_("BLKGETSIZE ioctl failed for %s\n"), dev);
+	    fatal(_("Disk %s: cannot get size\n"), dev);
 	}
 	return;
     }
diff -Naur util-linux-2.11x/hwclock/Makefile util-linux-2.11x-debian-patched/hwclock/Makefile
--- util-linux-2.11x/hwclock/Makefile	2002-07-06 23:23:58.000000000 +0200
+++ util-linux-2.11x-debian-patched/hwclock/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -3,6 +3,7 @@
 include ../make_include
 include ../MCONFIG
 
+ifeq "$(OS)" "linux"
 # Where to put man pages?
 
 MAN8= 		hwclock.8
@@ -11,6 +12,7 @@
 # See the "install" rule for the links. . .
 
 SBIN= 		hwclock
+endif
 
 
 all: $(SBIN)
diff -Naur util-linux-2.11x/lib/get_blocks.c util-linux-2.11x-debian-patched/lib/get_blocks.c
--- util-linux-2.11x/lib/get_blocks.c	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.11x-debian-patched/lib/get_blocks.c	2002-11-27 22:42:34.000000000 +0100
@@ -0,0 +1,92 @@
+/*
+ * unsigned long get_blocks(int fd)
+ *
+ * 	returns the number of 512-byte blocks of fd
+ *
+ * Most code ripped from:
+ * 
+ * 	mkswap.c
+ * 	mkfs.bfs.c
+ * 	mkfs.minix.c
+ *
+ * by Guillem Jover <guillem@hadrons.org>
+ * 
+ */
+
+#include "../defines.h"
+#include "get_blocks.h"
+#include <sys/types.h>
+#ifdef HAVE_st_blocks
+#include <sys/stat.h>
+#endif
+#include <unistd.h>
+
+#ifdef __linux__
+#include <sys/ioctl.h>
+
+/* cannot include <linux/fs.h> */
+#ifndef BLKGETSIZE
+/* return device size */
+#ifndef _IO
+/* pre-1.3.45 */
+#define BLKGETSIZE 0x1260
+#else
+/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
+#define BLKGETSIZE _IO(0x12,96)
+#endif
+#endif
+#endif /* __linux__ */
+
+static int
+valid_offset (int fd, off_t offset)
+{
+	char	ch;
+
+	if (lseek (fd, offset, 0) < 0)
+		return 0;
+	if (read (fd, &ch, 1) < 1)
+		return 0;
+	return 1;
+}
+
+static off_t 
+count_blocks (int fd)
+{
+	off_t	high, low, blocks;
+
+	low = 0;
+	for (high = 1; high > 0 && valid_offset (fd, high); high *= 2)
+		low = high;
+	while (low < high - 1)
+	{
+		const off_t	mid = (low + high) / 2;
+
+		if (valid_offset (fd, mid))
+			low = mid;
+		else
+			high = mid;
+	}
+	blocks = (low + 1) / 512;
+	return blocks;
+}
+
+unsigned long
+get_blocks (int fd)
+{
+#ifdef __linux__
+	{
+		unsigned long	blocks;
+		if (ioctl(fd, BLKGETSIZE, &blocks) >= 0)
+			return blocks;
+	}
+#endif /*  __linux__ */
+#ifdef HAVE_st_blocks
+	{
+		struct stat	st;
+		if (fstat(fd, &st) == 0)
+			return st.st_blocks;
+	}
+#endif
+	return count_blocks(fd);
+}
+
diff -Naur util-linux-2.11x/lib/get_blocks.h util-linux-2.11x-debian-patched/lib/get_blocks.h
--- util-linux-2.11x/lib/get_blocks.h	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.11x-debian-patched/lib/get_blocks.h	2002-11-27 22:42:34.000000000 +0100
@@ -0,0 +1,7 @@
+#ifndef GET_BLOCKS_H
+#define GET_BLOCKS_H
+
+extern unsigned long get_blocks (int fd);
+
+#endif
+
diff -Naur util-linux-2.11x/lib/Makefile util-linux-2.11x-debian-patched/lib/Makefile
--- util-linux-2.11x/lib/Makefile	2002-11-02 14:51:26.000000000 +0100
+++ util-linux-2.11x-debian-patched/lib/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -1,8 +1,9 @@
 include ../make_include
 include ../MCONFIG
 
-all: err.o my_reboot.o setproctitle.o env.o carefulputc.o xstrncpy.o md5.o
-
+all: err.o my_reboot.o setproctitle.o env.o carefulputc.o md5.o \
+	xgethostname.o xstrncpy.o get_blocks.o
+ 
 err.o: err.c
 
 my_reboot.o: my_reboot.c linux_reboot.h
@@ -15,6 +16,10 @@
 
 xstrncpy.o: xstrncpy.h
 
+xgethostname.o: xgethostname.h
+
+get_blocks.o: get_blocks.h
+
 md5.o: md5.c md5.h
 
 .PHONY: clean
diff -Naur util-linux-2.11x/lib/README.xgethostname util-linux-2.11x-debian-patched/lib/README.xgethostname
--- util-linux-2.11x/lib/README.xgethostname	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.11x-debian-patched/lib/README.xgethostname	2002-11-27 22:42:34.000000000 +0100
@@ -0,0 +1,76 @@
+A wrapper for gethostname that automatically checks system limitations.
+
+Latest version can always be found at:
+ftp://walfield.org/pub/people/neal/xgethostname/xgethostname-latest.tar.gz
+
+Author:
+Neal H Walfield <neal@cs.uml.edu>
+
+Version:
+April 13, 2002
+
+ChangeLog:
+2002-04-13  Neal H Walfield  <neal@walfield.org>
+
+	* VERSION: Update to 20010413.
+	* Release version 20010413.
+	
+2002-04-13  Neal H Walfield  <neal@walfield.org>
+
+	* xgethostname.c (xgethostname): gethostname returns -1 on error,
+	not the error code.  There is no need to use realloc as it copies
+	the unused buffer.
+
+2001-08-03  Neal H Walfield  <neal@cs.uml.edu>
+
+	* VERSION: Update to 20010803.
+	* Release version 20010803.
+
+2001-08-03  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Makefile: Make no assumptions about the make that the user
+	will be using.
+	* xgethostname.c (xgethostname): Be explicitly sure that the
+	returned buffer is NULL terminated.
+	Always compile in the while (err = ENAMETOOLONG) loop; this
+	may help to catch a very exotic implementation and does not
+	hurt anyone.
+
+2001-08-02  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Release version 20010802.
+
+2001-08-01  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Makefile: New file.
+	* README: New file.
+	* xgethostname.c (xgethostname) [!_SC_HOST_NAME_MAX]: Should
+	not be subject to this condition.
+	(xgethostname): If the system defines a limit < 256 and > 0,
+	do not artificially inflate it, rather, respect it.
+
+2001-07-30  Neal H Walfield  <neal@cs.uml.edu>
+
+	* REAMME: Move from here . . .
+	* xgethostname.2: to here.
+	Format it for man.
+
+2001-07-30  Neal H Walfield  <neal@cs.uml.edu>
+
+	* README: Fix grammer error.
+	* xgethostname.c: Likewise.
+	* xgethostname.h: Likewise.
+
+	* Makefile: New file.
+
+2001-07-29  Neal H Walfield  <neal@cs.uml.edu>
+
+	* Release version 20010729.
+
+	* AUTHOR: New file.
+	* ChangeLog: New file.
+	* COPYING: New file.
+	* README: New file.
+	* VERSION: New file.
+	* xgethostname.c: New file.
+	* xgethostname.h: New file.
diff -Naur util-linux-2.11x/lib/xgethostname.2 util-linux-2.11x-debian-patched/lib/xgethostname.2
--- util-linux-2.11x/lib/xgethostname.2	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.11x-debian-patched/lib/xgethostname.2	2002-11-27 22:42:34.000000000 +0100
@@ -0,0 +1,37 @@
+.TH XGETHOSTNAME 2 "30 July 2001" "xgethostname"
+.SH NAME
+xgethostname \- get the host name.
+.SH
+SYNOPSIS
+.BI "char *xgethostname (void);"
+.SH DESCRIPTION
+The xhostname function is intended to replace
+.BR gethostname(2),
+a function used to access the host name.  The old interface is
+inflexable given that it assumes the existance of the
+.BR MAXHOSTNAMELEN
+macro, which neither
+.BR POSIX
+nor the proposed
+.BR "Single Unix Specification version 3"
+guarantee to be defined.
+.SH RETURN VALUE
+On success, a malloced, null terminated (possibly truncated)
+string containing the host name is returned.  On failure,
+.I NULL
+is returned and errno is set.
+.SH ERRORS
+.TP
+.BR ENOMEM
+Failed to allocate memory.
+.LP
+As 
+.BR xgethostname
+is really just a wrapper around your systems
+.BR gethostname (2),
+see that man page for additional details.
+.SH "SEE ALSO"
+.BR gethostname (2)
+.SH AUTHOR
+.BR xgethostname
+was written by Neal H Walfield  <neal@cs.uml.edu>.
diff -Naur util-linux-2.11x/lib/xgethostname.c util-linux-2.11x-debian-patched/lib/xgethostname.c
--- util-linux-2.11x/lib/xgethostname.c	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.11x-debian-patched/lib/xgethostname.c	2002-11-27 22:42:34.000000000 +0100
@@ -0,0 +1,126 @@
+/* Copyright (c) 2001 Neal H Walfield <neal@cs.uml.edu>.
+   
+   This file is placed into the public domain.  Its distribution
+   is unlimited.
+
+   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
+   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+   INTERRUPTION) 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.
+ */
+
+/* NAME
+
+	xgethostname - get the host name.
+
+   SYNOPSIS
+
+   	char *xgethostname (void);
+
+   DESCRIPTION
+
+	The xhostname function is intended to replace gethostname(2), a
+	function used to access the host name.  The old interface is
+	inflexable given that it assumes the existance of the
+	MAXHOSTNAMELEN macro, which neither POSIX nor the proposed
+	Single Unix Specification version 3 guarantee to be defined.
+
+   RETURN VALUE
+
+	On success, a malloced, null terminated (possibly truncated)
+	string containing the host name is returned.  On failure,
+	NULL is returned and errno is set.
+ */
+
+#include <sys/param.h>	/* For MAXHOSTNAMELEN */
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include "xgethostname.h"
+
+char *
+xgethostname (void)
+{
+  int size = 0;
+  int addnull = 0;
+  char *buf;
+  int err;
+
+#ifdef MAXHOSTNAMELEN
+  size = MAXHOSTNAMELEN;
+  addnull = 1;
+#else /* MAXHOSTNAMELEN */
+#ifdef _SC_HOST_NAME_MAX
+  size = sysconf (_SC_HOST_NAME_MAX);
+  addnull = 1;
+#endif /* _SC_HOST_NAME_MAX */
+  if (size <= 0)
+    size = 256;
+#endif /* MAXHOSTNAMELEN */
+
+  buf = malloc (size + addnull);
+  if (! buf)
+    {
+      errno = ENOMEM;
+      return NULL;
+    }
+
+  err = gethostname (buf, size);
+  while (err == -1 && errno == ENAMETOOLONG)
+    {
+      free (buf);
+
+      size *= 2;
+      buf = malloc (size + addnull);
+      if (! buf)
+	{
+	  errno = ENOMEM;
+	  return NULL;
+	}
+      
+      err = gethostname (buf, size);
+    }
+
+  if (err)
+    {
+      if (buf)
+        free (buf);
+      errno = err;
+      return NULL;
+    }
+
+  if (addnull)
+    buf[size] = '\0';
+
+  return buf;
+}
+
+#ifdef WANT_TO_TEST_XGETHOSTNAME
+#include <stdio.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+  char *hostname;
+
+  hostname = xgethostname ();
+  if (! hostname)
+    {
+      perror ("xgethostname");
+      return 1;
+    }
+
+  printf ("%s\n", hostname);
+  free (hostname);
+
+  return 0;
+}
+#endif /* WANT_TO_TEST_XGETHOSTNAME */
diff -Naur util-linux-2.11x/lib/xgethostname.h util-linux-2.11x-debian-patched/lib/xgethostname.h
--- util-linux-2.11x/lib/xgethostname.h	1970-01-01 01:00:00.000000000 +0100
+++ util-linux-2.11x-debian-patched/lib/xgethostname.h	2002-11-27 22:42:34.000000000 +0100
@@ -0,0 +1,48 @@
+/* Copyright (c) 2001 Neal H Walfield <neal@cs.uml.edu>.
+   
+   This file is placed into the public domain.  Its distribution
+   is unlimited.
+
+   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
+   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+   INTERRUPTION) 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.
+ */
+
+/* NAME
+
+	xgethostname - get the host name.
+
+   SYNOPSIS
+
+   	char *xgethostname (void);
+
+   DESCRIPTION
+
+	The xhostname function is intended to replace gethostname(2), a
+	function used to access the host name.  The old interface is
+	inflexable given that it assumes the existance of the
+	MAXHOSTNAMELEN macro, which neither POSIX nor the proposed
+	Single Unix Specification version 3 guarantee to be defined.
+
+   RETURN VALUE
+
+	On success, a malloced, null terminated (possibly truncated)
+	string containing the host name is returned.  On failure,
+	NULL is returned and errno is set.
+ */
+
+#ifndef XGETHOSTNAME
+#define XGETHOSTNAME
+
+char * xgethostname (void);
+
+#endif /* XGETHOSTNAME */
+
diff -Naur util-linux-2.11x/login-utils/agetty.c util-linux-2.11x-debian-patched/login-utils/agetty.c
--- util-linux-2.11x/login-utils/agetty.c	2002-07-29 09:36:42.000000000 +0200
+++ util-linux-2.11x-debian-patched/login-utils/agetty.c	2002-11-27 22:42:34.000000000 +0100
@@ -17,8 +17,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/ioctl.h>
-#include <termio.h>
+#include <termios.h>
 #include <signal.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -30,10 +29,11 @@
 #include <getopt.h>
 #include <time.h>
 #include <sys/file.h>
+#include "xgethostname.h"
 #include "xstrncpy.h"
 #include "nls.h"
 
-#ifdef __linux__
+#if defined(unix)
 #include "pathnames.h"
 #include <sys/param.h>
 #define USE_SYSLOG
@@ -93,27 +93,6 @@
 #define DEF_SWITCH	0		/* default switch char */
 
  /*
-  * SunOS 4.1.1 termio is broken. We must use the termios stuff instead,
-  * because the termio -> termios translation does not clear the termios
-  * CIBAUD bits. Therefore, the tty driver would sometimes report that input
-  * baud rate != output baud rate. I did not notice that problem with SunOS
-  * 4.1. We will use termios where available, and termio otherwise.
-  */
-
-/* linux 0.12 termio is broken too, if we use it c_cc[VERASE] isn't set
-   properly, but all is well if we use termios?! */
-
-#ifdef	TCGETS
-#undef	TCGETA
-#undef	TCSETA
-#undef	TCSETAW
-#define	termio	termios
-#define	TCGETA	TCGETS
-#define	TCSETA	TCSETS
-#define	TCSETAW	TCSETSW
-#endif
-
- /*
   * This program tries to not use the standard-i/o library.  This keeps the
   * executable small on systems that do not have shared libraries (System V
   * Release <3).
@@ -221,13 +200,13 @@
 void parse_args P_((int argc, char **argv, struct options *op));
 void parse_speeds P_((struct options *op, char *arg));
 void update_utmp P_((char *line));
-void open_tty P_((char *tty, struct termio *tp, int local));
-void termio_init P_((struct termio *tp, int speed, struct options *op));
-void auto_baud P_((struct termio *tp));
-void do_prompt P_((struct options *op, struct termio *tp));
-void next_speed P_((struct termio *tp, struct options *op));
-char *get_logname P_((struct options *op, struct chardata *cp, struct termio *tp));
-void termio_final P_((struct options *op, struct termio *tp, struct chardata *cp));
+void open_tty P_((char *tty, struct termios *tp, int local));
+void termios_init P_((struct termios *tp, int speed, struct options *op));
+void auto_baud P_((struct termios *tp));
+void do_prompt P_((struct options *op, struct termios *tp));
+void next_speed P_((struct termios *tp, struct options *op));
+char *get_logname P_((struct options *op, struct chardata *cp, struct termios *tp));
+void termios_final P_((struct options *op, struct termios *tp, struct chardata *cp));
 int caps_lock P_((char *s));
 int bcode P_((char *s));
 void usage P_((void));
@@ -256,7 +235,7 @@
 {
     char   *logname = NULL;		/* login name, given to /bin/login */
     struct chardata chardata;		/* set by get_logname() */
-    struct termio termio;		/* terminal mode bits */
+    struct termios termios;		/* terminal mode bits */
     static struct options options = {
 	F_ISSUE,			/* show /etc/issue (SYSV_STYLE) */
 	0,				/* no timeout */
@@ -299,7 +278,7 @@
 
     parse_args(argc, argv, &options);
 
-#ifdef __linux__
+#if defined(unix)
 	setsid();
 #endif
 	
@@ -311,19 +290,19 @@
 
     debug(_("calling open_tty\n"));
     /* Open the tty as standard { input, output, error }. */
-    open_tty(options.tty, &termio, options.flags & F_LOCAL);
+    open_tty(options.tty, &termios, options.flags & F_LOCAL);
 
-#ifdef __linux__
+#if defined(unix)
 	{
 		int iv;
 		
 		iv = getpid();
-		(void) ioctl(0, TIOCSPGRP, &iv);
+		(void) tcsetpgrp(0, iv);
 	}
 #endif
-    /* Initialize the termio settings (raw mode, eight-bit, blocking i/o). */
-    debug(_("calling termio_init\n"));
-    termio_init(&termio, options.speeds[FIRST_SPEED], &options);
+    /* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */
+    debug(_("calling termios_init\n"));
+    termios_init(&termios, options.speeds[FIRST_SPEED], &options);
 
     /* write the modem init string and DON'T flush the buffers */
     if (options.flags & F_INITSTRING) {
@@ -339,7 +318,7 @@
     /* Optionally detect the baud rate from the modem status message. */
     debug(_("before autobaud\n"));
     if (options.flags & F_PARSE)
-	auto_baud(&termio);
+	auto_baud(&termios);
 
     /* Set the optional timer. */
     if (options.timeout)
@@ -363,8 +342,8 @@
     if (!(options.flags & F_NOPROMPT)) {
 	/* Read the login name. */
 	debug(_("reading login name\n"));
-	while ((logname = get_logname(&options, &chardata, &termio)) == 0)
-	  next_speed(&termio, &options);
+	while ((logname = get_logname(&options, &chardata, &termios)) == 0)
+	  next_speed(&termios, &options);
     }
 
     /* Disable timer. */
@@ -372,9 +351,9 @@
     if (options.timeout)
 	(void) alarm(0);
 
-    /* Finalize the termio settings. */
+    /* Finalize the termios settings. */
 
-    termio_final(&options, &termio, &chardata);
+    termios_final(&options, &termios, &chardata);
 
     /* Now the newline character should be properly written. */
 
@@ -629,7 +608,7 @@
 void
 open_tty(tty, tp, local)
      char   *tty;
-     struct termio *tp;
+     struct termios *tp;
      int    local;
 {
     /* Get rid of the present standard { output, error} if any. */
@@ -678,7 +657,7 @@
 	error(_("%s: dup problem: %m"), tty);	/* we have a problem */
 
     /*
-     * The following ioctl will fail if stdin is not a tty, but also when
+     * The following function will fail if stdin is not a tty, but also when
      * there is noise on the modem control lines. In the latter case, the
      * common course of action is (1) fix your cables (2) give the modem more
      * time to properly reset after hanging up. SunOS users can achieve (2)
@@ -686,8 +665,8 @@
      * 5 seconds seems to be a good value.
      */
 
-    if (ioctl(0, TCGETA, tp) < 0)
-	error("%s: ioctl: %m", tty);
+    if (tcgetattr(0, tp) < 0)
+	error("%s: tcgetattr: %m", tty);
 
     /*
      * It seems to be a terminal. Set proper protections and ownership. Mode
@@ -705,27 +684,27 @@
     errno = 0;					/* ignore above errors */
 }
 
-/* termio_init - initialize termio settings */
+/* termios_init - initialize termios settings */
 
 char gbuf[1024];
 char area[1024];
 
 void
-termio_init(tp, speed, op)
-     struct termio *tp;
+termios_init(tp, speed, op)
+     struct termios *tp;
      int     speed;
      struct options *op;
 {
 
     /*
-     * Initial termio settings: 8-bit characters, raw-mode, blocking i/o.
+     * Initial termios settings: 8-bit characters, raw-mode, blocking i/o.
      * Special characters are set after we have read the login name; all
      * reads will be done in raw mode anyway. Errors will be dealt with
      * lateron.
      */
-#ifdef __linux__
+#if defined(unix)
     /* flush input and output queues, important for modems! */
-    (void) ioctl(0, TCFLSH, TCIOFLUSH);
+    (void) tcflush(0, TCIOFLUSH);
 #endif
 
     tp->c_cflag = CS8 | HUPCL | CREAD | speed;
@@ -733,7 +712,10 @@
 	tp->c_cflag |= CLOCAL;
     }
 
-    tp->c_iflag = tp->c_lflag = tp->c_oflag = tp->c_line = 0;
+    tp->c_iflag = tp->c_lflag = tp->c_oflag = 0;
+#if defined(__linux__)
+    tp->c_line = 0;
+#endif
     tp->c_cc[VMIN] = 1;
     tp->c_cc[VTIME] = 0;
 
@@ -744,7 +726,7 @@
 	tp->c_cflag |= CRTSCTS;
 #endif
 
-    (void) ioctl(0, TCSETA, tp);
+    (void) tcsetattr(0, TCSANOW, tp);
 
     /* go to blocking input even in local mode */
     fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~O_NONBLOCK);
@@ -755,7 +737,7 @@
 /* auto_baud - extract baud rate from modem status message */
 void
 auto_baud(tp)
-     struct termio *tp;
+     struct termios *tp;
 {
     int     speed;
     int     vmin;
@@ -788,7 +770,7 @@
     tp->c_iflag |= ISTRIP;			/* enable 8th-bit stripping */
     vmin = tp->c_cc[VMIN];
     tp->c_cc[VMIN] = 0;				/* don't block if queue empty */
-    (void) ioctl(0, TCSETA, tp);
+    (void) tcsetattr(0, TCSANOW, tp);
 
     /*
      * Wait for a while, then read everything the modem has said so far and
@@ -801,8 +783,7 @@
 	for (bp = buf; bp < buf + nread; bp++) {
 	    if (isascii(*bp) && isdigit(*bp)) {
 		if ((speed = bcode(bp))) {
-		    tp->c_cflag &= ~CBAUD;
-		    tp->c_cflag |= speed;
+		    (void) cfsetospeed(tp, speed);
 		}
 		break;
 	    }
@@ -812,14 +793,14 @@
 
     tp->c_iflag = iflag;
     tp->c_cc[VMIN] = vmin;
-    (void) ioctl(0, TCSETA, tp);
+    (void) tcsetattr(0, TCSANOW, tp);
 }
 
 /* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
 void
 do_prompt(op, tp)
      struct options *op;
-     struct termio *tp;
+     struct termios *tp;
 {
 #ifdef	ISSUE
     FILE    *fd;
@@ -835,7 +816,7 @@
     if ((op->flags & F_ISSUE) && (fd = fopen(op->issue, "r"))) {
 	oflag = tp->c_oflag;			/* save current setting */
 	tp->c_oflag |= (ONLCR | OPOST);		/* map NL in output to CR-NL */
-	(void) ioctl(0, TCSETAW, tp);
+	(void) tcsetattr(0, TCSADRAIN, tp);
 
 
 	while ((c = getc(fd)) != EOF)
@@ -915,7 +896,7 @@
 			int i;
 
 			for (i = 0; speedtab[i].speed; i++) {
-			    if (speedtab[i].code == (tp->c_cflag & CBAUD)) {
+			    if (speedtab[i].code == cfgetospeed(tp)) {
 				printf("%ld", speedtab[i].speed);
 				break;
 			    }
@@ -947,16 +928,18 @@
 	fflush(stdout);
 
 	tp->c_oflag = oflag;			/* restore settings */
-	(void) ioctl(0, TCSETAW, tp);		/* wait till output is gone */
+	(void) tcsetattr(0, TCSADRAIN, tp);	/* wait till output is gone */
 	(void) fclose(fd);
     }
 #endif
-#ifdef __linux__
+#ifdef unix
 	{
-		char hn[MAXHOSTNAMELEN+1];
+		char *hn;
 
-		(void) gethostname(hn, MAXHOSTNAMELEN);
+		if (!(hn = xgethostname()))
+			error(_("can't get hostname"));
 		write(1, hn, strlen(hn));
+		free(hn);
 	}
 #endif		
     (void) write(1, LOGIN, sizeof(LOGIN) - 1);	/* always show login prompt */
@@ -965,15 +948,14 @@
 /* next_speed - select next baud rate */
 void
 next_speed(tp, op)
-     struct termio *tp;
+     struct termios *tp;
      struct options *op;
 {
     static int baud_index = FIRST_SPEED;/* current speed index */
 
     baud_index = (baud_index + 1) % op->numspeed;
-    tp->c_cflag &= ~CBAUD;
-    tp->c_cflag |= op->speeds[baud_index];
-    (void) ioctl(0, TCSETA, tp);
+    (void) cfsetospeed(0, op->speeds[baud_index]);
+    (void) tcsetattr(0, TCSANOW, tp);
 }
 
 /* get_logname - get user name, establish parity, speed, erase, kill, eol */
@@ -981,7 +963,7 @@
 char   *get_logname(op, cp, tp)
      struct options *op;
      struct chardata *cp;
-     struct termio *tp;
+     struct termios *tp;
 {
     static char logname[BUFSIZ];
     char   *bp;
@@ -1003,7 +985,7 @@
     /* Flush pending input (esp. after parsing or switching the baud rate). */
 
     (void) sleep(1);
-    (void) ioctl(0, TCFLSH, TCIFLUSH);
+    (void) tcflush(0, TCIFLUSH);
 
     /* Prompt for and read a login name. */
 
@@ -1087,11 +1069,11 @@
     return (logname);
 }
 
-/* termio_final - set the final tty mode bits */
+/* termios_final - set the final tty mode bits */
 void
-termio_final(op, tp, cp)
+termios_final(op, tp, cp)
      struct options *op;
-     struct termio *tp;
+     struct termios *tp;
      struct chardata *cp;
 {
     /* General terminal-independent stuff. */
@@ -1107,7 +1089,7 @@
     tp->c_cc[VEOL] = DEF_EOL;
 #ifdef __linux__
     tp->c_cc[VSWTC] = DEF_SWITCH;		/* default switch character */
-#else
+#elif defined(VSWTCH)
     tp->c_cc[VSWTCH] = DEF_SWITCH;		/* default switch character */
 #endif
 
@@ -1139,11 +1121,13 @@
     }
     /* Account for upper case without lower case. */
 
+#if defined(IUCLC) && defined(XCASE) && defined(OLCUC)
     if (cp->capslock) {
 	tp->c_iflag |= IUCLC;
 	tp->c_lflag |= XCASE;
 	tp->c_oflag |= OLCUC;
     }
+#endif
     /* Optionally enable hardware flow control */
 
 #ifdef	CRTSCTS
@@ -1153,8 +1137,8 @@
 
     /* Finally, make the new settings effective */
 
-    if (ioctl(0, TCSETA, tp) < 0)
-	error("%s: ioctl: TCSETA: %m", op->tty);
+    if (tcsetattr(0, TCSADRAIN, tp) < 0)
+	error("%s: tcsetattr: %m", op->tty);
 }
 
 /* caps_lock - string contains upper case without lower case */
diff -Naur util-linux-2.11x/login-utils/checktty.c util-linux-2.11x-debian-patched/login-utils/checktty.c
--- util-linux-2.11x/login-utils/checktty.c	2001-05-19 23:53:18.000000000 +0200
+++ util-linux-2.11x-debian-patched/login-utils/checktty.c	2002-11-27 22:42:34.000000000 +0100
@@ -138,7 +138,9 @@
 isapty(const char *tty)
 {
     char devname[100];
+#if defined(__linux__)
     struct stat stb;
+#endif
 
     /* avoid snprintf - old systems do not have it */
     if (strlen(tty) + 6 > sizeof(devname))
diff -Naur util-linux-2.11x/login-utils/last.c util-linux-2.11x-debian-patched/login-utils/last.c
--- util-linux-2.11x/login-utils/last.c	2002-03-08 23:59:41.000000000 +0100
+++ util-linux-2.11x-debian-patched/login-utils/last.c	2002-11-27 22:42:34.000000000 +0100
@@ -49,6 +49,7 @@
 
 #include "pathnames.h"
 #include "nls.h"
+#include "xgethostname.h"
 
 #define	SECDAY	(24*60*60)			/* seconds in a day */
 #define	NO	0				/* false/no */
@@ -430,15 +431,15 @@
 hostconv(char *arg) {
 	static int	first = 1;
 	static char	*hostdot,
-			name[MAXHOSTNAMELEN];
+			*name;
 	char	*argdot;
 
 	if (!(argdot = strchr(arg, '.')))
 		return;
 	if (first) {
 		first = 0;
-		if (gethostname(name, sizeof(name))) {
-			perror(_("last: gethostname"));
+		if (!(name = xgethostname())) {
+			perror(_("last: can't get hostname"));
 			exit(1);
 		}
 		hostdot = strchr(name, '.');
diff -Naur util-linux-2.11x/login-utils/login.c util-linux-2.11x-debian-patched/login-utils/login.c
--- util-linux-2.11x/login-utils/login.c	2002-10-08 15:25:56.000000000 +0200
+++ util-linux-2.11x-debian-patched/login-utils/login.c	2002-11-27 22:42:34.000000000 +0100
@@ -116,6 +116,7 @@
 #include "my_crypt.h"
 #include "login.h"
 #include "xstrncpy.h"
+#include "xgethostname.h"
 #include "nls.h"
 
 #ifdef __linux__
@@ -149,7 +150,7 @@
 }
 #endif
 
-#ifndef __linux__
+#if !defined(__linux__) && !defined(__GNU__)
 #  include <tzfile.h>
 #endif
 #include <lastlog.h>
@@ -203,18 +204,14 @@
 #define	TTYGRPNAME	"tty"		/* name of group to own ttys */
 /**#  define TTYGRPNAME      "other" **/
 
-#ifndef MAXPATHLEN
-#  define MAXPATHLEN 1024
-#endif
-
 /*
  * This bounds the time given to login.  Not a define so it can
  * be patched on machines where it's too small.
  */
-#ifndef __linux__
-int	timeout = 300;
+#if defined(__linux__) || defined(__GNU__)
+int	timeout = 60;		/* used in cryptocard.c */
 #else
-int     timeout = 60;		/* used in cryptocard.c */
+int	timeout = 300;
 #endif
 
 struct	passwd *pwd;		/* used in cryptocard.c */
@@ -224,7 +221,7 @@
 char    hostaddress[4];		/* used in checktty.c */
 char	*hostname;		/* idem */
 static char	*username, *tty_name, *tty_number;
-static char	thishost[100];
+static char	*thishost;
 static int	failures = 1;
 static pid_t	pid;
 
@@ -294,6 +291,7 @@
 	}
 }
 
+#ifdef CHOWNVCS
 /* true if the filedescriptor fd is a console tty, very Linux specific */
 static int
 consoletty(int fd) {
@@ -308,6 +306,7 @@
 #endif
     return 0;
 }
+#endif
 
 #if USE_PAM
 /*
@@ -362,7 +361,7 @@
     int ask, fflag, hflag, pflag, cnt, errsv;
     int quietlog, passwd_req;
     char *domain, *ttyn;
-    char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10];
+    char tname[sizeof(_PATH_TTY) + 10];
     char *termenv;
     char *childArgv[10];
     char *buff;
@@ -404,9 +403,11 @@
      * -h is used by other servers to pass the name of the remote
      *    host to login so that it may be placed in utmp and wtmp
      */
-    gethostname(tbuf, sizeof(tbuf));
-    xstrncpy(thishost, tbuf, sizeof(thishost));
-    domain = index(tbuf, '.');
+    if (!(thishost = xgethostname())) {
+	    fprintf(stderr, _("login: can't get hostname\n"));
+	    exit(1);
+    }
+    domain = index(thishost, '.');
     
     username = tty_name = hostname = NULL;
     fflag = hflag = pflag = 0;
@@ -867,23 +868,21 @@
        having the BSD setreuid() */
     
     {
-	char tmpstr[MAXPATHLEN];
+	char *tmpstr;
 	uid_t ruid = getuid();
 	gid_t egid = getegid();
 
 	/* avoid snprintf - old systems do not have it, or worse,
 	   have a libc in which snprintf is the same as sprintf */
-	if (strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2 > MAXPATHLEN)
-		quietlog = 0;
-	else {
-		sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN);
-		setregid(-1, pwd->pw_gid);
-		setreuid(0, pwd->pw_uid);
-		quietlog = (access(tmpstr, R_OK) == 0);
-		setuid(0); /* setreuid doesn't do it alone! */
-		setreuid(ruid, 0);
-		setregid(-1, egid);
-	}
+	tmpstr = malloc(strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2);
+	sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN);
+	setregid(-1, pwd->pw_gid);
+	setreuid(0, pwd->pw_uid);
+	quietlog = (access(tmpstr, R_OK) == 0);
+	setuid(0); /* setreuid doesn't do it alone! */
+	setreuid(ruid, 0);
+	setregid(-1, egid);
+	free(tmpstr);
     }
     
     /* for linux, write entries in utmp and wtmp */
@@ -1035,12 +1034,13 @@
     
     /* mailx will give a funny error msg if you forget this one */
     {
-      char tmp[MAXPATHLEN];
+      char *tmp;
+
       /* avoid snprintf */
-      if (sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 1 < MAXPATHLEN) {
-	      sprintf(tmp, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
-	      setenv("MAIL",tmp,0);
-      }
+      tmp = malloc(sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 2);
+      sprintf(tmp, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
+      setenv("MAIL", tmp, 0);
+      free(tmp);
     }
     
     /* LOGNAME is not documented in login(1) but
@@ -1187,13 +1187,15 @@
 	childArgv[childArgc++] = "-c";
 	childArgv[childArgc++] = buff;
     } else {
-	tbuf[0] = '-';
-	xstrncpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ?
-			   p + 1 : pwd->pw_shell),
-		sizeof(tbuf)-1);
+	char *tbuf, *shell_cmd;
+
+	tbuf = ((p = rindex(pwd->pw_shell, '/')) ? p + 1 : pwd->pw_shell);
+	shell_cmd = malloc(strlen(tbuf));
+	shell_cmd[0] = '-';
+	xstrncpy(shell_cmd + 1, tbuf, strlen(tbuf)-1);
 	
 	childArgv[childArgc++] = pwd->pw_shell;
-	childArgv[childArgc++] = tbuf;
+	childArgv[childArgc++] = shell_cmd;
     }
 
     childArgv[childArgc++] = NULL;
@@ -1260,14 +1262,14 @@
 
 void
 timedout(int sig) {
-    struct termio ti;
+    struct termios ti;
     
     fprintf(stderr, _("Login timed out after %d seconds\n"), timeout);
     
     /* reset echo */
-    ioctl(0, TCGETA, &ti);
+    tcgetattr(0, &ti);
     ti.c_lflag |= ECHO;
-    ioctl(0, TCSETA, &ti);
+    tcsetattr(0, TCSANOW, &ti);
     exit(0);			/* %% */
 }
 
diff -Naur util-linux-2.11x/login-utils/Makefile util-linux-2.11x-debian-patched/login-utils/Makefile
--- util-linux-2.11x/login-utils/Makefile	2001-09-29 20:11:24.000000000 +0200
+++ util-linux-2.11x-debian-patched/login-utils/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -18,8 +18,10 @@
 
 MAN8.GETTY=	agetty.8
 
-MAN8.INIT=	fastboot.8 fasthalt.8 halt.8 reboot.8 simpleinit.8 shutdown.8 \
-		initctl.8
+MAN8.INIT=	simpleinit.8 initctl.8
+ifeq "$(OS)" "linux"
+MAN8.INIT:=	$(MAN8.INIT) fastboot.8 fasthalt.8 halt.8 reboot.8 shutdown.8
+endif
 
 MAN8.PUTILS=	vipw.8 vigr.8
 
@@ -28,7 +30,10 @@
 
 SBIN.GETTY=	agetty
 
-SBIN.INIT=	simpleinit shutdown initctl
+SBIN.INIT=	simpleinit initctl
+ifeq "$(OS)" "linux"
+SBIN.INIT:=	$(SBIN.INIT) shutdown
+endif
 
 BIN.PUTILS=	login
 
@@ -95,18 +100,19 @@
 shutdown.o simpleinit.o: $(LIB)/linux_reboot.h
 wall.o: ttymsg.h $(LIB)/carefulputc.h
 
-agetty: agetty.o $(LIB)/xstrncpy.o
+agetty: agetty.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o
 chfn: chfn.o islocal.o setpwnam.o $(LIB)/env.o $(LIB)/xstrncpy.o
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM)
 chsh: chsh.o islocal.o setpwnam.o $(LIB)/env.o
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM)
-last: last.o
+last: last.o $(LIB)/xgethostname.o
 
 ifeq "$(HAVE_PAM)" "yes"
-login: login.o $(LIB)/setproctitle.o $(LIB)/xstrncpy.o
+login: login.o $(LIB)/setproctitle.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM)
 else
-login: login.o $(LIB)/xstrncpy.o $(LIB)/setproctitle.o checktty.o 
+login: login.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o \
+		$(LIB)/setproctitle.o checktty.o 
 	$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) 
 endif
 
@@ -128,17 +134,21 @@
 newgrp.o: $(LIB)/pathnames.h
 	$(CC) -c $(CFLAGS) $(PAMFL) newgrp.c 
 
-wall: wall.o ttymsg.o $(LIB)/carefulputc.o $(LIB)/xstrncpy.o
+wall: wall.o ttymsg.o $(LIB)/carefulputc.o $(LIB)/xstrncpy.o \
+		$(LIB)/xgethostname.o
 
 LOGINFLAGS=
 ifeq "$(USE_TTY_GROUP)" "yes"
 	LOGINFLAGS += -DUSE_TTY_GROUP
 endif
+ifeq "$(OS)" "linux"
 ifeq "$(ALLOW_VCS_USE)" "yes"
 	LOGINFLAGS += -DCHOWNVCS
 endif
+endif
 
-login.o: login.c $(LIB)/pathnames.h $(LIB)/setproctitle.c $(LIB)/setproctitle.h
+login.o: login.c $(LIB)/pathnames.h $(LIB)/setproctitle.c $(LIB)/setproctitle.h \
+		$(LIB)/xgethostname.h
 	$(CC) -c $(CFLAGS) $(PAMFL) $(LOGINFLAGS) login.c
 
 # LOGINFLAGS here only for -DUSE_TTY_GROUP
@@ -186,10 +196,12 @@
 	$(INSTALLDIR) $(MAN8DIR)
 	$(INSTALLMAN) $(MAN8.INIT) $(MAN8DIR)
 	# Make *relative* links for these
+ifeq "$(OS)" "linux"
 	(cd $(SHUTDOWNDIR); ln -sf shutdown reboot)
 	(cd $(SHUTDOWNDIR); ln -sf shutdown fastboot)
 	(cd $(SHUTDOWNDIR); ln -sf shutdown halt)
 	(cd $(SHUTDOWNDIR); ln -sf shutdown fasthalt)
+endif
 	(cd $(SHUTDOWNDIR); ln -sf initctl need)
 	(cd $(SHUTDOWNDIR); ln -sf initctl display-services)
 	(cd $(SHUTDOWNDIR); ln -sf initctl provide)
diff -Naur util-linux-2.11x/login-utils/simpleinit.c util-linux-2.11x-debian-patched/login-utils/simpleinit.c
--- util-linux-2.11x/login-utils/simpleinit.c	2002-11-27 22:43:15.000000000 +0100
+++ util-linux-2.11x-debian-patched/login-utils/simpleinit.c	2002-11-27 22:42:34.000000000 +0100
@@ -22,6 +22,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <time.h>
 #include <string.h>
 #include <signal.h>
 #include <pwd.h>
diff -Naur util-linux-2.11x/login-utils/simpleinit.h util-linux-2.11x-debian-patched/login-utils/simpleinit.h
--- util-linux-2.11x/login-utils/simpleinit.h	2000-11-05 13:41:35.000000000 +0100
+++ util-linux-2.11x-debian-patched/login-utils/simpleinit.h	2002-11-27 22:42:34.000000000 +0100
@@ -3,7 +3,7 @@
 
 
 #define ERRSTRING strerror (errno)
-#define COMMAND_SIZE  (PIPE_BUF - 4)
+#define COMMAND_SIZE  (_POSIX_PIPE_BUF - 4)
 
 
 #define COMMAND_TEST       0  /*  No wait, signal                            */
diff -Naur util-linux-2.11x/login-utils/wall.c util-linux-2.11x-debian-patched/login-utils/wall.c
--- util-linux-2.11x/login-utils/wall.c	2002-03-09 00:00:19.000000000 +0100
+++ util-linux-2.11x-debian-patched/login-utils/wall.c	2002-11-27 22:42:34.000000000 +0100
@@ -58,6 +58,7 @@
 #include <utmp.h>
 
 #include "nls.h"
+#include "xgethostname.h"
 #include "xstrncpy.h"
 #include "ttymsg.h"
 #include "pathnames.h"
@@ -150,8 +151,7 @@
 	time_t now;
 	FILE *fp;
 	int fd;
-	char *p, *whom, *where, hostname[MAXHOSTNAMELEN],
-		lbuf[MAXHOSTNAMELEN + 320],
+	char *p, *whom, *where, *hostname, lbuf[1024],
 		tmpname[sizeof(_PATH_TMP) + 20];
 
 	(void)sprintf(tmpname, "%s/wall.XXXXXX", _PATH_TMP);
@@ -162,6 +162,9 @@
 	(void)unlink(tmpname);
 
 	if (!nobanner) {
+		char *mesg, *mesg_notice;
+		int mesg_size, size;
+
 		if (!(whom = getlogin()) || !*whom)
 			whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
 		if (!whom || strlen(whom) > 100)
@@ -169,7 +172,11 @@
 		where = ttyname(2);
 		if (!where || strlen(where) > 100)
 			where = "somewhere";
-		(void)gethostname(hostname, sizeof(hostname));
+		if (!(hostname = xgethostname())) {
+			(void)fprintf(stderr, _("%s: can't get hostname.\n"),
+				progname);
+			exit(1);
+		}
 		(void)time(&now);
 		lt = localtime(&now);
 
@@ -182,13 +189,35 @@
 		 */
 		/* snprintf is not always available, but the sprintf's here
 		   will not overflow as long as %d takes at most 100 chars */
+
+		mesg_notice = _("Broadcast Message from %s@%s");
+		mesg_size = strlen(whom) + strlen(hostname) +
+			strlen(mesg_notice);
+		if (!(mesg = malloc(mesg_size))) {
+			(void)fprintf(stderr, _("%s: Out of memory!\n"),
+				progname);
+			exit(1);
+		}
+
 		(void)fprintf(fp, "\r%79s\r\n", " ");
-		(void)sprintf(lbuf, _("Broadcast Message from %s@%s"),
-			      whom, hostname);
-		(void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf);
-		(void)sprintf(lbuf, "        (%s) at %d:%02d ...",
-			      where, lt->tm_hour, lt->tm_min);
-		(void)fprintf(fp, "%-79.79s\r\n", lbuf);
+		(void)sprintf(mesg, mesg_notice, whom, hostname);
+		(void)fprintf(fp, "%-79.79s\007\007\r\n", mesg);
+
+		mesg_notice = "        (%s) at %d:%02d ...";
+		size = strlen(mesg_notice) + strlen(where);
+		if (mesg_size < size) {
+			if (!realloc(mesg, size)) {
+				(void)fprintf(stderr, _("%s: Out of memory!\n"),
+					progname);
+				exit(1);
+			}
+		}
+
+		(void)sprintf(mesg, mesg_notice, where,
+			lt->tm_hour, lt->tm_min);
+		(void)fprintf(fp, "%-79.79s\r\n", mesg);
+
+		free(mesg);
 	}
 	(void)fprintf(fp, "%79s\r\n", " ");
 
diff -Naur util-linux-2.11x/MCONFIG util-linux-2.11x-debian-patched/MCONFIG
--- util-linux-2.11x/MCONFIG	2002-11-27 22:43:15.000000000 +0100
+++ util-linux-2.11x-debian-patched/MCONFIG	2002-11-27 22:42:34.000000000 +0100
@@ -11,7 +11,8 @@
 # Select for CPU i386 if the binaries must be able to run on an intel 386
 # (by default i486 code is generated, see below)
 CPU=$(shell uname -m)
-ARCH=$(shell echo $(CPU) | sed 's/i.86/intel/;s/arm.*/arm/')
+ARCH=$(shell echo $(CPU) | sed 's/i.86.*/intel/;s/arm.*/arm/')
+OS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
 
 # If HAVE_PAM is set to "yes", then login, chfn, chsh, and newgrp
 # will use PAM for authentication. Additionally, passwd will not be
diff -Naur util-linux-2.11x/misc-utils/Makefile util-linux-2.11x-debian-patched/misc-utils/Makefile
--- util-linux-2.11x/misc-utils/Makefile	2002-11-02 14:51:02.000000000 +0100
+++ util-linux-2.11x-debian-patched/misc-utils/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -87,8 +87,8 @@
 mcookie.o: mcookie.c $(LIB)/md5.h
 reset: reset.sh
 script: script.o
-write.o: $(LIB)/carefulputc.h
-write: write.o $(LIB)/carefulputc.o
+write.o: $(LIB)/carefulputc.h $(LIB)/xgethostname.h
+write: write.o $(LIB)/carefulputc.o $(LIB)/xgethostname.o
 
 ifeq "$(HAVE_NCURSES)" "yes"
 setterm: setterm.o
diff -Naur util-linux-2.11x/misc-utils/mcookie.c util-linux-2.11x-debian-patched/misc-utils/mcookie.c
--- util-linux-2.11x/misc-utils/mcookie.c	2002-03-09 00:00:52.000000000 +0100
+++ util-linux-2.11x-debian-patched/misc-utils/mcookie.c	2002-11-27 22:42:34.000000000 +0100
@@ -20,18 +20,16 @@
  *
  */
 
-#ifdef __linux__
-#define HAVE_GETTIMEOFDAY 1
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include "md5.h"
-#if HAVE_GETTIMEOFDAY
+#include "../defines.h"
+#ifdef HAVE_gettimeofday
 #include <sys/time.h>
-#include <unistd.h>
 #endif
+#include <time.h>
+#include <unistd.h>
 #include "nls.h"
 
 #define BUFFERSIZE 4096
@@ -79,7 +77,7 @@
    pid_t             pid;
    char              *file = NULL;
    int               r;
-#if HAVE_GETTIMEOFDAY
+#ifdef HAVE_gettimeofday
    struct timeval    tv;
    struct timezone   tz;
 #else
@@ -98,7 +96,7 @@
 
    MD5Init( &ctx );
    
-#if HAVE_GETTIMEOFDAY
+#ifdef HAVE_gettimeofday
    gettimeofday( &tv, &tz );
    MD5Update( &ctx, (unsigned char *)&tv, sizeof( tv ) );
 #else
diff -Naur util-linux-2.11x/misc-utils/namei.c util-linux-2.11x-debian-patched/misc-utils/namei.c
--- util-linux-2.11x/misc-utils/namei.c	2002-03-09 00:00:59.000000000 +0100
+++ util-linux-2.11x-debian-patched/misc-utils/namei.c	2002-11-27 22:42:34.000000000 +0100
@@ -72,7 +72,8 @@
 main(int argc, char **argv) {
     extern int optind;
     int c;
-    char curdir[MAXPATHLEN];
+    int curdir_size;
+    char *curdir;
 
     setlocale(LC_ALL, "");
     bindtextdomain(PACKAGE, LOCALEDIR);
@@ -97,13 +98,28 @@
 	}
     }
 
-    if(getcwd(curdir, sizeof(curdir)) == NULL){
-	(void)fprintf(stderr,
-		      _("namei: unable to get current directory - %s\n"),
-		      curdir);
+    curdir_size = 1024;
+    curdir = malloc(curdir_size);
+    if (curdir==NULL){
+	(void)fprintf(stderr, _("namei: out of memory\n"));
 	exit(1);
     }
 
+    while (getcwd(curdir, curdir_size) == NULL){
+	if (errno!=ERANGE){
+	    (void)fprintf(stderr,
+			  _("namei: unable to get current directory - %s\n"),
+			  curdir);
+	    exit(1);
+	}
+	curdir_size *= 2;
+	realloc(curdir, curdir_size);
+	if (curdir==NULL){
+	    (void)fprintf(stderr, _("namei: out of memory\n"));
+	    exit(1);
+	}
+    }
+
 
     for(; optind < argc; optind++){
 	(void)printf("f: %s\n", argv[optind]);
diff -Naur util-linux-2.11x/misc-utils/script.c util-linux-2.11x-debian-patched/misc-utils/script.c
--- util-linux-2.11x/misc-utils/script.c	2002-03-09 00:01:09.000000000 +0100
+++ util-linux-2.11x-debian-patched/misc-utils/script.c	2002-11-27 22:42:34.000000000 +0100
@@ -54,10 +54,8 @@
 #include <sys/signal.h>
 #include "nls.h"
 
-#ifdef __linux__
 #include <unistd.h>
 #include <string.h>
-#endif
 
 #include "../defines.h"
 #ifdef HAVE_openpty
diff -Naur util-linux-2.11x/misc-utils/setterm.c util-linux-2.11x-debian-patched/misc-utils/setterm.c
--- util-linux-2.11x/misc-utils/setterm.c	2002-11-27 22:43:16.000000000 +0100
+++ util-linux-2.11x-debian-patched/misc-utils/setterm.c	2002-11-27 22:42:34.000000000 +0100
@@ -111,11 +111,7 @@
 #include <sys/time.h>
 #include "nls.h"
 
-#ifndef TCGETS
-/* TCGETS is either defined in termios.h, or here: */
-#include <asm/ioctls.h>
-#endif
-
+#ifdef __linux__
 #if __GNU_LIBRARY__ < 5
 #ifndef __alpha__
 # include <linux/unistd.h>
@@ -126,6 +122,7 @@
 #endif
 #endif
 extern int klogctl(int type, char *buf, int len);
+#endif /* __linux__ */
 
 /* Constants. */
 
@@ -164,11 +161,16 @@
 int opt_term, opt_reset, opt_initialize, opt_cursor;
 int opt_linewrap, opt_snow, opt_softscroll, opt_default, opt_foreground;
 int opt_background, opt_bold, opt_blink, opt_reverse, opt_underline;
-int opt_store, opt_clear, opt_blank, opt_snap, opt_snapfile, opt_standout;
-int opt_append, opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat;
+int opt_store, opt_clear, opt_blank, opt_standout;
+int opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat;
 int opt_tabs, opt_clrtabs, opt_regtabs, opt_appcursorkeys, opt_inversescreen;
-int opt_msg, opt_msglevel, opt_powersave, opt_powerdown;
+int opt_powerdown;
 int opt_blength, opt_bfreq;
+#ifdef __linux__
+int opt_append, opt_snap, opt_snapfile;
+int opt_powersave;
+int opt_msg, opt_msglevel;
+#endif /* __linux__ */
 
 /* Option controls.  The variable names have been contracted to ensure
  * uniqueness.
@@ -176,7 +178,7 @@
 char *opt_te_terminal_name;	/* Terminal name. */
 int opt_cu_on, opt_li_on, opt_sn_on, opt_so_on, opt_bo_on, opt_hb_on, opt_bl_on;
 int opt_re_on, opt_un_on, opt_rep_on, opt_appck_on, opt_invsc_on;
-int opt_msg_on;			/* Boolean switches. */
+				/* Boolean switches. */
 int opt_ke_type;		/* Keyboard type. */
 int opt_fo_color, opt_ba_color;	/* Colors. */
 int opt_ul_color, opt_hb_color;
@@ -184,16 +186,20 @@
 int opt_bl_min;			/* Blank screen. */
 int opt_blength_l;
 int opt_bfreq_f;
-int opt_sn_num = 0;		/* Snap screen. */
 int opt_st_attr;
 int opt_rt_len;			/* regular tab length */
 int opt_tb_array[161];		/* Array for tab list */
-int opt_msglevel_num;
 int opt_ps_mode, opt_pd_min;	/* powersave mode/powerdown time */
 
+#ifdef __linux__
+int opt_msg_on;
+int opt_msglevel_num;
+
+int opt_sn_num = 0;		/* Snap screen. */
 char opt_sn_name[200] = "screen.dump";
 
 static void screendump(int vcnum, FILE *F);
+#endif /* __linux__ */
 
 /* Command line parsing routines.
  *
@@ -401,6 +407,7 @@
 	}
 }
 
+#ifdef __linux__
 static void
 parse_powersave(int argc, char **argv, int *option, int *opt_mode, int *bad_arg) {
 	/* argc: Number of arguments for this option. */
@@ -431,6 +438,7 @@
 		*opt_mode = 0;
 	}
 }
+#endif /* __linux__ */
 
 #if 0
 static void
@@ -453,6 +461,7 @@
 }
 #endif
 
+#ifdef __linux__
 static void
 parse_msglevel(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {
 	/* argc: Number of arguments for this option. */
@@ -511,6 +520,7 @@
 	if (argc == 1)
 		strcpy((char *)opt_all, argv[0]);
 }
+#endif /* __linux__ */
 
 static void
 parse_tabs(int argc, char **argv, int *option, int *tab_array, int *bad_arg) {
@@ -708,6 +718,7 @@
 		parse_regtabs(argc, argv, &opt_regtabs, &opt_rt_len, bad_arg);
 	else if (STRCMP(option, "blank") == 0)
 		parse_blank(argc, argv, &opt_blank, &opt_bl_min, bad_arg);
+#ifdef __linux__
 	else if (STRCMP(option, "dump") == 0)
 		parse_snap(argc, argv, &opt_snap, &opt_sn_num, bad_arg);
 	else if (STRCMP(option, "append") == 0)
@@ -720,6 +731,7 @@
 		parse_msglevel(argc, argv, &opt_msglevel, &opt_msglevel_num, bad_arg);
 	else if (STRCMP(option, "powersave") == 0)
 		parse_powersave(argc, argv, &opt_powersave, &opt_ps_mode, bad_arg);
+#endif /* __linux__ */
 	else if (STRCMP(option, "powerdown") == 0)
 		parse_blank(argc, argv, &opt_powerdown, &opt_pd_min, bad_arg);
 	else if (STRCMP(option, "blength") == 0)
@@ -782,12 +794,14 @@
 	fprintf(stderr, _("  [ -clrtabs [ tab1 tab2 tab3 ... ] ]   (tabn = 1-160)\n"));
 	fprintf(stderr, _("  [ -regtabs [1-160] ]\n"));
 	fprintf(stderr, _("  [ -blank [0-60] ]\n"));
+#ifdef __linux__
 	fprintf(stderr, _("  [ -dump   [1-NR_CONSOLES] ]\n"));
 	fprintf(stderr, _("  [ -append [1-NR_CONSOLES] ]\n"));
 	fprintf(stderr, _("  [ -file dumpfilename ]\n"));
 	fprintf(stderr, _("  [ -msg [on|off] ]\n"));
 	fprintf(stderr, _("  [ -msglevel [0-8] ]\n"));
 	fprintf(stderr, _("  [ -powersave [on|vsync|hsync|powerdown|off] ]\n"));
+#endif /* __linux__ */
 	fprintf(stderr, _("  [ -powerdown [0-60] ]\n"));
 	fprintf(stderr, _("  [ -blength [0-2000] ]\n"));
 	fprintf(stderr, _("  [ -bfreq freqnumber ]\n"));
@@ -810,8 +824,9 @@
 static void
 perform_sequence(int vcterm) {
 	/* vcterm: Set if terminal is a virtual console. */
-
+#ifdef __linux__
 	int result;
+#endif
 /* Perform the selected options. */
 
 	/* -reset. */
@@ -1038,7 +1053,8 @@
 	/* -blank [0-60]. */
 	if (opt_blank && vcterm) 
 		printf("\033[9;%d]", opt_bl_min);
-    
+
+#ifdef __linux__
 	/* -powersave [on|vsync|hsync|powerdown|off] (console) */
 	if (opt_powersave) {
 		char ioctlarg[2];
@@ -1047,6 +1063,7 @@
 		if (ioctl(0,TIOCLINUX,ioctlarg))
 			fprintf(stderr,_("cannot (un)set powersave mode\n"));
 	}
+#endif /* __linux__ */
 
 	/* -powerdown [0-60]. */
 	if (opt_powerdown) {
@@ -1059,6 +1076,7 @@
 		/* nothing */;
 #endif
 
+#ifdef __linux__
 	/* -snap [1-NR_CONS]. */
 	if (opt_snap || opt_append) {
 		FILE *F;
@@ -1094,6 +1112,7 @@
 		if (result != 0)
 			printf(_("klogctl error: %s\n"), strerror(result));
 	}
+#endif /* __linux__ */
 
 	/* -blength [0-2000] */
 	if (opt_blength && vcterm) {
@@ -1107,10 +1126,12 @@
 
 }
 
+#ifdef __linux__
+#include <sys/param.h>
+
 static void
 screendump(int vcnum, FILE *F) {
-#include <sys/param.h>
-    char infile[MAXPATHLEN];
+    char infile[sizeof("/dev/vcsa") + sizeof(vcnum) * 4];
     unsigned char header[4];
     unsigned int rows, cols;
     int fd, i, j;
@@ -1181,6 +1202,7 @@
 	}
     }
 }
+#endif /* __linux__ */
 
 int
 main(int argc, char **argv) {
diff -Naur util-linux-2.11x/misc-utils/write.c util-linux-2.11x-debian-patched/misc-utils/write.c
--- util-linux-2.11x/misc-utils/write.c	2001-03-15 11:09:58.000000000 +0100
+++ util-linux-2.11x-debian-patched/misc-utils/write.c	2002-11-27 22:42:34.000000000 +0100
@@ -64,9 +64,10 @@
 #include <paths.h>
 #include "pathnames.h"
 #include "carefulputc.h"
+#include "xgethostname.h"
 #include "nls.h"
  
-void search_utmp(char *, char *, char *, uid_t);
+void search_utmp(char *, char **, char *, uid_t);
 void do_write(char *, char *, uid_t);
 void wr_fputs(char *);
 static void done(int);
@@ -78,7 +79,7 @@
 	time_t atime;
 	uid_t myuid;
 	int msgsok, myttyfd;
-	char tty[MAXPATHLEN], *mytty;
+	char *tty, *mytty;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -120,7 +121,7 @@
 	/* check args */
 	switch (argc) {
 	case 2:
-		search_utmp(argv[1], tty, mytty, myuid);
+		search_utmp(argv[1], &tty, mytty, myuid);
 		do_write(tty, mytty, myuid);
 		break;
 	case 3:
@@ -189,8 +190,10 @@
  *
  * Special case for writing to yourself - ignore the terminal you're
  * writing from, unless that's the only terminal with messages enabled.
+ *
+ * Returns tty as an allocated string.
  */
-void search_utmp(char *user, char *tty, char *mytty, uid_t myuid)
+void search_utmp(char *user, char **tty, char *mytty, uid_t myuid)
 
 {
 	struct utmp u;
@@ -224,7 +227,11 @@
 			++nttys;
 			if (atime > bestatime) {
 				bestatime = atime;
-				(void)strcpy(tty, atty);
+				if ((*tty = strdup(atty)) == NULL) {
+					(void)fprintf(stderr,
+						_("write: out of memory\n"));
+					exit(1);
+				}
 			}
 		}
 	}
@@ -236,7 +243,12 @@
 	}
 	if (nttys == 0) {
 		if (user_is_me) {		/* ok, so write to yourself! */
-			(void)strcpy(tty, mytty);
+			if ((*tty = strdup(mytty)) == NULL) {
+				(void)fprintf(stderr,
+					_("write: out of memory\n"));
+				exit(1);
+			}
+
 			return;
 		}
 		(void)fprintf(stderr,
@@ -245,7 +257,7 @@
 	} else if (nttys > 1) {
 		(void)fprintf(stderr,
 		    _("write: %s is logged in more than once; writing to %s\n"),
-		    user, tty);
+		    user, *tty);
 	}
 }
 
@@ -257,19 +269,23 @@
 
 {
 	struct stat s;
-	char path[MAXPATHLEN];
+	char *path;
 
-	if (strlen(tty) + 6 > sizeof(path))
-		return(1);
+	if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL){
+		(void)fprintf(stderr,_("write: out of memory\n"));
+		exit(1);
+	}
 	(void)sprintf(path, "/dev/%s", tty);
 	if (stat(path, &s) < 0) {
 		if (showerror)
 			(void)fprintf(stderr,
 			    "write: %s: %s\n", path, strerror(errno));
+		free(path);
 		return(1);
 	}
 	*msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0;	/* group write bit */
 	*atimeP = s.st_atime;
+	free(path);
 	return(0);
 }
 
@@ -280,7 +296,7 @@
 	char *login, *pwuid, *nows;
 	struct passwd *pwd;
 	time_t now;
-	char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512];
+	char *path, *host, *host_tmp, line[512];
 
 	/* Determine our login name(s) before the we reopen() stdout */
 	if ((pwd = getpwuid(myuid)) != NULL)
@@ -290,8 +306,10 @@
 	if ((login = getlogin()) == NULL)
 		login = pwuid;
 
-	if (strlen(tty) + 6 > sizeof(path))
+	if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL) {
+		(void)fprintf(stderr, _("write: out of memory\n"));
 		exit(1);
+	}
 	(void)sprintf(path, "/dev/%s", tty);
 	if ((freopen(path, "w", stdout)) == NULL) {
 		(void)fprintf(stderr, "write: %s: %s\n",
@@ -299,12 +317,16 @@
 		exit(1);
 	}
 
+	free(path);
+
 	(void)signal(SIGINT, done);
 	(void)signal(SIGHUP, done);
 
 	/* print greeting */
-	if (gethostname(host, sizeof(host)) < 0)
-		(void)strcpy(host, "???");
+	if ((host_tmp = xgethostname()) != NULL)
+		host = host_tmp;
+	else
+		host = "???";
 	now = time((time_t *)NULL);
 	nows = ctime(&now);
 	nows[16] = '\0';
@@ -317,6 +339,8 @@
 			     login, host, mytty, nows + 11);
 	printf("\r\n");
 
+	free(host_tmp);
+
 	while (fgets(line, sizeof(line), stdin) != NULL)
 		wr_fputs(line);
 }
diff -Naur util-linux-2.11x/mount/Makefile util-linux-2.11x-debian-patched/mount/Makefile
--- util-linux-2.11x/mount/Makefile	2002-11-27 22:43:16.000000000 +0100
+++ util-linux-2.11x-debian-patched/mount/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -10,10 +10,12 @@
 COMPILE = $(CC) -c $(CFLAGS) $(DEFINES)
 LINK = $(CC) $(LDFLAGS)
 
+ifeq "$(OS)" "linux"
 SUID_PROGS = mount umount
 NOSUID_PROGS = swapon losetup
 MAN5 = fstab.5 nfs.5
 MAN8 = mount.8 swapoff.8 swapon.8 umount.8 losetup.8
+endif
 
 ifeq "$(HAVE_PIVOT_ROOT)" "yes"
 NOSUID_PROGS := $(NOSUID_PROGS) pivot_root
diff -Naur util-linux-2.11x/sys-utils/ipcrm.c util-linux-2.11x-debian-patched/sys-utils/ipcrm.c
--- util-linux-2.11x/sys-utils/ipcrm.c	2002-04-24 16:42:54.000000000 +0200
+++ util-linux-2.11x-debian-patched/sys-utils/ipcrm.c	2002-11-27 22:42:34.000000000 +0100
@@ -26,7 +26,7 @@
 /* for tolower and isupper */
 #include <ctype.h>
 
-#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+#if defined (__GLIBC__) && !defined(_SEM_SEMUN_UNDEFINED)
 /* union semun is defined by including <sys/sem.h> */
 #else
 /* according to X/OPEN we have to define it ourselves */
diff -Naur util-linux-2.11x/sys-utils/ipcs.c util-linux-2.11x-debian-patched/sys-utils/ipcs.c
--- util-linux-2.11x/sys-utils/ipcs.c	2002-07-05 02:21:20.000000000 +0200
+++ util-linux-2.11x-debian-patched/sys-utils/ipcs.c	2002-11-27 22:42:34.000000000 +0100
@@ -78,7 +78,7 @@
 /* The last arg of semctl is a union semun, but where is it defined?
    X/OPEN tells us to define it ourselves, but until recently
    Linux include files would also define it. */
-#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+#if defined (__GLIBC__) && !defined(_SEM_SEMUN_UNDEFINED)
 /* union semun is defined by including <sys/sem.h> */
 #else
 /* according to X/OPEN we have to define it ourselves */
@@ -95,7 +95,7 @@
    <linux/ipc.h>, which defines a struct ipc_perm with such fields.
    glibc-1.09 has no support for sysv ipc.
    glibc 2 uses __key, __seq */
-#if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
+#if defined (__GLIBC__) && __GLIBC__ > 1
 #define KEY __key
 #else
 #define KEY key
diff -Naur util-linux-2.11x/sys-utils/Makefile util-linux-2.11x-debian-patched/sys-utils/Makefile
--- util-linux-2.11x/sys-utils/Makefile	2001-11-09 18:13:50.000000000 +0100
+++ util-linux-2.11x-debian-patched/sys-utils/Makefile	2002-11-27 22:42:34.000000000 +0100
@@ -8,22 +8,32 @@
 
 # Where to put man pages?
 
-MAN1=		arch.1 readprofile.1
+MAN1=		arch.1
 
-MAN8= 		ctrlaltdel.8 cytune.8 dmesg.8 \
-		ipcrm.8 ipcs.8 renice.8 \
-		setsid.8 sln.8 tunelp.8
+MAN8= 		ipcrm.8 ipcs.8 renice.8 \
+		setsid.8 sln.8
+
+ifeq "$(OS)" "linux"
+MAN1:= $(MAN1) readprofile.1
+MAN8:= $(MAN8) ctrlaltdel.8 cytune.8 dmesg.8 tunelp.8
+endif
 
 # Where to put binaries?
 # See the "install" rule for the links. . .
 
-BIN=            arch dmesg
+BIN=            arch
 
-USRBIN=		cytune ipcrm ipcs renice setsid
+ifeq "$(OS)" "linux"
+BIN:= $(BIN) dmesg
+endif
 
-USRSBIN=	readprofile tunelp
+USRBIN=		ipcrm ipcs renice setsid
 
+ifeq "$(OS)" "linux"
+USRBIN:= $(USRBIN) cytune
+USRSBIN=	readprofile tunelp
 SBIN= 		ctrlaltdel
+endif
 
 NOTMADE=
 
@@ -37,10 +47,12 @@
 endif
 endif
 
+ifeq "$(OS)" "linux"
 ifeq "$(ARCH)" "intel"
 MAN8:=$(MAN8) rdev.8 ramsize.8 rootflags.8 vidmode.8
 USRSBIN:=$(USRSBIN) rdev
 endif
+endif
 
 # Where to put datebase files?
 
@@ -86,11 +98,13 @@
 	$(INSTALLBIN) $(BIN) $(BINDIR)
 	$(INSTALLBIN) $(USRBIN) $(USRBINDIR)
 	$(INSTALLBIN) $(USRSBIN) $(USRSBINDIR)
+ifeq "$(OS)" "linux"
 ifeq "$(ARCH)" "intel"
 	(cd $(USRSBINDIR); ln -sf rdev ramsize)
 	(cd $(USRSBINDIR); ln -sf rdev vidmode)
 	(cd $(USRSBINDIR); ln -sf rdev rootflags)
 endif
+endif
 	$(INSTALLDIR) $(MAN1DIR) $(MAN8DIR) $(INFODIR)
 	$(INSTALLMAN) $(MAN1) $(MAN1DIR)
 	$(INSTALLMAN) $(MAN8) $(MAN8DIR)
diff -Naur util-linux-2.11x/text-utils/more.c util-linux-2.11x-debian-patched/text-utils/more.c
--- util-linux-2.11x/text-utils/more.c	2002-11-27 22:43:16.000000000 +0100
+++ util-linux-2.11x-debian-patched/text-utils/more.c	2002-11-27 22:42:34.000000000 +0100
@@ -74,6 +74,14 @@
 
 #define stty(fd,argp)  tcsetattr(fd,TCSANOW,argp)
 
+/* TAB3 and TABDLY are in XPG3 and up */
+#if !defined(TABDLY) && defined(TBDELAY)
+#define TABDLY		TBDELAY
+#endif
+#if !defined(TAB3) && defined(XTABS)
+#define TAB3		XTABS
+#endif
+
 /* some function declarations */
 void initterm(void);
 void kill_line(void);
@@ -1644,7 +1652,7 @@
     }
     if (feof (file)) {
 	if (!no_intty) {
-#ifndef __linux__
+#ifdef STDIO_S_EOF_SEEN
 				/* No longer in libc 4.5.8. . . */
 	    file->_flags &= ~STDIO_S_EOF_SEEN; /* why doesn't fseek do this ??!!??! */
 #endif
@@ -1890,8 +1898,8 @@
     no_intty = tcgetattr(fileno(stdin), &otty);
     tcgetattr(fileno(stderr), &otty);
     savetty0 = otty;
-    slow_tty = (otty.c_cflag & CBAUD) < B1200;
-    hardtabs = (otty.c_oflag & TABDLY) != XTABS;
+    slow_tty = cfgetospeed(&otty) < B1200;
+    hardtabs = (otty.c_oflag & TABDLY) != TAB3;
     if (!no_tty) {
 	otty.c_lflag &= ~(ICANON|ECHO);
 	otty.c_cc[VMIN] = 1;
