瀏覽代碼

Add faux_buf_empty()

Serj Kalichev 1 年之前
父節點
當前提交
b5674aef22
共有 3 個文件被更改,包括 26 次插入0 次删除
  1. 1 0
      faux/buf.h
  2. 24 0
      faux/buf/buf.c
  3. 1 0
      faux/faux.map

+ 1 - 0
faux/buf.h

@@ -37,6 +37,7 @@ ssize_t faux_buf_dwrite_lock_easy(faux_buf_t *buf, void **data);
 ssize_t faux_buf_dwrite_unlock_easy(faux_buf_t *buf, size_t really_written);
 ssize_t faux_buf_dread_lock_easy(faux_buf_t *buf, void **data);
 ssize_t faux_buf_dread_unlock_easy(faux_buf_t *buf, size_t really_readed);
+bool_t faux_buf_empty(faux_buf_t *buf);
 
 C_DECL_END
 

+ 24 - 0
faux/buf/buf.c

@@ -84,6 +84,30 @@ void faux_buf_free(faux_buf_t *buf)
 }
 
 
+/** @brief Empty dynamic buffer object.
+ *
+ * @param [in] buf Buffer object.
+ */
+bool_t faux_buf_empty(faux_buf_t *buf)
+{
+	if (!buf)
+		return BOOL_FALSE;
+
+	// Don't empty locked buffer
+	if (faux_buf_is_rlocked(buf) ||
+		faux_buf_is_wlocked(buf))
+		return BOOL_FALSE;
+
+	faux_list_del_all(buf->list);
+	buf->rpos = 0;
+	buf->wpos = buf->chunk_size;
+	buf->len = 0;
+	buf->wchunk = NULL;
+
+	return BOOL_TRUE;
+}
+
+
 /** @brief Returns length of buffer.
  *
  * @param [in] buf Allocated and initialized buffer object.

+ 1 - 0
faux/faux.map

@@ -375,6 +375,7 @@ FAUX_2.0 {
 		faux_buf_dwrite_unlock_easy;
 		faux_buf_dread_lock_easy;
 		faux_buf_dread_unlock_easy;
+		faux_buf_empty;
 
 		testc_version_major;
 		testc_version_minor;