logo

utils-extra

Collection of extra tools for Unixes

sname.c (776B)


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