aboutsummaryrefslogtreecommitdiff
path: root/version.c
diff options
context:
space:
mode:
authorUsman Akinyemi <usmanakinyemi202@gmail.com>2025-02-15 21:20:49 +0530
committerJunio C Hamano <gitster@pobox.com>2025-02-18 09:05:12 -0800
commit0a78d61247922f30ebf2ce09025dcaa7bd7e3583 (patch)
tree52572e28b9fbca5fd2281f6fcd2507210bd79c18 /version.c
parentcdfd081df6fa42e6cd0da1d978d41b836c1f292b (diff)
downloadgit-0a78d61247922f30ebf2ce09025dcaa7bd7e3583.tar.xz
version: refactor get_uname_info()
Some code from "builtin/bugreport.c" uses uname(2) to get system information. Let's refactor this code into a new get_uname_info() function, so that we can reuse it in a following commit. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'version.c')
-rw-r--r--version.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/version.c b/version.c
index 60df71fd0e..3ec8b8243d 100644
--- a/version.c
+++ b/version.c
@@ -3,6 +3,7 @@
#include "version-def.h"
#include "strbuf.h"
#include "sane-ctype.h"
+#include "gettext.h"
const char git_version_string[] = GIT_VERSION;
const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
@@ -47,3 +48,22 @@ const char *git_user_agent_sanitized(void)
return agent;
}
+
+int get_uname_info(struct strbuf *buf)
+{
+ struct utsname uname_info;
+
+ if (uname(&uname_info)) {
+ strbuf_addf(buf, _("uname() failed with error '%s' (%d)\n"),
+ strerror(errno),
+ errno);
+ return -1;
+ }
+
+ strbuf_addf(buf, "%s %s %s %s\n",
+ uname_info.sysname,
+ uname_info.release,
+ uname_info.version,
+ uname_info.machine);
+ return 0;
+}