nsh/uname: improve compatibility for non-GNU compilers

The alloca() function is machine- and compiler-dependent.  For certain
applications, its use can improve efficiency compared to the use of
malloc(3) plus free(3).  In certain cases, it can also simplify memory
deallocation in applications that use longjmp(3) or siglongjmp(3).
Otherwise, its use is discouraged.

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an 2024-02-08 15:49:47 +08:00 committed by Xiang Xiao
parent 1cb991cce7
commit 05ffbabca7

View File

@ -690,6 +690,7 @@ int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
FAR const char *str; FAR const char *str;
struct lib_memoutstream_s stream; struct lib_memoutstream_s stream;
struct utsname info; struct utsname info;
struct utsname output;
unsigned int set; unsigned int set;
int option; int option;
bool badarg; bool badarg;
@ -780,8 +781,7 @@ int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
/* Process each option */ /* Process each option */
first = true; first = true;
lib_memoutstream(&stream, alloca(sizeof(struct utsname)), lib_memoutstream(&stream, (FAR char *)&output, sizeof(output));
sizeof(struct utsname));
for (i = 0; set != 0; i++) for (i = 0; set != 0; i++)
{ {
unsigned int mask = (1 << i); unsigned int mask = (1 << i);