Rizin
unix-like reverse engineering framework and cli tools
checkTag.c
Go to the documentation of this file.
1 /*
2  checkTag.c - Version validation tool for LZ4
3  Copyright (C) Yann Collet 2018 - present
4 
5  GPL v2 License
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 
21  You can contact the author at :
22  - LZ4 homepage : http://www.lz4.org
23  - LZ4 source repo : https://github.com/lz4/lz4
24 */
25 
26 /* checkTag command :
27  * $ ./checkTag tag
28  * checkTag validates tags of following format : v[0-9].[0-9].[0-9]{any}
29  * The tag is then compared to LZ4 version number.
30  * They are compatible if first 3 digits are identical.
31  * Anything beyond that is free, and doesn't impact validation.
32  * Example : tag v1.8.1.2 is compatible with version 1.8.1
33  * When tag and version are not compatible, program exits with error code 1.
34  * When they are compatible, it exists with a code 0.
35  * checkTag is intended to be used in automated testing environment.
36  */
37 
38 #include <stdio.h> /* printf */
39 #include <string.h> /* strlen, strncmp */
40 #include "lz4.h" /* LZ4_VERSION_STRING */
41 
42 
43 /* validate() :
44  * @return 1 if tag is compatible, 0 if not.
45  */
46 static int validate(const char* const tag)
47 {
48  size_t const tagLength = strlen(tag);
49  size_t const verLength = strlen(LZ4_VERSION_STRING);
50 
51  if (tagLength < 2) return 0;
52  if (tag[0] != 'v') return 0;
53  if (tagLength <= verLength) return 0;
54 
55  if (strncmp(LZ4_VERSION_STRING, tag+1, verLength)) return 0;
56 
57  return 1;
58 }
59 
60 int main(int argc, const char** argv)
61 {
62  const char* const exeName = argv[0];
63  const char* const tag = argv[1];
64  if (argc!=2) {
65  printf("incorrect usage : %s tag \n", exeName);
66  return 2;
67  }
68 
69  printf("Version : %s \n", LZ4_VERSION_STRING);
70  printf("Tag : %s \n", tag);
71 
72  if (validate(tag)) {
73  printf("OK : tag is compatible with lz4 version \n");
74  return 0;
75  }
76 
77  printf("!! error : tag and versions are not compatible !! \n");
78  return 1;
79 }
int main(int argc, const char **argv)
Definition: checkTag.c:60
static int validate(const char *const tag)
Definition: checkTag.c:46
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define LZ4_VERSION_STRING
Definition: lz4.h:110