Home | History | Annotate | Download | only in lib
      1 // SPDX-License-Identifier: GPL-2.0-or-later
      2 /*
      3  * Copyright (c) 2018 Mylne Josserand <mylene.josserand (at) bootlin.com>
      4  *
      5  */
      6 
      7 #include <stdio.h>
      8 #include <unistd.h>
      9 #include <string.h>
     10 
     11 static void print_help(void)
     12 {
     13 	printf("Usage: tst_getconf variable\n\n");
     14 	printf("       variable: can be PAGESIZE/PAGE_SIZE");
     15 	printf(" or _NPROCESSORS_ONLN (for the moment)\n\n");
     16 	printf("example: tst_getconf PAGESIZE\n");
     17 }
     18 
     19 int main(int argc, char *argv[])
     20 {
     21 	int opt;
     22 
     23 	while ((opt = getopt(argc, argv, ":h")) != -1) {
     24 		switch (opt) {
     25 		case 'h':
     26 			print_help();
     27 			return 0;
     28 		default:
     29 			print_help();
     30 			return 1;
     31 		}
     32 	}
     33 
     34 	if (argc != 2) {
     35 		print_help();
     36 		return 1;
     37 	}
     38 
     39 	if (!strcmp(argv[optind], "_NPROCESSORS_ONLN")) {
     40 		printf("%ld\n", sysconf(_SC_NPROCESSORS_ONLN));
     41 	} else if (!strcmp(argv[optind], "PAGESIZE") ||
     42 		   !strcmp(argv[optind], "PAGE_SIZE")) {
     43 		printf("%ld\n", sysconf(_SC_PAGE_SIZE));
     44 	} else {
     45 		printf("tst_getconf: Unrecognized variable \'%s\'\n",
     46 		       argv[optind]);
     47 		return -1;
     48 	}
     49 
     50 	return 0;
     51 }
     52