xref: /openbsd-src/gnu/usr.bin/perl/cpan/DB_File/version.c (revision 256a93a44f36679bee503f12e49566c2183f6181)
1b39c5158Smillert /*
2b39c5158Smillert 
3b39c5158Smillert  version.c -- Perl 5 interface to Berkeley DB
4b39c5158Smillert 
5*de8cc8edSafresh1  written by Paul Marquess <pmqs@cpan.org>
6b39c5158Smillert  last modified 2nd Jan 2002
7b39c5158Smillert  version 1.802
8b39c5158Smillert 
9b39c5158Smillert  All comments/suggestions/problems are welcome
10b39c5158Smillert 
11b39c5158Smillert      Copyright (c) 1995-2002 Paul Marquess. All rights reserved.
12b39c5158Smillert      This program is free software; you can redistribute it and/or
13b39c5158Smillert      modify it under the same terms as Perl itself.
14b39c5158Smillert 
15b39c5158Smillert  Changes:
16b39c5158Smillert         1.71 -  Support for Berkeley DB version 3.
17898184e3Ssthen                 Support for Berkeley DB 2/3's backward compatibility mode.
18b39c5158Smillert         1.72 -  No change.
19b39c5158Smillert         1.73 -  Added support for threading
20b39c5158Smillert         1.74 -  Added Perl core patch 7801.
21b39c5158Smillert 
22b39c5158Smillert 
23b39c5158Smillert */
24b39c5158Smillert 
25b39c5158Smillert #define PERL_NO_GET_CONTEXT
26b39c5158Smillert #include "EXTERN.h"
27b39c5158Smillert #include "perl.h"
28b39c5158Smillert #include "XSUB.h"
29b39c5158Smillert 
30b39c5158Smillert #include <db.h>
31b39c5158Smillert 
32b39c5158Smillert void
33b39c5158Smillert #ifdef CAN_PROTOTYPE
__getBerkeleyDBInfo(void)34b39c5158Smillert __getBerkeleyDBInfo(void)
35b39c5158Smillert #else
36b39c5158Smillert __getBerkeleyDBInfo()
37b39c5158Smillert #endif
38b39c5158Smillert {
39b39c5158Smillert #ifdef dTHX
40b39c5158Smillert     dTHX;
41b39c5158Smillert #endif
42b39c5158Smillert     SV * version_sv = perl_get_sv("DB_File::db_version", GV_ADD|GV_ADDMULTI) ;
43b39c5158Smillert     SV * ver_sv = perl_get_sv("DB_File::db_ver", GV_ADD|GV_ADDMULTI) ;
44b39c5158Smillert     SV * compat_sv = perl_get_sv("DB_File::db_185_compat", GV_ADD|GV_ADDMULTI) ;
45b39c5158Smillert 
46b39c5158Smillert #ifdef DB_VERSION_MAJOR
47b39c5158Smillert     int Major, Minor, Patch ;
48b39c5158Smillert 
49b39c5158Smillert     (void)db_version(&Major, &Minor, &Patch) ;
50b39c5158Smillert 
51b39c5158Smillert     /* Check that the versions of db.h and libdb.a are the same */
52b39c5158Smillert     if (Major != DB_VERSION_MAJOR || Minor != DB_VERSION_MINOR )
53b39c5158Smillert                 /* || Patch != DB_VERSION_PATCH) */
54b39c5158Smillert 
55b39c5158Smillert         croak("\nDB_File was build with libdb version %d.%d.%d,\nbut you are attempting to run it with libdb version %d.%d.%d\n",
56b39c5158Smillert                 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
57b39c5158Smillert                 Major, Minor, Patch) ;
58b39c5158Smillert 
59b39c5158Smillert     /* check that libdb is recent enough  -- we need 2.3.4 or greater */
60b39c5158Smillert     if (Major == 2 && (Minor < 3 || (Minor ==  3 && Patch < 4)))
61b39c5158Smillert         croak("DB_File needs Berkeley DB 2.3.4 or greater, you have %d.%d.%d\n",
62b39c5158Smillert                  Major, Minor, Patch) ;
63b39c5158Smillert 
64b39c5158Smillert     {
65b39c5158Smillert         char buffer[40] ;
66b39c5158Smillert         sprintf(buffer, "%d.%d", Major, Minor) ;
67b39c5158Smillert         sv_setpv(version_sv, buffer) ;
68b39c5158Smillert         sprintf(buffer, "%d.%03d%03d", Major, Minor, Patch) ;
69b39c5158Smillert         sv_setpv(ver_sv, buffer) ;
70b39c5158Smillert     }
71b39c5158Smillert 
72b39c5158Smillert #else /* ! DB_VERSION_MAJOR */
73b39c5158Smillert     sv_setiv(version_sv, 1) ;
74b39c5158Smillert     sv_setiv(ver_sv, 1) ;
75b39c5158Smillert #endif /* ! DB_VERSION_MAJOR */
76b39c5158Smillert 
77b39c5158Smillert #ifdef COMPAT185
78b39c5158Smillert     sv_setiv(compat_sv, 1) ;
79b39c5158Smillert #else /* ! COMPAT185 */
80b39c5158Smillert     sv_setiv(compat_sv, 0) ;
81b39c5158Smillert #endif /* ! COMPAT185 */
82b39c5158Smillert 
83b39c5158Smillert }
84