X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fgetkernel.c;fp=lib%2Fgetkernel.c;h=b9a36c8de69493e97d9f083435eda269e8c186ca;hb=dffca81b18d54e1ea6db1213b85e1741bd85861f;hp=0000000000000000000000000000000000000000;hpb=4db12f3b28c20f8b013c27c6cf0fbae5b336732f;p=util-vserver.git diff --git a/lib/getkernel.c b/lib/getkernel.c new file mode 100644 index 0000000..b9a36c8 --- /dev/null +++ b/lib/getkernel.c @@ -0,0 +1,58 @@ +// $Id$ --*- c++ -*-- + +// Copyright (C) 2011 Daniel Hokka Zakrisson +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +int +vc_get_kernel() +{ + static int linux_ver = -1; + if (linux_ver == -1) { + struct utsname uts; + char *p; + int part, n; + if (uname(&uts) == -1) + return -1; + part = 0; + n = 0; + linux_ver = 0; + for (p = uts.release; *p && part < 3; p++) { + if (*p == '.') { + if (part < 3) { + linux_ver |= n << (8 * (2 - part)); + n = 0; + part++; + } + } + else if (isdigit(*p)) { + n *= 10; + n += *p - '0'; + } + else + break; + } + if (n > 0 && part < 3) + linux_ver |= n << (8 * (2 - part)); + } + return linux_ver; +}