Browse Source

bytestring: use newly added mem helpers

Reviwed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Cody P Schafer 10 years ago
parent
commit
22a03695fd
1 changed files with 3 additions and 6 deletions
  1. 3 6
      ccan/bytestring/bytestring.h

+ 3 - 6
ccan/bytestring/bytestring.h

@@ -94,8 +94,7 @@ static inline struct bytestring bytestring_from_string(const char *s)
  */
  */
 static inline bool bytestring_eq(struct bytestring a, struct bytestring b)
 static inline bool bytestring_eq(struct bytestring a, struct bytestring b)
 {
 {
-	return (a.len == b.len)
-		&& (memcmp(a.ptr, b.ptr, a.len) == 0);
+	return memeq(a.ptr, a.len, b.ptr, b.len);
 }
 }
 
 
 /**
 /**
@@ -149,8 +148,7 @@ static inline struct bytestring bytestring_slice(struct bytestring s,
 static inline bool bytestring_starts(struct bytestring s,
 static inline bool bytestring_starts(struct bytestring s,
 				     struct bytestring prefix)
 				     struct bytestring prefix)
 {
 {
-	return (s.len >= prefix.len) && (memcmp(s.ptr,
-						prefix.ptr, prefix.len) == 0);
+	return memstarts(s.ptr, s.len, prefix.ptr, prefix.len);
 }
 }
 
 
 /**
 /**
@@ -163,8 +161,7 @@ static inline bool bytestring_starts(struct bytestring s,
 static inline bool bytestring_ends(struct bytestring s,
 static inline bool bytestring_ends(struct bytestring s,
 				   struct bytestring suffix)
 				   struct bytestring suffix)
 {
 {
-	return (s.len >= suffix.len) && (memcmp(s.ptr + s.len - suffix.len,
-						suffix.ptr, suffix.len) == 0);
+	return memends(s.ptr, s.len, suffix.ptr, suffix.len);
 }
 }
 
 
 /**
 /**