zephyr/lib/posix/options/uname.c
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00

53 lines
1.7 KiB
C

/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <zephyr/kernel.h>
#include <zephyr/net/hostname.h>
#include <zephyr/posix/sys/utsname.h>
#include <zephyr/version.h>
#ifdef CONFIG_NET_HOSTNAME_ENABLE
#define UTSNAME_NODENAME CONFIG_NET_HOSTNAME
#else
#define UTSNAME_NODENAME "zephyr"
#endif
#if defined(__DATE__) && defined(__TIME__)
#define UTSNAME_VERSION(_ver) _ver " " __DATE__ " " __TIME__
#else
#define UTSNAME_VERSION(_ver) _ver
#endif
#if defined(BUILD_VERSION) && !IS_EMPTY(BUILD_VERSION)
#define VERSION_BUILD STRINGIFY(BUILD_VERSION)
#else
#define VERSION_BUILD KERNEL_VERSION_STRING
#endif
#define UTSNAME_INITIALIZER(_sys, _node, _rel, _ver, _mach) \
{ \
.sysname = _sys, .nodename = _node, .release = _rel, \
.version = UTSNAME_VERSION(_ver), .machine = _mach, \
}
static const struct utsname z_name = UTSNAME_INITIALIZER(
"Zephyr", UTSNAME_NODENAME, KERNEL_VERSION_STRING, VERSION_BUILD, CONFIG_ARCH);
BUILD_ASSERT(sizeof(z_name.sysname) >= sizeof("Zephyr"));
BUILD_ASSERT(sizeof(z_name.release) >= sizeof(KERNEL_VERSION_STRING));
BUILD_ASSERT(sizeof(z_name.version) >= sizeof(UTSNAME_VERSION(VERSION_BUILD)));
BUILD_ASSERT(sizeof(z_name.machine) >= sizeof(CONFIG_ARCH));
int uname(struct utsname *name)
{
memcpy(name, &z_name, sizeof(*name));
if (IS_ENABLED(CONFIG_NET_HOSTNAME_ENABLE)) {
strncpy(name->nodename, net_hostname_get(), sizeof(name->nodename));
name->nodename[sizeof(name->nodename) - 1] = '\0';
}
return 0;
}