| 1 | /* |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 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 | |
| 11 | /* checkTag : validation tool for libzstd |
| 12 | * command : |
| 13 | * $ ./checkTag tag |
| 14 | * checkTag validates tags of following format : v[0-9].[0-9].[0-9]{any} |
| 15 | * The tag is then compared to zstd version number. |
| 16 | * They are compatible if first 3 digits are identical. |
| 17 | * Anything beyond that is free, and doesn't impact validation. |
| 18 | * Example : tag v1.8.1.2 is compatible with version 1.8.1 |
| 19 | * When tag and version are not compatible, program exits with error code 1. |
| 20 | * When they are compatible, it exists with a code 0. |
| 21 | * checkTag is intended to be used in automated testing environment. |
| 22 | */ |
| 23 | |
| 24 | #include <stdio.h> /* printf */ |
| 25 | #include <string.h> /* strlen, strncmp */ |
| 26 | #include "zstd.h" /* ZSTD_VERSION_STRING */ |
| 27 | |
| 28 | |
| 29 | /* validate() : |
| 30 | * @return 1 if tag is compatible, 0 if not. |
| 31 | */ |
| 32 | static int validate(const char* const tag) |
| 33 | { |
| 34 | size_t const tagLength = strlen(tag); |
| 35 | size_t const verLength = strlen(ZSTD_VERSION_STRING); |
| 36 | |
| 37 | if (tagLength < 2) return 0; |
| 38 | if (tag[0] != 'v') return 0; |
| 39 | if (tagLength <= verLength) return 0; |
| 40 | |
| 41 | if (strncmp(ZSTD_VERSION_STRING, tag+1, verLength)) return 0; |
| 42 | |
| 43 | return 1; |
| 44 | } |
| 45 | |
| 46 | int main(int argc, const char** argv) |
| 47 | { |
| 48 | const char* const exeName = argv[0]; |
| 49 | const char* const tag = argv[1]; |
| 50 | if (argc!=2) { |
| 51 | printf("incorrect usage : %s tag \n", exeName); |
| 52 | return 2; |
| 53 | } |
| 54 | |
| 55 | printf("Version : %s \n", ZSTD_VERSION_STRING); |
| 56 | printf("Tag : %s \n", tag); |
| 57 | |
| 58 | if (validate(tag)) { |
| 59 | printf("OK : tag is compatible with zstd version \n"); |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | printf("!! error : tag and versions are not compatible !! \n"); |
| 64 | return 1; |
| 65 | } |