Release soft dependencies if they stop early.
[oweals/dinit.git] / src / cpbuffer.h
index 978720430b47a0b51d8a8e11eb75b35c139fba04..1478b740a9ac2512c971f85e61b0e962ab45279e 100644 (file)
@@ -26,7 +26,12 @@ template <int SIZE> class CPBuffer
         int pos = cur_idx + index;
         if (pos >= SIZE) pos -= SIZE;
     
-        return &buf[cur_idx];
+        return &buf[pos];
+    }
+    
+    char * get_buf_base()
+    {
+        return buf;
     }
     
     int get_contiguous_length(char *ptr)
@@ -66,6 +71,12 @@ template <int SIZE> class CPBuffer
         return 1;
     }
     
+    // Trim the buffer to the specified length (must be less than current length)
+    void trim_to(int new_length)
+    {
+        length = new_length;
+    }
+    
     char operator[](int idx) noexcept
     {
         int dest_idx = cur_idx + idx;