# aomenx/get_next_line architecture

> Architecture diagram of the GitHub repository aomenx/get_next_line, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aomenx/get_next_line
- Repository: https://github.com/aomenx/get_next_line

## Overview

Get Next Line is a small C library that returns one allocated line per call from a file descriptor, retaining unread bytes across calls. The mandatory entry point holds one buffer; the bonus entry point keeps independent buffers in a linked list so calls can be interleaved across descriptors. Both fill by reading and searching for newline, then extract a line; shared buffer utilities reserve/compact/grow storage. The README documents these behaviors; the relationships shown below are supported by the excerpts and README.

Main entry points: [`get_next_line.c`](https://github.com/aomenx/get_next_line/blob/master/get_next_line.c) (Single-fd reader), [`get_next_line_bonus.c`](https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.c) (Multi-fd reader), [`get_next_line_utils.c`](https://github.com/aomenx/get_next_line/blob/master/get_next_line_utils.c) (Buffer operations), [`get_next_line_utils_bonus.c`](https://github.com/aomenx/get_next_line/blob/master/get_next_line_utils_bonus.c) (Buffer operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Line readers"]
  node_mandatory["Single-fd reader<br/>[get_next_line.c]"]
  node_mandatory_header["Mandatory types<br/>[get_next_line.h]"]
  node_bonus["Multi-fd reader"]
  node_bonus_header["Bonus types"]
end

subgraph group_buffer["Buffer handling"]
  node_mandatory_fill["Read and extract<br/>[get_next_line.c]"]
  node_mandatory_utils["Buffer operations"]
  node_bonus_fill["Read and extract"]
  node_bonus_utils["Buffer operations"]
end

subgraph group_state["Descriptor state"]
  node_single_state[("Static buffer<br/>[get_next_line.c]")]
  node_fd_states[("Per-fd linked states")]
end

node_caller(("Library caller"))
node_fd(("File descriptor"))

node_caller -->|"calls"| node_mandatory
node_caller -->|"calls"| node_bonus
node_mandatory -->|"invokes"| node_mandatory_fill
node_mandatory -->|"uses"| node_single_state
node_mandatory_fill -->|"calls"| node_mandatory_utils
node_mandatory -->|"reads from"| node_fd
node_bonus -->|"invokes"| node_bonus_fill
node_bonus -->|"manages"| node_fd_states
node_bonus_fill -->|"calls"| node_bonus_utils
node_bonus -->|"reads from"| node_fd
node_mandatory -->|"returns allocated line"| node_caller
node_bonus -->|"returns allocated line"| node_caller

click node_mandatory "https://github.com/aomenx/get_next_line/blob/master/get_next_line.c"
click node_mandatory_header "https://github.com/aomenx/get_next_line/blob/master/get_next_line.h"
click node_bonus "https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.c"
click node_bonus_header "https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.h"
click node_mandatory_fill "https://github.com/aomenx/get_next_line/blob/master/get_next_line.c"
click node_mandatory_utils "https://github.com/aomenx/get_next_line/blob/master/get_next_line_utils.c"
click node_bonus_fill "https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.c"
click node_bonus_utils "https://github.com/aomenx/get_next_line/blob/master/get_next_line_utils_bonus.c"
click node_single_state "https://github.com/aomenx/get_next_line/blob/master/get_next_line.c"
click node_fd_states "https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mandatory,node_mandatory_header,node_bonus,node_bonus_header toneBlue
class node_mandatory_fill,node_mandatory_utils,node_bonus_fill,node_bonus_utils toneAmber
class node_single_state,node_fd_states toneMint
class node_caller,node_fd toneIndigo
```

## Components

### Line readers

- [Single-fd reader](https://github.com/aomenx/get_next_line/blob/master/get_next_line.c): `get_next_line.c`
- [Mandatory types](https://github.com/aomenx/get_next_line/blob/master/get_next_line.h): `get_next_line.h`
- [Multi-fd reader](https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.c): `get_next_line_bonus.c`
- [Bonus types](https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.h): `get_next_line_bonus.h`

### Buffer handling

- [Read and extract](https://github.com/aomenx/get_next_line/blob/master/get_next_line.c): `get_next_line.c`
- [Buffer operations](https://github.com/aomenx/get_next_line/blob/master/get_next_line_utils.c): `get_next_line_utils.c`
- [Read and extract](https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.c): `get_next_line_bonus.c`
- [Buffer operations](https://github.com/aomenx/get_next_line/blob/master/get_next_line_utils_bonus.c): `get_next_line_utils_bonus.c`

### Descriptor state

- [Static buffer](https://github.com/aomenx/get_next_line/blob/master/get_next_line.c): `get_next_line.c`
- [Per-fd linked states](https://github.com/aomenx/get_next_line/blob/master/get_next_line_bonus.c): `get_next_line_bonus.c`

### Other components

- **Library caller**
- **File descriptor**

## Connections

- Library caller → Single-fd reader: calls (evidence: `README.md`)
- Library caller → Multi-fd reader: calls (evidence: `README.md`)
- Single-fd reader → Read and extract: invokes (evidence: `get_next_line.c`)
- Single-fd reader → Static buffer: uses (evidence: `get_next_line.c`)
- Read and extract → Buffer operations: calls (evidence: `get_next_line.c`)
- Single-fd reader → File descriptor: reads from (evidence: `README.md`)
- Multi-fd reader → Read and extract: invokes (evidence: `get_next_line_bonus.c`)
- Multi-fd reader → Per-fd linked states: manages (evidence: `get_next_line_bonus.c`)
- Read and extract → Buffer operations: calls (evidence: `get_next_line_bonus.c`)
- Multi-fd reader → File descriptor: reads from (evidence: `README.md`)
- Single-fd reader → Library caller: returns allocated line (evidence: `README.md`)
- Multi-fd reader → Library caller: returns allocated line (evidence: `README.md`)
