2012-03-07 12:04:59 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
2012-03-07 12:04:59 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of Sortix.
|
2012-03-07 12:04:59 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix 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, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
2012-03-07 12:04:59 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix 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.
|
2012-03-07 12:04:59 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2012-03-07 12:04:59 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
kernelinfo.cpp
|
|
|
|
Lets user-space query information about the kernel.
|
2012-03-07 12:04:59 -05:00
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2012-03-21 19:52:29 -04:00
|
|
|
#include <sortix/kernel/platform.h>
|
2013-01-08 18:41:35 -05:00
|
|
|
#include <sortix/kernel/syscall.h>
|
|
|
|
|
2012-09-22 10:44:50 -04:00
|
|
|
#include <errno.h>
|
2013-01-08 18:41:35 -05:00
|
|
|
|
2012-03-07 12:04:59 -05:00
|
|
|
#include "kernelinfo.h"
|
|
|
|
|
|
|
|
#ifndef VERSIONSTR
|
|
|
|
#define VERSIONSTR "unknown"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Sortix {
|
|
|
|
namespace Info {
|
|
|
|
|
|
|
|
const char* KernelInfo(const char* req)
|
|
|
|
{
|
2012-09-22 16:53:11 -04:00
|
|
|
if ( strcmp(req, "name") == 0 ) { return "Sortix"; }
|
|
|
|
if ( strcmp(req, "version") == 0 ) { return VERSIONSTR; }
|
|
|
|
if ( strcmp(req, "builddate") == 0 ) { return __DATE__; }
|
|
|
|
if ( strcmp(req, "buildtime") == 0 ) { return __TIME__; }
|
2012-03-07 12:04:59 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t SysKernelInfo(const char* req, char* resp, size_t resplen)
|
|
|
|
{
|
|
|
|
const char* str = KernelInfo(req);
|
2012-09-22 10:44:50 -04:00
|
|
|
if ( !str ) { errno = EINVAL; return -1; }
|
2012-09-22 16:40:44 -04:00
|
|
|
size_t stringlen = strlen(str);
|
2012-03-07 12:04:59 -05:00
|
|
|
if ( resplen < stringlen + 1 )
|
|
|
|
{
|
2012-09-22 10:44:50 -04:00
|
|
|
errno = ERANGE;
|
2012-03-07 12:04:59 -05:00
|
|
|
return (ssize_t) stringlen;
|
|
|
|
}
|
2012-09-22 16:44:50 -04:00
|
|
|
strcpy(resp, str);
|
2012-03-07 12:04:59 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
Syscall::Register(SYSCALL_KERNELINFO, (void*) SysKernelInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Info
|
|
|
|
} // namespace Sortix
|