Index: apt-pkg/init.cc
--- apt-pkg/init.cc.orig	2006-06-22 00:16:15 +0200
+++ apt-pkg/init.cc	2006-11-14 11:21:20 +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");
 	      
    bool Res = true;
    
Index: apt-pkg/luaiface.cc
--- apt-pkg/luaiface.cc.orig	2006-06-22 00:16:15 +0200
+++ apt-pkg/luaiface.cc	2006-11-14 11:21:20 +0100
@@ -76,7 +76,7 @@
 Lua::Lua()
       : DepCache(0), Cache(0), CacheControl(0), Fix(0), DontFix(0)
 {
-   _config->CndSet("Dir::Bin::scripts", PKGDATADIR "/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	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmhandler.h	2006-11-14 11:21:48 +0100
@@ -10,11 +10,13 @@
 #ifndef PKGLIB_RPMHANDLER_H
 #define PKGLIB_RPMHANDLER_H
 
+#include "config.h"
 #include <apt-pkg/fileutl.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xmlreader.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	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmpackagedata.cc	2006-11-14 11:21:20 +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	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmpm.cc	2006-11-14 11:21:20 +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	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmpm.h	2006-11-14 11:21:20 +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	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmrecords.h	2006-11-14 11:21:20 +0100
@@ -19,6 +19,7 @@
 #pragma interface "apt-pkg/rpmrecords.h"
 #endif 
 
+#include <rpm/glob.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/rpmhandler.h>
Index: apt-pkg/rpm/rpmsrcrecords.h
--- apt-pkg/rpm/rpmsrcrecords.h.orig	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmsrcrecords.h	2006-11-14 11:21:20 +0100
@@ -15,6 +15,7 @@
 #pragma interface "apt-pkg/rpmsrcrecords.h"
 #endif 
 
+#include <rpm/glob.h>
 #include <apt-pkg/srcrecords.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/rpmhandler.h>
Index: apt-pkg/rpm/rpmsystem.cc
--- apt-pkg/rpm/rpmsystem.cc.orig	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmsystem.cc	2006-11-14 11:21:20 +0100
@@ -137,13 +137,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");
 
@@ -244,7 +244,7 @@
    rpmReadConfigFiles(NULL, NULL);
    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	2006-06-22 00:16:14 +0200
+++ apt-pkg/rpm/rpmversion.cc	2006-11-14 11:21:20 +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	2006-06-22 00:16:15 +0200
+++ apt-pkg/sourcelist.cc	2006-11-14 11:21:20 +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	2006-06-22 00:16:19 +0200
+++ cmdline/apt-shell.cc	2006-11-14 11:21:20 +0100
@@ -3769,7 +3769,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"
@@ -3791,8 +3791,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	2006-06-22 00:16:21 +0200
+++ configure.in	2006-11-14 11:21:20 +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: configure
--- configure.orig	2006-06-22 00:16:21 +0200
+++ configure	2006-11-14 11:21:20 +0100
@@ -24222,6 +24222,12 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <netdb.h>
+#ifdef h_errno
+h_errno
+#endif
+#ifdef h_errno
+h_errno
+#endif
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
Index: lua/Makefile.in
--- lua/Makefile.in.orig	2006-06-22 00:16:09 +0200
+++ lua/Makefile.in	2006-11-14 11:21:20 +0100
@@ -248,7 +248,7 @@
 luac_luac_SOURCES = luac/luac.c luac/print.c lopcodes.c
 luac_luac_CFLAGS = -DLUA_OPNAMES
 liblua_la_CFLAGS = -DUSE_DLOPEN -DWITH_POSIX
-liblua_la_LIBADD = -lm -ldl
+liblua_la_LIBADD = -lm `if [ -f /lib/libdl.so -o -f /usr/lib/libdl.so ]; then echo 'x-ldl' | sed -e 's;^x;;'; fi`
 liblua_la_SOURCES = \
 		local/linit.c \
 		local/linit.h \
Index: lua/local/lrexlib.c
--- lua/local/lrexlib.c.orig	2006-06-22 00:16:07 +0200
+++ lua/local/lrexlib.c	2006-11-14 11:21:20 +0100
@@ -20,6 +20,7 @@
 
 #ifdef WITH_POSIX
 
+#include <sys/types.h>
 #include <regex.h>
 
 static int posix_comp(lua_State *L) {
Index: methods/gpg.cc
--- methods/gpg.cc.orig	2006-06-22 00:16:16 +0200
+++ methods/gpg.cc	2006-11-14 11:21:20 +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	2006-06-22 00:16:16 +0200
+++ methods/http.cc	2006-11-14 11:21:20 +0100
@@ -707,7 +707,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	2006-06-22 00:16:04 +0200
+++ test/scratch.cc	2006-11-14 11:21:20 +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	2006-06-22 00:16:12 +0200
+++ tools/cached_md5.cc	2006-11-14 11:21:20 +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/countpkglist.cc
--- tools/countpkglist.cc.orig	2006-06-22 00:16:12 +0200
+++ tools/countpkglist.cc	2006-11-14 11:21:20 +0100
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
-
+#include <glob.h>
 #include <rpm/rpmlib.h>
 
 int main(int argc, char *argv[])
Index: tools/genbasedir
--- tools/genbasedir.orig	2006-06-22 00:16:12 +0200
+++ tools/genbasedir	2006-11-14 11:21:20 +0100
@@ -46,7 +46,7 @@
 phashstuff()
 {
     size=`getsize $1`
-    md5=`md5sum $1|cut -f1 -d\  `
+    md5=`openssl md5 <$1`
     echo " $md5 $size $2"
 }
 
@@ -183,7 +183,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`
@@ -238,9 +238,9 @@
 	fi
 
     if test x$updateinfo = x; then
-    	(cd $basedir; genpkglist $progress $bloat $meta_opts $cacheopts --index $srcidxdir/srcidx.$comp $topdir $comp)
+    	(cd $basedir; @l_prefix@/bin/genpkglist $progress $bloat $meta_opts $cacheopts --index $srcidxdir/srcidx.$comp $topdir $comp)
     else
-    	(cd $basedir; genpkglist $progress $bloat $meta_opts $cacheopts --index $srcidxdir/srcidx.$comp --info $updateinfo $topdir $comp)
+    	(cd $basedir; @l_prefix@/bin/genpkglist $progress $bloat $meta_opts $cacheopts --index $srcidxdir/srcidx.$comp --info $updateinfo $topdir $comp)
     fi
 
     if [ -z "$meta" -a -f $basedir/pkglist.$comp ]; then
@@ -330,9 +330,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
@@ -449,14 +449,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" \
@@ -477,7 +477,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
@@ -616,6 +616,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	2006-06-22 00:16:12 +0200
+++ tools/genpkglist.cc	2006-11-14 11:21:20 +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>
@@ -386,7 +386,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	2006-06-22 00:16:12 +0200
+++ tools/gensrclist.cc	2006-11-14 11:21:20 +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>
@@ -140,6 +140,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];
