Browse Source

bytes_t: Add bytes_shift and bytes_nullterminate

Luke Dashjr 12 years ago
parent
commit
40a3e7ce27
1 changed files with 14 additions and 0 deletions
  1. 14 0
      util.h

+ 14 - 0
util.h

@@ -224,12 +224,26 @@ void bytes_cpy(bytes_t *dst, const bytes_t *src)
 	memcpy(dst->buf, src->buf, dst->sz);
 }
 
+static inline
+void bytes_shift(bytes_t *b, size_t shift)
+{
+	b->sz -= shift;
+	memmove(bytes_buf(b), &bytes_buf(b)[shift], bytes_len(b));
+}
+
 static inline
 void bytes_reset(bytes_t *b)
 {
 	b->sz = 0;
 }
 
+static inline
+void bytes_nullterminate(bytes_t *b)
+{
+	bytes_append(b, "", 1);
+	--b->sz;
+}
+
 static inline
 void bytes_free(bytes_t *b)
 {