sname.c (814B)
- // Collection of Unix tools, comparable to coreutils
- // SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: MPL-2.0
- #define _GNU_SOURCE
- #include <stdio.h> // printf(), perror()
- #include <stdlib.h> // exit()
- #include <sys/utsname.h> // utsname, uname()
- void
- print_kv(char *key, char *value)
- {
- if(printf("%s %s\n", key, value) < 0)
- {
- perror("sname: printf");
- exit(1);
- }
- }
- int
- main()
- {
- struct utsname name;
- if(uname(&name) != 0)
- {
- perror("uname");
- return 1;
- }
- #ifdef __linux__
- print_kv("domainname", name.domainname);
- #endif
- print_kv("machine", name.machine);
- print_kv("nodename", name.nodename);
- print_kv("release", name.release);
- print_kv("sysname", name.sysname);
- print_kv("version", name.version);
- return 0;
- }