[v2,1/4] pdbg: Add in parser for uint8_t
diff mbox series

Message ID 20190418012658.23315-2-rashmica.g@gmail.com
State New
Headers show
Series
  • Add i2c put and get to pdbg
Related show

Checks

Context Check Description
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (854c4c5facff43af9e0fe5d7062b58f631987b0b)

Commit Message

Rashmica Gupta April 18, 2019, 1:26 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(+)

Patch
diff mbox series

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);