blob: ab406fea2825fb4be9091e7af39568690271bab8 [file] [log] [blame]
Theodore Ts'o521e3681997-04-29 17:48:10 +00001/*
2 * version.c --- Return the version of the ext2 library
3 *
4 * Copyright (C) 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
Theodore Ts'o543547a2010-05-17 21:31:56 -04007 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
Theodore Ts'o521e3681997-04-29 17:48:10 +00009 * %End-Header%
10 */
11
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000012#if HAVE_UNISTD_H
Theodore Ts'o521e3681997-04-29 17:48:10 +000013#include <unistd.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000014#endif
Theodore Ts'o521e3681997-04-29 17:48:10 +000015#include <string.h>
16#include <stdio.h>
17#include <ctype.h>
Theodore Ts'o521e3681997-04-29 17:48:10 +000018
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000019#include "ext2_fs.h"
Theodore Ts'o521e3681997-04-29 17:48:10 +000020#include "ext2fs.h"
21
22#include "../../version.h"
23
24static const char *lib_version = E2FSPROGS_VERSION;
25static const char *lib_date = E2FSPROGS_DATE;
26
27int ext2fs_parse_version_string(const char *ver_string)
28{
29 const char *cp;
Theodore Ts'oa2df22f2007-07-08 12:37:13 -040030 int version = 0, dot_count = 0;
Theodore Ts'o521e3681997-04-29 17:48:10 +000031
Theodore Ts'o2ecc6fe1997-04-29 17:57:00 +000032 for (cp = ver_string; *cp; cp++) {
Theodore Ts'oa2df22f2007-07-08 12:37:13 -040033 if (*cp == '.') {
34 if (dot_count++)
35 break;
36 else
37 continue;
38 }
Theodore Ts'oda83cb62005-01-06 23:52:45 -050039 if (!isdigit(*cp))
40 break;
Theodore Ts'o521e3681997-04-29 17:48:10 +000041 version = (version * 10) + (*cp - '0');
42 }
43 return version;
44}
45
46
47int ext2fs_get_library_version(const char **ver_string,
48 const char **date_string)
49{
50 if (ver_string)
51 *ver_string = lib_version;
52 if (date_string)
53 *date_string = lib_date;
54
55 return ext2fs_parse_version_string(lib_version);
56}