##
##  rpm-4.0.2.patch.porting -- Annotated patch file
##  Copyright (c) 2000-2001 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2001 Ralf S. Engelschall <rse.com>
##
##  This file assembles changes to existing RPM source files between
##  the original RedHat RPM and the OpenPKG RPM variant. It can be
##  automatically applied to a vanilla RedHat RPM source tree with the
##  'patch' tool to upgrade those files. Each patch snippet is annotated
##  with a short description.
##
##  Created on: 23-Sep-2001
##

+---------------------------------------------------------------------------
| Replace RedHat-specific #include with general one.
| Add support for Berkeley-DB 3.2.x.
+---------------------------------------------------------------------------
Index: lib/db3.c
--- lib/db3.c	2001/02/15 00:16:09	1.1.1.3
+++ lib/db3.c	2001/06/25 14:49:03	1.2
@@ -13,7 +13,7 @@
 
 #include "system.h"
 
-#include <db3/db.h>
+#include <db.h>
 
 #include <rpmlib.h>
 #include <rpmmacro.h>
@@ -135,7 +135,7 @@
 
 	xx = db_env_create(&dbenv, 0);
 	xx = cvtdberr(dbi, "db_env_create", rc, _debug);
-#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
+#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR >= 1
 	xx = dbenv->remove(dbenv, dbhome, 0);
 #else
 	xx = dbenv->remove(dbenv, dbhome, NULL, 0);
@@ -213,7 +213,7 @@
  /* dbenv->set_tx_max(???) */
  /* dbenv->set_tx_recover(???) */
     if (dbi->dbi_no_fsync) {
-#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
+#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR >= 1
 	xx = db_env_set_func_fsync(db3_fsync_disable);
 #else
 	xx = dbenv->set_func_fsync(dbenv, db3_fsync_disable);
@@ -231,7 +231,7 @@
 #endif	/* __USE_DB3 */
 
 #if defined(__USE_DB3)
-#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
+#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR >= 1
     rc = dbenv->open(dbenv, dbhome, eflags, dbi->dbi_perms);
 #else
     rc = dbenv->open(dbenv, dbhome, NULL, eflags, dbi->dbi_perms);

+---------------------------------------------------------------------------
| Replace RedHat-specific #include with general one.
+---------------------------------------------------------------------------
Index: lib/dbconfig.c
--- lib/dbconfig.c	2001/02/14 19:49:14	1.1.1.1
+++ lib/dbconfig.c	2001/06/25 14:49:03	1.2
@@ -4,7 +4,7 @@
 
 #include "system.h"
 
-#include <db3/db.h>
+#include <db.h>
 
 #include <rpmlib.h>
 #include <rpmmacro.h>

+---------------------------------------------------------------------------
| Avoid non-portable construct: a self-referencing structure
| declaration cannot be combined with the corresponding typedef.
| Although GCC supports this (and does the correct thing), most 
| other stricter compilers complain and fail.
+---------------------------------------------------------------------------
Index: rpmio/rpmmacro.h
--- rpmio/rpmmacro.h	2000/12/11 18:41:27	1.1.1.2
+++ rpmio/rpmmacro.h	2001/06/25 19:26:59	1.2
@@ -6,14 +6,15 @@
  */
 
 /*! The structure used to store a macro. */
-typedef /*@abstract@*/ struct MacroEntry {
+struct MacroEntry {
     struct MacroEntry *prev;/*!< Macro entry stack. */
     const char *name;	/*!< Macro name. */
     const char *opts;	/*!< Macro parameters (a la getopt) */
     const char *body;	/*!< Macro body. */
     int	used;		/*!< No. of expansions. */
     int	level;		/*!< Scoping level. */
-} MacroEntry;
+};
+typedef /*@abstract@*/ struct MacroEntry MacroEntry;
 
 /*! The structure used to store the set of macros in a context. */
 typedef /*@abstract@*/ struct MacroContext {

+---------------------------------------------------------------------------
| Add support for OSF1/Tru64.
+---------------------------------------------------------------------------
Index: misc/fnmatch.h
--- misc/fnmatch.h	2000/03/10 22:02:29	1.1.1.2
+++ misc/fnmatch.h	2001/06/25 19:43:38	1.2
@@ -55,7 +55,7 @@
 #define	FNM_NOESCAPE	(1 << 1) /* Backslashes don't quote special chars.  */
 #define	FNM_PERIOD	(1 << 2) /* Leading `.' is matched only explicitly.  */
 
-#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _GNU_SOURCE
+#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _GNU_SOURCE || defined __osf__
 # define FNM_FILE_NAME	 FNM_PATHNAME	/* Preferred GNU name.  */
 # define FNM_LEADING_DIR (1 << 3)	/* Ignore `/...' after a match.  */
 # define FNM_CASEFOLD	 (1 << 4)	/* Compare without regard to case.  */

+---------------------------------------------------------------------------
| Add support for OSF1/Tru64.
+---------------------------------------------------------------------------
Index: misc/glob.h
--- misc/glob.h	2000/03/11 20:59:30	1.1.1.3
+++ misc/glob.h	2001/06/25 19:43:38	1.2
@@ -74,7 +74,7 @@
 #define	GLOB_PERIOD	(1 << 7)/* Leading `.' can be matched by metachars.  */
 
 #if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \
-     || defined _GNU_SOURCE)
+     || defined _GNU_SOURCE || defined __osf__ )
 # define GLOB_MAGCHAR	 (1 << 8)/* Set in gl_flags if any metachars seen.  */
 # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions.  */
 # define GLOB_BRACE	 (1 << 10)/* Expand "{a,b}" to "a" "b".  */

+---------------------------------------------------------------------------
| Make sure db1xxx() function references are only used if Berkeley-DB
| 1.x was really found.
+---------------------------------------------------------------------------
Index: lib/rpmdb.c
--- lib/rpmdb.c	2001/02/23 21:43:20	1.1.1.17
+++ lib/rpmdb.c	2001/06/25 19:45:29	1.2
@@ -2124,6 +2124,7 @@
     case 2:
     case 1:
     case 0:
+#if USE_DB1
 	for (i = 0; i < dbiTagsMax; i++) {
 	    const char * base = db1basename(dbiTags[i]);
 	    sprintf(filename, "%s/%s/%s", rootdir, dbpath, base);
@@ -2131,6 +2132,7 @@
 	    xx = unlink(filename);
 	    free((void *)base);
 	}
+#endif
 	break;
     }
 
@@ -2213,6 +2215,7 @@
     case 2:
     case 1:
     case 0:
+#if USE_DB1
 	for (i = 0; i < dbiTagsMax; i++) {
 	    const char * base;
 	    int rpmtag;
@@ -2240,6 +2243,7 @@
 		rc = 1;
 	    free((void *)base);
 	}
+#endif
 	break;
     }
     if (rc || _olddbapi == _newdbapi)

+---------------------------------------------------------------------------
| Add support for BSD getmntinfo(3).
+---------------------------------------------------------------------------
Index: acconfig.h
--- acconfig.h	2000/12/11 18:40:56	1.1.1.7
+++ acconfig.h	2001/07/05 11:44:10	1.2
@@ -65,6 +65,9 @@
 /* Define as 1 if you have getmntinfo_r() (only osf?) */
 #undef HAVE_GETMNTINFO_R
 
+/* Define as 1 if you have getmntinfo() */
+#undef HAVE_GETMNTINFO
+
 /* Define as 1 if you have "struct mnttab" (only sco?) */
 #undef HAVE_STRUCT_MNTTAB
 

+---------------------------------------------------------------------------
| Add support for BSD getmntinfo(3).
+---------------------------------------------------------------------------
Index: config.h.in
--- config.h.in	2001/02/21 20:47:08	1.1.1.12
+++ config.h.in	2001/07/05 11:44:10	1.11
@@ -123,6 +123,9 @@
 /* Define as 1 if you have getmntinfo_r() (only osf?) */
 #undef HAVE_GETMNTINFO_R
 
+/* Define as 1 if you have getmntinfo() */
+#undef HAVE_GETMNTINFO
+
 /* Define as 1 if you have "struct mnttab" (only sco?) */
 #undef HAVE_STRUCT_MNTTAB
 

+---------------------------------------------------------------------------
| Add support for BSD getmntinfo(3).
+---------------------------------------------------------------------------
Index: configure.in
--- configure.in	2001/02/25 17:13:26	1.1.1.17
+++ configure.in	2001/07/05 11:44:11	1.2
@@ -815,12 +815,13 @@
 AC_CHECK_FUNCS(getpassphrase)
 
 AC_CHECK_FUNC(getmntent, AC_DEFINE(HAVE_GETMNTENT), [
+ AC_CHECK_FUNC(getmntinfo, AC_DEFINE(HAVE_GETMNTINFO), [
   AC_CHECK_FUNC(mntctl, AC_DEFINE(HAVE_MNTCTL),[
     AC_CHECK_FUNC(getmntinfo_r, AC_DEFINE(HAVE_GETMNTINFO_R), [
       AC_CHECK_LIB(c_r, getmntinfo_r, [LIBS="$LIBS -lc_r"; 
 					AC_DEFINE(HAVE_GETMNTINFO_R)], [
 		 AC_DEFINE([USE_GETMNTENT], 1, [Defined if getmntent replacement is used])
-                 LIBOBJS="$LIBOBJS getmntent.o"])])])])
+                 LIBOBJS="$LIBOBJS getmntent.o"])])])])])
 
 AC_CHECK_FUNC(lchown,
    [__CHOWN_RHF="%{__chown} -Rhf"

+---------------------------------------------------------------------------
| Add support for BSD getmntinfo(3).
+---------------------------------------------------------------------------
Index: system.h
--- system.h	2000/12/11 18:40:56	1.1.1.5
+++ system.h	2001/07/05 11:44:11	1.2
@@ -325,7 +325,7 @@
 #define lchown chown
 #endif
 
-#if HAVE_GETMNTINFO_R || HAVE_MNTCTL
+#if HAVE_GETMNTINFO_R || HAVE_GETMNTINFO || HAVE_MNTCTL
 # define GETMNTENT_ONE 0
 # define GETMNTENT_TWO 0
 # if HAVE_SYS_MNTCTL_H

+---------------------------------------------------------------------------
| Add support for BSD getmntinfo(3).
+---------------------------------------------------------------------------
Index: lib/fs.c
--- lib/fs.c	2001/01/15 23:10:04	1.1.1.8
+++ lib/fs.c	2001/07/05 11:44:14	1.2
@@ -138,7 +138,7 @@
 #   if GETMNTENT_ONE || GETMNTENT_TWO
     our_mntent item;
     FILE * mtab;
-#   elif HAVE_GETMNTINFO_R
+#   elif HAVE_GETMNTINFO_R || HAVE_GETMNTINFO
     struct statfs * mounts = NULL;
     int mntCount = 0, bufSize = 0, flags = MNT_NOWAIT;
     int nextMount = 0;
@@ -155,6 +155,8 @@
 	}
 #   elif HAVE_GETMNTINFO_R
 	getmntinfo_r(&mounts, flags, &mntCount, &bufSize);
+#   elif HAVE_GETMNTINFO
+	mntCount = getmntinfo(&mounts, flags);
 #   endif
 
     filesystems = xcalloc((numAlloced + 1), sizeof(*filesystems));	/* XXX memory leak */
@@ -175,7 +177,7 @@
 	    /* Solaris, maybe others */
 	    if (getmntent(mtab, &item)) break;
 	    mntdir = item.our_mntdir;
-#	elif HAVE_GETMNTINFO_R
+#	elif HAVE_GETMNTINFO_R || HAVE_GETMNTINFO
 	    if (nextMount == mntCount) break;
 	    mntdir = mounts[nextMount++].f_mntonname;
 #	endif
+---------------------------------------------------------------------------
| Fix inconsistency in declaration.
+---------------------------------------------------------------------------
Index: rpmio/rpmio_internal.h
--- rpmio/rpmio_internal.h.orig	Fri Aug  9 22:21:42 2002
+++ rpmio/rpmio_internal.h	Fri Aug  9 22:21:42 2002
@@ -5,7 +5,7 @@
  * \file rpmio/rpmio_internal.h
  */
 
-static inline int fdFileno(void * cookie);
+inline int fdFileno(void * cookie);
 
 #include <rpmio.h>
 #include <rpmurl.h>
+---------------------------------------------------------------------------
| Fix for FreeBSD 5.0
+---------------------------------------------------------------------------
Index: misc/glob.h
--- misc/glob.h	2002/09/23 16:45:45	1.1
+++ misc/glob.h	2002/09/23 16:46:23
@@ -46,7 +46,7 @@
 #endif /* C++ or ANSI C.  */
 
 /* We need `size_t' for the following definitions.  */
-#ifndef __size_t
+#if !defined(__size_t) && !defined(_SIZE_T_DECLARED)
 # if defined __GNUC__ && __GNUC__ >= 2
 typedef __SIZE_TYPE__ __size_t;
 #  ifdef _XOPEN_SOURCE
