logo

utils

Old programs, got split in utils-std and utils-extra git clone https://hacktivis.me/git/utils.git

sname.c (814B)


  1. // Collection of Unix tools, comparable to coreutils
  2. // SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #define _GNU_SOURCE
  5. #include <stdio.h> // printf(), perror()
  6. #include <stdlib.h> // exit()
  7. #include <sys/utsname.h> // utsname, uname()
  8. void
  9. print_kv(char *key, char *value)
  10. {
  11. if(printf("%s %s\n", key, value) < 0)
  12. {
  13. perror("sname: printf");
  14. exit(1);
  15. }
  16. }
  17. int
  18. main()
  19. {
  20. struct utsname name;
  21. if(uname(&name) != 0)
  22. {
  23. perror("uname");
  24. return 1;
  25. }
  26. #ifdef __linux__
  27. print_kv("domainname", name.domainname);
  28. #endif
  29. print_kv("machine", name.machine);
  30. print_kv("nodename", name.nodename);
  31. print_kv("release", name.release);
  32. print_kv("sysname", name.sysname);
  33. print_kv("version", name.version);
  34. return 0;
  35. }