diff mbox series

[v2,11/16] pdbg: Add in parser for uint16_t

Message ID 20180907064015.1058-12-rashmica.g@gmail.com
State Accepted
Headers show
Series Basic gdbserver for POWER8 | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/build-multiarch fail Test build-multiarch on branch master

Commit Message

Rashmica Gupta Sept. 7, 2018, 6:40 a.m. UTC
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
---
 src/parsers.c | 18 ++++++++++++++++++
 src/parsers.h |  2 ++
 2 files changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/src/parsers.c b/src/parsers.c
index 6cbe06d..868c383 100644
--- a/src/parsers.c
+++ b/src/parsers.c
@@ -37,6 +37,24 @@  uint32_t *parse_number32(const char *argv)
 	return n;
 }
 
+uint16_t *parse_number16(const char *argv)
+{
+	unsigned long long tmp;
+	uint16_t *n = malloc(sizeof(*n));
+	char *endptr;
+
+	if (!argv)
+		return NULL;
+
+	errno = 0;
+	tmp = strtoul(argv, &endptr, 0);
+	if (errno || *endptr != '\0' || tmp > UINT16_MAX)
+		return NULL;
+
+	*n = tmp;
+	return n;
+}
+
 /* Parse a GPR number, returning an error if it's greater than 32 */
 int *parse_gpr(const char *argv)
 {
diff --git a/src/parsers.h b/src/parsers.h
index b5f23cf..935c242 100644
--- a/src/parsers.h
+++ b/src/parsers.h
@@ -8,12 +8,14 @@ 
 #define ADDRESS32 (parse_number32, NULL)
 #define DATA (parse_number64, NULL)
 #define DATA32 (parse_number32, NULL)
+#define DATA16 (parse_number16, NULL)
 #define DEFAULT_DATA(default) (parse_number64, default)
 #define GPR (parse_gpr, NULL)
 #define SPR (parse_spr, NULL)
 
 uint64_t *parse_number64(const char *argv);
 uint32_t *parse_number32(const char *argv);
+uint16_t *parse_number16(const char *argv);
 int *parse_gpr(const char *argv);
 int *parse_spr(const char *argv);
 bool *parse_flag_noarg(const char *argv);