1 /*
2 Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
3
4 See the accompanying file LICENSE, version 2009-Jan-02 or later
5 (the contents of which are also included in unzip.h) for terms of use.
6 If, for some reason, all these files are missing, the Info-ZIP license
7 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
8 */
9 /*---------------------------------------------------------------------------
10
11 unzipstb.c
12
13 Simple stub function for UnZip DLL (or shared library, whatever); does
14 exactly the same thing as normal UnZip, except for additional printf()s
15 of various version numbers, solely as a demonstration of what can/should
16 be checked when using the DLL. (If major version numbers ever differ,
17 assume program is incompatible with DLL--especially if DLL version is
18 older. This is not likely to be a problem with *this* simple program,
19 but most user programs will be much more complex.)
20
21 ---------------------------------------------------------------------------*/
22
23 #include <stdio.h>
24 #include "unzip.h"
25 #if defined(MODERN) && !defined(NO_STDDEF_H)
26 # include <stddef.h>
27 #endif
28 #include "unzvers.h"
29
main(int argc,char * argv[])30 int main(int argc, char *argv[])
31 {
32 static ZCONST UzpVer *pVersion; /* no pervert jokes, please... */
33
34 pVersion = UzpVersion();
35
36 printf("UnZip stub: checking version numbers (DLL is dated %s)\n",
37 pVersion->date);
38 printf(" UnZip versions: expecting %u.%u%u, using %u.%u%u%s\n",
39 UZ_MAJORVER, UZ_MINORVER, UZ_PATCHLEVEL, pVersion->unzip.major,
40 pVersion->unzip.minor, pVersion->unzip.patchlevel, pVersion->betalevel);
41 printf(" ZipInfo versions: expecting %u.%u%u, using %u.%u%u\n",
42 ZI_MAJORVER, ZI_MINORVER, UZ_PATCHLEVEL, pVersion->zipinfo.major,
43 pVersion->zipinfo.minor, pVersion->zipinfo.patchlevel);
44
45 /*
46 D2_M*VER and os2dll.* are obsolete, though retained for compatibility:
47
48 printf(" OS2 DLL versions: expecting %u.%u%u, using %u.%u%u\n",
49 D2_MAJORVER, D2_MINORVER, D2_PATCHLEVEL, pVersion->os2dll.major,
50 pVersion->os2dll.minor, pVersion->os2dll.patchlevel);
51 */
52
53 if (pVersion->flag & 2)
54 printf(" using zlib version %s\n", pVersion->zlib_version);
55
56 /* This example code only uses the dll calls UzpVersion() and
57 * UzpMain(). The APIs for these two calls have maintained backward
58 * compatibility since at least the UnZip release 5.3 !
59 */
60 # define UZDLL_MINVERS_MAJOR 5
61 # define UZDLL_MINVERS_MINOR 3
62 # define UZDLL_MINVERS_PATCHLEVEL 0
63 /* This UnZip DLL stub requires a DLL version of at least: */
64 if ( (pVersion->unzip.major < UZDLL_MINVERS_MAJOR) ||
65 ((pVersion->unzip.major == UZDLL_MINVERS_MAJOR) &&
66 ((pVersion->unzip.minor < UZDLL_MINVERS_MINOR) ||
67 ((pVersion->unzip.minor == UZDLL_MINVERS_MINOR) &&
68 (pVersion->unzip.patchlevel < UZDLL_MINVERS_PATCHLEVEL)
69 )
70 )
71 ) )
72 {
73 printf(" aborting because of too old UnZip DLL version!\n");
74 return -1;
75 }
76
77 /* In case the offsetof() macro is not supported by some C compiler
78 environment, it might be replaced by something like:
79 ((extent)(void *)&(((UzpVer *)0)->dllapimin))
80 */
81 if (pVersion->structlen >=
82 #if defined(MODERN) && !defined(NO_STDDEF_H)
83 ( offsetof(UzpVer, dllapimin)
84 #else
85 ((unsigned)&(((UzpVer *)0)->dllapimin))
86 #endif
87 + sizeof(_version_type) ))
88 {
89 #ifdef OS2DLL
90 # define UZ_API_COMP_MAJOR UZ_OS2API_COMP_MAJOR
91 # define UZ_API_COMP_MINOR UZ_OS2API_COMP_MINOR
92 # define UZ_API_COMP_REVIS UZ_OS2API_COMP_REVIS
93 #else /* !OS2DLL */
94 #ifdef WINDLL
95 # define UZ_API_COMP_MAJOR UZ_WINAPI_COMP_MAJOR
96 # define UZ_API_COMP_MINOR UZ_WINAPI_COMP_MINOR
97 # define UZ_API_COMP_REVIS UZ_WINAPI_COMP_REVIS
98 #else /* !WINDLL */
99 # define UZ_API_COMP_MAJOR UZ_GENAPI_COMP_MAJOR
100 # define UZ_API_COMP_MINOR UZ_GENAPI_COMP_MINOR
101 # define UZ_API_COMP_REVIS UZ_GENAPI_COMP_REVIS
102 #endif /* ?WINDLL */
103 #endif /* ?OS2DLL */
104 printf(
105 " UnZip API version: can handle <= %u.%u%u, DLL supplies %u.%u%u\n",
106 UZ_API_COMP_MAJOR, UZ_API_COMP_MINOR, UZ_API_COMP_REVIS,
107 pVersion->dllapimin.major, pVersion->dllapimin.minor,
108 pVersion->dllapimin.patchlevel);
109 if ( (pVersion->dllapimin.major > UZ_API_COMP_MAJOR) ||
110 ((pVersion->dllapimin.major == UZ_API_COMP_MAJOR) &&
111 ((pVersion->dllapimin.minor > UZ_API_COMP_MINOR) ||
112 ((pVersion->dllapimin.minor == UZ_API_COMP_MINOR) &&
113 (pVersion->dllapimin.patchlevel > UZ_API_COMP_REVIS)
114 )
115 )
116 ) )
117 {
118 printf(" aborting because of unsupported dll api version!\n");
119 return -1;
120 }
121 }
122 printf("\n");
123
124 /* call the actual UnZip routine (string-arguments version) */
125 return UzpMain(argc, argv);
126 }
127