Byte buffer.  
More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <assert.h>
#include "buffer.h"
Go to the source code of this file.
◆ _GNU_SOURCE
◆ buffer_clear()
      
        
          | void buffer_clear | ( | Buffer * | buf | ) |  | 
      
 
- Parameters
- 
  
  
Clears a buffer. The buffer becomes valid again. 
Definition at line 96 of file buffer.c.
 
 
◆ buffer_destroy()
      
        
          | void buffer_destroy | ( | Buffer * | buf | ) |  | 
      
 
- Parameters
- 
  
  
Frees a buffer and the buf pointer. 
Definition at line 87 of file buffer.c.
 
 
◆ buffer_fill()
      
        
          | bool buffer_fill | ( | Buffer * | buf, | 
        
          |  |  | const char * | data, | 
        
          |  |  | size_t | len | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | buf | a Buffer |  | data | data to write to the buffer |  | len | number of bytes to write |  
 
- Returns
- true on success
Writes bytes to a buffer. 
Definition at line 153 of file buffer.c.
 
 
◆ buffer_fill_from_fd()
      
        
          | ssize_t buffer_fill_from_fd | ( | Buffer * | buf, | 
        
          |  |  | int | fd, | 
        
          |  |  | size_t | count | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | buf | a Buffer |  | fd | a file descriptor |  | count | bytes to read from the file descriptor |  
 
- Returns
- number of bytes read from the file descriptor and written to the buffer, -1 on failure
Reads bytes from a file and writes the data to the buffer. 
Definition at line 189 of file buffer.c.
 
 
◆ buffer_flush()
      
        
          | bool buffer_flush | ( | const Buffer * | buf, | 
        
          |  |  | char ** | dst, | 
        
          |  |  | size_t * | len | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | buf | a Buffer |  | dst | location to store buffer data |  | len | buffer length |  
 
- Returns
- true on success
Copies data from the buffer to a string (if buffer is valid). dst will be resized automatically if necessary. 
Definition at line 267 of file buffer.c.
 
 
◆ buffer_free()
      
        
          | void buffer_free | ( | Buffer * | buf | ) |  | 
      
 
- Parameters
- 
  
  
Frees a buffer without freeing the buf pointer. 
Definition at line 79 of file buffer.c.
 
 
◆ buffer_init()
      
        
          | void buffer_init | ( | Buffer * | buf, | 
        
          |  |  | size_t | max_size | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | buf | a Buffer |  | max_size | maximum buffer length |  
 
Initializes a buffer. 
Definition at line 59 of file buffer.c.
 
 
◆ buffer_is_empty()
      
        
          | bool buffer_is_empty | ( | const Buffer * | buf | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- true if the buffer is empty
Checks if a buffer is empty. 
Definition at line 123 of file buffer.c.
 
 
◆ buffer_is_valid()
      
        
          | bool buffer_is_valid | ( | const Buffer * | buf | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- true if the buffer is valid
Checks if a buffer is valid. 
Definition at line 115 of file buffer.c.
 
 
◆ buffer_len()
      
        
          | size_t buffer_len | ( | const Buffer * | buf | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- length of the buffer
Gets the length of the buffer. 
Definition at line 105 of file buffer.c.
 
 
◆ buffer_new()
      
        
          | Buffer * buffer_new | ( | size_t | max_size | ) |  | 
      
 
- Parameters
- 
  
    | max_size | maximum buffer length |  
 
- Returns
- a new Buffer
Creates a new buffer. 
Definition at line 41 of file buffer.c.
 
 
◆ buffer_read_line()
      
        
          | bool buffer_read_line | ( | Buffer * | buf, | 
        
          |  |  | char ** | dst, | 
        
          |  |  | size_t * | len | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | buf | a Buffer |  | dst | location to store read string |  | len | length of dst |  
 
- Returns
- true if a line could be read from the buffer
Tries to read a line from the buffer. dst will be resized automatically if necessary. 
Definition at line 240 of file buffer.c.
 
 
◆ buffer_to_string()
      
        
          | char * buffer_to_string | ( | const Buffer * | buf | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- a newly-allocated string
Converts the data from the buffer to a new string. Returns NULL if buffer is invalid. 
Definition at line 287 of file buffer.c.