15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * version.c --- Return the version of the ext2 library
3eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *
4eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * Copyright (C) 1997 Theodore Ts'o.
5eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *
6eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * %Begin-Header%
7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * This file may be redistributed under the terms of the GNU Library
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * General Public License, version 2.
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * %End-Header%
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if HAVE_UNISTD_H
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <unistd.h>
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string.h>
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdio.h>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <ctype.h>
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ext2_fs.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ext2fs.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "../../version.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const char *lib_version = E2FSPROGS_VERSION;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const char *lib_date = E2FSPROGS_DATE;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ext2fs_parse_version_string(const char *ver_string)
28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch{
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	const char *cp;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	int version = 0, dot_count = 0;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	for (cp = ver_string; *cp; cp++) {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		if (*cp == '.') {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			if (dot_count++)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)				break;
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch			else
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)				continue;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		if (!isdigit(*cp))
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			break;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		version = (version * 10) + (*cp - '0');
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch	}
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch	return version;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ext2fs_get_library_version(const char **ver_string,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			       const char **date_string)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	if (ver_string)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		*ver_string = lib_version;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	if (date_string)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		*date_string = lib_date;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	return ext2fs_parse_version_string(lib_version);
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)