version.c revision d1154eb460efe588eaed3d439c1caaca149fa362
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * version.c --- Return the version of the blkid library
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright (C) 2004 Theodore Ts'o.
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * %Begin-Header%
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * This file may be redistributed under the terms of the GNU Public
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * %End-Header%
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry */
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "config.h"
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if HAVE_UNISTD_H
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <unistd.h>
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string.h>
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <stdio.h>
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <ctype.h>
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <blkid/blkid.h>
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "../../version.h"
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char *lib_version = E2FSPROGS_VERSION;
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char *lib_date = E2FSPROGS_DATE;
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint blkid_parse_version_string(const char *ver_string)
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char *cp;
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int version = 0;
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (cp = ver_string; *cp; cp++) {
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (*cp == '.')
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			continue;
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!isdigit(*cp))
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		version = (version * 10) + (*cp - '0');
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return version;
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint blkid_get_library_version(const char **ver_string,
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			       const char **date_string)
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (ver_string)
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		*ver_string = lib_version;
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (date_string)
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		*date_string = lib_date;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return blkid_parse_version_string(lib_version);
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry