[kernel][lib][cbuf] C -> CPP conversion

Minimal changes.

Change-Id: I7038cb98ae20fface9e87687ad1ddd2fd06a99df
Tested: build and validate that the cbuf continues to work.
diff --git a/kernel/lib/cbuf/cbuf.c b/kernel/lib/cbuf/cbuf.cpp
similarity index 79%
rename from kernel/lib/cbuf/cbuf.c
rename to kernel/lib/cbuf/cbuf.cpp
index aae4449..48d0f38 100644
--- a/kernel/lib/cbuf/cbuf.c
+++ b/kernel/lib/cbuf/cbuf.cpp
@@ -5,50 +5,48 @@
 // license that can be found in the LICENSE file or at
 // https://opensource.org/licenses/MIT
 
-#include <stdlib.h>
-#include <debug.h>
-#include <trace.h>
-#include <pow2.h>
-#include <string.h>
-#include <assert.h>
 #include <lib/cbuf.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <fbl/algorithm.h>
 #include <kernel/event.h>
 #include <kernel/spinlock.h>
+#include <pow2.h>
+#include <stdlib.h>
+#include <string.h>
+#include <trace.h>
 
 #define LOCAL_TRACE 0
 
 #define INC_POINTER(cbuf, ptr, inc) \
     modpow2(((ptr) + (inc)), (cbuf)->len_pow2)
 
-void cbuf_initialize(cbuf_t *cbuf, size_t len)
-{
+void cbuf_initialize(cbuf_t* cbuf, size_t len) {
     cbuf_initialize_etc(cbuf, len, malloc(len));
 }
 
-void cbuf_initialize_etc(cbuf_t *cbuf, size_t len, void *buf)
-{
+void cbuf_initialize_etc(cbuf_t* cbuf, size_t len, void* buf) {
     DEBUG_ASSERT(cbuf);
     DEBUG_ASSERT(len > 0);
-    DEBUG_ASSERT(ispow2(len));
+    DEBUG_ASSERT(fbl::is_pow2(len));
 
     cbuf->head = 0;
     cbuf->tail = 0;
-    cbuf->len_pow2 = log2_uint_floor(len);
-    cbuf->buf = buf;
+    cbuf->len_pow2 = log2_ulong_floor(len);
+    cbuf->buf = static_cast<char*>(buf);
     event_init(&cbuf->event, false, 0);
     spin_lock_init(&cbuf->lock);
 
     LTRACEF("len %zu, len_pow2 %u\n", len, cbuf->len_pow2);
 }
 
-size_t cbuf_space_avail(cbuf_t *cbuf)
-{
+size_t cbuf_space_avail(cbuf_t* cbuf) {
     uint consumed = modpow2((uint)(cbuf->head - cbuf->tail), cbuf->len_pow2);
     return valpow2(cbuf->len_pow2) - consumed - 1;
 }
 
-size_t cbuf_write_char(cbuf_t *cbuf, char c)
-{
+size_t cbuf_write_char(cbuf_t* cbuf, char c) {
     DEBUG_ASSERT(cbuf);
 
     spin_lock_saved_state_t state;
@@ -61,8 +59,9 @@
         cbuf->head = INC_POINTER(cbuf, cbuf->head, 1);
         ret = 1;
 
-        if (cbuf->head != cbuf->tail)
+        if (cbuf->head != cbuf->tail) {
             event_signal(&cbuf->event, true);
+        }
     }
 
     spin_unlock_irqrestore(&cbuf->lock, state);
@@ -70,8 +69,7 @@
     return ret;
 }
 
-size_t cbuf_read_char(cbuf_t *cbuf, char *c, bool block)
-{
+size_t cbuf_read_char(cbuf_t* cbuf, char* c, bool block) {
     DEBUG_ASSERT(cbuf);
     DEBUG_ASSERT(c);
 
@@ -99,9 +97,9 @@
 
     spin_unlock_irqrestore(&cbuf->lock, state);
 
-    if (block && ret == 0)
+    if (block && ret == 0) {
         goto retry;
+    }
 
     return ret;
 }
-
diff --git a/kernel/lib/cbuf/include/lib/cbuf.h b/kernel/lib/cbuf/include/lib/cbuf.h
index 7e444ce..16425b9 100644
--- a/kernel/lib/cbuf/include/lib/cbuf.h
+++ b/kernel/lib/cbuf/include/lib/cbuf.h
@@ -7,11 +7,10 @@
 
 #pragma once
 
-#include <zircon/compiler.h>
-#include <sys/types.h>
 #include <kernel/event.h>
 #include <kernel/spinlock.h>
-#include <iovec.h>
+#include <sys/types.h>
+#include <zircon/compiler.h>
 
 __BEGIN_CDECLS
 
@@ -19,7 +18,7 @@
     uint head;
     uint tail;
     uint len_pow2;
-    char *buf;
+    char* buf;
     event_t event;
     spin_lock_t lock;
 } cbuf_t;
@@ -33,7 +32,7 @@
  * @param[in] cbuf A pointer to the cbuf structure to allocate.
  * @param[in] len The minimum number of bytes for the underlying data buffer.
  */
-void cbuf_initialize(cbuf_t *cbuf, size_t len);
+void cbuf_initialize(cbuf_t* cbuf, size_t len);
 
 /**
  * cbuf_initalize_etc
@@ -44,7 +43,7 @@
  * @param[in] len The size of the supplied buffer, in bytes.
  * @param[in] buf A pointer to the memory to be used for internal storage.
  */
-void cbuf_initialize_etc(cbuf_t *cbuf, size_t len, void *buf);
+void cbuf_initialize_etc(cbuf_t* cbuf, size_t len, void* buf);
 
 /**
  * cbuf_space_avail
@@ -54,11 +53,10 @@
  * @return The number of free space available in the cbuf (IOW - the maximum
  * number of bytes which can currently be written)
  */
-size_t cbuf_space_avail(cbuf_t *cbuf);
+size_t cbuf_space_avail(cbuf_t* cbuf);
 
 /* special cases for dealing with a single char of data */
-size_t cbuf_read_char(cbuf_t *cbuf, char *c, bool block);
-size_t cbuf_write_char(cbuf_t *cbuf, char c);
+size_t cbuf_read_char(cbuf_t* cbuf, char* c, bool block);
+size_t cbuf_write_char(cbuf_t* cbuf, char c);
 
 __END_CDECLS
-
diff --git a/kernel/lib/cbuf/rules.mk b/kernel/lib/cbuf/rules.mk
index 22a0c66..56b93ab 100644
--- a/kernel/lib/cbuf/rules.mk
+++ b/kernel/lib/cbuf/rules.mk
@@ -10,6 +10,6 @@
 MODULE := $(LOCAL_DIR)
 
 MODULE_SRCS += \
-	$(LOCAL_DIR)/cbuf.c
+	$(LOCAL_DIR)/cbuf.cpp
 
 include make/module.mk