This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f233c5860cf49ad538a0b245968b319192f3f614
Author: wangmingrong1 <[email protected]>
AuthorDate: Thu Aug 15 18:00:20 2024 +0800

    libc/lib_utsname: Store version number for debugging and preventing 
optimization
    
    In order to directly read the version information of the current file from 
elf or bin files, memory files, etc., for easy debugging and one-to-one 
correspondence.
    
    Signed-off-by: wangmingrong1 <[email protected]>
---
 libs/libc/misc/lib_utsname.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/libs/libc/misc/lib_utsname.c b/libs/libc/misc/lib_utsname.c
index 77fc671e7f..57aa62d590 100644
--- a/libs/libc/misc/lib_utsname.c
+++ b/libs/libc/misc/lib_utsname.c
@@ -47,6 +47,20 @@
 #include <nuttx/version.h>
 #include <unistd.h>
 
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char g_sysname[] = "NuttX";
+static char g_machine[] = CONFIG_ARCH;
+static char g_release[] = CONFIG_VERSION_STRING;
+
+#if defined(__DATE__) && defined(__TIME__)
+static char g_version[] = CONFIG_VERSION_BUILD " " __DATE__ " " __TIME__;
+#else
+static char g_version[] = CONFIG_VERSION_BUILD;
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -83,26 +97,15 @@ int uname(FAR struct utsname *name)
 {
   int ret = 0;
 
-  /* Copy the strings.  Assure that each is NUL terminated. */
-
-  strlcpy(name->sysname, "NuttX", sizeof(name->sysname));
-
   /* Get the hostname */
 
   ret = gethostname(name->nodename, HOST_NAME_MAX);
   name->nodename[HOST_NAME_MAX - 1] = '\0';
 
-  strlcpy(name->release,  CONFIG_VERSION_STRING, sizeof(name->release));
-
-#if defined(__DATE__) && defined(__TIME__) && \
-    !defined(CONFIG_LIBC_UNAME_DISABLE_TIMESTAMP)
-  snprintf(name->version, VERSION_NAMELEN, "%s %s %s",
-           CONFIG_VERSION_BUILD, __DATE__, __TIME__);
-#else
-  strlcpy(name->version,  CONFIG_VERSION_BUILD, sizeof(name->version));
-#endif
-
-  strlcpy(name->machine,  CONFIG_ARCH, sizeof(name->machine));
+  strlcpy(name->sysname, g_sysname, sizeof(name->sysname));
+  strlcpy(name->release, g_release, sizeof(name->release));
+  strlcpy(name->version, g_version, sizeof(name->version));
+  strlcpy(name->machine, g_machine, sizeof(name->machine));
 
   return ret;
 }

Reply via email to