unzipstb.c 4.9 KB

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