checkTag.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2018-2021, Yann Collet, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. /* checkTag : validation tool for libzstd
  11. * command :
  12. * $ ./checkTag tag
  13. * checkTag validates tags of following format : v[0-9].[0-9].[0-9]{any}
  14. * The tag is then compared to zstd version number.
  15. * They are compatible if first 3 digits are identical.
  16. * Anything beyond that is free, and doesn't impact validation.
  17. * Example : tag v1.8.1.2 is compatible with version 1.8.1
  18. * When tag and version are not compatible, program exits with error code 1.
  19. * When they are compatible, it exists with a code 0.
  20. * checkTag is intended to be used in automated testing environment.
  21. */
  22. #include <stdio.h> /* printf */
  23. #include <string.h> /* strlen, strncmp */
  24. #include "zstd.h" /* ZSTD_VERSION_STRING */
  25. /* validate() :
  26. * @return 1 if tag is compatible, 0 if not.
  27. */
  28. static int validate(const char* const tag)
  29. {
  30. size_t const tagLength = strlen(tag);
  31. size_t const verLength = strlen(ZSTD_VERSION_STRING);
  32. if (tagLength < 2) return 0;
  33. if (tag[0] != 'v') return 0;
  34. if (tagLength <= verLength) return 0;
  35. if (strncmp(ZSTD_VERSION_STRING, tag+1, verLength)) return 0;
  36. return 1;
  37. }
  38. int main(int argc, const char** argv)
  39. {
  40. const char* const exeName = argv[0];
  41. const char* const tag = argv[1];
  42. if (argc!=2) {
  43. printf("incorrect usage : %s tag \n", exeName);
  44. return 2;
  45. }
  46. printf("Version : %s \n", ZSTD_VERSION_STRING);
  47. printf("Tag : %s \n", tag);
  48. if (validate(tag)) {
  49. printf("OK : tag is compatible with zstd version \n");
  50. return 0;
  51. }
  52. printf("!! error : tag and versions are not compatible !! \n");
  53. return 1;
  54. }