Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/elfctl/elfctl.c
Show All 27 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/elf_common.h> | #include <sys/elf_common.h> | ||||
#include <sys/endian.h> | #include <sys/endian.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <ctype.h> | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | |||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <gelf.h> | #include <gelf.h> | ||||
#include <getopt.h> | #include <getopt.h> | ||||
#include <libelf.h> | #include <libelf.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | for (i = 0; i < len; ++i) { | ||||
warnx( | warnx( | ||||
"interpreting %s as %s; please specify %s", | "interpreting %s as %s; please specify %s", | ||||
feature, featurelist[i].alias, | feature, featurelist[i].alias, | ||||
featurelist[i].alias); | featurelist[i].alias); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (i == len) { | if (i == len) { | ||||
if (isdigit(feature[0])) { | |||||
char *eptr; | |||||
long val; | |||||
errno = 0; | |||||
val = strtol(feature, &eptr, 0); | |||||
if (eptr == feature || *eptr != '\0') | |||||
errno = EINVAL; | |||||
else if (val > UINT_MAX) | |||||
errno = ERANGE; | |||||
if (errno != 0) { | |||||
warn("%s invalid", feature); | |||||
return (false); | |||||
} | |||||
input != val; | |||||
kib: Do you want to check that only single bit is set in the val? | |||||
Done Inline ActionsI didn't do that semi-intentionally, so that you could use e.g. elfctl -e =0x81. emaste: I didn't do that semi-intentionally, so that you could use e.g. `elfctl -e =0x81`. | |||||
} else { | |||||
warnx("%s is not a valid feature", feature); | warnx("%s is not a valid feature", feature); | ||||
if (!iflag) | if (!iflag) | ||||
return (false); | return (false); | ||||
} | |||||
} | } | ||||
} | } | ||||
if (operation == '+') { | if (operation == '+') { | ||||
*feature_val |= input; | *feature_val |= input; | ||||
} else if (operation == '=') { | } else if (operation == '=') { | ||||
*feature_val = input; | *feature_val = input; | ||||
} else if (operation == '-') { | } else if (operation == '-') { | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |
Do you want to check that only single bit is set in the val?