-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation for posix uname. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
- Loading branch information
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,7 +353,7 @@ process applications. | |
getenv(), | ||
setenv(), | ||
sysconf(), | ||
uname(), | ||
uname(),yes | ||
unsetenv() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2023 Meta | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ | ||
#define ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ | ||
|
||
#include "version.h" | ||
|
||
#include <errno.h> | ||
#include <stdint.h> | ||
|
||
#include <zephyr/net/hostname.h> | ||
#include <zephyr/toolchain/common.h> | ||
#include <zephyr/net/hostname.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* sysname */ | ||
#define SYS_NAMELEN sizeof("Zephyr") | ||
|
||
/* nodename */ | ||
#ifdef CONFIG_NET_HOSTNAME_ENABLE | ||
#define NODE_NAMELEN NET_HOSTNAME_MAX_LEN | ||
#else | ||
#define NODE_NAMELEN SYS_NAMELEN | ||
#endif | ||
|
||
/* release */ | ||
#define RELEASE_NAMELEN sizeof(KERNEL_VERSION_STRING) | ||
|
||
/* version */ | ||
#if defined(__DATE__) && defined(__TIME__) | ||
#define DATETIME_LEN (sizeof(__DATE__) + sizeof(__TIME__)) | ||
#else | ||
#define DATETIME_LEN 0 | ||
#endif | ||
|
||
#ifdef BUILD_VERSION | ||
#define VERSION_BUILD STRINGIFY(BUILD_VERSION) | ||
#else | ||
#define VERSION_BUILD KERNEL_VERSION_STRING | ||
#endif | ||
#define VERSION_BUILD_LEN sizeof(VERSION_BUILD) | ||
|
||
/** | ||
* In case anyone wondered if this length has been adjusted for '\0', it will | ||
* be formatted in utsname.c as: | ||
* "%s %s %s", VERSION_BUILD, __DATE__, __TIME__ | ||
* the '\0' of VERSION_BUILD_LEN & __DATE__ will be used for the space that | ||
* follows, '\0' of __TIME__ will be used for the \0 of the formatted VERSION | ||
* string. In the end the size of the array should fit the string snugly. | ||
*/ | ||
#define VERSION_NAMELEN (VERSION_BUILD_LEN + DATETIME_LEN) | ||
|
||
/* machine */ | ||
#define MACHINE_NAMELEN sizeof(CONFIG_ARCH) | ||
|
||
struct utsname { | ||
char sysname[SYS_NAMELEN]; | ||
char nodename[NODE_NAMELEN]; | ||
char release[RELEASE_NAMELEN]; | ||
char version[VERSION_NAMELEN]; | ||
char machine[MACHINE_NAMELEN]; | ||
}; | ||
|
||
int uname(struct utsname *name); | ||
|
||
#undef SYS_NAMELEN | ||
#undef NODE_NAMELEN | ||
#undef RELEASE_NAMELEN | ||
#undef VERSION_NAMELEN | ||
#undef MACHINE_NAMELEN | ||
#undef DATETIME_LEN | ||
#undef VERSION_BUILD_LEN | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2023 Meta | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <zephyr/posix/sys/utsname.h> | ||
|
||
int uname(struct utsname *name) | ||
{ | ||
if (name == NULL) { | ||
return -1; | ||
errno = EINVAL; | ||
} | ||
|
||
strncpy(name->sysname, "Zephyr", sizeof(name->sysname)); | ||
strncpy(name->nodename, net_hostname_get(), sizeof(name->nodename)); | ||
strncpy(name->release, KERNEL_VERSION_STRING, sizeof(name->release)); | ||
#if defined(__DATE__) && defined(__TIME__) | ||
snprintf(name->version, sizeof(name->version), "%s %s %s", VERSION_BUILD, __DATE__, | ||
__TIME__); | ||
#else | ||
strncpy(name->version, VERSION_BUILD, sizeof(name->version)); | ||
#endif | ||
strncpy(name->machine, CONFIG_ARCH, sizeof(name->machine)); | ||
|
||
return 0; | ||
} |