mirror of
https://github.com/thepigeongenerator/cpusetcores.git
synced 2025-12-17 22:15:46 +01:00
improve number parsing in opts.c
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "opts.h"
|
#include "opts.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -36,8 +37,11 @@ u8 getoptions(int argc, char *const *argv, int *ncpus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
|
char *end;
|
||||||
char *num = argv[optind];
|
char *num = argv[optind];
|
||||||
*ncpus = atoi(num);
|
*ncpus = strtol(num, &end, 0);
|
||||||
|
if (errno || end == num || *end != '\0')
|
||||||
|
fatal("failed to parse numeric value from string '%s'", num);
|
||||||
} else if (opts & OPT_LIST_CORES) {
|
} else if (opts & OPT_LIST_CORES) {
|
||||||
*ncpus = -1;
|
*ncpus = -1;
|
||||||
} else
|
} else
|
||||||
|
|||||||
Reference in New Issue
Block a user