mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libutil: Introduce util_arch module
The util_arch module is supposed to provide general information about the underlying architecture of the machine in use. Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
02aaff72fa
commit
2ca7db75d3
74
libutil/util_arch_example.c
Normal file
74
libutil/util_arch_example.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* util_arch_example - Example program for util_arch
|
||||
*
|
||||
* Copyright IBM Corp. 2021
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
|
||||
//! [code]
|
||||
#include "lib/util_arch.h"
|
||||
#include "lib/util_opt.h"
|
||||
#include "lib/util_prg.h"
|
||||
|
||||
static const struct util_prg prg = {
|
||||
.desc = "Example for util_arch.",
|
||||
.copyright_vec = {
|
||||
{
|
||||
.owner = "IBM Corp.",
|
||||
.pub_first = 2021,
|
||||
.pub_last = 2021,
|
||||
},
|
||||
UTIL_PRG_COPYRIGHT_END
|
||||
}
|
||||
};
|
||||
|
||||
static struct util_opt opt_vec[] = {
|
||||
UTIL_OPT_HELP,
|
||||
UTIL_OPT_VERSION,
|
||||
UTIL_OPT_END
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int mach_type;
|
||||
unsigned long hsa_maxsize;
|
||||
|
||||
util_prg_init(&prg);
|
||||
util_opt_init(opt_vec, NULL);
|
||||
|
||||
while (1) {
|
||||
int opt = util_opt_getopt_long(argc, argv);
|
||||
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
util_prg_print_help();
|
||||
util_opt_print_help();
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'v':
|
||||
util_prg_print_version();
|
||||
exit(EXIT_SUCCESS);
|
||||
case '?':
|
||||
default:
|
||||
fprintf(stderr, "Try '--help' for more information.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
mach_type = util_arch_machine_type();
|
||||
hsa_maxsize = util_arch_hsa_maxsize();
|
||||
|
||||
printf("Machine type: %s (%d)\n",
|
||||
util_arch_machine_type_to_str(mach_type), mach_type);
|
||||
printf("This machine type: %s\n", util_arch_machine_type_str());
|
||||
printf("HSA max. size: %lu MiB\n", hsa_maxsize / (1024 * 1024));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
//! [code]
|
||||
Reference in New Issue
Block a user