X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fdatabase.c;h=2edbee456d4e3a933a51b8c4e5104760cfb13740;hb=049da880d371adc57bbcf9b1246db9f283763880;hp=9cf085f8d9d0df9ecbe3599767d374517b6f1ea5;hpb=98a6e4055a1fa624c592ac06f79287d55196ca37;p=chise%2Fxemacs-chise.git.1 diff --git a/src/database.c b/src/database.c index 9cf085f..2edbee4 100644 --- a/src/database.c +++ b/src/database.c @@ -43,22 +43,42 @@ Boston, MA 02111-1307, USA. */ /* glibc 2.1 doesn't have this problem with DB 2.x */ #if !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) #ifdef HAVE_INTTYPES_H +#ifndef __BIT_TYPES_DEFINED__ #define __BIT_TYPES_DEFINED__ +#endif #include +#if !HAVE_U_INT8_T typedef uint8_t u_int8_t; +#endif +#if !HAVE_U_INT16_T typedef uint16_t u_int16_t; +#endif +#if !HAVE_U_INT32_T typedef uint32_t u_int32_t; +#endif #ifdef WE_DONT_NEED_QUADS +#if !HAVE_U_INT64_T typedef uint64_t u_int64_t; +#endif #endif /* WE_DONT_NEED_QUADS */ #endif /* HAVE_INTTYPES_H */ #endif /* !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) */ +/* Berkeley DB wants __STDC__ to be defined; else if does `#define const' */ +#if ! defined (__STDC__) && ! defined(__cplusplus) +#define __STDC__ 0 +#endif #include DB_H_FILE /* Berkeley db's header file */ #ifndef DB_VERSION_MAJOR # define DB_VERSION_MAJOR 1 #endif /* DB_VERSION_MAJOR */ +#ifndef DB_VERSION_MINOR +# define DB_VERSION_MINOR 0 +#endif /* DB_VERSION_MINOR */ Lisp_Object Qberkeley_db; Lisp_Object Qhash, Qbtree, Qrecno, Qunknown; +#if DB_VERSION_MAJOR > 2 +Lisp_Object Qqueue; +#endif #endif /* HAVE_BERKELEY_DB */ #ifdef HAVE_DBM @@ -369,6 +389,9 @@ berkdb_subtype (Lisp_Database *db) case DB_BTREE: return Qbtree; case DB_HASH: return Qhash; case DB_RECNO: return Qrecno; +#if DB_VERSION_MAJOR > 2 + case DB_QUEUE: return Qqueue; +#endif default: return Qunknown; } } @@ -644,6 +667,10 @@ and defaults to 0755. real_subtype = DB_BTREE; else if (EQ (subtype, Qrecno)) real_subtype = DB_RECNO; +#if DB_VERSION_MAJOR > 2 + else if (EQ (subtype, Qqueue)) + real_subtype = DB_QUEUE; +#endif else signal_simple_error ("Unsupported subtype", subtype); @@ -669,10 +696,31 @@ and defaults to 0755. if (strchr (acc, 'r') && !strchr (acc, 'w')) accessmask |= DB_RDONLY; } +#if DB_VERSION_MAJOR == 2 status = db_open (filename, real_subtype, accessmask, modemask, NULL , NULL, &dbase); if (status) return Qnil; +#else + status = db_create (&dbase, NULL, 0); + if (status) + return Qnil; +#if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1) + status = dbase->open (dbase, filename, NULL, + real_subtype, accessmask, modemask); +#else /* DB_VERSION >= 4.1 */ + /* DB_AUTO_COMMIT requires transaction support, don't try it */ + status = dbase->open (dbase, NULL, filename, NULL, real_subtype, + accessmask, modemask); +#endif /* DB_VERSION < 4.1 */ + if (status) + { + dbase->close (dbase, 0); + return Qnil; + } +#endif /* DB_VERSION_MAJOR > 2 */ + /* Normalize into system specific file modes. Only for printing */ + accessmask = accessmask & DB_RDONLY ? O_RDONLY : O_RDWR; #endif /* DB_VERSION_MAJOR */ db = allocate_database (); @@ -744,7 +792,7 @@ If there is no corresponding value, return DEFAULT (defaults to nil). } } -DEFUN ("map-database", Fmapdatabase, 2, 2, 0, /* +DEFUN ("map-database", Fmap_database, 2, 2, 0, /* Map FUNCTION over entries in DATABASE, calling it with two args, each key and value in the database. */ @@ -771,12 +819,15 @@ syms_of_database (void) defsymbol (&Qhash, "hash"); defsymbol (&Qbtree, "btree"); defsymbol (&Qrecno, "recno"); +#if DB_VERSION_MAJOR > 2 + defsymbol (&Qqueue, "queue"); +#endif defsymbol (&Qunknown, "unknown"); #endif DEFSUBR (Fopen_database); DEFSUBR (Fdatabasep); - DEFSUBR (Fmapdatabase); + DEFSUBR (Fmap_database); DEFSUBR (Fput_database); DEFSUBR (Fget_database); DEFSUBR (Fremove_database);