[Pdbg] [PATCH v2 1/4] pdbg: Add in parser for uint8_t
Rashmica Gupta
rashmica.g at gmail.com
Thu Apr 18 11:26:55 AEST 2019
Signed-off-by: Rashmica Gupta <rashmica.g at gmail.com>
---
src/parsers.c | 18 ++++++++++++++++++
src/parsers.h | 2 ++
2 files changed, 20 insertions(+)
diff --git a/src/parsers.c b/src/parsers.c
index 8575784..4c03db9 100644
--- a/src/parsers.c
+++ b/src/parsers.c
@@ -56,6 +56,24 @@ uint16_t *parse_number16(const char *argv)
return n;
}
+uint8_t *parse_number8(const char *argv)
+{
+ unsigned long long tmp;
+ uint8_t *n = malloc(sizeof(*n));
+ char *endptr;
+
+ if (!argv)
+ return NULL;
+
+ errno = 0;
+ tmp = strtoul(argv, &endptr, 0);
+ if (errno || *endptr != '\0' || tmp > UINT8_MAX)
+ return NULL;
+
+ *n = tmp;
+ return n;
+}
+
/* Parse an 8-bit number that is a power of 2 */
uint8_t *parse_number8_pow2(const char *argv)
{
diff --git a/src/parsers.h b/src/parsers.h
index ba52178..27ada1f 100644
--- a/src/parsers.h
+++ b/src/parsers.h
@@ -9,6 +9,7 @@
#define DATA (parse_number64, NULL)
#define DATA32 (parse_number32, NULL)
#define DATA16 (parse_number16, NULL)
+#define DATA8 (parse_number8, NULL)
#define DEFAULT_DATA(default) (parse_number64, default)
#define GPR (parse_gpr, NULL)
#define SPR (parse_spr, NULL)
@@ -16,6 +17,7 @@
uint64_t *parse_number64(const char *argv);
uint32_t *parse_number32(const char *argv);
uint16_t *parse_number16(const char *argv);
+uint8_t *parse_number8(const char *argv);
uint8_t *parse_number8_pow2(const char *argv);
int *parse_gpr(const char *argv);
int *parse_spr(const char *argv);
--
2.17.2
More information about the Pdbg
mailing list