2015-07-03 15:50:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* include/sys/utsname.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Stavros Polymenis. All rights reserved.
|
|
|
|
* Author: Stavros Polymenis <sp@orbitalfox.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/utsname.h>
|
2019-01-27 13:24:24 +01:00
|
|
|
#include <stdio.h>
|
2015-07-03 15:50:27 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <nuttx/version.h>
|
2017-08-01 14:50:53 +02:00
|
|
|
#include <unistd.h>
|
2015-07-05 18:45:00 +02:00
|
|
|
|
|
|
|
/* In the protected and kernel build modes where kernel and application code
|
|
|
|
* are separated, some of these common system property must reside only in
|
|
|
|
* the kernel. In that case, uname() can only be called from user space via
|
|
|
|
* a kernel system call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if (!defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_BUILD_KERNEL)) || \
|
|
|
|
defined(__KERNEL__)
|
2015-07-03 15:50:27 +02:00
|
|
|
|
2015-07-05 14:46:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-07-03 15:50:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uname
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The uname() function will store information identifying the current
|
|
|
|
* system in the structure pointed to by name.
|
|
|
|
*
|
|
|
|
* The uname() function uses the utsname structure defined in
|
|
|
|
* <sys/utsname.h>.
|
|
|
|
*
|
|
|
|
* The uname() function will return a string naming the current system in
|
|
|
|
* the character array sysname. Similarly, nodename will contain the name
|
|
|
|
* of this node within an implementation-defined communications network.
|
|
|
|
* The arrays release and version will further identify the operating
|
|
|
|
* system. The array machine will contain a name that identifies the
|
|
|
|
* hardware that the system is running on.
|
|
|
|
*
|
|
|
|
* The format of each member is implementation-defined.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* name - The user-provided buffer to receive the system information.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Upon successful completion, a non-negative value will be returned.
|
|
|
|
* Otherwise, -1 will be returned and errno set to indicate the error.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int uname(FAR struct utsname *name)
|
|
|
|
{
|
2019-04-04 18:40:39 +02:00
|
|
|
int ret = 0;
|
2015-07-03 15:50:27 +02:00
|
|
|
|
2015-07-05 14:46:00 +02:00
|
|
|
/* Copy the strings. Assure that each is NUL terminated. */
|
|
|
|
|
2015-07-04 23:20:36 +02:00
|
|
|
strncpy(name->sysname, "NuttX", SYS_NAMELEN);
|
2015-07-03 15:50:27 +02:00
|
|
|
|
|
|
|
/* Get the hostname */
|
|
|
|
|
2015-07-08 19:11:52 +02:00
|
|
|
if (-1 == gethostname(name->nodename, HOST_NAME_MAX))
|
2015-07-03 15:50:27 +02:00
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2019-03-25 00:58:51 +01:00
|
|
|
name->nodename[HOST_NAME_MAX - 1] = '\0';
|
2015-07-05 14:46:00 +02:00
|
|
|
|
|
|
|
strncpy(name->release, CONFIG_VERSION_STRING, SYS_NAMELEN);
|
2019-03-25 00:58:51 +01:00
|
|
|
name->release[SYS_NAMELEN - 1] = '\0';
|
2015-07-05 14:46:00 +02:00
|
|
|
|
2019-01-27 13:24:24 +01:00
|
|
|
#if defined(__DATE__) && defined(__TIME__)
|
|
|
|
snprintf(name->version, VERSION_NAMELEN, "%s %s %s",
|
|
|
|
CONFIG_VERSION_BUILD, __DATE__, __TIME__);
|
|
|
|
#else
|
2015-07-05 14:46:00 +02:00
|
|
|
strncpy(name->version, CONFIG_VERSION_BUILD, VERSION_NAMELEN);
|
2019-01-27 13:24:24 +01:00
|
|
|
#endif
|
2019-03-25 00:58:51 +01:00
|
|
|
name->version[VERSION_NAMELEN - 1] = '\0';
|
2015-07-05 14:46:00 +02:00
|
|
|
|
|
|
|
strncpy(name->machine, CONFIG_ARCH, SYS_NAMELEN);
|
2019-03-25 00:58:51 +01:00
|
|
|
name->machine[SYS_NAMELEN - 1] = '\0';
|
2015-07-03 15:50:27 +02:00
|
|
|
|
|
|
|
return ret;
|
2015-10-04 23:04:00 +02:00
|
|
|
}
|
2015-07-05 18:45:00 +02:00
|
|
|
|
|
|
|
#endif /* (!CONFIG_BUILD_PROTECTED) && !CONFIG_BUILD_KERNEL) || __KERNEL__ */
|