reldb 0.1.0
Recreational SQLite
Loading...
Searching...
No Matches
inputbuffer.h File Reference

Defines the InputBuffer structure and related I/O functions. More...

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for inputbuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  InputBuffer
 A structure to hold dynamically allocated string input data. More...

Typedefs

typedef ptrdiff_t ssize_t
 Signed size type, typically used to represent lengths or -1 for errors.

Functions

InputBuffernew_input_buffer (void)
 Allocates and initializes a new InputBuffer.
ssize_t getline (char **lineptr, size_t *n, FILE *stream)
 Reads an entire line from a stream into a dynamically resizing buffer.
void read_input (InputBuffer *input_buffer)
 Reads a line of input from standard input into the buffer.
void close_input_buffer (InputBuffer *input_buffer)
 Frees the memory associated with an InputBuffer.

Detailed Description

Defines the InputBuffer structure and related I/O functions.

Provides a dynamic buffer structure and helper functions to safely read arbitrary-length input from a file stream or standard input.

Definition in file inputbuffer.h.

Typedef Documentation

◆ ssize_t

typedef ptrdiff_t ssize_t

Signed size type, typically used to represent lengths or -1 for errors.

Definition at line 18 of file inputbuffer.h.

Function Documentation

◆ close_input_buffer()

void close_input_buffer ( InputBuffer * input_buffer)

Frees the memory associated with an InputBuffer.

Parameters
[in]input_bufferThe buffer to free. Must not be NULL.

Definition at line 72 of file inputbuffer.c.

Here is the caller graph for this function:

◆ getline()

ssize_t getline ( char ** lineptr,
size_t * n,
FILE * stream )

Reads an entire line from a stream into a dynamically resizing buffer.

Parameters
[in,out]lineptrPointer to the character buffer pointer.
[in,out]nPointer to the size of the allocated buffer.
[in]streamThe file stream to read from (e.g., stdin).
Returns
The number of characters read, or -1 on EOF or error.

Definition at line 24 of file inputbuffer.c.

Here is the caller graph for this function:

◆ new_input_buffer()

InputBuffer * new_input_buffer ( void )

Allocates and initializes a new InputBuffer.

Creates a fresh InputBuffer struct on the heap, setting its pointers to NULL and lengths to 0.

Returns
A pointer to the newly allocated InputBuffer.

Definition at line 9 of file inputbuffer.c.

◆ read_input()

void read_input ( InputBuffer * input_buffer)

Reads a line of input from standard input into the buffer.

Wraps getline to safely read from stdin. It also strips the trailing newline character and updates the input_length property. Exits the program automatically if reading fails.

Parameters
[in,out]input_bufferThe buffer to read data into.

Definition at line 56 of file inputbuffer.c.

Here is the call graph for this function: