]> git.mdlowis.com Git - projs/libcds.git/commitdiff
Convert to standard types (C99)
authorMike D. Lowis <mike@mdlowis.com>
Mon, 8 Apr 2013 20:34:58 +0000 (16:34 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Mon, 8 Apr 2013 20:34:58 +0000 (16:34 -0400)
source/buffer/buf.c
source/buffer/buf.h
source/list/sll.c
source/list/sll.h

index bf44e00e3b564f23e5becd37602b9f19f87d68f0..76b64ec5d0c0d02d469d94101041c2b00e1939a3 100644 (file)
@@ -21,7 +21,7 @@ buf_t* buf_new(size_t size)
     return buf;
 }
 
-void buf_free(buf_t* buf, int free_contents)
+void buf_free(buf_t* buf, bool free_contents)
 {
     buf_clear(buf,free_contents);
     free( buf->buffer );
@@ -33,19 +33,19 @@ size_t buf_size(buf_t* buf)
     return (size_t)buf->size;
 }
 
-int buf_empty(buf_t* buf)
+bool buf_empty(buf_t* buf)
 {
     return (buf->reads == buf->writes);
 }
 
-int buf_full(buf_t* buf)
+bool buf_full(buf_t* buf)
 {
     int full = !buf_empty(buf);
     full &= ((buf->reads % buf->size) == (buf->writes % buf->size));
     return full;
 }
 
-void buf_clear(buf_t* buf, int free_contents)
+void buf_clear(buf_t* buf, bool free_contents)
 {
     if (free_contents)
     {
@@ -69,14 +69,14 @@ void* buf_read(buf_t* buf)
     return data;
 }
 
-int buf_write(buf_t* buf, void* data)
+bool buf_write(buf_t* buf, void* data)
 {
-    int success = 0;
+    bool success = false;
     if (!buf_full(buf))
     {
         buf->buffer[ buf->writes % buf->size ] = data;
         buf->writes++;
-        success = 1;
+        success = true;
     }
     return success;
 }
index 165795d4c508e51e393a48f27ec42c33cbbb3343..773d34b9f1bfe77da788aac58071bb922868fa24 100644 (file)
@@ -11,6 +11,8 @@
 extern "C" {
 #endif
 
+#include <stdbool.h>
+
 /** A structure defining a circular buffer */
 typedef struct {
     void** buffer; /**< Pointer to the buffer */
@@ -34,7 +36,7 @@ buf_t* buf_new(size_t size);
  * @param buf           The buffer to free.
  * @param free_contents Whether unread contents should also be freed.
  */
-void buf_free(buf_t* buf, int free_contents);
+void buf_free(buf_t* buf, bool free_contents);
 
 /**
  * @brief Returns the size of the provided buffer.
@@ -52,7 +54,7 @@ size_t buf_size(buf_t* buf);
  *
  * @return 1 if the buffer is empty 0 otherwise.
  */
-int buf_empty(buf_t* buf);
+bool buf_empty(buf_t* buf);
 
 /**
  * @brief Returns whether the buffer is full.
@@ -61,7 +63,7 @@ int buf_empty(buf_t* buf);
  *
  * @return 1 if the buffer is full 0 otherwise.
  */
-int buf_full(buf_t* buf);
+bool buf_full(buf_t* buf);
 
 /**
  * @brief Clears all unread data from the provided buffer.
@@ -69,7 +71,7 @@ int buf_full(buf_t* buf);
  * @param buf           The buffer to clear.
  * @param free_contents Whether the unread contents should also be freed.
  */
-void buf_clear(buf_t* buf, int free_contents);
+void buf_clear(buf_t* buf, bool free_contents);
 
 /**
  * @brief Reads an item from the provided buffer.
@@ -88,7 +90,7 @@ void* buf_read(buf_t* buf);
  *
  * @return 1 on successful write 0 otherwise.
  */
-int buf_write(buf_t* buf, void* data);
+bool buf_write(buf_t* buf, void* data);
 
 #ifdef __cplusplus
 }
index 550fee23a4888a97971bcdd785fce57d4c50d882..66ddf4ca975a5fdc0e2a4bdeeb2de5bff9fdfadb 100644 (file)
@@ -17,7 +17,7 @@ sll_node_t* sll_new_node(void* contents)
     return node;
 }
 
-void sll_free(sll_t* list, int free_contents)
+void sll_free(sll_t* list, bool free_contents)
 {
     sll_node_t* node = list->head;
     while( NULL != node )
@@ -29,7 +29,7 @@ void sll_free(sll_t* list, int free_contents)
     free( list );
 }
 
-void sll_free_node(sll_node_t* node, int free_contents)
+void sll_free_node(sll_node_t* node, bool free_contents)
 {
     if( free_contents )
     {
@@ -48,9 +48,9 @@ sll_node_t* sll_back( sll_t* list )
     return list->tail;
 }
 
-unsigned int sll_size(sll_t* list)
+size_t sll_size(sll_t* list)
 {
-    unsigned int length = 0;
+    size_t length = 0;
     sll_node_t* node = list->head;
     while( NULL != node )
     {
@@ -60,16 +60,16 @@ unsigned int sll_size(sll_t* list)
     return length;
 }
 
-int sll_empty(sll_t* list)
+bool sll_empty(sll_t* list)
 {
     return ((NULL == list->head) && (NULL == list->tail));
 }
 
 
-sll_node_t* sll_at(sll_t* list, unsigned int index)
+sll_node_t* sll_at(sll_t* list, size_t index)
 {
     sll_node_t* node = NULL;
-    unsigned int cur_index = 0;
+    size_t cur_index = 0;
     sll_node_t* cur_node = list->head;
     while( NULL != cur_node )
     {
@@ -151,7 +151,7 @@ sll_node_t* sll_pop_back( sll_t* list )
     return node;
 }
 
-sll_node_t* sll_insert( sll_t* list, unsigned int index, void* contents)
+sll_node_t* sll_insert( sll_t* list, size_t index, void* contents)
 {
     sll_node_t* new_node = NULL;
     if( 0 == index )
@@ -176,7 +176,7 @@ sll_node_t* sll_insert( sll_t* list, unsigned int index, void* contents)
     return new_node;
 }
 
-sll_node_t* sll_delete( sll_t* list, unsigned int index, int free_contents)
+sll_node_t* sll_delete( sll_t* list, size_t index, bool free_contents)
 {
     sll_node_t* node = NULL;
 
@@ -208,7 +208,7 @@ sll_node_t* sll_delete( sll_t* list, unsigned int index, int free_contents)
     return node;
 }
 
-sll_t* sll_clear(sll_t* list, int free_contents)
+sll_t* sll_clear(sll_t* list, bool free_contents)
 {
     sll_node_t* node = list->head;
     while(NULL != node)
index 9e0e3fb6337b4693a6dca08e6ae998134eb76eeb..b49443c8425fe7f5778f78d8cf67c99b1e358e34 100644 (file)
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <stdbool.h>
+
 /** A linked list node. */
 typedef struct sll_node_t
 {
@@ -48,7 +50,7 @@ sll_node_t* sll_new_node(void* contents);
  * @param list          The list to be freed.
  * @param free_contents Whether or not to also free the contents of each node.
  **/
-void sll_free(sll_t* list, int free_contents);
+void sll_free(sll_t* list, bool free_contents);
 
 /**
  * @brief Frees all memory used by a node.
@@ -59,7 +61,7 @@ void sll_free(sll_t* list, int free_contents);
  * @param node
  * @param free_contents
  */
-void sll_free_node(sll_node_t* node, int free_contents);
+void sll_free_node(sll_node_t* node, bool free_contents);
 
 /**
  * @brief Returns pointer to first node in the list
@@ -89,7 +91,7 @@ sll_node_t* sll_back( sll_t* list );
  *
  * @return The number of elements in the list.
  **/
-unsigned int sll_size(sll_t* list);
+size_t sll_size(sll_t* list);
 
 /**
  * @brief Returns whether the list is empty or not.
@@ -98,7 +100,7 @@ unsigned int sll_size(sll_t* list);
  *
  * @return Whether the list is empty, 1 for true and 0 for false.
  */
-int sll_empty(sll_t* list);
+bool sll_empty(sll_t* list);
 
 /**
  * @brief   Return the node at the specified index in a linked list.
@@ -111,7 +113,7 @@ int sll_empty(sll_t* list);
  *
  * @return A pointer to the node at the supplied index, NULL if out of range.
  **/
-sll_node_t* sll_at(sll_t* list, unsigned int index);
+sll_node_t* sll_at(sll_t* list, size_t index);
 
 /**
  * @brief Adds a new node to the front of an existing linked list.
@@ -176,7 +178,7 @@ sll_node_t* sll_pop_back( sll_t* list );
  *
  * @return Pointer to the newly inserted node, NULL if index is out of range.
  **/
-sll_node_t* sll_insert( sll_t* list, unsigned int index, void* contents);
+sll_node_t* sll_insert( sll_t* list, size_t index, void* contents);
 
 /**
  * @brief Deletes a node from the supplied list.
@@ -192,7 +194,7 @@ sll_node_t* sll_insert( sll_t* list, unsigned int index, void* contents);
  *
  * @return Pointer to the node that is now at the supplied index.
  **/
-sll_node_t* sll_delete( sll_t* list, unsigned int index, int free_contents);
+sll_node_t* sll_delete( sll_t* list, size_t index, bool free_contents);
 
 /**
  * @brief Deletes all elements in the provided list
@@ -202,7 +204,7 @@ sll_node_t* sll_delete( sll_t* list, unsigned int index, int free_contents);
  *
  * @return A pointer to the cleared list.
  */
-sll_t* sll_clear(sll_t* list, int free_contents);
+sll_t* sll_clear(sll_t* list, bool free_contents);
 
 #ifdef __cplusplus
 }