Index: apt-pkg/deb/debsystem.cc
--- apt-pkg/deb/debsystem.cc.orig	2003-12-23 21:18:33.000000000 +0100
+++ apt-pkg/deb/debsystem.cc	2004-01-24 20:20:12.000000000 +0100
@@ -162,7 +162,7 @@
       be the only users of these */
    Cnf.CndSet("Dir::State::userstatus","status.user"); // Defunct
    Cnf.CndSet("Dir::State::status","/var/lib/dpkg/status");
-   Cnf.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
+   Cnf.CndSet("Dir::Bin::dpkg","@l_prefix@/bin/dpkg");
    
    return true;
 }
@@ -187,7 +187,7 @@
    signed Score = 0;
    if (FileExists(Cnf.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
        Score += 10;
-   if (FileExists(Cnf.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
+   if (FileExists(Cnf.FindFile("Dir::Bin::dpkg","@l_prefix@/bin/dpkg")) == true)
       Score += 10;
    if (FileExists("/etc/debian_version") == true)
       Score += 10;
Index: apt-pkg/init.cc
--- apt-pkg/init.cc.orig	2003-12-23 21:18:15.000000000 +0100
+++ apt-pkg/init.cc	2004-01-24 20:20:12.000000000 +0100
@@ -45,10 +45,10 @@
       Cnf.Set("APT::Architecture",COMMON_OS "-" COMMON_CPU);
    // CNC:2002-09-10
    //Cnf.Set("APT::Build-Essential::", "build-essential");
-   Cnf.Set("Dir","/");
+   Cnf.Set("Dir","@l_prefix@");
    
    // State   
-   Cnf.Set("Dir::State","var/lib/apt/");
+   Cnf.Set("Dir::State","var/apt/lib/");
    
    /* Just in case something goes horribly wrong, we can fall back to the
       old /var/state paths.. */
@@ -61,7 +61,7 @@
    Cnf.Set("Dir::State::cdroms","cdroms.list");
    
    // Cache
-   Cnf.Set("Dir::Cache","var/cache/apt/");
+   Cnf.Set("Dir::Cache","var/apt/cache/");
    Cnf.Set("Dir::Cache::archives","archives/");
    Cnf.Set("Dir::Cache::srcpkgcache","srcpkgcache.bin");
    Cnf.Set("Dir::Cache::pkgcache","pkgcache.bin");
@@ -76,7 +76,7 @@
    Cnf.Set("Dir::Etc::main","apt.conf");
    Cnf.Set("Dir::Etc::parts","apt.conf.d");
    Cnf.Set("Dir::Etc::preferences","preferences");
-   Cnf.Set("Dir::Bin::methods",LIBDIR "/apt/methods");
+   Cnf.Set("Dir::Bin::methods","@l_prefix@/lib/apt/methods");
    Cnf.Set("Acquire::ComprExtension", ".bz2");
 	      
    bool Res = true;
Index: apt-pkg/luaiface.cc
--- apt-pkg/luaiface.cc.orig	2003-12-23 21:19:11.000000000 +0100
+++ apt-pkg/luaiface.cc	2004-01-24 20:20:12.000000000 +0100
@@ -81,7 +81,7 @@
 Lua::Lua()
       : DepCache(0), Cache(0), CacheControl(0), Fix(0), DontFix(0)
 {
-   _config->CndSet("Dir::Bin::scripts", "/usr/lib/apt/scripts");
+   _config->CndSet("Dir::Bin::scripts", "@l_prefix@/lib/apt/scripts");
 
    const luaL_reg lualibs[] = {
       {"base", luaopen_base},
Index: apt-pkg/rpm/rpmhandler.h
--- apt-pkg/rpm/rpmhandler.h.orig	2003-12-23 21:19:27.000000000 +0100
+++ apt-pkg/rpm/rpmhandler.h	2004-01-24 20:20:12.000000000 +0100
@@ -12,6 +12,7 @@
 
 #include <apt-pkg/fileutl.h>
 
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 #include <rpm/rpmmacro.h>
 
Index: apt-pkg/rpm/rpmpackagedata.cc
--- apt-pkg/rpm/rpmpackagedata.cc.orig	2003-12-23 21:19:36.000000000 +0100
+++ apt-pkg/rpm/rpmpackagedata.cc	2004-01-24 20:20:12.000000000 +0100
@@ -12,6 +12,7 @@
 
 #include <apti18n.h>
 
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 
 RPMPackageData::RPMPackageData()
Index: apt-pkg/rpm/rpmpm.cc
--- apt-pkg/rpm/rpmpm.cc.orig	2003-12-23 21:19:20.000000000 +0100
+++ apt-pkg/rpm/rpmpm.cc	2004-01-24 20:20:12.000000000 +0100
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <iostream>
 
+#include <rpm/glob.h>
 #if RPM_VERSION >= 0x040100
 #include <rpm/rpmdb.h>
 #define packagesTotal rpmcliPackagesTotal 
Index: apt-pkg/rpm/rpmpm.h
--- apt-pkg/rpm/rpmpm.h.orig	2003-12-23 21:19:23.000000000 +0100
+++ apt-pkg/rpm/rpmpm.h	2004-01-24 20:20:12.000000000 +0100
@@ -11,6 +11,7 @@
 #ifndef PKGLIB_rpmPM_H
 #define PKGLIB_rpmPM_H
 
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 #if RPM_VERSION >= 0x040100
 #include <rpm/rpmts.h>
Index: apt-pkg/rpm/rpmrecords.h
--- apt-pkg/rpm/rpmrecords.h.orig	2003-12-23 21:19:51.000000000 +0100
+++ apt-pkg/rpm/rpmrecords.h	2004-01-24 20:20:12.000000000 +0100
@@ -21,6 +21,7 @@
 
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/fileutl.h>
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 
   
Index: apt-pkg/rpm/rpmsrcrecords.h
--- apt-pkg/rpm/rpmsrcrecords.h.orig	2003-12-23 21:20:01.000000000 +0100
+++ apt-pkg/rpm/rpmsrcrecords.h	2004-01-24 20:20:12.000000000 +0100
@@ -17,6 +17,7 @@
 
 #include <apt-pkg/srcrecords.h>
 #include <apt-pkg/fileutl.h>
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 
   
Index: apt-pkg/rpm/rpmsystem.cc
--- apt-pkg/rpm/rpmsystem.cc.orig	2003-12-23 21:19:32.000000000 +0100
+++ apt-pkg/rpm/rpmsystem.cc	2004-01-24 20:20:12.000000000 +0100
@@ -126,13 +126,13 @@
 /* These are the rpm specific configuration variables.. */
 bool rpmSystem::Initialize(Configuration &Cnf)
 {
-   Cnf.CndSet("Dir::Bin::rpm","/bin/rpm");
+   Cnf.CndSet("Dir::Bin::rpm","@l_prefix@/bin/rpm");
    Cnf.CndSet("Dir::Etc::rpmpriorities", "rpmpriorities");
    Cnf.CndSet("Dir::Etc::translatelist", "translate.list");
    Cnf.CndSet("Dir::Etc::translateparts", "translate.list.d");
    Cnf.CndSet("Dir::State::prefetch", "prefetch");
-   Cnf.CndSet("Dir::Locale","/usr/share/locale");
-   Cnf.CndSet("Acquire::DistroID","Conectiva"); // hee hee
+   Cnf.CndSet("Dir::Locale","@l_prefix@/share/locale");
+   Cnf.CndSet("Acquire::DistroID","OpenPKG");
    Cnf.CndSet("Acquire::CDROM::Mount", "/mnt/cdrom");
    Cnf.CndSet("Acquire::CDROM::Copy-All", "true");
 
@@ -229,7 +229,7 @@
 
    if (FileExists(RPMDBHandler::DataPath(false)))
       Score += 10;
-   if (FileExists(Cnf.FindFile("Dir::Bin::rpm","/bin/rpm")) == true)
+   if (FileExists(Cnf.FindFile("Dir::Bin::rpm","@l_prefix@/bin/rpm")) == true)
       Score += 10;
 
    return Score;
Index: apt-pkg/rpm/rpmversion.cc
--- apt-pkg/rpm/rpmversion.cc.orig	2003-12-23 21:19:34.000000000 +0100
+++ apt-pkg/rpm/rpmversion.cc	2004-01-24 20:20:12.000000000 +0100
@@ -22,6 +22,7 @@
 #include <apt-pkg/rpmversion.h>
 #include <apt-pkg/pkgcache.h>
 
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 #include <rpm/misc.h>
 
Index: apt-pkg/sourcelist.cc
--- apt-pkg/sourcelist.cc.orig	2003-12-23 21:17:28.000000000 +0100
+++ apt-pkg/sourcelist.cc	2004-01-24 20:20:12.000000000 +0100
@@ -105,7 +105,7 @@
    // Check for an absolute dists specification.
    if (Dist.empty() == false && Dist[Dist.size() - 1] == '/')
    {
-      if (ParseQuoteWord(Buffer,Section) == true)
+      if (ParseQuoteWord(Buffer,Section) == false)
 	 return _error->Error(_("Malformed line %lu in source list %s (Absolute dist)"),CurLine,File.c_str());
       Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture"));
       return CreateItem(List,URI,Dist,Section,Vendor);
Index: cmdline/apt-shell.cc
--- cmdline/apt-shell.cc.orig	2003-12-23 21:31:46.000000000 +0100
+++ cmdline/apt-shell.cc	2004-01-24 20:20:12.000000000 +0100
@@ -3672,7 +3672,7 @@
       "   remove - Remove packages\n"
       "   keep - Keep packages\n"
       "   upgrade - Perform a global upgrade\n"
-      "   dist-upgrade - Perform a globla distribution upgrade\n"
+      "   dist-upgrade - Perform a global distribution upgrade\n"
       "   build-dep - Install build-dependencies for source packages\n"
 //      "   dselect-upgrade - Follow dselect selections\n"
       "   update - Retrieve new lists of packages\n"
@@ -3694,8 +3694,7 @@
       "   autoclean - Erase old downloaded archive files\n"
       "\n"
       "For more information type \"help <cmd>\" or \"<cmd> [-h|--help]\".\n"
-      "\n"
-      "                       This APT has Super Cow Powers.\n");
+      );
    return true;
 }
 
Index: configure.in
--- configure.in.orig	2003-12-23 21:15:40.000000000 +0100
+++ configure.in	2004-01-24 20:21:50.000000000 +0100
@@ -47,7 +47,7 @@
 
    dnl Check for RPM version
    AC_MSG_CHECKING(for RPM version)
-   RPM_VERSION_RAW=`LANG= LC_ALL= $RPM_PATH --version | sed 's/^RPM version //'`
+   RPM_VERSION_RAW=`LANG= LC_ALL= $RPM_PATH --version | sed 's/^OpenPKG RPM //'`
    RPM_VERSION_MAJOR=`echo $RPM_VERSION_RAW | cut -d. -f1`
    RPM_VERSION_MINOR=`echo $RPM_VERSION_RAW | cut -d. -f2`
    RPM_VERSION_MICRO=`echo $RPM_VERSION_RAW | cut -d. -f3`
@@ -68,9 +68,9 @@
 
    dnl Check for RPM libraries and headers
 
-   AC_CHECK_LIB(bz2,BZ2_bzopen, [],
+   AC_CHECK_LIB(rpmbz2,BZ2_bzopen, [],
 		[AC_MSG_ERROR([Can't find libbz2 library])])
-   AC_CHECK_LIB(z,gzopen, [],
+   AC_CHECK_LIB(rpmz,gzopen, [],
 		[AC_MSG_ERROR([Can't find libz library])])
    AC_CHECK_HEADERS(db1/db.h)
 
@@ -79,13 +79,13 @@
 		   [AC_MSG_ERROR([Can't find rpmlib.h])])
 
    if test $RPM_VERSION_MAJOR -lt 4; then
-      RPMLIBS="-lrpm -lz -lbz2 -lpopt"
+      RPMLIBS="@l_rpmlibs_base@ @l_rpmlibs_extra@"
    else
       AC_CHECK_LIB(rpmdb,rpmdbOpen,
-         [RPMDBLIBS="-lrpmdb"],
+         [RPMDBLIBS="@l_rpmlibs_base@"],
          [RPMDBLIBS="-ldb-3.1"],
-         [-lrpm -lrpmio -lz -lbz2 -lpopt])
-      RPMLIBS="-lrpm $RPMDBLIBS -lrpmio -lz -lbz2 -lpopt"
+         [@l_rpmlibs_base@ @l_rpmlibs_extra@])
+      RPMLIBS="@l_rpmlibs_base@ $RPMDBLIBS @l_rpmlibs_extra@"
    fi
    AC_MSG_CHECKING(for RPM libraries)
    AC_MSG_RESULT($RPMLIBS)
Index: lua/Makefile.in
--- lua/Makefile.in.orig	2003-12-23 21:13:37.000000000 +0100
+++ lua/Makefile.in	2004-01-24 20:20:12.000000000 +0100
@@ -192,7 +192,7 @@
 luac_luac_CFLAGS = -DLUA_OPNAMES
 
 liblua_la_CFLAGS = -DUSE_DLOPEN -DWITH_POSIX
-liblua_la_LIBADD = -lm -ldl
+liblua_la_LIBADD = -lm
 liblua_la_SOURCES = \
 		local/linit.c \
 		local/linit.h \
Index: lua/local/lrexlib.c
--- lua/local/lrexlib.c.orig	2003-12-23 21:13:42.000000000 +0100
+++ lua/local/lrexlib.c	2004-01-24 20:20:12.000000000 +0100
@@ -20,6 +20,7 @@
 
 #ifdef WITH_POSIX
 
+#include <sys/types.h>
 #include <regex.h>
 
 static int rex_comp(lua_State *L) {
Index: methods/gpg.cc
--- methods/gpg.cc.orig	2003-12-23 21:24:04.000000000 +0100
+++ methods/gpg.cc	2004-01-24 20:20:12.000000000 +0100
@@ -10,6 +10,11 @@
 #include <stdio.h>
 #include <sys/wait.h>
 
+#ifdef OPENPKG_SOLARIS
+#include <sys/syscall.h>
+#include <sys/systm.h>
+#endif
+
 #include <apti18n.h>
 
 class GPGMethod : public pkgAcqMethod
@@ -173,7 +178,81 @@
 }
 #undef STRCMP
 
+#ifdef OPENPKG_SOLARIS
+
+static const char letters[] =
+"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+
+static int gen_tempname (char *tmpl)
+{
+    int len;
+    char *XXXXXX;
+    static uint64_t value;
+    uint64_t random_time_bits;
+    int count, fd = -1;
+    int save_errno = errno;
+
+    len = strlen(tmpl);
+    if ( len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) {
+        __set_errno(EINVAL);
+        return -1;
+    }
+
+    XXXXXX = &tmpl[len - 6];
+    random_time_bits = time(NULL);
+    value += random_time_bits ^ getpid();
+
+    for ( count = 0; count < TMP_MAX; value += 7777, ++count) {
+        uint64_t v = value;
+        XXXXXX[0] = letters[v % 62];
+        v /= 62;
+        XXXXXX[1] = letters[v % 62];
+        v /= 62;
+        XXXXXX[2] = letters[v % 62];
+        v /= 62;
+        XXXXXX[3] = letters[v % 62];
+        v /= 62;
+        XXXXXX[4] = letters[v % 62];
+        v /= 62;
+        XXXXXX[5] = letters[v % 62];
+
+        fd = mkdir(tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
+
+        if ( fd > 0 ) {
+            __set_errno(save_errno);
+            return fd;
+        }
+        else if ( errno != EEXIST ) {
+            return -1;
+        }
+
+    }
+
+    __set_errno(EEXIST);
+    return -1;
+}
+
+static char *mkdtemp(char *templat) 
+{
+    if (gen_tempname (templat))
+        return NULL;
+    else
+        return templat;
+}
+
+static void unsetenv(char *varname)
+{
+    char *tempstr = (char *)malloc(strlen(varname) + 2);
+    if ( tempstr == (char *)NULL ) {
+        return;
+    }
+    sprintf(tempstr, "%s=", varname);
+    tempstr[strlen(varname) + 1] = '\0';
+    putenv(tempstr);
+    free(tempstr);
+}
 
+#endif /* OPENPKG_SOLARIS */
 
 char *getFileSigner(const char *file, const char *sigfile,
 		    const char *outfile, string &signerKeyID)
Index: methods/http.cc
--- methods/http.cc.orig	2003-12-23 21:24:14.000000000 +0100
+++ methods/http.cc	2004-01-24 20:20:12.000000000 +0100
@@ -680,7 +680,7 @@
    // CNC:2003-01-29
    string UserAgent = _config->Find("Acquire::http::User-Agent");
    if (UserAgent.empty() == true) 
-	  UserAgent = "RPM APT-HTTP/1.3";
+	  UserAgent = "OpenPKG RPM APT-HTTP/1.3";
    Req += string("User-Agent: ") + UserAgent + "\r\n\r\n";
    
    if (Debug == true)
Index: test/scratch.cc
--- test/scratch.cc.orig	2003-12-23 21:13:20.000000000 +0100
+++ test/scratch.cc	2004-01-24 20:20:12.000000000 +0100
@@ -51,7 +51,7 @@
    
 /*   Db.GetFLCache().BeginDiverLoad();
    pkgFLCache::PkgIterator Pkg(Db.GetFLCache(),0);
-   if (Db.GetFLCache().AddDiversion(Pkg,"/usr/include/linux/kerneld.h","/usr/bin/nslookup") == false)
+   if (Db.GetFLCache().AddDiversion(Pkg,"/usr/include/linux/kerneld.h","@l_prefix@/bin/nslookup") == false)
       cerr << "Error!" << endl;
 
    const char *Tmp = "/usr/include/linux/kerneld.h";
Index: tools/cached_md5.cc
--- tools/cached_md5.cc.orig	2003-12-23 21:16:37.000000000 +0100
+++ tools/cached_md5.cc	2004-01-24 20:20:12.000000000 +0100
@@ -1,11 +1,11 @@
 /*
  * $Id: cached_md5.cc,v 1.4 2003/01/29 13:47:31 niemeyer Exp $
  */
-#include <alloca.h>
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 #include <stdlib.h>
 #include <string.h>
Index: tools/genbasedir
--- tools/genbasedir.orig	2003-12-23 21:16:47.000000000 +0100
+++ tools/genbasedir	2004-01-24 20:20:12.000000000 +0100
@@ -43,7 +43,7 @@
 phashstuff()
 {
     size=`getsize $1`
-    md5=`md5sum $1|cut -f1 -d\  `
+    md5=`openssl md5 <$1`
     echo " $md5 $size $2"
 }
 
@@ -171,7 +171,7 @@
 	rm -f $comps; touch $comps
 	for dir in $topdir/RPMS.* $topdir/SRPMS.* $topdir/../SRPMS.*; do
 		if [ -d $dir ]; then
-			echo $dir | sed 's/.*\.//' >> $comps
+			echo $dir | sed 's/.*RPMS\.//' >> $comps
 		fi
 	done
 	components=`cat $comps|sort|uniq`
@@ -226,9 +226,9 @@
 	fi
 
     if test x$updateinfo = x; then
-    	(cd $basedir; genpkglist $progress $bloat $meta_opts --index $srcidxdir/srcidx.$comp $topdir $comp)
+    	(cd $basedir; @l_prefix@/bin/genpkglist $progress $bloat $meta_opts --index $srcidxdir/srcidx.$comp $topdir $comp)
     else
-    	(cd $basedir; genpkglist $progress $bloat $meta_opts --index $srcidxdir/srcidx.$comp --info $updateinfo $topdir $comp)
+    	(cd $basedir; @l_prefix@/bin/genpkglist $progress $bloat $meta_opts --index $srcidxdir/srcidx.$comp --info $updateinfo $topdir $comp)
     fi
 
     if [ -z "$meta" -a -f $basedir/pkglist.$comp ]; then
@@ -318,9 +318,9 @@
     fi
 
     if [ $mapi -ne 0 ]; then
-        (cd $basedir; gensrclist $progress $flat $meta_opts --mapi $srctopdir $comp $srcidxdir/srcidx.$comp)
+        (cd $basedir; @l_prefix@/bin/gensrclist $progress $flat $meta_opts --mapi $srctopdir $comp $srcidxdir/srcidx.$comp)
     else
-        (cd $basedir; gensrclist $progress $flat $meta_opts $srctopdir $comp $srcidxdir/srcidx)
+        (cd $basedir; @l_prefix@/bin/gensrclist $progress $flat $meta_opts $srctopdir $comp $srcidxdir/srcidx)
     fi
 
     if [ -z "$meta" -a -f $basedir/srclist.$comp ]; then
@@ -424,14 +424,14 @@
 		if [ $partial -eq 0 ]; then
 			echo -n "Updating global release file... "
 			sed -n -e "/^MD5Sum:/q" \
-				   -e "s/^Date:.*\$/Date: `date -R`/" \
+				   -e "s/^Date:.*\$/Date: `date '+%a, %d %b %Y %H:%M:%S %z' | sed -e 's/%z/+0000/'`/" \
 				   -e "s/^Components:.*\$/Components: $components/" \
 				   -e "p" $release.old > $release
 			echo "MD5Sum:" >> $release
 		else
 			echo -n "Partially updating global release file... "
 			sed -n -e "/^\$/q" \
-				   -e "s/^Date:.*\$/Date: `date -R`/" \
+				   -e "s/^Date:.*\$/Date: `date '+%a, %d %b %Y %H:%M:%S %z' | sed -e 's/%z/+0000/'`/" \
 				   -e "p" $release.old > $release.pre
 			for comp in $components; do
 				sed -e "\#^ .* $pkglist_.$comp\(.bz2\)\?\$#d" \
@@ -452,7 +452,7 @@
 		echo "Label: Unknown"             >> $release
 		echo "Suite: Unknown"             >> $release
 		echo "Codename: Unknown"          >> $release
-		echo "Date: `date -R`"            >> $release
+		echo "Date: `date '+%a, %d %b %Y %H:%M:%S %z' | sed -e 's/%z/+0000/'`"            >> $release
 		echo "Architectures: Unknown"     >> $release
 		echo "Components: $components"    >> $release
 		echo "Description: Not available" >> $release
@@ -591,6 +591,4 @@
 	rm -f $basedir/hashfile.gpg.old
 fi
 
-echo "All your base are belong to us!!!"
-
 # vim:ts=4:sw=4
Index: tools/genpkglist.cc
--- tools/genpkglist.cc.orig	2003-12-23 21:16:54.000000000 +0100
+++ tools/genpkglist.cc	2004-01-24 20:20:12.000000000 +0100
@@ -1,11 +1,11 @@
 /*
  * $Id: genpkglist.cc,v 1.7 2003/01/30 17:18:21 niemeyer Exp $
  */
-#include <alloca.h>
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 #include <stdlib.h>
 #include <string.h>
@@ -369,7 +369,7 @@
 }
 
 int scandir(const char * dir, struct dirent *** namelist, 
-        int (* select)(struct dirent *), 
+        int (* select)(const struct dirent *), 
         int (* cmp)(const void *, const void *))
 
 {
Index: tools/gensrclist.cc
--- tools/gensrclist.cc.orig	2003-12-23 21:16:39.000000000 +0100
+++ tools/gensrclist.cc	2004-01-24 20:20:12.000000000 +0100
@@ -1,11 +1,11 @@
 /*
  * $Id: gensrclist.cc,v 1.8 2003/01/30 17:18:21 niemeyer Exp $
  */
-#include <alloca.h>
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <rpm/glob.h>
 #include <rpm/rpmlib.h>
 #include <stdlib.h>
 #include <string.h>
@@ -134,6 +134,89 @@
 }
 #endif
 
+#ifndef HAVE_SCANDIR
+// from glibc 1.09.1  mod'd by jmik, ins'd by asm, fix'd by sbi
+int alphasort(const void * a, const void * b)
+{
+  return strcmp ((*(struct dirent **) a)->d_name,
+                 (*(struct dirent **) b)->d_name);
+}
+
+int scandir(const char * dir, struct dirent *** namelist, 
+        int (* select)(const struct dirent *), 
+        int (* cmp)(const void *, const void *))
+
+{
+  DIR *dp = opendir (dir);
+  struct dirent **v = NULL;
+  size_t vsize = 0, i;
+  struct dirent *d;
+  int save;
+
+  if (dp == NULL)
+    return -1;
+
+  save = errno;
+  errno = 0;
+
+  i = 0;
+  while ((d = readdir (dp)) != NULL)
+    {
+    if (select == NULL || (*select) (d))
+      {
+        if (i == vsize)
+          {
+            struct dirent **newv;
+            if (vsize == 0)
+              vsize = 10;
+            else
+              vsize *= 2;
+            newv = (struct dirent **) realloc (v, vsize * sizeof (*v));
+            if (newv == NULL)
+              {
+              lose:
+                errno = ENOMEM;
+                break;
+              }
+            v = newv;
+          }
+
+        v[i] = (struct dirent *) malloc (d->d_reclen);
+        if (v[i] == NULL)
+          goto lose;
+
+        // *v[i++] = *d;
+	memcpy(v[i], d, d->d_reclen);
+	i++;
+      }
+    }
+
+  v[i] = NULL;
+
+  if (errno != 0)
+    {
+      save = errno;
+      (void) closedir (dp);
+      while (i > 0)
+        free (v[--i]);
+      free (v);
+      errno = save;
+      return -1;
+    }
+
+  (void) closedir (dp);
+  errno = save;
+
+  /* Sort the list if we have a comparison function to sort with.  */
+  if (cmp != NULL)
+    qsort (v, i, sizeof (struct dirent *), cmp);
+
+  *namelist = v;
+  return i;
+}
+// end of new stuff from glibc
+#endif
+
 int main(int argc, char ** argv) 
 {
    char buf[300];
