mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 10:36:04 +08:00
✨ feat(components): add uname support
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-03-27 xqyjlj add uname
|
||||
*/
|
||||
|
||||
#ifndef __SYS_UTSNAME_H__
|
||||
#define __SYS_UTSNAME_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_MUSLLIBC
|
||||
/* this is required for musl <sys/utsname.h> */
|
||||
#ifndef _POSIX_SOURCE
|
||||
#define _POSIX_SOURCE
|
||||
#include_next <sys/utsname.h>
|
||||
/* limiting influence of _POSIX_SOURCE */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
#else /* def _POSIX_SOURCE */
|
||||
#include_next <sys/utsname.h>
|
||||
#endif
|
||||
#else
|
||||
|
||||
struct utsname
|
||||
{
|
||||
char sysname[65];
|
||||
char nodename[65];
|
||||
char release[65];
|
||||
char version[65];
|
||||
char machine[65];
|
||||
char domainname[65];
|
||||
};
|
||||
|
||||
int uname(struct utsname *);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -34,6 +34,7 @@
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <poll.h>
|
||||
@@ -4566,6 +4567,37 @@ rt_weak sysret_t sys_cacheflush(void *addr, int size, int cache)
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
sysret_t sys_uname(struct utsname *uts)
|
||||
{
|
||||
struct utsname utsbuff = {0};
|
||||
int ret = 0;
|
||||
char *machine;
|
||||
|
||||
if (!lwp_user_accessable((void *)uts, sizeof(struct utsname)))
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
rt_strncpy(utsbuff.sysname, "RT-Thread", sizeof(utsbuff.sysname));
|
||||
utsbuff.nodename[0] = '\0';
|
||||
ret = rt_snprintf(utsbuff.release, sizeof(utsbuff.release), "%u.%u.%u",
|
||||
RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH);
|
||||
if (ret < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
ret = rt_snprintf(utsbuff.version, sizeof(utsbuff.version), "RT-Thread %u.%u.%u %s %s",
|
||||
RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH, __DATE__, __TIME__);
|
||||
if (ret < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
machine = rt_hw_cpu_arch();
|
||||
rt_strncpy(utsbuff.machine, machine, sizeof(utsbuff.machine));
|
||||
|
||||
utsbuff.domainname[0] = '\0';
|
||||
lwp_put_to_user(uts, &utsbuff, sizeof utsbuff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const static struct rt_syscall_def func_table[] =
|
||||
{
|
||||
SYSCALL_SIGN(sys_exit), /* 01 */
|
||||
@@ -4776,6 +4808,7 @@ const static struct rt_syscall_def func_table[] =
|
||||
SYSCALL_SIGN(sys_mq_getsetattr),
|
||||
SYSCALL_SIGN(sys_mq_close),
|
||||
SYSCALL_SIGN(sys_stat), //TODO should be replaced by sys_lstat if symbolic link are implemented
|
||||
SYSCALL_SIGN(sys_uname), /* 170 */
|
||||
};
|
||||
|
||||
const void *lwp_get_sys_api(rt_uint32_t number)
|
||||
|
||||
Reference in New Issue
Block a user