Submitted By:            Randy McMurchy <randy_at_linuxfromscratch_dot_org>
Date:                    2005-08-26
Initial Package Version: 1.4.3
Upstream Status:         Not submitted
Origin:                  Debian (http://packages.debian.org/testing/source/svgalib)
Description:             This is all of Debian's patches rolled into one. It fixes
                         many things including building with all versions of GCC
                         (up to and including GCC-4.0.1)


diff -Naur svgalib-1.4.3-orig/Makefile svgalib-1.4.3/Makefile
--- svgalib-1.4.3-orig/Makefile	2001-04-18 17:35:51.000000000 +0000
+++ svgalib-1.4.3/Makefile	2005-08-26 16:56:12.000000000 +0000
@@ -110,10 +110,6 @@
 
 installheaders:
 	@echo Installing header files in $(includedir).
-	@if [ -f /usr/include/vga.h ]; then \
-		rm -f /usr/include/vga.h /usr/include/vgagl.h; \
-		echo Old header files in /usr/include removed.; \
-	fi
 	mkdir -p $(includedir)
 	@cp $(srcdir)/src/vga.h $(includedir)/vga.h
 	@chmod a+r $(includedir)/vga.h
@@ -134,26 +130,14 @@
 		chmod a+r $(libdir)/$$foo; \
 	done
 endif
-	@if [ -f /usr/lib/libvga.sa ]; then \
-		rm -f /usr/lib/libvga.sa /usr/lib/libvgagl.sa; \
-		echo Old stubs in /usr/lib removed.; \
-	fi
-	@rm -f $(OBSOLETESHAREDIMAGES)
-ifndef KEEPSHAREDLIBS
-	@echo "Removing shared library images (old & current)..."
-	@for i in $(OBSOLETELDIRS); do \
-	    rm -f `echo $(OBSOLETESHAREDIMAGES) | sed s?/lib/?$$i?g`; \
-         done
-endif
 	mkdir -p $(sharedlibdir)
 	@echo Installing shared library image as \
 		$(addprefix $(sharedlibdir)/,$(notdir $(SHAREDLIBS))).
 	@for foo in $(notdir $(SHAREDLIBS)); do \
 		$(INSTALL_SHLIB) sharedlib/$$foo $(sharedlibdir)/$$foo; \
-		(cd $(sharedlibdir); \
-		 ln -sf $$foo `echo $$foo | sed 's/\.so\..*/.so/'` ); \
+		cp -d sharedlib/`echo $$foo | sed 's/\.so\..*/.so/'` $(sharedlibdir); \
+		cp -d sharedlib/`echo $$foo | sed 's/\.so\..*/.so/'`.$(MAJOR_VER) $(sharedlibdir); \
 	done
-	@ldconfig
 
 ifdef INSTALLAOUTDIR
 
@@ -166,10 +150,9 @@
 		$(addprefix $(INSTALLAOUTDIR),$(notdir $(SHAREDLIBS))).
 	@for foo in $(notdir $(SHAREDAOUTLIBS)); do \
 		$(INSTALL_SHLIB) sharedlib/$$foo $(TOPDIR)/$(INSTALLAOUTDIR)$$foo; \
-		(cd $(TOPDIR)/$(INSTALLAOUTDIR); \
-		 ln -sf $$foo `echo $$foo | sed 's/\.so\..*/.so/'` ); \
+		cp -d sharedlib/`echo $$foo | sed 's/\.so\..*/.so/'` $(sharedlibdir); \
+		cp -d sharedlib/`echo $$foo | sed 's/\.so\..*/.so/'`.$(MAJOR_VER) $(sharedlibdir); \
 	done
-	@ldconfig
 
 else
 
@@ -180,10 +163,8 @@
 
 installstaticlib: static
 	@echo Installing static libraries in $(libdir).
-	@rm -f /usr/lib/libvga.a
 	@$(INSTALL_DATA) staticlib/libvga.a $(libdir)/libvga.a
 	@chmod a+r $(libdir)/libvga.a
-	@rm -f /usr/lib/libvgagl.a
 	@$(INSTALL_DATA) staticlib/libvgagl.a $(libdir)/libvgagl.a
 	@chmod a+r $(libdir)/libvgagl.a
 
@@ -192,14 +173,6 @@
 		echo No $(bindir) directory, creating it.; \
 		mkdir $(bindir); \
 	fi
-	@if [ -f /usr/bin/restorefont ]; then \
-		echo Removing old utilities in /usr/bin.; \
-		for x in $(UTILS); do rm -f /usr/bin/$$x; done; \
-	fi
-	@if [ -f /usr/bin/convfont ]; then \
-		echo Removing inappropriate utilities in /usr/bin.; \
-		rm -f /usr/bin/convfont /usr/bin/setmclk; \
-	fi
 	@echo Installing textmode utilities in $(bindir):
 	@echo "restorefont:      Save/restore textmode font."
 	@cp utils/restorefont $(bindir)
@@ -213,8 +186,10 @@
 	@cp utils/textmode $(bindir)
 	@echo "savetextmode:     Script that saves textmode information used by 'textmode'."
 	@cp utils/savetextmode $(bindir)
-	@echo "mode3:       Restore textmode by setting VESA mode 3."
-	@cp lrmi-0.6m/mode3 $(bindir)
+	@echo "mode3:            Restore textmode by setting VESA mode 3."
+	@if [ -e lrmi-0.6m/mode3 ]; then cp lrmi-0.6m/mode3 $(bindir); fi
+	@echo "vga_reset:        Restore textmode by resetting graphic board."
+	@if [ -e lrmi-0.6m/vga_reset ]; then cp lrmi-0.6m/vga_reset $(bindir); fi
 	@echo "Installing keymap utilities in $(bindir):"
 	@echo "svgakeymap:       Perl script that generates scancode conversion maps."
 	@cp utils/svgakeymap $(bindir)
@@ -426,8 +401,10 @@
 	$(MAKE) -f $(srcdir)/utils/Makefile srcdir="$(srcdir)")
 
 lrmi:
+ifneq (y,$(NO_ASM))
 	(cd lrmi-0.6m;\
 	$(MAKE))
+endif
 
 backup: $(BACKUP)
 
@@ -462,7 +439,6 @@
 
 distclean:
 	(cd $(srcdir)/doc; $(MAKE) clean)
-	(cd $(srcdir)/doc; $(MAKE) ../0-README)
 	(cd $(srcdir)/src; $(MAKE) clean)
 	(cd $(srcdir)/gl; $(MAKE) clean)
 	(cd $(srcdir)/utils; $(MAKE) clean)
diff -Naur svgalib-1.4.3-orig/Makefile.cfg svgalib-1.4.3/Makefile.cfg
--- svgalib-1.4.3-orig/Makefile.cfg	2001-05-29 14:39:13.000000000 +0000
+++ svgalib-1.4.3/Makefile.cfg	2005-08-26 16:56:12.000000000 +0000
@@ -16,6 +16,9 @@
 # Configuration Section
 #----------------------------------------------------------------------
 
+# Architecture
+arch = $(shell uname -m | sed 's/i.86.*/i386/;s/arm.*/arm/')
+
 # Source directory.
 #srcdir = /usr/local/src/svgalib-$(VERSION)
 srcdir = $(shell sh -c pwd)
@@ -52,7 +55,9 @@
 
 #uncomment this if your compiler fails on compiling the assembler in
 #src/vgaconvplanar.c, gl/inlstring.h, gl/line.c or gl/scale.c
-# NO_ASM = y
+ifneq (i386, $(arch))
+NO_ASM = y
+endif
 
 # Uncomment this if you want root processes to be able to always get a new
 # VC. Alas, some games misuse suid root privs and become root, svgalib cannot
@@ -126,20 +131,22 @@
 INCLUDE_ET4000_DRIVER = y
 INCLUDE_CIRRUS_DRIVER = y
 INCLUDE_TVGA_DRIVER = y
-#INCLUDE_OAK_DRIVER = y
-#INCLUDE_EGA_DRIVER = y
+INCLUDE_OAK_DRIVER = y
+INCLUDE_EGA_DRIVER = y
 INCLUDE_MACH32_DRIVER = y
 INCLUDE_S3_DRIVER = y
-#INCLUDE_ET3000_DRIVER = y
-#INCLUDE_GVGA6400_DRIVER = y
-#INCLUDE_ARK_DRIVER = y
-#INCLUDE_ATI_DRIVER = y
-#INCLUDE_ALI_DRIVER = y
+INCLUDE_ET3000_DRIVER = y
+INCLUDE_GVGA6400_DRIVER = y
+INCLUDE_ARK_DRIVER = y
+INCLUDE_ATI_DRIVER = y
+INCLUDE_ALI_DRIVER = y
 INCLUDE_CHIPS_DRIVER = y
 INCLUDE_APM_DRIVER = y
 INCLUDE_NV3_DRIVER = y
 INCLUDE_ET6000_DRIVER = y
+ifneq (y,$(NO_ASM))
 INCLUDE_VESA_DRIVER = y
+endif
 INCLUDE_MX_DRIVER = y
 INCLUDE_PARADISE_DRIVER = y
 INCLUDE_RAGE_DRIVER = y
@@ -150,7 +157,9 @@
 INCLUDE_NEO_DRIVER = y
 INCLUDE_R128_DRIVER = y
 INCLUDE_G400_DRIVER = y
+ifndef SUPPRESS_FOR_LIBC5
 INCLUDE_FBDEV_DRIVER = y
+endif
 INCLUDE_SAVAGE_DRIVER = y
 #
 # Comment out any adapter you don't want to autodetect.
@@ -158,15 +167,15 @@
 INCLUDE_ET4000_DRIVER_TEST = y
 INCLUDE_CIRRUS_DRIVER_TEST = y
 INCLUDE_TVGA_DRIVER_TEST = y
-#INCLUDE_OAK_DRIVER_TEST = y
-#INCLUDE_EGA_DRIVER_TEST = y
+INCLUDE_OAK_DRIVER_TEST = y
+INCLUDE_EGA_DRIVER_TEST = y
 INCLUDE_MACH32_DRIVER_TEST = y
-#INCLUDE_GVGA6400_DRIVER_TEST = y
+INCLUDE_GVGA6400_DRIVER_TEST = y
 INCLUDE_S3_DRIVER_TEST = y
-#INCLUDE_ET3000_DRIVER_TEST = y
+INCLUDE_ET3000_DRIVER_TEST = y
 #INCLUDE_ARK_DRIVER_TEST = y
-#INCLUDE_ATI_DRIVER_TEST = y
-#INCLUDE_ALI_DRIVER_TEST = y
+INCLUDE_ATI_DRIVER_TEST = y
+INCLUDE_ALI_DRIVER_TEST = y
 INCLUDE_CHIPS_DRIVER_TEST = y
 INCLUDE_APM_DRIVER_TEST = y
 INCLUDE_NV3_DRIVER_TEST = y
@@ -270,9 +279,9 @@
 CFLAGS   = $(WARN) $(DLLFLAGS) $(INCLUDES) $(OPTIMIZE) $(DEFINES)
 # ELF doesn't like -N. It is beneficial for small tools with a.out
 ifeq (a.out, $(TARGET_FORMAT))
-	LDFLAGS   = -N -s
+	LDFLAGS   = -N 
 else
-	LDFLAGS   = -s
+	LDFLAGS   = 
 endif
 
 # Uncomment the following if you are compiling a.out shared libraries
@@ -289,6 +298,6 @@
 
 # Utilites used.
 AR	  = ar
-INSTALL_PROGRAM	= install -c -s -m 755 -o root -g bin
+INSTALL_PROGRAM	= install -c -m 755 -o root -g bin
 INSTALL_SHLIB	= install -c -m 755 -o root -g bin
 INSTALL_DATA	= install -c -m 644 -o root -g bin
diff -Naur svgalib-1.4.3-orig/doc/README.keymap svgalib-1.4.3/doc/README.keymap
--- svgalib-1.4.3-orig/doc/README.keymap	1998-12-05 10:00:01.000000000 +0000
+++ svgalib-1.4.3/doc/README.keymap	2005-08-26 16:56:12.000000000 +0000
@@ -83,7 +83,7 @@
 equivalents in the layout expected by the program.
 
 A program called svgakeymap is provided to generate these maps from the
-keytable files in /usr/lib/kbd/keytables; you must have perl for it to work.
+keytable files in /usr/share/keymaps; you must have perl for it to work.
 Creating a keymap file with svgakeymap is easy; to make a map to convert
 scancodes from a US Dvorak keyboard to a US QWERTY keyboard as for our example
 above:
diff -Naur svgalib-1.4.3-orig/doc/man1/savetextmode.1 svgalib-1.4.3/doc/man1/savetextmode.1
--- svgalib-1.4.3-orig/doc/man1/savetextmode.1	1998-03-26 20:14:36.000000000 +0000
+++ svgalib-1.4.3/doc/man1/savetextmode.1	2005-08-26 16:56:12.000000000 +0000
@@ -10,7 +10,11 @@
 .SH DESCRIPTION
 These are simple scripts to save the SVGA register state when in textmode to the
 files
-.IR /tmp/fontdata " and " /tmp/textregs
+.IR /etc/vga/fontdata " and " /etc/vga/textregs
+.RI ( $HOME/.vga/fontdata " and " $HOME/.vga/textregs
+if directory
+.I /etc/vga
+is not writeable)
 or to restore it from these files.
 
 The actual utilities used are
@@ -40,9 +44,13 @@
 will understand.
 
 .SH FILES
-.I /tmp/fontdata
+.I /etc/vga/fontdata
+or
+.I $HOME/.vga/fontdata
 .br
-.I /tmp/textregs
+.I /etc/vga/textregs
+or
+.I $HOME/.vga/textregs
 
 .SH SEE ALSO
 
diff -Naur svgalib-1.4.3-orig/doc/man1/svgakeymap.1 svgalib-1.4.3/doc/man1/svgakeymap.1
--- svgalib-1.4.3-orig/doc/man1/svgakeymap.1	1998-12-05 10:00:01.000000000 +0000
+++ svgalib-1.4.3/doc/man1/svgakeymap.1	2005-08-26 16:56:12.000000000 +0000
@@ -9,7 +9,7 @@
 Generates a keymap conversion file for
 .BR svgalib (7)
 from two keytable definitions. Keytables are searched for in
-.I /usr/lib/kbd/keytables
+.I /usr/share/keymaps
 and are automatically filtered through
 .BR gzip (1)
 if necessary.
@@ -22,7 +22,7 @@
 or piped in any creative manner you wish.
 
 .SH FILES
-.I /usr/lib/kbd/keytables/*.map[.gz]
+.I /usr/share/keymaps/*/*/*.map[.gz]
 .RS
 The system keytable files used by
 .BR loadkeys "(1)."
diff -Naur svgalib-1.4.3-orig/gl/Makefile svgalib-1.4.3/gl/Makefile
--- svgalib-1.4.3-orig/gl/Makefile	1999-07-18 08:14:45.000000000 +0000
+++ svgalib-1.4.3/gl/Makefile	2005-08-26 16:56:12.000000000 +0000
@@ -10,6 +10,8 @@
 srcdir    = ..
 VPATH     = $(srcdir)/gl
 
+INCLUDES += -I$(srcdir)/src
+
 ifeq (a.out, $(TARGET_FORMAT))
   DEFINES += -DSVGA_AOUT
 endif
@@ -28,9 +30,12 @@
 all:	libvgagl.a
 .PHONY: all clean dep
 
+libvgagl.so: libvgagl.so.$(VERSION)
 libvgagl.so.$(VERSION): $(MODULES)
 	$(CC) -s -shared -Wl,-soname,libvgagl.so.$(MAJOR_VER) -o libvgagl.so.$(VERSION) \
-	  $(MODULES)
+	  $(MODULES) $(SHLIBLIBS) -L$(srcdir)/sharedlib -lvga
+	ln -sf libvgagl.so.$(VERSION) libvgagl.so
+	ln -sf libvgagl.so.$(VERSION) libvgagl.so.$(MAJOR_VER)
 
 libvgagl.a: $(MODULES)
 	rm -f libvgagl.a
@@ -63,7 +68,7 @@
 	$(CC) $(INCLUDES) -MM $(patsubst %.o,$(srcdir)/gl/%.c,$(MODULES)) >>.depend.gl
 
 clean:
-	rm -f .depend.gl *.bak *.o *~ libvgagl.a libvgagl.so.$(VERSION)
+	rm -f .depend.gl *.bak *.o *~ libvgagl.a libvgagl.so*
 
 #
 # include a dependency file if one exists
diff -Naur svgalib-1.4.3-orig/gl/driver.c svgalib-1.4.3/gl/driver.c
--- svgalib-1.4.3-orig/gl/driver.c	1999-07-18 08:18:44.000000000 +0000
+++ svgalib-1.4.3/gl/driver.c	2005-08-26 16:56:12.000000000 +0000
@@ -33,7 +33,7 @@
 /* However bswap is not supported by 386 */
 
     if (MODEFLAGS & MODEFLAG_24BPP_REVERSED)
-#ifdef __alpha__
+#if defined(__alpha__) || defined(NO_ASSEMBLY)
 	c = ((c >> 0) & 0xff) << 16 |
 	    ((c >> 8) & 0xff) << 8 |
 	    ((c >> 16) & 0xff) << 0;
diff -Naur svgalib-1.4.3-orig/gl/inlstring.h svgalib-1.4.3/gl/inlstring.h
--- svgalib-1.4.3-orig/gl/inlstring.h	1999-09-20 18:45:31.000000000 +0000
+++ svgalib-1.4.3/gl/inlstring.h	2005-08-26 16:56:12.000000000 +0000
@@ -1,6 +1,6 @@
 /* Based on functions in linux/string.h */
 
-#include <linux/types.h>	/* for size_t */
+#include <stddef.h>	/* for size_t */
 
 #if defined(__alpha__) || defined (NO_ASSEMBLY)
 
@@ -98,7 +98,7 @@
 	       "cmpl $12,%%edx\n\t"
 	       "jl 1f\n\t"	/* if (count >= 12) */
 
-	       "movzbl %%al,%%ax\n\t"
+	       "movzbl %%al,%%eax\n\t"
 	       "movl %%eax,%%ecx\n\t"
 	       "shll $8,%%ecx\n\t"	/* c |= c << 8 */
 	       "orl %%ecx,%%eax\n\t"
@@ -236,7 +236,7 @@
 	       "cmpl $0,%%edx\n\t"	/* none left? */
 	       "jle 4f\n\t"	/* finished */
 
-	       "mov %%ecx,%%eax\n\t"
+	       "movl %%ecx,%%eax\n\t"
 	       "shrl $8,%%ecx\n\t"	/* R in cl */
 
 	       "3:\n\t"		/* write last few pixels */
diff -Naur svgalib-1.4.3-orig/gl/mem.S svgalib-1.4.3/gl/mem.S
--- svgalib-1.4.3-orig/gl/mem.S	1996-12-18 00:19:26.000000000 +0000
+++ svgalib-1.4.3/gl/mem.S	2005-08-26 16:56:12.000000000 +0000
@@ -76,7 +76,7 @@
 	jz 4f			/* none left */
 
 3:	movl (%esi),%eax
-	movw %eax,(%edi)
+	movw %ax,(%edi)
 	shrl $16,%eax
 	movb %al,2(%edi)
 	addl $4,%esi
diff -Naur svgalib-1.4.3-orig/gl/text.c svgalib-1.4.3/gl/text.c
--- svgalib-1.4.3-orig/gl/text.c	2000-03-08 19:04:54.000000000 +0000
+++ svgalib-1.4.3/gl/text.c	2005-08-26 16:56:12.000000000 +0000
@@ -288,7 +288,7 @@
 		    break;
 		case 3:
 		    *(ushort *) bitmap = bg;
-		    *(bitmap + 2) = bg;
+		    *(bitmap + 2) = bg >> 16;
 		    bitmap += 3;
 		    break;
 		case 4:
diff -Naur svgalib-1.4.3-orig/include/vgamouse.h svgalib-1.4.3/include/vgamouse.h
--- svgalib-1.4.3-orig/include/vgamouse.h	2000-08-21 05:10:15.000000000 +0000
+++ svgalib-1.4.3/include/vgamouse.h	2005-08-26 16:56:12.000000000 +0000
@@ -24,7 +24,8 @@
 #define MOUSE_PNP 12
 #define MOUSE_WACOM_GRAPHIRE 13
 #define MOUSE_DRMOUSE4DS 14
-#define MOUSE_LAST MOUSE_DRMOUSE4DS
+#define MOUSE_UNCONFIGURED 15
+#define MOUSE_LAST MOUSE_UNCONFIGURED
 
 #define MOUSE_ORIENTATION_VERTICAL 0
 #define MOUSE_ORIENTATION_HORIZONTAL 1
diff -Naur svgalib-1.4.3-orig/lrmi-0.6m/mode3.c svgalib-1.4.3/lrmi-0.6m/mode3.c
--- svgalib-1.4.3-orig/lrmi-0.6m/mode3.c	1998-08-16 13:35:42.000000000 +0000
+++ svgalib-1.4.3/lrmi-0.6m/mode3.c	2005-08-26 16:56:12.000000000 +0000
@@ -6,6 +6,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
+#if __GLIBC__ >= 2
+#include <sys/io.h>            /* libc6 iopl() */
+#endif
 #include <sys/ioctl.h>
 #include <sys/kd.h>
 #include <sys/stat.h>
diff -Naur svgalib-1.4.3-orig/lrmi-0.6m/vbemodeinfo.c svgalib-1.4.3/lrmi-0.6m/vbemodeinfo.c
--- svgalib-1.4.3-orig/lrmi-0.6m/vbemodeinfo.c	1999-06-26 20:10:17.000000000 +0000
+++ svgalib-1.4.3/lrmi-0.6m/vbemodeinfo.c	2005-08-26 16:56:12.000000000 +0000
@@ -8,6 +8,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
+#if __GLIBC__ >= 2
+#include <sys/io.h>            /* libc6 iopl() */
+#endif
 #include <sys/ioctl.h>
 #include <sys/kd.h>
 #include <sys/stat.h>
diff -Naur svgalib-1.4.3-orig/lrmi-0.6m/vbetest.c svgalib-1.4.3/lrmi-0.6m/vbetest.c
--- svgalib-1.4.3-orig/lrmi-0.6m/vbetest.c	1998-10-20 13:23:59.000000000 +0000
+++ svgalib-1.4.3/lrmi-0.6m/vbetest.c	2005-08-26 16:56:12.000000000 +0000
@@ -7,6 +7,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#if __GLIBC__ >= 2
+#include <sys/io.h>            /* libc6 iopl() */
+#endif
 #include <sys/ioctl.h>
 #include <sys/kd.h>
 #include <sys/stat.h>
diff -Naur svgalib-1.4.3-orig/lrmi-0.6m/vga_reset.c svgalib-1.4.3/lrmi-0.6m/vga_reset.c
--- svgalib-1.4.3-orig/lrmi-0.6m/vga_reset.c	1999-06-11 19:26:04.000000000 +0000
+++ svgalib-1.4.3/lrmi-0.6m/vga_reset.c	2005-08-26 16:56:12.000000000 +0000
@@ -6,6 +6,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
+#if __GLIBC__ >= 2
+#include <sys/io.h>            /* libc6 iopl() */
+#endif
 
 #include "lrmi.h"
 
diff -Naur svgalib-1.4.3-orig/mach/mach64.c svgalib-1.4.3/mach/mach64.c
--- svgalib-1.4.3-orig/mach/mach64.c	1998-04-11 18:35:27.000000000 +0000
+++ svgalib-1.4.3/mach/mach64.c	2005-08-26 16:56:12.000000000 +0000
@@ -51,6 +51,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#if __GLIBC__ >= 2
+#include <sys/io.h>            /* libc6 iopl() */
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
diff -Naur svgalib-1.4.3-orig/src/Makefile svgalib-1.4.3/src/Makefile
--- svgalib-1.4.3-orig/src/Makefile	2001-05-29 14:36:53.000000000 +0000
+++ svgalib-1.4.3/src/Makefile	2005-08-26 16:56:12.000000000 +0000
@@ -14,7 +14,7 @@
 # Compiler Section (overrides Makefile.cfg)
 #----------------------------------------------------------------------
 
-INCLUDES += -I$(srcdir)/src
+INCLUDES += -I$(srcdir)/src -I$(srcdir)/src/config
 
 #----------------------------------------------------------------------
 # Rules Section
@@ -388,13 +388,16 @@
 # These rules are for ELF only.
 libvga.so.$(VERSION): $(ALLOBJS)
 	$(CC) -s -shared -Wl,-soname,libvga.so.$(MAJOR_VER) \
-	  -o libvga.so.$(VERSION) $(ALLOBJS) -lm
+	  -o libvga.so.$(VERSION) $(ALLOBJS) $(SHLIBLIBS) -lm
+	ln -sf libvga.so.$(VERSION) libvga.so
+	ln -sf libvga.so.$(VERSION) libvga.so.$(MAJOR_VER)
 
 $(sharedlibdir)/libvga.so.$(VERSION): libvga.so.$(VERSION)
 	$(INSTALL_PROGRAM) $< $(sharedlibdir)/$<
-	ldconfig
 
 install: $(sharedlibdir)/libvga.so.$(VERSION)
+	cp -df sharedlib/libvga.so $(sharedlibdir)/
+	cp -df sharedlib/libvga.so.$(MAJOR_VER) $(sharedlibdir)/
 
 endif	  
 
@@ -408,9 +411,11 @@
 vga.o: vga.c
 	$(CC) $(CFLAGS) $(VGA_DEFINES) -c -o $@ $<
 
-#lrmi must NOT be compiled as -fPIC
+# XXX: Upstream used this so it may break, disabled to close an RC
+# lrmi must NOT be compiled as -fPIC
 lrmi.o: lrmi.c
-	$(CC) $(CFLAGS:-fPIC=) -c -o $@ $<
+	$(CC) $(CFLAGS) -c -o $@ $<
+#	$(CC) $(CFLAGS:-fPIC=) -c -o $@ $<
 
 $(RAMDAC): %.o: %.c
 	$(CC) $(CFLAGS) $(RAMDAC_DEFINES) -c -o $@ $<
diff -Naur svgalib-1.4.3-orig/src/apm.c svgalib-1.4.3/src/apm.c
--- svgalib-1.4.3-orig/src/apm.c	2000-10-11 16:35:18.000000000 +0000
+++ svgalib-1.4.3/src/apm.c	2005-08-26 16:56:12.000000000 +0000
@@ -151,12 +151,12 @@
    regs[APMREG_SAVE(15)] = (k >> 8)&0xff;
    regs[APMREG_SAVE(16)] = (k >> 16) & 0xff ;
    regs[APMREG_SAVE(17)] = ( k >> 24 ) & 0xff ;
-   (unsigned long)regs[APMREG_SAVE(18)] = inlXR(0xf0) ;
-   (unsigned long)regs[APMREG_SAVE(22)] = inlXR(0xf4) ;
-   (unsigned long)regs[APMREG_SAVE(26)] = inlXR(0x140) ;
-   (unsigned short)regs[APMREG_SAVE(30)] = inlXR(0x144) ;
-   (unsigned long)regs[APMREG_SAVE(32)] = inXR(0x148) ;
-   (unsigned short)regs[APMREG_SAVE(36)] = inXR(0x14c) ;
+   regs[APMREG_SAVE(18)] = inlXR(0xf0) ;
+   regs[APMREG_SAVE(22)] = inlXR(0xf4) ;
+   regs[APMREG_SAVE(26)] = inlXR(0x140) ;
+   regs[APMREG_SAVE(30)] = inlXR(0x144) ;
+   regs[APMREG_SAVE(32)] = inXR(0x148) ;
+   regs[APMREG_SAVE(36)] = inXR(0x14c) ;
 
     return APM_TOTAL_REGS - VGA_TOTAL_REGS;
 }
diff -Naur svgalib-1.4.3-orig/src/ati.c svgalib-1.4.3/src/ati.c
--- svgalib-1.4.3-orig/src/ati.c	1999-07-27 16:36:18.000000000 +0000
+++ svgalib-1.4.3/src/ati.c	2005-08-26 16:56:12.000000000 +0000
@@ -31,6 +31,9 @@
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <unistd.h>
+#if __GLIBC__ >= 2
+#include <sys/io.h>            /* libc6 iopl() */
+#endif
 
 #include "vga.h"
 #include "libvga.h"
diff -Naur svgalib-1.4.3-orig/src/chips.c svgalib-1.4.3/src/chips.c
--- svgalib-1.4.3-orig/src/chips.c	2001-04-02 15:10:11.000000000 +0000
+++ svgalib-1.4.3/src/chips.c	2005-08-26 16:56:12.000000000 +0000
@@ -85,6 +85,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>		/* iopl() */
+#if __GLIBC__ >= 2
+#include <sys/io.h>            /* libc6 iopl() */
+#endif
 #include <signal.h>		/* sigprocmask */
 #include <sys/mman.h>
 #include "vga.h"
diff -Naur svgalib-1.4.3-orig/src/config/libvga.config svgalib-1.4.3/src/config/libvga.config
--- svgalib-1.4.3-orig/src/config/libvga.config	2001-05-29 15:16:58.000000000 +0000
+++ svgalib-1.4.3/src/config/libvga.config	2005-08-26 16:56:12.000000000 +0000
@@ -31,7 +31,15 @@
 # mouse DRMOUSE4DS	# Digital Research double-wheeled mouse
 # mouse none		# None
 
-mouse Microsoft
+mouse unconfigured
+
+# (DEBIAN NOTE: the mouse used to default to microsoft, but this was changed
+#  to fix bug #13458. If your mouse used to work fine, you can simply change
+#  it back to read "microsoft" again. If you are careful to change *only that
+#  one word*, and not to add or remove extra whitespace, the package
+#  installation will continue to update this file without requiring user
+#  intervention because of a modified config file.
+#  This applies to all mouse types, not just microsoft.)
 
 # Mouse/keyboard customisation by 101 (Attila Lendvai). If you have any good
 # ideas you can reach me at 101@kempelen.inf.bme.hu
@@ -243,7 +251,17 @@
 HorizSync 31.5 35.5
 VertRefresh 50 90
 
-# Montitor timings
+# If you have a NeoMagic card on a Toshiba Libretto 100, 110 use that instead
+
+# HorizSync 31.5 70
+# VertRefresh 50 100
+# Modeline "800x480"   50  800  856  976 1024   480  483  490  504 +hsync +vsync
+# newmode  800 480 256       800 1
+# newmode  800 480 32768    1600 2
+# newmode  800 480 65536    1600 2
+# newmode  800 480 16777216 2400 3
+
+# Monitor timings
 #
 # These are prefered over the default timings (if monitor and chipset
 # can handle them). Not all drivers use them at the moment, and Mach32
@@ -330,13 +348,13 @@
 # chipset BANSHEE	# Banshee/V3.
 # chipset SIS		# SiS 5597/6326/620/530 cards / integrated vga.
 # chipset I740		# Intel i740 based cards.
-# chipset FBDev		# Use the kernel frame buffer device for graphics
-			# display.
-# chipset G400		# Matrox G200/G400/G450
-# chipset R128		# ATI Rage 128
-# chipset SAVAGE	# S3 savage family
-# chipset LAGUNA	# Cirrus Logic 546x (laguna) 
-
+# chipset NEOMAGIC
+# chipset LAGUNA	# Cirrus Logic Laguna series (546X)
+# chipset FBDEV		# Use kernel fbdev, instead of direct hardware.
+# chipset G400		# Matrox Mystique/G100/G200/G400/G450
+# chipset R128		# Ati Rage128
+# chipset SAVAGE	# S3 chipsets Savage
+# chipset C&T		# Chips and Technologies
 
 # EGA Color/mono mode:
 # Required if chipset is EGA.
@@ -396,3 +414,8 @@
 		      # (main symptom is some modes are out of sync),
 		      # try enabling this. If it helps, please report to
 		      # me (matan@svgalib.org) 
+
+# NeoMagicLibretto100
+		      # Enable if you have a NeoMagic card on a Toshiba
+		      # Libretto 100, 110, etc
+
diff -Naur svgalib-1.4.3-orig/src/driver.h svgalib-1.4.3/src/driver.h
--- svgalib-1.4.3-orig/src/driver.h	2001-05-29 14:38:35.000000000 +0000
+++ svgalib-1.4.3/src/driver.h	2005-08-26 16:56:12.000000000 +0000
@@ -17,7 +17,7 @@
 #include "timing.h"
 #include "accel.h"
 
-#define MAX_REGS 5000 /* VESA needs a lot of storage space */
+#define MAX_REGS 11196 /* VESA needs a lot of storage space */
 
 typedef struct {
     void (*savepalette)(unsigned char *red, unsigned char *green, unsigned char *blue);
diff -Naur svgalib-1.4.3-orig/src/egadrv.c svgalib-1.4.3/src/egadrv.c
--- svgalib-1.4.3-orig/src/egadrv.c	1999-07-27 16:36:19.000000000 +0000
+++ svgalib-1.4.3/src/egadrv.c	2005-08-26 16:56:12.000000000 +0000
@@ -10,6 +10,7 @@
 
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include "vga.h"
 #include "libvga.h"
diff -Naur svgalib-1.4.3-orig/src/et6000.c svgalib-1.4.3/src/et6000.c
--- svgalib-1.4.3-orig/src/et6000.c	2000-07-07 12:49:10.000000000 +0000
+++ svgalib-1.4.3/src/et6000.c	2005-08-26 16:56:12.000000000 +0000
@@ -3,6 +3,9 @@
 #include <stdlib.h>    /*  Testing modeline update. */
 #include <stdio.h>
 #include <unistd.h>
+#if __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
 #include <stdarg.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -10,7 +13,6 @@
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
-#include <linux/pci.h>
 #include "timing.h"
 #include "interface.h"
 #include "vgaregs.h"
diff -Naur svgalib-1.4.3-orig/src/fb_lnx.h svgalib-1.4.3/src/fb_lnx.h
--- svgalib-1.4.3-orig/src/fb_lnx.h	1970-01-01 00:00:00.000000000 +0000
+++ svgalib-1.4.3/src/fb_lnx.h	2005-08-26 16:56:12.000000000 +0000
@@ -0,0 +1,331 @@
+#ifndef _LINUX_FB_H
+#define _LINUX_FB_H
+
+#include <stdint.h>
+
+/* Definitions of frame buffers						*/
+
+#define FB_MAJOR		29
+#define FB_MAX			32	/* sufficient for now */
+
+/* ioctls
+   0x46 is 'F'								*/
+#define FBIOGET_VSCREENINFO	0x4600
+#define FBIOPUT_VSCREENINFO	0x4601
+#define FBIOGET_FSCREENINFO	0x4602
+#define FBIOGETCMAP		0x4604
+#define FBIOPUTCMAP		0x4605
+#define FBIOPAN_DISPLAY		0x4606
+#define FBIO_CURSOR            _IOWR('F', 0x08, struct fb_cursor)
+/* 0x4607-0x460B are defined below */
+/* #define FBIOGET_MONITORSPEC	0x460C */
+/* #define FBIOPUT_MONITORSPEC	0x460D */
+/* #define FBIOSWITCH_MONIBIT	0x460E */
+#define FBIOGET_CON2FBMAP	0x460F
+#define FBIOPUT_CON2FBMAP	0x4610
+#define FBIOBLANK		0x4611		/* arg: 0 or vesa level + 1 */
+#define FBIOGET_VBLANK		_IOR('F', 0x12, struct fb_vblank)
+#define FBIO_ALLOC              0x4613
+#define FBIO_FREE               0x4614
+#define FBIOGET_GLYPH           0x4615
+#define FBIOGET_HWCINFO         0x4616
+#define FBIOPUT_MODEINFO        0x4617
+#define FBIOGET_DISPINFO        0x4618
+
+
+#define FB_TYPE_PACKED_PIXELS		0	/* Packed Pixels	*/
+#define FB_TYPE_PLANES			1	/* Non interleaved planes */
+#define FB_TYPE_INTERLEAVED_PLANES	2	/* Interleaved planes	*/
+#define FB_TYPE_TEXT			3	/* Text/attributes	*/
+#define FB_TYPE_VGA_PLANES		4	/* EGA/VGA planes	*/
+
+#define FB_AUX_TEXT_MDA		0	/* Monochrome text */
+#define FB_AUX_TEXT_CGA		1	/* CGA/EGA/VGA Color text */
+#define FB_AUX_TEXT_S3_MMIO	2	/* S3 MMIO fasttext */
+#define FB_AUX_TEXT_MGA_STEP16	3	/* MGA Millenium I: text, attr, 14 reserved bytes */
+#define FB_AUX_TEXT_MGA_STEP8	4	/* other MGAs:      text, attr,  6 reserved bytes */
+
+#define FB_AUX_VGA_PLANES_VGA4		0	/* 16 color planes (EGA/VGA) */
+#define FB_AUX_VGA_PLANES_CFB4		1	/* CFB4 in planes (VGA) */
+#define FB_AUX_VGA_PLANES_CFB8		2	/* CFB8 in planes (VGA) */
+
+#define FB_VISUAL_MONO01		0	/* Monochr. 1=Black 0=White */
+#define FB_VISUAL_MONO10		1	/* Monochr. 1=White 0=Black */
+#define FB_VISUAL_TRUECOLOR		2	/* True color	*/
+#define FB_VISUAL_PSEUDOCOLOR		3	/* Pseudo color (like atari) */
+#define FB_VISUAL_DIRECTCOLOR		4	/* Direct color */
+#define FB_VISUAL_STATIC_PSEUDOCOLOR	5	/* Pseudo color readonly */
+
+#define FB_ACCEL_NONE		0	/* no hardware accelerator	*/
+#define FB_ACCEL_ATARIBLITT	1	/* Atari Blitter		*/
+#define FB_ACCEL_AMIGABLITT	2	/* Amiga Blitter                */
+#define FB_ACCEL_S3_TRIO64	3	/* Cybervision64 (S3 Trio64)    */
+#define FB_ACCEL_NCR_77C32BLT	4	/* RetinaZ3 (NCR 77C32BLT)      */
+#define FB_ACCEL_S3_VIRGE	5	/* Cybervision64/3D (S3 ViRGE)	*/
+#define FB_ACCEL_ATI_MACH64GX	6	/* ATI Mach 64GX family		*/
+#define FB_ACCEL_DEC_TGA	7	/* DEC 21030 TGA		*/
+#define FB_ACCEL_ATI_MACH64CT	8	/* ATI Mach 64CT family		*/
+#define FB_ACCEL_ATI_MACH64VT	9	/* ATI Mach 64CT family VT class */
+#define FB_ACCEL_ATI_MACH64GT	10	/* ATI Mach 64CT family GT class */
+#define FB_ACCEL_SUN_CREATOR	11	/* Sun Creator/Creator3D	*/
+#define FB_ACCEL_SUN_CGSIX	12	/* Sun cg6			*/
+#define FB_ACCEL_SUN_LEO	13	/* Sun leo/zx			*/
+#define FB_ACCEL_IMS_TWINTURBO	14	/* IMS Twin Turbo		*/
+#define FB_ACCEL_3DLABS_PERMEDIA2 15	/* 3Dlabs Permedia 2		*/
+#define FB_ACCEL_MATROX_MGA2064W 16	/* Matrox MGA2064W (Millenium)	*/
+#define FB_ACCEL_MATROX_MGA1064SG 17	/* Matrox MGA1064SG (Mystique)	*/
+#define FB_ACCEL_MATROX_MGA2164W 18	/* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGA2164W_AGP 19	/* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGAG100	20	/* Matrox G100 (Productiva G100) */
+#define FB_ACCEL_MATROX_MGAG200	21	/* Matrox G200 (Myst, Mill, ...) */
+#define FB_ACCEL_SUN_CG14	22	/* Sun cgfourteen		 */
+#define FB_ACCEL_SUN_BWTWO	23	/* Sun bwtwo			*/
+#define FB_ACCEL_SUN_CGTHREE	24	/* Sun cgthree			*/
+#define FB_ACCEL_SUN_TCX	25	/* Sun tcx			*/
+#define FB_ACCEL_MATROX_MGAG400	26	/* Matrox G400			*/
+#define FB_ACCEL_NV3		27	/* nVidia RIVA 128              */
+#define FB_ACCEL_NV4		28	/* nVidia RIVA TNT		*/
+#define FB_ACCEL_NV5		29	/* nVidia RIVA TNT2		*/
+#define FB_ACCEL_CT_6555x	30	/* C&T 6555x			*/
+#define FB_ACCEL_3DFX_BANSHEE	31	/* 3Dfx Banshee			*/
+#define FB_ACCEL_ATI_RAGE128	32	/* ATI Rage128 family		*/
+#define FB_ACCEL_IGS_CYBER2000	33	/* CyberPro 2000		*/
+#define FB_ACCEL_IGS_CYBER2010	34	/* CyberPro 2010		*/
+#define FB_ACCEL_IGS_CYBER5000	35	/* CyberPro 5000		*/
+#define FB_ACCEL_SIS_GLAMOUR    36	/* SiS 300/630/540              */
+#define FB_ACCEL_3DLABS_PERMEDIA3 37	/* 3Dlabs Permedia 3		*/
+#define FB_ACCEL_ATI_RADEON	38	/* ATI Radeon family		*/
+#define FB_ACCEL_I810           39      /* Intel 810/815                */
+#define FB_ACCEL_SIS_GLAMOUR_2  40	/* SiS 315, 650, 740		*/
+#define FB_ACCEL_SIS_XABRE      41	/* SiS 330 ("Xabre")		*/
+
+#define FB_ACCEL_NEOMAGIC_NM2070 90	/* NeoMagic NM2070              */
+#define FB_ACCEL_NEOMAGIC_NM2090 91	/* NeoMagic NM2090              */
+#define FB_ACCEL_NEOMAGIC_NM2093 92	/* NeoMagic NM2093              */
+#define FB_ACCEL_NEOMAGIC_NM2097 93	/* NeoMagic NM2097              */
+#define FB_ACCEL_NEOMAGIC_NM2160 94	/* NeoMagic NM2160              */
+#define FB_ACCEL_NEOMAGIC_NM2200 95	/* NeoMagic NM2200              */
+#define FB_ACCEL_NEOMAGIC_NM2230 96	/* NeoMagic NM2230              */
+#define FB_ACCEL_NEOMAGIC_NM2360 97	/* NeoMagic NM2360              */
+#define FB_ACCEL_NEOMAGIC_NM2380 98	/* NeoMagic NM2380              */
+
+
+struct fb_fix_screeninfo {
+	char id[16];			/* identification string eg "TT Builtin" */
+	unsigned long smem_start;	/* Start of frame buffer mem */
+					/* (physical address) */
+	uint32_t smem_len;			/* Length of frame buffer mem */
+	uint32_t type;			/* see FB_TYPE_*		*/
+	uint32_t type_aux;			/* Interleave for interleaved Planes */
+	uint32_t visual;			/* see FB_VISUAL_*		*/ 
+	uint16_t xpanstep;			/* zero if no hardware panning  */
+	uint16_t ypanstep;			/* zero if no hardware panning  */
+	uint16_t ywrapstep;		/* zero if no hardware ywrap    */
+	uint32_t line_length;		/* length of a line in bytes    */
+	unsigned long mmio_start;	/* Start of Memory Mapped I/O   */
+					/* (physical address) */
+	uint32_t mmio_len;			/* Length of Memory Mapped I/O  */
+	uint32_t accel;			/* Type of acceleration available */
+	uint16_t reserved[3];		/* Reserved for future compatibility */
+};
+
+/* Interpretation of offset for color fields: All offsets are from the right,
+ * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
+ * can use the offset as right argument to <<). A pixel afterwards is a bit
+ * stream and is written to video memory as that unmodified. This implies
+ * big-endian byte order if bits_per_pixel is greater than 8.
+ */
+struct fb_bitfield {
+	uint32_t offset;			/* beginning of bitfield	*/
+	uint32_t length;			/* length of bitfield		*/
+	uint32_t msb_right;		/* != 0 : Most significant bit is */ 
+					/* right */ 
+};
+
+#define FB_NONSTD_HAM		1	/* Hold-And-Modify (HAM)        */
+
+#define FB_ACTIVATE_NOW		0	/* set values immediately (or vbl)*/
+#define FB_ACTIVATE_NXTOPEN	1	/* activate on next open	*/
+#define FB_ACTIVATE_TEST	2	/* don't set, round up impossible */
+#define FB_ACTIVATE_MASK       15
+					/* values			*/
+#define FB_ACTIVATE_VBL	       16	/* activate values on next vbl  */
+#define FB_CHANGE_CMAP_VBL     32	/* change colormap on vbl	*/
+#define FB_ACTIVATE_ALL	       64	/* change all VCs on this fb	*/
+
+#define FB_ACCELF_TEXT		1	/* text mode acceleration */
+
+#define FB_SYNC_HOR_HIGH_ACT	1	/* horizontal sync high active	*/
+#define FB_SYNC_VERT_HIGH_ACT	2	/* vertical sync high active	*/
+#define FB_SYNC_EXT		4	/* external sync		*/
+#define FB_SYNC_COMP_HIGH_ACT	8	/* composite sync high active   */
+#define FB_SYNC_BROADCAST	16	/* broadcast video timings      */
+					/* vtotal = 144d/288n/576i => PAL  */
+					/* vtotal = 121d/242n/484i => NTSC */
+#define FB_SYNC_ON_GREEN	32	/* sync on green */
+
+#define FB_VMODE_NONINTERLACED  0	/* non interlaced */
+#define FB_VMODE_INTERLACED	1	/* interlaced	*/
+#define FB_VMODE_DOUBLE		2	/* double scan */
+#define FB_VMODE_MASK		255
+
+#define FB_VMODE_YWRAP		256	/* ywrap instead of panning     */
+#define FB_VMODE_SMOOTH_XPAN	512	/* smooth xpan possible (internally used) */
+#define FB_VMODE_CONUPDATE	512	/* don't update x/yoffset	*/
+
+#define PICOS2KHZ(a) (1000000000UL/(a))
+#define KHZ2PICOS(a) (1000000000UL/(a))
+
+struct fb_var_screeninfo {
+	uint32_t xres;			/* visible resolution		*/
+	uint32_t yres;
+	uint32_t xres_virtual;		/* virtual resolution		*/
+	uint32_t yres_virtual;
+	uint32_t xoffset;			/* offset from virtual to visible */
+	uint32_t yoffset;			/* resolution			*/
+
+	uint32_t bits_per_pixel;		/* guess what			*/
+	uint32_t grayscale;		/* != 0 Graylevels instead of colors */
+
+	struct fb_bitfield red;		/* bitfield in fb mem if true color, */
+	struct fb_bitfield green;	/* else only length is significant */
+	struct fb_bitfield blue;
+	struct fb_bitfield transp;	/* transparency			*/	
+
+	uint32_t nonstd;			/* != 0 Non standard pixel format */
+
+	uint32_t activate;			/* see FB_ACTIVATE_*		*/
+
+	uint32_t height;			/* height of picture in mm    */
+	uint32_t width;			/* width of picture in mm     */
+
+	uint32_t accel_flags;		/* acceleration flags (hints)	*/
+
+	/* Timing: All values in pixclocks, except pixclock (of course) */
+	uint32_t pixclock;			/* pixel clock in ps (pico seconds) */
+	uint32_t left_margin;		/* time from sync to picture	*/
+	uint32_t right_margin;		/* time from picture to sync	*/
+	uint32_t upper_margin;		/* time from sync to picture	*/
+	uint32_t lower_margin;
+	uint32_t hsync_len;		/* length of horizontal sync	*/
+	uint32_t vsync_len;		/* length of vertical sync	*/
+	uint32_t sync;			/* see FB_SYNC_*		*/
+	uint32_t vmode;			/* see FB_VMODE_*		*/
+	uint32_t rotate;			/* angle we rotate counter clockwise */
+	uint32_t reserved[5];		/* Reserved for future compatibility */
+};
+
+struct fb_cmap {
+	uint32_t start;			/* First entry	*/
+	uint32_t len;			/* Number of entries */
+	uint16_t *red;			/* Red values	*/
+	uint16_t *green;
+	uint16_t *blue;
+	uint16_t *transp;			/* transparency, can be NULL */
+};
+
+struct fb_con2fbmap {
+	uint32_t console;
+	uint32_t framebuffer;
+};
+
+/* VESA Blanking Levels */
+#define VESA_NO_BLANKING        0
+#define VESA_VSYNC_SUSPEND      1
+#define VESA_HSYNC_SUSPEND      2
+#define VESA_POWERDOWN          3
+
+struct fb_monspecs {
+	uint32_t hfmin;			/* hfreq lower limit (Hz) */
+	uint32_t hfmax; 			/* hfreq upper limit (Hz) */
+	uint16_t vfmin;			/* vfreq lower limit (Hz) */
+	uint16_t vfmax;			/* vfreq upper limit (Hz) */
+	uint32_t dclkmin;                  /* pixelclock lower limit (Hz) */
+	uint32_t dclkmax;                  /* pixelclock upper limit (Hz) */
+	unsigned gtf  : 1;              /* supports GTF */
+	unsigned dpms : 1;		/* supports DPMS */
+};
+
+#define FB_VBLANK_VBLANKING	0x001	/* currently in a vertical blank */
+#define FB_VBLANK_HBLANKING	0x002	/* currently in a horizontal blank */
+#define FB_VBLANK_HAVE_VBLANK	0x004	/* vertical blanks can be detected */
+#define FB_VBLANK_HAVE_HBLANK	0x008	/* horizontal blanks can be detected */
+#define FB_VBLANK_HAVE_COUNT	0x010	/* global retrace counter is available */
+#define FB_VBLANK_HAVE_VCOUNT	0x020	/* the vcount field is valid */
+#define FB_VBLANK_HAVE_HCOUNT	0x040	/* the hcount field is valid */
+#define FB_VBLANK_VSYNCING	0x080	/* currently in a vsync */
+#define FB_VBLANK_HAVE_VSYNC	0x100	/* verical syncs can be detected */
+
+struct fb_vblank {
+	uint32_t flags;			/* FB_VBLANK flags */
+	uint32_t count;			/* counter of retraces since boot */
+	uint32_t vcount;			/* current scanline position */
+	uint32_t hcount;			/* current scandot position */
+	uint32_t reserved[4];		/* reserved for future compatibility */
+};
+
+/* Internal HW accel */
+#define ROP_COPY 0
+/* #define ROP_XOR  1		Already defined by svgalib */
+
+struct fb_copyarea {
+	uint32_t dx;
+	uint32_t dy;
+	uint32_t width;
+	uint32_t height;
+	uint32_t sx;
+	uint32_t sy;
+};
+
+struct fb_fillrect {
+	uint32_t dx;	/* screen-relative */
+	uint32_t dy;
+	uint32_t width;
+	uint32_t height;
+	uint32_t color;
+	uint32_t rop;
+};
+
+struct fb_image {
+	uint32_t dx;		/* Where to place image */
+	uint32_t dy;
+	uint32_t width;		/* Size of image */
+	uint32_t height;
+	uint32_t fg_color;		/* Only used when a mono bitmap */
+	uint32_t bg_color;
+	uint8_t  depth;		/* Depth of the image */
+	const char *data;	/* Pointer to image data */
+	struct fb_cmap cmap;	/* color map info */
+};
+
+/*
+ * hardware cursor control
+ */
+
+#define FB_CUR_SETCUR   0x01
+#define FB_CUR_SETPOS   0x02
+#define FB_CUR_SETHOT   0x04
+#define FB_CUR_SETCMAP  0x08
+#define FB_CUR_SETSHAPE 0x10
+#define FB_CUR_SETSIZE	0x20
+#define FB_CUR_SETALL   0xFF
+
+struct fbcurpos {
+	uint16_t x, y;
+};
+
+struct fb_cursor {
+	uint16_t set;		/* what to set */
+	uint16_t enable;		/* cursor on/off */
+	uint16_t rop;		/* bitop operation */
+	char *mask;		/* cursor mask bits */
+	struct fbcurpos hot;	/* cursor hot spot */
+	struct fb_image	image;	/* Cursor image */
+};
+
+#define FB_PIXMAP_DEFAULT 1     /* used internally by fbcon */
+#define FB_PIXMAP_SYSTEM  2     /* memory is in system RAM  */
+#define FB_PIXMAP_IO      4     /* memory is iomapped       */
+#define FB_PIXMAP_SYNC    256   /* set if GPU can DMA       */
+
+#endif /* _LINUX_FB_H */
diff -Naur svgalib-1.4.3-orig/src/fbdev.c svgalib-1.4.3/src/fbdev.c
--- svgalib-1.4.3-orig/src/fbdev.c	2000-08-27 15:16:06.000000000 +0000
+++ svgalib-1.4.3/src/fbdev.c	2005-08-26 16:56:12.000000000 +0000
@@ -1,13 +1,13 @@
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
-#include <linux/fb.h>
-#include <linux/kd.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "kd_lnx.h"
+#include "fb_lnx.h"
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
@@ -353,7 +353,7 @@
 			unsigned char *green,
 			unsigned char *blue)
 {
-	__u16 r[256], g[256], b[256], t[256];
+	uint16_t r[256], g[256], b[256], t[256];
 	struct fb_cmap cmap;
 	unsigned i;
 
@@ -379,7 +379,7 @@
 			   const unsigned char *green,
 			   const unsigned char *blue)
 {
-	__u16 r[256], g[256], b[256], t[256];
+	uint16_t r[256], g[256], b[256], t[256];
 	struct fb_cmap cmap;
 	unsigned i;
 
@@ -403,7 +403,7 @@
 
 static int fbdev_setpalette(int index, int red, int green, int blue)
 {
-	__u16 r, g, b, t;
+	uint16_t r, g, b, t;
 	struct fb_cmap cmap;
 
 	r = (red << 10) | (red << 4) | (red >> 2);
@@ -424,7 +424,7 @@
 
 static void fbdev_getpalette(int index, int *red, int *green, int *blue)
 {
-	__u16 r, g, b, t;
+	uint16_t r, g, b, t;
 	struct fb_cmap cmap;
 
 	cmap.start = 0;
diff -Naur svgalib-1.4.3-orig/src/gvga6400.c svgalib-1.4.3/src/gvga6400.c
--- svgalib-1.4.3-orig/src/gvga6400.c	1999-07-27 16:36:19.000000000 +0000
+++ svgalib-1.4.3/src/gvga6400.c	2005-08-26 16:56:12.000000000 +0000
@@ -178,7 +178,31 @@
     int result = 0;
     int address;
 
+    /*  Ensure that this open gets a file descriptor greater
+     *  than 2, else problems can occur with stdio functions
+     *  under certain strange conditions:  */
+    if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1)) {
+        perror("/dev/null");
+        exit(1);
+    }
+    if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)) {
+        perror("/dev/null");
+        exit(1);
+    }
+    if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)) {
+        perror("/dev/null");
+        exit(1);
+    }
     mem_fd = open("/dev/mem", O_RDONLY);
+    if (mem_fd == -1) {
+        perror("/dev/mem");
+        exit(-1);
+    }
+    /*  Ensure this file is closed if we were ever to exec something else...  */
+    if (fcntl(mem_fd, F_SETFD, 1) == -1) {
+        perror("fcntl");
+        exit(-1);
+    }
 
     /* Changed to use valloc(). */
     if ((vga_bios = valloc(4096)) == NULL) {
diff -Naur svgalib-1.4.3-orig/src/joystick/joydev.h svgalib-1.4.3/src/joystick/joydev.h
--- svgalib-1.4.3-orig/src/joystick/joydev.h	1999-09-28 16:38:01.000000000 +0000
+++ svgalib-1.4.3/src/joystick/joydev.h	2005-08-26 16:56:12.000000000 +0000
@@ -1,46 +1,45 @@
-#include <linux/version.h>
+#ifndef _LINUX_JOYSTICK_H
+#define _LINUX_JOYSTICK_H
 
-#if ( LINUX_VESION_CODE >= 131584) 
-#include <linux/joystick.h>
-#else
-/* Joystick interface modeled after svgalibs keyboard and mouse interfaces 
- * Copyright 1998 Daniel Engström <daniel.engstrom@riksnett.no> 
- * Partly based on code from 
- * joystick-0.7.3 Copyright (C) 1992, 1993 Author C. Smith
- * and 
- * joystick-1.0.6 Copyright (C) 1997 Vojtech Pavlik 
+/*
+ * $Id: joystick.h,v 1.3 2000/11/30 11:07:05 vojtech Exp $
+ *
+ *  Copyright (C) 1996-2000 Vojtech Pavlik
+ *
+ *  Sponsored by SuSE
  */
 
-#include <sys/ioctl.h> /* for _IOR(x) and _IOW(x) macros */ 
-#include <sys/types.h>
 /*
- * IOCTL commands for joystick driver
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or 
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * 
+ * Should you need to contact me, the author, you can do so either by
+ * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
+ * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
  */
-				/* get driver version */
-#define JSIOCGVERSION		_IOR('j', 0x01, u_int32_t)
 
-				/* get number of axes */
-#define JSIOCGAXES		_IOR('j', 0x11, u_int8_t)
-				/* get number of buttons */
-#define JSIOCGBUTTONS		_IOR('j', 0x12, u_int8_t)
-
-		                /* set correction values */
-#define JSIOCSCORR		_IOW('j', 0x21, struct js_corr[4])
-		                /* get correction values */
-#define JSIOCGCORR		_IOR('j', 0x22, struct js_corr[4])
+#include <stdint.h>
+#include <sys/ioctl.h> /* for _IOR(x) and _IOW(x) macros */
+
+/* From <linux/input.h> */
+#define KEY_MAX                 0x1ff
 
 /*
- * Types and constants for get/set correction
+ * Version
  */
 
-#define JS_CORR_NONE		0x00		/* returns raw values */
-#define JS_CORR_BROKEN		0x01		/* broken line */
-
-struct js_corr {
-	int32_t coef[8];
-	u_int16_t prec;
-	u_int16_t type;
-};
+#define JS_VERSION		0x020100
 
 /*
  * Types and constants for reading from /dev/js
@@ -51,41 +50,82 @@
 #define JS_EVENT_INIT		0x80	/* initial state of device */
 
 struct js_event {
-        u_int32_t time;		/* time when event happened in miliseconds 
-				 * since open */
-        u_int16_t value;	/* new value */
-        u_int8_t  type;		/* type of event, see above */
-        u_int8_t  number;	/* axis/button number */
+	uint32_t time;	/* event timestamp in milliseconds */
+	int16_t value;	/* value */
+	uint8_t type;	/* event type */
+	uint8_t number;	/* axis/button number */
+};
+
+/*
+ * IOCTL commands for joystick driver
+ */
+
+#define JSIOCGVERSION		_IOR('j', 0x01, uint32_t)				/* get driver version */
+
+#define JSIOCGAXES		_IOR('j', 0x11, uint8_t)				/* get number of axes */
+#define JSIOCGBUTTONS		_IOR('j', 0x12, uint8_t)				/* get number of buttons */
+#define JSIOCGNAME(len)		_IOC(_IOC_READ, 'j', 0x13, len)			/* get identifier string */
+
+#define JSIOCSCORR		_IOW('j', 0x21, struct js_corr)			/* set correction values */
+#define JSIOCGCORR		_IOR('j', 0x22, struct js_corr)			/* get correction values */
+
+#define JSIOCSAXMAP		_IOW('j', 0x31, uint8_t[ABS_MAX])			/* set axis mapping */
+#define JSIOCGAXMAP		_IOR('j', 0x32, uint8_t[ABS_MAX])			/* get axis mapping */
+#define JSIOCSBTNMAP		_IOW('j', 0x33, uint16_t[KEY_MAX - BTN_MISC])	/* set button mapping */
+#define JSIOCGBTNMAP		_IOR('j', 0x34, uint16_t[KEY_MAX - BTN_MISC])	/* get button mapping */
+
+/*
+ * Types and constants for get/set correction
+ */
+
+#define JS_CORR_NONE		0x00	/* returns raw values */
+#define JS_CORR_BROKEN		0x01	/* broken line */
+
+struct js_corr {
+	int32_t coef[8];
+	int16_t prec;
+	uint16_t type;
 };
 
 /*
- * Backward (version 0.x) compatibility definitions
+ * v0.x compatibility definitions
  */
 
-#define JS_RETURN 	sizeof(struct JS_DATA_TYPE)
-#define JS_TRUE 	1
-#define JS_FALSE 	0
-#define JS_X_0		0x01		/* bit mask for x-axis js0 */
-#define JS_Y_0		0x02		/* bit mask for y-axis js0 */
-#define JS_X_1		0x04		/* bit mask for x-axis js1 */
-#define JS_Y_1		0x08		/* bit mask for y-axis js1 */
-#define JS_MAX 		2		/* max number of joysticks */
-
-#define JS_SET_CAL 0x01		/*ioctl cmd to set joystick correction factor*/
-#define JS_GET_CAL 0x02		/*ioctl cmd to get joystick correction factor*/
-#define JS_SET_TIMEOUT 0x03	/*ioctl cmd to set maximum number of iterations
-				  to wait for a timeout*/
-#define JS_GET_TIMEOUT		0x04	/*as above, to get*/
-#define JS_SET_TIMELIMIT	0x05	/*set data retention time*/
-#define JS_GET_TIMELIMIT	0x06	/*get data retention time*/
-#define JS_GET_ALL		0x07	/*get the whole JS_DATA[minor] struct*/
-#define JS_SET_ALL		0x08	/*set the whole JS_DATA[minor] struct
-						  except JS_BUSY!*/
+#define JS_RETURN		sizeof(struct JS_DATA_TYPE)
+#define JS_TRUE			1
+#define JS_FALSE		0
+#define JS_X_0			0x01
+#define JS_Y_0			0x02
+#define JS_X_1			0x04
+#define JS_Y_1			0x08
+#define JS_MAX			2
+
+#define JS_DEF_TIMEOUT		0x1300
+#define JS_DEF_CORR		0
+#define JS_DEF_TIMELIMIT	10L
+
+#define JS_SET_CAL		1
+#define JS_GET_CAL		2
+#define JS_SET_TIMEOUT		3
+#define JS_GET_TIMEOUT		4
+#define JS_SET_TIMELIMIT	5
+#define JS_GET_TIMELIMIT	6
+#define JS_GET_ALL		7
+#define JS_SET_ALL		8
 
-/* version 0.x struct */
 struct JS_DATA_TYPE {
-	int buttons;		/* immediate button state */
-	int x;                  /* immediate x axis value */
-	int y;                  /* immediate y axis value */
+	int buttons;
+	int x;
+	int y;
 };
-#endif
+
+struct JS_DATA_SAVE_TYPE {
+	int JS_TIMEOUT;
+	int BUSY;
+	long JS_EXPIRETIME;
+	long JS_TIMELIMIT;
+	struct JS_DATA_TYPE JS_SAVE;
+	struct JS_DATA_TYPE JS_CORR;
+};
+
+#endif /* _LINUX_JOYSTICK_H */
diff -Naur svgalib-1.4.3-orig/src/kd_lnx.h svgalib-1.4.3/src/kd_lnx.h
--- svgalib-1.4.3-orig/src/kd_lnx.h	1970-01-01 00:00:00.000000000 +0000
+++ svgalib-1.4.3/src/kd_lnx.h	2005-08-26 16:56:12.000000000 +0000
@@ -0,0 +1,167 @@
+#ifndef _LINUX_KD_H
+#define _LINUX_KD_H
+
+/* 0x4B is 'K', to avoid collision with termios and vt */
+
+#define GIO_FONT	0x4B60	/* gets font in expanded form */
+#define PIO_FONT	0x4B61	/* use font in expanded form */
+
+#define GIO_FONTX	0x4B6B	/* get font using struct consolefontdesc */
+#define PIO_FONTX	0x4B6C	/* set font using struct consolefontdesc */
+struct consolefontdesc {
+	unsigned short charcount;	/* characters in font (256 or 512) */
+	unsigned short charheight;	/* scan lines per character (1-32) */
+	char *chardata;			/* font data in expanded form */
+};
+
+#define PIO_FONTRESET   0x4B6D	/* reset to default font */
+
+#define GIO_CMAP	0x4B70	/* gets colour palette on VGA+ */
+#define PIO_CMAP	0x4B71	/* sets colour palette on VGA+ */
+
+#define KIOCSOUND	0x4B2F	/* start sound generation (0 for off) */
+#define KDMKTONE	0x4B30	/* generate tone */
+
+#define KDGETLED	0x4B31	/* return current led state */
+#define KDSETLED	0x4B32	/* set led state [lights, not flags] */
+#define 	LED_SCR		0x01	/* scroll lock led */
+#define 	LED_NUM		0x02	/* num lock led */
+#define 	LED_CAP		0x04	/* caps lock led */
+
+#define KDGKBTYPE	0x4B33	/* get keyboard type */
+#define 	KB_84		0x01
+#define 	KB_101		0x02 	/* this is what we always answer */
+#define 	KB_OTHER	0x03
+
+#define KDADDIO		0x4B34	/* add i/o port as valid */
+#define KDDELIO		0x4B35	/* del i/o port as valid */
+#define KDENABIO	0x4B36	/* enable i/o to video board */
+#define KDDISABIO	0x4B37	/* disable i/o to video board */
+
+#define KDSETMODE	0x4B3A	/* set text/graphics mode */
+#define		KD_TEXT		0x00
+#define		KD_GRAPHICS	0x01
+#define		KD_TEXT0	0x02	/* obsolete */
+#define		KD_TEXT1	0x03	/* obsolete */
+#define KDGETMODE	0x4B3B	/* get current mode */
+
+#define KDMAPDISP	0x4B3C	/* map display into address space */
+#define KDUNMAPDISP	0x4B3D	/* unmap display from address space */
+
+typedef char scrnmap_t;
+#define		E_TABSZ		256
+#define GIO_SCRNMAP	0x4B40	/* get screen mapping from kernel */
+#define PIO_SCRNMAP	0x4B41	/* put screen mapping table in kernel */
+#define GIO_UNISCRNMAP  0x4B69	/* get full Unicode screen mapping */
+#define PIO_UNISCRNMAP  0x4B6A  /* set full Unicode screen mapping */
+
+#define GIO_UNIMAP	0x4B66	/* get unicode-to-font mapping from kernel */
+struct unipair {
+	unsigned short unicode;
+	unsigned short fontpos;
+};
+struct unimapdesc {
+	unsigned short entry_ct;
+	struct unipair *entries;
+};
+#define PIO_UNIMAP	0x4B67	/* put unicode-to-font mapping in kernel */
+#define PIO_UNIMAPCLR	0x4B68	/* clear table, possibly advise hash algorithm */
+struct unimapinit {
+	unsigned short advised_hashsize;  /* 0 if no opinion */
+	unsigned short advised_hashstep;  /* 0 if no opinion */
+	unsigned short advised_hashlevel; /* 0 if no opinion */
+};
+
+#define UNI_DIRECT_BASE 0xF000	/* start of Direct Font Region */
+#define UNI_DIRECT_MASK 0x01FF	/* Direct Font Region bitmask */
+
+#define		K_RAW		0x00
+#define		K_XLATE		0x01
+#define		K_MEDIUMRAW	0x02
+#define		K_UNICODE	0x03
+#define KDGKBMODE	0x4B44	/* gets current keyboard mode */
+#define KDSKBMODE	0x4B45	/* sets current keyboard mode */
+
+#define		K_METABIT	0x03
+#define		K_ESCPREFIX	0x04
+#define KDGKBMETA	0x4B62	/* gets meta key handling mode */
+#define KDSKBMETA	0x4B63	/* sets meta key handling mode */
+
+#define		K_SCROLLLOCK	0x01
+#define		K_NUMLOCK	0x02
+#define		K_CAPSLOCK	0x04
+#define	KDGKBLED	0x4B64	/* get led flags (not lights) */
+#define	KDSKBLED	0x4B65	/* set led flags (not lights) */
+
+struct kbentry {
+	unsigned char kb_table;
+	unsigned char kb_index;
+	unsigned short kb_value;
+};
+#define		K_NORMTAB	0x00
+#define		K_SHIFTTAB	0x01
+#define		K_ALTTAB	0x02
+#define		K_ALTSHIFTTAB	0x03
+
+#define KDGKBENT	0x4B46	/* gets one entry in translation table */
+#define KDSKBENT	0x4B47	/* sets one entry in translation table */
+
+struct kbsentry {
+	unsigned char kb_func;
+	unsigned char kb_string[512];
+};
+#define KDGKBSENT	0x4B48	/* gets one function key string entry */
+#define KDSKBSENT	0x4B49	/* sets one function key string entry */
+
+struct kbdiacr {
+        unsigned char diacr, base, result;
+};
+struct kbdiacrs {
+        unsigned int kb_cnt;    /* number of entries in following array */
+	struct kbdiacr kbdiacr[256];    /* MAX_DIACR from keyboard.h */
+};
+#define KDGKBDIACR      0x4B4A  /* read kernel accent table */
+#define KDSKBDIACR      0x4B4B  /* write kernel accent table */
+
+struct kbkeycode {
+	unsigned int scancode, keycode;
+};
+#define KDGETKEYCODE	0x4B4C	/* read kernel keycode table entry */
+#define KDSETKEYCODE	0x4B4D	/* write kernel keycode table entry */
+
+#define KDSIGACCEPT	0x4B4E	/* accept kbd generated signals */
+
+struct kbd_repeat {
+	int delay;	/* in msec; <= 0: don't change */
+	int period;	/* in msec; <= 0: don't change */
+			/* earlier this field was misnamed "rate" */
+};
+
+#define KDKBDREP        0x4B52  /* set keyboard delay/repeat rate;
+				 * actually used values are returned */
+
+#define KDFONTOP	0x4B72	/* font operations */
+
+struct console_font_op {
+	unsigned int op;	/* operation code KD_FONT_OP_* */
+	unsigned int flags;	/* KD_FONT_FLAG_* */
+	unsigned int width, height;	/* font size */
+	unsigned int charcount;
+	unsigned char *data;	/* font data with height fixed to 32 */
+};
+
+#define KD_FONT_OP_SET		0	/* Set font */
+#define KD_FONT_OP_GET		1	/* Get font */
+#define KD_FONT_OP_SET_DEFAULT	2	/* Set font to default, data points to name / NULL */
+#define KD_FONT_OP_COPY		3	/* Copy from another console */
+
+#define KD_FONT_FLAG_DONT_RECALC 	1	/* Don't recalculate hw charcell size [compat] */
+#ifdef __KERNEL__
+#define KD_FONT_FLAG_OLD		0x80000000	/* Invoked via old interface [compat] */
+#endif
+
+/* note: 0x4B00-0x4B4E all have had a value at some time;
+   don't reuse for the time being */
+/* note: 0x4B60-0x4B6D, 0x4B70-0x4B72 used above */
+
+#endif /* _LINUX_KD_H */
diff -Naur svgalib-1.4.3-orig/src/keyboard/keyboard.c svgalib-1.4.3/src/keyboard/keyboard.c
--- svgalib-1.4.3-orig/src/keyboard/keyboard.c	2000-10-08 12:37:40.000000000 +0000
+++ svgalib-1.4.3/src/keyboard/keyboard.c	2005-08-26 16:56:12.000000000 +0000
@@ -28,18 +28,18 @@
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <termios.h>
-#include <linux/kd.h>
+#include "kd_lnx.h"
 /* linux/keyboard.h defines NR_KEYS and some scancode-like constants, so it */
 /* should also be useful for svgalib programs using the keyboard. It misses */
 /* a few KERNEL ifdefs around kernel data structures though. */
-#include <linux/keyboard.h>
+#include "keyboard_lnx.h"
 #include <sys/vt.h>
 /* Needed to check uid of keymap files */
 #include <sys/stat.h>
 #include <unistd.h>
 
 #include <vga.h>
-#include "../libvga.h"
+#include "libvga.h"
 #include "vgakeyboard.h"
 #include "driver.h"
 
diff -Naur svgalib-1.4.3-orig/src/keyboard/keyboard_lnx.h svgalib-1.4.3/src/keyboard/keyboard_lnx.h
--- svgalib-1.4.3-orig/src/keyboard/keyboard_lnx.h	1970-01-01 00:00:00.000000000 +0000
+++ svgalib-1.4.3/src/keyboard/keyboard_lnx.h	2005-08-26 16:56:12.000000000 +0000
@@ -0,0 +1,425 @@
+#ifndef __LINUX_KEYBOARD_H
+#define __LINUX_KEYBOARD_H
+
+/* From <linux/input.h> */
+#define KEY_MAX                 0x1ff
+
+#define KG_SHIFT	0
+#define KG_CTRL		2
+#define KG_ALT		3
+#define KG_ALTGR	1
+#define KG_SHIFTL	4
+#define KG_KANASHIFT	4
+#define KG_SHIFTR	5
+#define KG_CTRLL	6
+#define KG_CTRLR	7
+#define KG_CAPSSHIFT	8
+
+#define NR_SHIFT	9
+
+#define NR_KEYS		(KEY_MAX+1)
+#define MAX_NR_KEYMAPS	256
+/* This means 128Kb if all keymaps are allocated. Only the superuser
+	may increase the number of keymaps beyond MAX_NR_OF_USER_KEYMAPS. */
+#define MAX_NR_OF_USER_KEYMAPS 256 	/* should be at least 7 */
+
+#define MAX_NR_FUNC	256	/* max nr of strings assigned to keys */
+
+#define KT_LATIN	0	/* we depend on this being zero */
+#define KT_LETTER	11	/* symbol that can be acted upon by CapsLock */
+#define KT_FN		1
+#define KT_SPEC		2
+#define KT_PAD		3
+#define KT_DEAD		4
+#define KT_CONS		5
+#define KT_CUR		6
+#define KT_SHIFT	7
+#define KT_META		8
+#define KT_ASCII	9
+#define KT_LOCK		10
+#define KT_SLOCK	12
+
+#define K(t,v)		(((t)<<8)|(v))
+#define KTYP(x)		((x) >> 8)
+#define KVAL(x)		((x) & 0xff)
+
+#define K_F1		K(KT_FN,0)
+#define K_F2		K(KT_FN,1)
+#define K_F3		K(KT_FN,2)
+#define K_F4		K(KT_FN,3)
+#define K_F5		K(KT_FN,4)
+#define K_F6		K(KT_FN,5)
+#define K_F7		K(KT_FN,6)
+#define K_F8		K(KT_FN,7)
+#define K_F9		K(KT_FN,8)
+#define K_F10		K(KT_FN,9)
+#define K_F11		K(KT_FN,10)
+#define K_F12		K(KT_FN,11)
+#define K_F13		K(KT_FN,12)
+#define K_F14		K(KT_FN,13)
+#define K_F15		K(KT_FN,14)
+#define K_F16		K(KT_FN,15)
+#define K_F17		K(KT_FN,16)
+#define K_F18		K(KT_FN,17)
+#define K_F19		K(KT_FN,18)
+#define K_F20		K(KT_FN,19)
+#define K_FIND		K(KT_FN,20)
+#define K_INSERT	K(KT_FN,21)
+#define K_REMOVE	K(KT_FN,22)
+#define K_SELECT	K(KT_FN,23)
+#define K_PGUP		K(KT_FN,24) /* PGUP is a synonym for PRIOR */
+#define K_PGDN		K(KT_FN,25) /* PGDN is a synonym for NEXT */
+#define K_MACRO	 	K(KT_FN,26)
+#define K_HELP		K(KT_FN,27)
+#define K_DO		K(KT_FN,28)
+#define K_PAUSE	 	K(KT_FN,29)
+#define K_F21		K(KT_FN,30)
+#define K_F22		K(KT_FN,31)
+#define K_F23		K(KT_FN,32)
+#define K_F24		K(KT_FN,33)
+#define K_F25		K(KT_FN,34)
+#define K_F26		K(KT_FN,35)
+#define K_F27		K(KT_FN,36)
+#define K_F28		K(KT_FN,37)
+#define K_F29		K(KT_FN,38)
+#define K_F30		K(KT_FN,39)
+#define K_F31		K(KT_FN,40)
+#define K_F32		K(KT_FN,41)
+#define K_F33		K(KT_FN,42)
+#define K_F34		K(KT_FN,43)
+#define K_F35		K(KT_FN,44)
+#define K_F36		K(KT_FN,45)
+#define K_F37		K(KT_FN,46)
+#define K_F38		K(KT_FN,47)
+#define K_F39		K(KT_FN,48)
+#define K_F40		K(KT_FN,49)
+#define K_F41		K(KT_FN,50)
+#define K_F42		K(KT_FN,51)
+#define K_F43		K(KT_FN,52)
+#define K_F44		K(KT_FN,53)
+#define K_F45		K(KT_FN,54)
+#define K_F46		K(KT_FN,55)
+#define K_F47		K(KT_FN,56)
+#define K_F48		K(KT_FN,57)
+#define K_F49		K(KT_FN,58)
+#define K_F50		K(KT_FN,59)
+#define K_F51		K(KT_FN,60)
+#define K_F52		K(KT_FN,61)
+#define K_F53		K(KT_FN,62)
+#define K_F54		K(KT_FN,63)
+#define K_F55		K(KT_FN,64)
+#define K_F56		K(KT_FN,65)
+#define K_F57		K(KT_FN,66)
+#define K_F58		K(KT_FN,67)
+#define K_F59		K(KT_FN,68)
+#define K_F60		K(KT_FN,69)
+#define K_F61		K(KT_FN,70)
+#define K_F62		K(KT_FN,71)
+#define K_F63		K(KT_FN,72)
+#define K_F64		K(KT_FN,73)
+#define K_F65		K(KT_FN,74)
+#define K_F66		K(KT_FN,75)
+#define K_F67		K(KT_FN,76)
+#define K_F68		K(KT_FN,77)
+#define K_F69		K(KT_FN,78)
+#define K_F70		K(KT_FN,79)
+#define K_F71		K(KT_FN,80)
+#define K_F72		K(KT_FN,81)
+#define K_F73		K(KT_FN,82)
+#define K_F74		K(KT_FN,83)
+#define K_F75		K(KT_FN,84)
+#define K_F76		K(KT_FN,85)
+#define K_F77		K(KT_FN,86)
+#define K_F78		K(KT_FN,87)
+#define K_F79		K(KT_FN,88)
+#define K_F80		K(KT_FN,89)
+#define K_F81		K(KT_FN,90)
+#define K_F82		K(KT_FN,91)
+#define K_F83		K(KT_FN,92)
+#define K_F84		K(KT_FN,93)
+#define K_F85		K(KT_FN,94)
+#define K_F86		K(KT_FN,95)
+#define K_F87		K(KT_FN,96)
+#define K_F88		K(KT_FN,97)
+#define K_F89		K(KT_FN,98)
+#define K_F90		K(KT_FN,99)
+#define K_F91		K(KT_FN,100)
+#define K_F92		K(KT_FN,101)
+#define K_F93		K(KT_FN,102)
+#define K_F94		K(KT_FN,103)
+#define K_F95		K(KT_FN,104)
+#define K_F96		K(KT_FN,105)
+#define K_F97		K(KT_FN,106)
+#define K_F98		K(KT_FN,107)
+#define K_F99		K(KT_FN,108)
+#define K_F100		K(KT_FN,109)
+#define K_F101		K(KT_FN,110)
+#define K_F102		K(KT_FN,111)
+#define K_F103		K(KT_FN,112)
+#define K_F104		K(KT_FN,113)
+#define K_F105		K(KT_FN,114)
+#define K_F106		K(KT_FN,115)
+#define K_F107		K(KT_FN,116)
+#define K_F108		K(KT_FN,117)
+#define K_F109		K(KT_FN,118)
+#define K_F110		K(KT_FN,119)
+#define K_F111		K(KT_FN,120)
+#define K_F112		K(KT_FN,121)
+#define K_F113		K(KT_FN,122)
+#define K_F114		K(KT_FN,123)
+#define K_F115		K(KT_FN,124)
+#define K_F116		K(KT_FN,125)
+#define K_F117		K(KT_FN,126)
+#define K_F118		K(KT_FN,127)
+#define K_F119		K(KT_FN,128)
+#define K_F120		K(KT_FN,129)
+#define K_F121		K(KT_FN,130)
+#define K_F122		K(KT_FN,131)
+#define K_F123		K(KT_FN,132)
+#define K_F124		K(KT_FN,133)
+#define K_F125		K(KT_FN,134)
+#define K_F126		K(KT_FN,135)
+#define K_F127		K(KT_FN,136)
+#define K_F128		K(KT_FN,137)
+#define K_F129		K(KT_FN,138)
+#define K_F130		K(KT_FN,139)
+#define K_F131		K(KT_FN,140)
+#define K_F132		K(KT_FN,141)
+#define K_F133		K(KT_FN,142)
+#define K_F134		K(KT_FN,143)
+#define K_F135		K(KT_FN,144)
+#define K_F136		K(KT_FN,145)
+#define K_F137		K(KT_FN,146)
+#define K_F138		K(KT_FN,147)
+#define K_F139		K(KT_FN,148)
+#define K_F140		K(KT_FN,149)
+#define K_F141		K(KT_FN,150)
+#define K_F142		K(KT_FN,151)
+#define K_F143		K(KT_FN,152)
+#define K_F144		K(KT_FN,153)
+#define K_F145		K(KT_FN,154)
+#define K_F146		K(KT_FN,155)
+#define K_F147		K(KT_FN,156)
+#define K_F148		K(KT_FN,157)
+#define K_F149		K(KT_FN,158)
+#define K_F150		K(KT_FN,159)
+#define K_F151		K(KT_FN,160)
+#define K_F152		K(KT_FN,161)
+#define K_F153		K(KT_FN,162)
+#define K_F154		K(KT_FN,163)
+#define K_F155		K(KT_FN,164)
+#define K_F156		K(KT_FN,165)
+#define K_F157		K(KT_FN,166)
+#define K_F158		K(KT_FN,167)
+#define K_F159		K(KT_FN,168)
+#define K_F160		K(KT_FN,169)
+#define K_F161		K(KT_FN,170)
+#define K_F162		K(KT_FN,171)
+#define K_F163		K(KT_FN,172)
+#define K_F164		K(KT_FN,173)
+#define K_F165		K(KT_FN,174)
+#define K_F166		K(KT_FN,175)
+#define K_F167		K(KT_FN,176)
+#define K_F168		K(KT_FN,177)
+#define K_F169		K(KT_FN,178)
+#define K_F170		K(KT_FN,179)
+#define K_F171		K(KT_FN,180)
+#define K_F172		K(KT_FN,181)
+#define K_F173		K(KT_FN,182)
+#define K_F174		K(KT_FN,183)
+#define K_F175		K(KT_FN,184)
+#define K_F176		K(KT_FN,185)
+#define K_F177		K(KT_FN,186)
+#define K_F178		K(KT_FN,187)
+#define K_F179		K(KT_FN,188)
+#define K_F180		K(KT_FN,189)
+#define K_F181		K(KT_FN,190)
+#define K_F182		K(KT_FN,191)
+#define K_F183		K(KT_FN,192)
+#define K_F184		K(KT_FN,193)
+#define K_F185		K(KT_FN,194)
+#define K_F186		K(KT_FN,195)
+#define K_F187		K(KT_FN,196)
+#define K_F188		K(KT_FN,197)
+#define K_F189		K(KT_FN,198)
+#define K_F190		K(KT_FN,199)
+#define K_F191		K(KT_FN,200)
+#define K_F192		K(KT_FN,201)
+#define K_F193		K(KT_FN,202)
+#define K_F194		K(KT_FN,203)
+#define K_F195		K(KT_FN,204)
+#define K_F196		K(KT_FN,205)
+#define K_F197		K(KT_FN,206)
+#define K_F198		K(KT_FN,207)
+#define K_F199		K(KT_FN,208)
+#define K_F200		K(KT_FN,209)
+#define K_F201		K(KT_FN,210)
+#define K_F202		K(KT_FN,211)
+#define K_F203		K(KT_FN,212)
+#define K_F204		K(KT_FN,213)
+#define K_F205		K(KT_FN,214)
+#define K_F206		K(KT_FN,215)
+#define K_F207		K(KT_FN,216)
+#define K_F208		K(KT_FN,217)
+#define K_F209		K(KT_FN,218)
+#define K_F210		K(KT_FN,219)
+#define K_F211		K(KT_FN,220)
+#define K_F212		K(KT_FN,221)
+#define K_F213		K(KT_FN,222)
+#define K_F214		K(KT_FN,223)
+#define K_F215		K(KT_FN,224)
+#define K_F216		K(KT_FN,225)
+#define K_F217		K(KT_FN,226)
+#define K_F218		K(KT_FN,227)
+#define K_F219		K(KT_FN,228)
+#define K_F220		K(KT_FN,229)
+#define K_F221		K(KT_FN,230)
+#define K_F222		K(KT_FN,231)
+#define K_F223		K(KT_FN,232)
+#define K_F224		K(KT_FN,233)
+#define K_F225		K(KT_FN,234)
+#define K_F226		K(KT_FN,235)
+#define K_F227		K(KT_FN,236)
+#define K_F228		K(KT_FN,237)
+#define K_F229		K(KT_FN,238)
+#define K_F230		K(KT_FN,239)
+#define K_F231		K(KT_FN,240)
+#define K_F232		K(KT_FN,241)
+#define K_F233		K(KT_FN,242)
+#define K_F234		K(KT_FN,243)
+#define K_F235		K(KT_FN,244)
+#define K_F236		K(KT_FN,245)
+#define K_F237		K(KT_FN,246)
+#define K_F238		K(KT_FN,247)
+#define K_F239		K(KT_FN,248)
+#define K_F240		K(KT_FN,249)
+#define K_F241		K(KT_FN,250)
+#define K_F242		K(KT_FN,251)
+#define K_F243		K(KT_FN,252)
+#define K_F244		K(KT_FN,253)
+#define K_F245		K(KT_FN,254)
+#define K_UNDO		K(KT_FN,255)
+
+
+#define K_HOLE		K(KT_SPEC,0)
+#define K_ENTER		K(KT_SPEC,1)
+#define K_SH_REGS	K(KT_SPEC,2)
+#define K_SH_MEM	K(KT_SPEC,3)
+#define K_SH_STAT	K(KT_SPEC,4)
+#define K_BREAK		K(KT_SPEC,5)
+#define K_CONS		K(KT_SPEC,6)
+#define K_CAPS		K(KT_SPEC,7)
+#define K_NUM		K(KT_SPEC,8)
+#define K_HOLD		K(KT_SPEC,9)
+#define K_SCROLLFORW	K(KT_SPEC,10)
+#define K_SCROLLBACK	K(KT_SPEC,11)
+#define K_BOOT		K(KT_SPEC,12)
+#define K_CAPSON	K(KT_SPEC,13)
+#define K_COMPOSE	K(KT_SPEC,14)
+#define K_SAK		K(KT_SPEC,15)
+#define K_DECRCONSOLE	K(KT_SPEC,16)
+#define K_INCRCONSOLE	K(KT_SPEC,17)
+#define K_SPAWNCONSOLE	K(KT_SPEC,18)
+#define K_BARENUMLOCK	K(KT_SPEC,19)
+
+#define K_ALLOCATED	K(KT_SPEC,126) /* dynamically allocated keymap */
+#define K_NOSUCHMAP	K(KT_SPEC,127) /* returned by KDGKBENT */
+
+#define K_P0		K(KT_PAD,0)
+#define K_P1		K(KT_PAD,1)
+#define K_P2		K(KT_PAD,2)
+#define K_P3		K(KT_PAD,3)
+#define K_P4		K(KT_PAD,4)
+#define K_P5		K(KT_PAD,5)
+#define K_P6		K(KT_PAD,6)
+#define K_P7		K(KT_PAD,7)
+#define K_P8		K(KT_PAD,8)
+#define K_P9		K(KT_PAD,9)
+#define K_PPLUS		K(KT_PAD,10)	/* key-pad plus */
+#define K_PMINUS	K(KT_PAD,11)	/* key-pad minus */
+#define K_PSTAR		K(KT_PAD,12)	/* key-pad asterisk (star) */
+#define K_PSLASH	K(KT_PAD,13)	/* key-pad slash */
+#define K_PENTER	K(KT_PAD,14)	/* key-pad enter */
+#define K_PCOMMA	K(KT_PAD,15)	/* key-pad comma: kludge... */
+#define K_PDOT		K(KT_PAD,16)	/* key-pad dot (period): kludge... */
+#define K_PPLUSMINUS	K(KT_PAD,17)	/* key-pad plus/minus */
+#define K_PPARENL	K(KT_PAD,18)	/* key-pad left parenthesis */
+#define K_PPARENR	K(KT_PAD,19)	/* key-pad right parenthesis */
+
+#define NR_PAD		20
+
+#define K_DGRAVE	K(KT_DEAD,0)
+#define K_DACUTE	K(KT_DEAD,1)
+#define K_DCIRCM	K(KT_DEAD,2)
+#define K_DTILDE	K(KT_DEAD,3)
+#define K_DDIERE	K(KT_DEAD,4)
+#define K_DCEDIL	K(KT_DEAD,5)
+
+#define NR_DEAD		6
+
+#define K_DOWN		K(KT_CUR,0)
+#define K_LEFT		K(KT_CUR,1)
+#define K_RIGHT		K(KT_CUR,2)
+#define K_UP		K(KT_CUR,3)
+
+#define K_SHIFT		K(KT_SHIFT,KG_SHIFT)
+#define K_CTRL		K(KT_SHIFT,KG_CTRL)
+#define K_ALT		K(KT_SHIFT,KG_ALT)
+#define K_ALTGR		K(KT_SHIFT,KG_ALTGR)
+#define K_SHIFTL	K(KT_SHIFT,KG_SHIFTL)
+#define K_SHIFTR	K(KT_SHIFT,KG_SHIFTR)
+#define K_CTRLL	 	K(KT_SHIFT,KG_CTRLL)
+#define K_CTRLR	 	K(KT_SHIFT,KG_CTRLR)
+#define K_CAPSSHIFT	K(KT_SHIFT,KG_CAPSSHIFT)
+
+#define K_ASC0		K(KT_ASCII,0)
+#define K_ASC1		K(KT_ASCII,1)
+#define K_ASC2		K(KT_ASCII,2)
+#define K_ASC3		K(KT_ASCII,3)
+#define K_ASC4		K(KT_ASCII,4)
+#define K_ASC5		K(KT_ASCII,5)
+#define K_ASC6		K(KT_ASCII,6)
+#define K_ASC7		K(KT_ASCII,7)
+#define K_ASC8		K(KT_ASCII,8)
+#define K_ASC9		K(KT_ASCII,9)
+#define K_HEX0		K(KT_ASCII,10)
+#define K_HEX1		K(KT_ASCII,11)
+#define K_HEX2		K(KT_ASCII,12)
+#define K_HEX3		K(KT_ASCII,13)
+#define K_HEX4		K(KT_ASCII,14)
+#define K_HEX5		K(KT_ASCII,15)
+#define K_HEX6		K(KT_ASCII,16)
+#define K_HEX7		K(KT_ASCII,17)
+#define K_HEX8		K(KT_ASCII,18)
+#define K_HEX9		K(KT_ASCII,19)
+#define K_HEXa		K(KT_ASCII,20)
+#define K_HEXb		K(KT_ASCII,21)
+#define K_HEXc		K(KT_ASCII,22)
+#define K_HEXd		K(KT_ASCII,23)
+#define K_HEXe		K(KT_ASCII,24)
+#define K_HEXf		K(KT_ASCII,25)
+
+#define NR_ASCII	26
+
+#define K_SHIFTLOCK	K(KT_LOCK,KG_SHIFT)
+#define K_CTRLLOCK	K(KT_LOCK,KG_CTRL)
+#define K_ALTLOCK	K(KT_LOCK,KG_ALT)
+#define K_ALTGRLOCK	K(KT_LOCK,KG_ALTGR)
+#define K_SHIFTLLOCK	K(KT_LOCK,KG_SHIFTL)
+#define K_SHIFTRLOCK	K(KT_LOCK,KG_SHIFTR)
+#define K_CTRLLLOCK	K(KT_LOCK,KG_CTRLL)
+#define K_CTRLRLOCK	K(KT_LOCK,KG_CTRLR)
+
+#define K_SHIFT_SLOCK	K(KT_SLOCK,KG_SHIFT)
+#define K_CTRL_SLOCK	K(KT_SLOCK,KG_CTRL)
+#define K_ALT_SLOCK	K(KT_SLOCK,KG_ALT)
+#define K_ALTGR_SLOCK	K(KT_SLOCK,KG_ALTGR)
+#define K_SHIFTL_SLOCK	K(KT_SLOCK,KG_SHIFTL)
+#define K_SHIFTR_SLOCK	K(KT_SLOCK,KG_SHIFTR)
+#define K_CTRLL_SLOCK	K(KT_SLOCK,KG_CTRLL)
+#define K_CTRLR_SLOCK	K(KT_SLOCK,KG_CTRLR)
+
+#define NR_LOCK		8
+
+#define MAX_DIACR	256
+#endif
diff -Naur svgalib-1.4.3-orig/src/libvga.h svgalib-1.4.3/src/libvga.h
--- svgalib-1.4.3-orig/src/libvga.h	2000-07-06 16:08:11.000000000 +0000
+++ svgalib-1.4.3/src/libvga.h	2005-08-26 16:56:12.000000000 +0000
@@ -284,8 +284,8 @@
 
 static __inline__ void port_outl(int value, int port)
 {
-    __asm__ volatile ("outl %0,%1"
-             ::"a" ((unsigned long)value), "d" ((unsigned short) port));
+    __asm__ volatile ("outl %0,%w1"
+             ::"a" ((unsigned int)value), "Nd" ((unsigned short) port));
 }
 
 static __inline__ int port_in(int port)
@@ -309,9 +309,9 @@
 static __inline__ int port_inl(int port)
 {
     unsigned int value;
-    __asm__ volatile("inl %1,%0" :
+    __asm__ volatile("inl %w1,%0" :
                	     "=a" (value) :
-                     "d" ((unsigned short)port));
+                     "Nd" ((unsigned short)port));
     return value;
 }
 
@@ -351,7 +351,7 @@
 
 #define zero_sa_mask(maskptr) memset(maskptr, 0, sizeof(sigset_t))
 
-#if 0
+#if __GLIBC__ >= 2
 
 #define SVGALIB_ACQUIRE_SIG SIGUSR2
 #define SVGALIB_RELEASE_SIG SIGUSR1
diff -Naur svgalib-1.4.3-orig/src/mach32.c svgalib-1.4.3/src/mach32.c
--- svgalib-1.4.3-orig/src/mach32.c	1999-09-29 16:52:14.000000000 +0000
+++ svgalib-1.4.3/src/mach32.c	2005-08-26 16:56:12.000000000 +0000
@@ -1520,9 +1520,18 @@
 	    /*  Ensure that this fopen gets a file descriptor greater
 	     *  than 2, else problems can occur with stdio functions
 	     *  under certain strange conditions:  */
-	    if (fcntl(0,F_GETFD) < 0) open("/dev/null", O_RDONLY);
-	    if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
-	    if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
+            if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1)){
+	      /* perror("/dev/null"); */
+	      exit(1);
+            }
+            if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+	      /* perror("/dev/null"); */
+	      exit(1);
+            }
+            if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+	      /* perror("/dev/null"); */
+	      exit(1);
+            }
 	    fd = fopen(eeprom_fname, "wb");
 	    if (fd == NULL) {
 	      writerr:
@@ -1544,8 +1553,8 @@
 		goto writerr;
 	    printf("mach32: Notice: new EEPROM file >%s< succesful created.\n",
 		   eeprom_fname);
-	  finish_w_eeprom:
 	}
+	finish_w_eeprom:
 	/* Change eeprom contents if requested: */
 	if (!(eeprom_option & EEPROM_USE_MEMCFG))
 	    mach32_eeprom[6] = 0;
diff -Naur svgalib-1.4.3-orig/src/mouse/mouse.c svgalib-1.4.3/src/mouse/mouse.c
--- svgalib-1.4.3-orig/src/mouse/mouse.c	2000-09-16 19:07:14.000000000 +0000
+++ svgalib-1.4.3/src/mouse/mouse.c	2005-08-26 16:56:12.000000000 +0000
@@ -7,6 +7,7 @@
 #include <vga.h>
 #include "vgamouse.h"
 #include "../libvga.h"
+#include <stdio.h>
 
 extern int mouse_open;
 
@@ -47,6 +48,13 @@
 	    currentinthandler = NULL;
 	
 	    /* Initialize mouse device. */
+	    if (m_type == MOUSE_UNCONFIGURED) {
+	      fprintf(stderr,
+		      "Warning: you have not yet configured your mouse type. If you have no mouse,\n"
+		      "setting the type to `none' in " SVGALIB_CONFIG_FILE " will get rid of this\n"
+		      "annoying message.\n");
+	      return -1;
+	    }
 	    if (m_type == MOUSE_NONE || m_type < MOUSE_MICROSOFT || m_type > MOUSE_LAST)
 		return -1;
 	    if (ms_init())
diff -Naur svgalib-1.4.3-orig/src/mouse/ms.c svgalib-1.4.3/src/mouse/ms.c
--- svgalib-1.4.3-orig/src/mouse/ms.c	2000-08-21 05:10:15.000000000 +0000
+++ svgalib-1.4.3/src/mouse/ms.c	2005-08-26 16:56:12.000000000 +0000
@@ -427,6 +427,22 @@
     if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
     if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
 
+    /*  Ensure that the open will get a file descriptor greater
+     *  than 2, else problems can occur with stdio functions
+     *  under certain strange conditions:  */
+    if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+
     /* Set the proper wheel delta */
     if(m_wheel_steps)
         m_wheel_delta = (360 / m_wheel_steps);
diff -Naur svgalib-1.4.3-orig/src/mouse/vgamouse.h svgalib-1.4.3/src/mouse/vgamouse.h
--- svgalib-1.4.3-orig/src/mouse/vgamouse.h	2000-08-21 05:10:15.000000000 +0000
+++ svgalib-1.4.3/src/mouse/vgamouse.h	2005-08-26 16:56:12.000000000 +0000
@@ -24,7 +24,8 @@
 #define MOUSE_PNP 12
 #define MOUSE_WACOM_GRAPHIRE 13
 #define MOUSE_DRMOUSE4DS 14
-#define MOUSE_LAST MOUSE_DRMOUSE4DS
+#define MOUSE_UNCONFIGURED 15
+#define MOUSE_LAST MOUSE_UNCONFIGURED
 
 #define MOUSE_ORIENTATION_VERTICAL 0
 #define MOUSE_ORIENTATION_HORIZONTAL 1
diff -Naur svgalib-1.4.3-orig/src/neo.c svgalib-1.4.3/src/neo.c
--- svgalib-1.4.3-orig/src/neo.c	2000-10-11 16:44:48.000000000 +0000
+++ svgalib-1.4.3/src/neo.c	2005-08-26 16:56:12.000000000 +0000
@@ -10,8 +10,7 @@
  --> Please do not select such modes :-)
 
 Note:
-  When use Toshiba Libretto100,110, please define "LIBRETTO100" at
-  line 19 in src/neo.c
+  When use Toshiba Libretto100,110.
   And add the following lines to libvga.config
   -------------------------------------------------------------------
    HorizSync 31.5 70
@@ -40,7 +39,6 @@
 
 #undef DEBUG
 #undef NEO_PCI_BURST
-#undef LIBRETTO100  /* Define if Toshiba Libretto100/110 */
 
 #define TRUE (1)
 #define FALSE (0)
@@ -101,6 +99,7 @@
 static void neo_unlock(void);
 static void neo_lock(void);
 
+extern unsigned char __svgalib_neolibretto100;
 static int neo_memory;
 static int NeoChipset;
 static int NeoPanelWidth, NeoPanelHeight;
@@ -954,11 +953,10 @@
 	break;
     case 0x01:
 	NeoPanelWidth  = 800;
-#ifdef LIBRETTO100
+	if (__svgalib_neolibretto100)
 	NeoPanelHeight = 480;
-#else /* LIBRETTO100 */
+        else
 	NeoPanelHeight = 600;
-#endif /* LIBRETTO100 */
 	break;
     case 0x02:
 	NeoPanelWidth  = 1024;
diff -Naur svgalib-1.4.3-orig/src/r128.c svgalib-1.4.3/src/r128.c
--- svgalib-1.4.3-orig/src/r128.c	2001-05-30 08:02:14.000000000 +0000
+++ svgalib-1.4.3/src/r128.c	2005-08-26 16:56:12.000000000 +0000
@@ -313,7 +313,7 @@
     OUTREG(R128_AMCGPIO_MASK,     restore->amcgpio_mask);
     OUTREG(R128_AMCGPIO_EN_REG,   restore->amcgpio_en_reg);
     OUTREG(R128_CLOCK_CNTL_INDEX, restore->clock_cntl_index);
-    OUTREG(R128_GEN_RESET_CNTL,   restore->gen_reset_cntl);
+//    OUTREG(R128_GEN_RESET_CNTL,   restore->gen_reset_cntl);
     OUTREG(R128_DP_DATATYPE,      restore->dp_datatype);
 
     R128RestoreCommonRegisters( restore);
@@ -443,6 +443,10 @@
     save->mem_vga_wp_sel     = 0;
     save->mem_vga_rp_sel     = 0;
     save->bus_cntl           = BusCntl;
+
+    save->config_cntl        = INREG(R128_CONFIG_CNTL);
+    save->amcgpio_en_reg   = INREG(R128_AMCGPIO_EN_REG);
+    save->amcgpio_mask     = INREG(R128_AMCGPIO_MASK);
     /*
      * If bursts are enabled, turn on discards and aborts
      */
diff -Naur svgalib-1.4.3-orig/src/s3.c svgalib-1.4.3/src/s3.c
--- svgalib-1.4.3-orig/src/s3.c	2000-05-03 12:23:57.000000000 +0000
+++ svgalib-1.4.3/src/s3.c	2005-08-26 16:56:12.000000000 +0000
@@ -474,7 +474,6 @@
 	    dac_used->restoreState(regs);
 	    return old_values;
 	}
-    default:
     }
     return 0;
 }
diff -Naur svgalib-1.4.3-orig/src/vesa.c svgalib-1.4.3/src/vesa.c
--- svgalib-1.4.3-orig/src/vesa.c	2000-10-11 16:34:45.000000000 +0000
+++ svgalib-1.4.3/src/vesa.c	2005-08-26 16:56:12.000000000 +0000
@@ -375,8 +375,6 @@
        	return 1;
     };
 
-printf("%x\n",address    );
-
     __svgalib_textprog|=1;
 
     /* Get I/O priviledge */
diff -Naur svgalib-1.4.3-orig/src/vga.c svgalib-1.4.3/src/vga.c
--- svgalib-1.4.3-orig/src/vga.c	2001-05-29 14:37:55.000000000 +0000
+++ svgalib-1.4.3/src/vga.c	2005-08-26 16:56:12.000000000 +0000
@@ -38,6 +38,7 @@
 #include "vgaregs.h"
 #include "vgaversion.h"
 
+#include <syslog.h>
 #ifdef BACKGROUND
 #include "vgabg.h"
 
@@ -305,8 +306,6 @@
     {0, 0, 0, 0, 0},
     {0, 0, 0, 0, 0},
     {0, 0, 0, 0, 0},
-    {0, 0, 0, 0, 0},
-    {0, 0, 0, 0, 0},
     {0, 0, 0, 0, 0}
 };
 
@@ -327,6 +326,7 @@
 unsigned char __svgalib_novccontrol = 0; /* this is not the main card with VC'S (not yet supported) */
 unsigned char __svgalib_simple = 0;
 unsigned char __svgalib_ragedoubleclock = 0;
+unsigned char __svgalib_neolibretto100 = 0;
 
 /* default palette values */
 static const unsigned char default_red[256]
@@ -507,10 +507,10 @@
 
 static unsigned char *graph_buf = NULL;		/* saves graphics data during flip */
 
-static unsigned char *font_buf1;	/* saved font data - plane 2 */
-static unsigned char *font_buf2;	/* saved font data - plane 3 */
-static unsigned char *text_buf1;	/* saved text data - plane 0 */
-static unsigned char *text_buf2;	/* saved text data - plane 1 */
+static unsigned char *font_buf1 = NULL;	/* saved font data - plane 2 */
+static unsigned char *font_buf2 = NULL;	/* saved font data - plane 3 */
+static unsigned char *text_buf1 = NULL;	/* saved text data - plane 0 */
+static unsigned char *text_buf2 = NULL;	/* saved text data - plane 1 */
 
 static struct termios text_termio;	/* text mode termio parameters     */
 static struct termios graph_termio;	/* graphics mode termio parameters */
@@ -843,15 +843,48 @@
     /*  Ensure that the open will get a file descriptor greater
      *  than 2, else problems can occur with stdio functions
      *  under certain strange conditions:  */
-    if (fcntl(0,F_GETFD) < 0) open("/dev/null", O_RDONLY);
-    if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
-    if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
+    if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1)){
+      /* perror("/dev/null"); */
+      exit(1);
+    }
+    if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+      /* perror("/dev/null"); */
+      exit(1);
+    }
+    if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+      /* perror("/dev/null"); */
+      exit(1);
+    }
 
-    if (__svgalib_mem_fd < 0)
+    /*
+     * we now use -1 for "not opened" and -2 for "opened and closed
+     * again", to avoid the problems with zgv where this routine is
+     * called after the descriptor has been opened and then closed again.
+     * I don't know why this happens, but we certainly don't want to
+     * re-open it and leave it lying around ...
+     *
+     * This isn't an issue for stock svgalib, which just leaves
+     * __svgalib_mem_fd set to the now-closed descriptor.  But with
+     * Debian's addition of the close-on-exec flag below, we do need to
+     * know whether we expect this to be open or not.
+     *
+     *   -- ASM 30/08/99
+     */
+
+    if (__svgalib_mem_fd == -1)
 	if ((__svgalib_mem_fd = open("/dev/mem", O_RDWR)) < 0) {
 	    printf("svgalib: Cannot open /dev/mem.\n");
 	    exit(1);
 	}
+
+    /*  Ensure this file is closed if we ever exec something else...  */
+    if (__svgalib_mem_fd >= 0) {
+      if (fcntl(__svgalib_mem_fd, F_SETFD, 1) == -1) {
+	perror("fcntl 808");
+	exit(-1);
+      }
+    }
+
 #ifdef BACKGROUND
 #if BACKGROUND == 1
 
@@ -868,6 +901,12 @@
 	          __svgalib_processnumber);
 	      exit(-1);
 	     }
+        /*  Ensure this file is closed if we ever exec something else...  */
+        if (fcntl(__svgalib_mem_fd, F_SETFD, 1) == -1)
+	    {
+            perror("fcntl 831");
+            exit(-1);
+	    }
 	}
 #endif
 #endif
@@ -904,9 +943,18 @@
 
     /*  The code below assumes file descriptors 0, 1, and 2
      *  are already open; make sure that's true.  */
-    if (fcntl(0,F_GETFD) < 0) open("/dev/null", O_RDONLY);
-    if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
-    if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
+    if ( (fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ( (fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ( (fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
 
     /*
      * Now, it would be great if we could use /dev/tty and see what it is connected to.
@@ -926,8 +974,8 @@
         return;                 /* perfect */
     }
 
-    if ((__svgalib_tty_fd = open("/dev/console", O_RDWR)) < 0) {
-        printf("svgalib: can't open /dev/console \n");
+    if ((__svgalib_tty_fd = open("/dev/tty0", O_RDWR)) < 0) {
+        printf("svgalib: can't open /dev/tty0 \n");
         exit(1);
     }
     if (ioctl(__svgalib_tty_fd, VT_OPENQRY, &svgalib_vc) < 0)
@@ -1953,8 +2001,8 @@
     };
     __vga_mmap();
 
-    if ((long) GM < 0) {
-	printf("svgalib: mmap error rrr\n");
+    if (GM == MAP_FAILED) {
+	printf("svgalib: mmap error: %s\n", strerror(errno));
 	exit(1);
     }
     /* disable video */
@@ -2473,6 +2521,12 @@
 {
     unsigned int getsize;
 
+    /* robert@debian.org, May, 26th 2002: check for valid font_buf buffer */
+    if (!font_buf1) {
+	 syslog(LOG_DEBUG, "svgalib: uninitialized variable: font_buf1");
+	 return;
+    }	 
+	    
     getsize = fontbufsize;
     if (getsize > FONT_SIZE)
 	getsize = FONT_SIZE;
@@ -2484,6 +2538,12 @@
 void vga_puttextfont(void *font)
 {
     unsigned int putsize;
+    
+    /* robert@debian.org, May, 26th 2002: check for valid font_buf buffer */
+    if (!font_buf1 || !font_buf2) {
+	 syslog(LOG_DEBUG, "svgalib: uninitialized variable: font_buf1 or font_buf2");
+	 return;
+    }	 
 
 #ifdef BACKGROUND
         if (-1 == mprotect(font_buf1,FONT_SIZE*2,PROT_READ|PROT_WRITE))
@@ -3582,14 +3642,14 @@
     "joystick0", "joystick1", "joystick2", "joystick3",
     "textprog", "vesatext", "vesasave", "secondary", "bandwidth", 
     "novccontrol", "newmode", "noprocpci", "vesatextmode", "pcistart",
-    "ragedoubleclock", "vesacputype",
+    "ragedoubleclock", "vesacputype", "neomagiclibretto100",
     NULL};
 
 static char *conf_mousenames[] =
 {
   "Microsoft", "MouseSystems", "MMSeries", "Logitech", "Busmouse", "PS2",
     "MouseMan", "gpm", "Spaceball", "none", "IntelliMouse", "IMPS2", "pnp", 
-    "WacomGraphire", "DRMOUSE4DS", NULL};
+    "WacomGraphire", "DRMOUSE4DS", "unconfigured", NULL};
 
 static int check_digit(char *ptr, char *digits)
 {
@@ -3914,7 +3974,7 @@
 
 #define ML_GETINT(x) \
 	ptr = strtok(NULL, " "); if(!ptr) break; \
-	mmt.##x = atoi(ptr);
+	mmt.x = atoi(ptr);
 
 	    ML_GETINT(HDisplay);
 	    ML_GETINT(HSyncStart);
@@ -4132,6 +4192,9 @@
         };
 #endif
         break;
+    case 67:
+        __svgalib_neolibretto100=1;
+        break;
   }
   leave:
     return strtok(NULL, " ");
@@ -4319,7 +4382,24 @@
 
 int vga_init(void)
 {
-    int retval = 0;
+    int retval = -1;
+
+    /*
+     *	Make sure we know where our stdout/stderr are going
+     *  (based on code by Kevin Vajk)
+     */
+
+    if(fcntl(0, F_GETFD)<0)
+	if(open("/dev/null", O_RDWR, 0)<0)
+    		goto bail;
+    if(fcntl(1, F_GETFD)<0)
+	if(open("/dev/null", O_RDWR, 0)<0)
+    		goto bail;
+    if(fcntl(2, F_GETFD)<0)
+	if(open("/dev/null", O_RDWR, 0)<0)
+    		goto bail;
+
+    retval = 0;
 
 #if 0
     __svgalib_open_devconsole();
@@ -4381,6 +4461,15 @@
    
     close(__svgalib_mem_fd);
 
+    /* ASM 30/08/99: Not quite sure what's going on here, but it is
+       possible to call open_mem after this FD is closed now, and this
+       breaks Debian's addition of the set-close-on-exec flag at the
+       end of open_mem if it thinks the FD is still open.  But we
+       can't set it to -1, or it will just be opened again, which is
+       presumably not the idea if it's been explicitly closed here! */
+    __svgalib_mem_fd=-2;
+   
+    if (mouse_type != MOUSE_NONE) {
 #ifdef DEBUG
 	    printf("svgalib: Opening mouse (type = %x).\n", mouse_type | mouse_modem_ctl);
 #endif
@@ -4388,9 +4477,11 @@
 		printf("svgalib: Failed to initialize mouse.\n");
 	    else
 		mouse_open = 1;
+    }
 
     /* Michael: I assume this is a misunderstanding, when svgalib was developed,
        there were no saved uids, thus setting effective uid sufficed... */
+bail:
     if ( __svgalib_security_revokeallprivs == 1 ) {
 	setuid(getuid());  
 	setgid(getgid());
diff -Naur svgalib-1.4.3-orig/src/vgabg.h svgalib-1.4.3/src/vgabg.h
--- svgalib-1.4.3-orig/src/vgabg.h	1999-07-27 16:36:19.000000000 +0000
+++ svgalib-1.4.3/src/vgabg.h	2005-08-26 16:56:12.000000000 +0000
@@ -27,7 +27,6 @@
 
 /* Linear video memory things */
 
-extern void *__svgalib_linearframebuffer;
 extern void *__svgalib_physaddr;
 extern unsigned char *__svgalib_graph_mem_linear_orginal;
 extern unsigned char *__svgalib_graph_mem_linear_check;
diff -Naur svgalib-1.4.3-orig/src/vgamisc.c svgalib-1.4.3/src/vgamisc.c
--- svgalib-1.4.3-orig/src/vgamisc.c	1999-07-27 16:36:19.000000000 +0000
+++ svgalib-1.4.3/src/vgamisc.c	2005-08-26 16:56:12.000000000 +0000
@@ -73,8 +73,7 @@
     return __svgalib_graph_mem;
 }
 
-#include <syscall.h>
-#include <linux/kernel.h>
+#include <sys/sysinfo.h>
 
 int __svgalib_physmem(void)
 {
@@ -84,7 +83,7 @@
 #else
     struct sysinfo si;
     si.totalram = 0;
-    syscall(SYS_sysinfo, &si);
+    sysinfo(&si);
     return si.totalram;
 #endif
 }
@@ -274,7 +273,7 @@
     return -1;
 }
 
-#if 1
+#if 0
 
 /*
  * The other code doesn't work under Linux/Alpha (I think
diff -Naur svgalib-1.4.3-orig/src/vgapix.c svgalib-1.4.3/src/vgapix.c
--- svgalib-1.4.3-orig/src/vgapix.c	1999-07-27 16:36:19.000000000 +0000
+++ svgalib-1.4.3/src/vgapix.c	2005-08-26 16:56:12.000000000 +0000
@@ -26,7 +26,7 @@
 /* However bswap is not supported by 386 */
 
     if (MODEFLAGS & RGB_MISORDERED)
-#ifdef __alpha__
+#if defined(__alpha__) || defined(NO_ASSEMBLY)
 	c = ((c >> 0) & 0xff) << 16 |
 	    ((c >> 8) & 0xff) << 8 |
 	    ((c >> 16) & 0xff) << 0;
diff -Naur svgalib-1.4.3-orig/utils/Makefile svgalib-1.4.3/utils/Makefile
--- svgalib-1.4.3-orig/utils/Makefile	1999-07-21 16:41:18.000000000 +0000
+++ svgalib-1.4.3/utils/Makefile	2005-08-26 16:56:12.000000000 +0000
@@ -13,9 +13,10 @@
 # Compiler Section (overrides Makefile.cfg)
 #----------------------------------------------------------------------
 
-CFLAGS = $(WARN) $(OPTIMIZE) -I../include
+CFLAGS = $(WARN) $(OPTIMIZE) -I../include -I$(srcdir)/src
 #Use the next one for the Alpha/AXP if you need it
 #LDFLAGS = -L../staticlib 
+LDFLAGS = -L$(srcdir)/sharedlib
 LIBS = -lvga -lm
 
 #----------------------------------------------------------------------
@@ -32,7 +33,6 @@
 
 .o:
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $* $*.o $(LIBS)
-	chmod 4755 $*
 
 all: $(UTILPROGS)
 .PHONY: all clean cleanbin dep
@@ -56,7 +56,7 @@
 	$(INSTALLPROG) $(UTILPROGS) $(UTILINSTALLDIR)
 
 .depend:
-	gcc -MM $(patsubst %.o,$(srcdir)/utils/%.c,$(OBJECTS)) >.depend
+	gcc -MM -I$(srcdir)/src $(patsubst %.o,$(srcdir)/utils/%.c,$(OBJECTS)) >.depend
 
 #
 # include a dependency file if one exists
diff -Naur svgalib-1.4.3-orig/utils/convfont.c svgalib-1.4.3/utils/convfont.c
--- svgalib-1.4.3-orig/utils/convfont.c	1995-09-30 14:50:30.000000000 +0000
+++ svgalib-1.4.3/utils/convfont.c	2005-08-26 16:56:12.000000000 +0000
@@ -14,7 +14,7 @@
 FILE *tf;
 
 
-void
+int
 main (int argc, char **argv)
 {
   int i;
@@ -29,23 +29,23 @@
 	       "at least defining the first 128 characters is a good idea. The fontheight\n"
 	       "should be in the range 1-32.\n"
 	);
-      exit (1);
+      return 1;
     }
   if ((sf = fopen (argv[1], "rb")) == NULL)
     {
       printf ("convfont: Unable to open file.\n");
-      exit (1);
+      return 1;
     }
   if ((tf = fopen (argv[3], "wb")) == NULL)
     {
       printf ("convfont: Unable to create file.\n");
-      exit (1);
+      return 1;
     }
   fontheight = atoi (argv[2]);
   if (fontheight < 1 || fontheight > 32)
     {
       printf ("convfont: Invalid fontheight.\n");
-      exit (1);
+      return 1;
     }
 
   fseek (sf, 0, SEEK_END);
@@ -56,7 +56,7 @@
   if (font_nuchars < 1 || font_nuchars > 256)
     {
       printf ("convfont: Invalid number of characters in font.\n");
-      exit (1);
+      return 1;
     }
   fread (sfontbuf, 1, sfontsize, sf);
   fclose (sf);
@@ -77,5 +77,5 @@
   printf ("Writing font file.\n");
   fwrite (tfontbuf, 1, 32 * 256, tf);
   fclose (tf);
-  exit (0);
+  return 0;
 }
diff -Naur svgalib-1.4.3-orig/utils/fix132x43.c svgalib-1.4.3/utils/fix132x43.c
--- svgalib-1.4.3-orig/utils/fix132x43.c	1995-09-30 14:50:30.000000000 +0000
+++ svgalib-1.4.3/utils/fix132x43.c	2005-08-26 16:56:12.000000000 +0000
@@ -54,7 +54,7 @@
 static void fixfont (int);
 
 
-void
+int
 main (int argc, char *argv[])
 {
   int vgaIOBase;
@@ -76,19 +76,19 @@
 #endif
       printf ("	-r	Switch to 8 line characters again (350 line frame, 70 Hz).\n");
       printf ("LINES environment variable is used to detect 43 or 44 line console.\n");
-      exit (0);
+      return 0;
     }
 
   if (argv[1][0] != '-')
     {
       printf ("Must specify -f, -v or -r.\n");
-      exit (1);
+      return 1;
     }
 
   if (argv[1][1] != 'f' && argv[1][1] != 'v' && argv[1][1] != 'w' && argv[1][1] != 'r')
     {
       printf ("Must specify -f, -v, or -r.\n");
-      exit (1);
+      return 1;
     }
 
   lines = atoi (getenv ("LINES"));
@@ -197,7 +197,7 @@
     }
 #endif
 
-  exit (0);
+  return 0;
 }
 
 
diff -Naur svgalib-1.4.3-orig/utils/gtf/gtfcalc.c svgalib-1.4.3/utils/gtf/gtfcalc.c
--- svgalib-1.4.3-orig/utils/gtf/gtfcalc.c	1999-07-17 12:13:02.000000000 +0000
+++ svgalib-1.4.3/utils/gtf/gtfcalc.c	2005-08-26 16:56:12.000000000 +0000
@@ -329,7 +329,7 @@
 
 #ifdef	TESTING_GTF
 
-void main(int argc,char *argv[])
+int main(int argc,char *argv[])
 {
 	FILE		*f;
 	double		xPixels,yPixels,freq;
@@ -359,7 +359,7 @@
 		printf("\n");
 		printf("GTFCALC will print a summary of the results found, and dump the CRTC\n");
 		printf("values to the UVCONFIG.CRT file in the format used by SciTech Display Doctor.\n");
-		exit(1);
+		return 1;
 		}
 
 	/* Get values from command line */
@@ -377,7 +377,7 @@
 		GTF_calcTimings(xPixels,yPixels,freq,GTF_lockPF,false,interlace,&t);
 	else {
 		printf("Unknown command line!\n");
-		exit(1);
+		return 1;
 		}
 
 	/* Dump summary info to standard output */
@@ -435,6 +435,8 @@
 		fprintf(f, "%.2f\n", t.dotClock);
 		fclose(f);
 		}
+
+	return 0;
 }
 
 #endif	/* TESTING */
diff -Naur svgalib-1.4.3-orig/utils/restorefont.c svgalib-1.4.3/utils/restorefont.c
--- svgalib-1.4.3-orig/utils/restorefont.c	1997-12-04 21:48:32.000000000 +0000
+++ svgalib-1.4.3/utils/restorefont.c	2005-08-26 16:56:12.000000000 +0000
@@ -4,6 +4,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include "../src/libvga.h"
 
 /*
  * Note: Observe that when writing the font to a file, the file to write is
@@ -11,11 +12,11 @@
  * given up). This means that there is no major security hole lurking here.
  */
 
-void main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
     FILE *f;
     unsigned char *font;
-    size_t font_size = 0x2000; /* buffer size in 1.2.11 and before */
+    size_t font_size = FONT_SIZE; /* buffer size in 1.2.11 and before */
     int can_set = 0;
     struct stat statbuf;
 
@@ -24,23 +25,23 @@
 	printf("Syntax: restorefont option filename\n");
 	printf("	-r filename	Restore VGA font from file.\n");
 	printf("	-w filename	Write current VGA font to file.\n");
-	exit(0);
+	return 0;
     }
     if (argv[1][0] != '-') {
 	printf("Must specify -r or -w.\n");
-	exit(1);
+	return 1;
     }
     switch (argv[1][1]) {
     case 'r':
     case 'w':
 	if (argc != 3) {
 	    printf("Must specify filename.\n");
-	    exit(1);
+	    return 1;
 	}
 	break;
     default:
 	printf("Invalid option. Must specify -r or -w.\n");
-	exit(1);
+	return 1;
     }
     vga_disabledriverreport();
     vga_setchipset(VGA);	/* avoid SVGA detection */
@@ -52,6 +53,9 @@
 	    can_set = 1;
 	    /* Query the preferred data size: */
 	    font_size = vga_ext_set(VGA_EXT_FONT_SIZE, 0);
+	    if (font_size < FONT_SIZE) {
+		    font_size = FONT_SIZE;
+	    }	    
 	}
     }
 
@@ -71,7 +75,7 @@
 	    perror("restorefont");
 	  ex_no_errno:
 	    vga_setmode(TEXT);
-	    exit(1);
+	    return 1;
 	}
 	if (fstat(fileno(f), &statbuf))
 	    goto error;
@@ -113,5 +117,5 @@
 	break;
     }
     vga_setmode(TEXT);
-    exit(0);
+    return 0;
 }
diff -Naur svgalib-1.4.3-orig/utils/restorepalette.c svgalib-1.4.3/utils/restorepalette.c
--- svgalib-1.4.3-orig/utils/restorepalette.c	1997-06-25 08:42:46.000000000 +0000
+++ svgalib-1.4.3/utils/restorepalette.c	2005-08-26 16:56:12.000000000 +0000
@@ -105,18 +105,22 @@
     }
 }
 
-void
+int
 main (int argc, char *argv[])
 {
   int i;
+  int chipset;
 
   vga_init ();
 
   if (argc > 1)
     process_palette_file (argv);
 
-  if (vga_getcurrentchipset () != EGA)
+  /* robert@debian.org, May 26 2002: added check for chipset != FBDEV */
+  chipset = vga_getcurrentchipset ();
+  if(chipset != EGA)
     {
+      if (chipset != FBDEV)
       /* Restore textmode/16-color mode palette */
       for (i = 0; i < 16; i++)
 	{
@@ -133,9 +137,11 @@
 	vga_setpalette (i, default_red[i], default_green[i],
 			default_blue[i]);
 
+      if (chipset != FBDEV) {
       port_in (IS1_RC);
       delay ();
       port_out (0x20, ATT_IW);	/* enable display */
+      }
     }
-  exit (0);
+  return 0;
 }
diff -Naur svgalib-1.4.3-orig/utils/restoretextmode.c svgalib-1.4.3/utils/restoretextmode.c
--- svgalib-1.4.3-orig/utils/restoretextmode.c	1996-12-17 23:12:28.000000000 +0000
+++ svgalib-1.4.3/utils/restoretextmode.c	2005-08-26 16:56:12.000000000 +0000
@@ -14,7 +14,7 @@
 
 unsigned char regs[MAX_REGS];
 
-void
+int
 main (int argc, char *argv[])
 {
   vga_init ();
@@ -24,12 +24,12 @@
       printf ("Syntax: restoretextmode option filename\n");
       printf ("	-r filename	Restore registers from file.\n");
       printf ("	-w filename	Write registers to file.\n");
-      exit (0);
+      return 0;
     }
   if (argv[1][0] != '-')
     {
       printf ("Must specify -r or -w.\n");
-      exit (1);
+      return 1;
     }
   switch (argv[1][1])
     {
@@ -38,12 +38,12 @@
       if (argc != 3)
 	{
 	  printf ("Must specify filename.\n");
-	  exit (1);
+	  return 1;
 	}
       break;
     default:
       printf ("Invalid option. Must specify -r or -w.\n");
-      exit (1);
+      return 1;
     }
   if (argv[1][1] == 'r')
     {
@@ -53,14 +53,14 @@
 	{
 	error:
 	  perror ("restoretextmode");
-	  exit (1);
+	  return 1;
 	}
       if (1 != fread (regs, MAX_REGS, 1, f))
 	{
 	  if (errno)
 	    goto error;
 	  puts ("restoretextmode: input file corrupted.");
-	  exit (1);
+	  return 1;
 	}
       fclose (f);
     }
@@ -86,5 +86,5 @@
       if (fclose (f))
 	goto error;
     }
-  exit (0);
+  return 0;
 }
diff -Naur svgalib-1.4.3-orig/utils/runx svgalib-1.4.3/utils/runx
--- svgalib-1.4.3-orig/utils/runx	1997-08-02 06:37:04.000000000 +0000
+++ svgalib-1.4.3/utils/runx	2005-08-26 16:56:12.000000000 +0000
@@ -5,8 +5,8 @@
 # running X, and 'textmode' after. This will restore the textmode registers
 # and the VGA palette in addition to the VGA font.
 
-echo Saving font in /tmp/fontdata
-restorefont -w /tmp/fontdata
+echo Saving font in $HOME/.fontdata
+restorefont -w $HOME/.fontdata
 startx
-echo Restoring font from /tmp/fontdata
-restorefont -r /tmp/fontdata
+echo Restoring font from $HOME/.fontdata
+restorefont -r $HOME/.fontdata
diff -Naur svgalib-1.4.3-orig/utils/savetextmode svgalib-1.4.3/utils/savetextmode
--- svgalib-1.4.3-orig/utils/savetextmode	1998-12-05 07:01:38.000000000 +0000
+++ svgalib-1.4.3/utils/savetextmode	2005-08-26 16:56:12.000000000 +0000
@@ -1,4 +1,14 @@
 #!/bin/sh
-rm -f /etc/vga/textregs /etc/vga/fontdata
-restoretextmode -w /etc/vga/textregs
-restorefont -w /etc/vga/fontdata
+dir=/etc/vga
+if [ ! -w "$dir" ]; then
+  dir="$HOME/.vga"
+  mkdir -p -m 700 "$dir"
+fi
+if [ -f /etc/textregs -o -f /etc/fontdata ]; then
+  echo >&2 "WARNING: the textregs and fontdata files have moved in this"
+  echo >&2 "         release from /etc to /etc/vga; please remove or rename"
+  echo >&2 "         your old versions."
+fi
+rm -f "$dir/textregs" "$dir/fontdata"
+restoretextmode -w "$dir/textregs"
+restorefont -w "$dir/fontdata"
diff -Naur svgalib-1.4.3-orig/utils/setmclk.c svgalib-1.4.3/utils/setmclk.c
--- svgalib-1.4.3-orig/utils/setmclk.c	1995-09-30 14:50:30.000000000 +0000
+++ svgalib-1.4.3/utils/setmclk.c	2005-08-26 16:56:12.000000000 +0000
@@ -41,7 +41,7 @@
 #include <vga.h>
 #include "../src/libvga.h"	/* For port I/O macros. */
 
-void
+int
 main (void)
 {
   vga_init ();
@@ -50,7 +50,7 @@
       printf ("Not a Cirrus.\n");
       printf ("Continue anyway (y/n)?\n");
       if (getchar () != 'y')
-	exit (-1);
+	return -1;
     }
 
   /* Unlock extended registers. */
@@ -84,5 +84,5 @@
   outb (0x3c5, NEW_MCLK);
   printf ("New MCLK value: %02x\n", NEW_MCLK);
 
-  exit (0);
+  return 0;
 }
diff -Naur svgalib-1.4.3-orig/utils/svgakeymap svgalib-1.4.3/utils/svgakeymap
--- svgalib-1.4.3-orig/utils/svgakeymap	1998-12-05 10:00:01.000000000 +0000
+++ svgalib-1.4.3/utils/svgakeymap	2005-08-26 16:56:12.000000000 +0000
@@ -7,16 +7,16 @@
 #   svgakeymap [physical_map [program_map]] > output.keymap
 #
 # The conversion map is output to stdout; you may wish to redirect it.
-# Keymaps are searched for in /usr/lib/kbd/keytables and are automatically
+# Keymaps are searched for in /usr/share/keymaps and are automatically
 # filtered through gzip if necessary.
 #
 # Read the file README.keymap from the svgalib distribution for more info.
 
-$ktd = "/usr/lib/kbd/keytables/";
+$ktd = "/usr/share/keymaps/";
 if(scalar(@ARGV) > 0) {
     $inmap = $ARGV[0];
 } else {
-    $inmap = "us";
+    $inmap = "i386/qwerty/us";
 }
 if(scalar(@ARGV) > 1) {
     $outmap = $ARGV[1];
@@ -34,7 +34,7 @@
 
         unless(-e $bob) {
             # Tack a .gz on it
-            $bob .= ".map";
+            $bob .= ".kmap";
             #print "$bob\n";
             
             unless(-e $bob) {
diff -Naur svgalib-1.4.3-orig/utils/textmode svgalib-1.4.3/utils/textmode
--- svgalib-1.4.3-orig/utils/textmode	1998-12-05 07:00:00.000000000 +0000
+++ svgalib-1.4.3/utils/textmode	2005-08-26 16:56:12.000000000 +0000
@@ -1,4 +1,18 @@
 #!/bin/sh
-restoretextmode -r /etc/vga/textregs
-restorefont -r /etc/vga/fontdata
+
+dir=/etc/vga
+[ -w "$dir" ] || dir="$HOME/.vga"
+
+if [ -f "$dir/textregs" -o -f "$dir/fontdata" ]; then
+  restoretextmode -r "$dir/textregs"
+  restorefont -r "$dir/fontdata"
+elif [ -f /etc/textregs -o -f /etc/fontdata ]; then
+  echo >&2 "WARNING: the textregs and fontdata files have moved in this"
+  echo >&2 "         release from /etc to /etc/vga; please remove or rename"
+  echo >&2 "         your old versions."
+  echo "Using old location for data files."
+  restoretextmode -r /etc/textregs
+  restorefont -r /etc/fontdata
+fi
+
 restorepalette
