• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * version.c --- Return the version of the ext2 library
3  *
4  * Copyright (C) 1997 Theodore Ts'o.
5  *
6  * %Begin-Header%
7  * This file may be redistributed under the terms of the GNU Library
8  * General Public License, version 2.
9  * %End-Header%
10  */
11 
12 #include "config.h"
13 #if HAVE_UNISTD_H
14 #include <unistd.h>
15 #endif
16 #include <string.h>
17 #include <stdio.h>
18 #include <ctype.h>
19 
20 #include "ext2_fs.h"
21 #include "ext2fs.h"
22 
23 #include "../../version.h"
24 
25 static const char *lib_version = E2FSPROGS_VERSION;
26 static const char *lib_date = E2FSPROGS_DATE;
27 
ext2fs_parse_version_string(const char * ver_string)28 int ext2fs_parse_version_string(const char *ver_string)
29 {
30 	const char *cp;
31 	int version = 0, dot_count = 0;
32 
33 	for (cp = ver_string; *cp; cp++) {
34 		if (*cp == '.') {
35 			if (dot_count++)
36 				break;
37 			else
38 				continue;
39 		}
40 		if (!isdigit(*cp))
41 			break;
42 		version = (version * 10) + (*cp - '0');
43 	}
44 	return version;
45 }
46 
47 
ext2fs_get_library_version(const char ** ver_string,const char ** date_string)48 int ext2fs_get_library_version(const char **ver_string,
49 			       const char **date_string)
50 {
51 	if (ver_string)
52 		*ver_string = lib_version;
53 	if (date_string)
54 		*date_string = lib_date;
55 
56 	return ext2fs_parse_version_string(lib_version);
57 }
58